Skip to content

Added relationships for CA CI XH HA HG #3

Merged
merged 2 commits into from
Mar 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,6 @@ class CA implements GeiaEntity {
@XmlElement(name = "preventive_maintenance_checks_and_services_indicator_code")
String preventiveMaintenanceChecksAndServicesIndicatorCode

transient List<CI> ciChildren = new ArrayList<>()

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ class CI implements GeiaEntity {
@XmlElement(name = "task_provision_logistics_support_analysis_control_number_type")
String taskProvisionLcnType

transient HG hgChild
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ class HA implements GeiaEntity {
@XmlElement(name = "item_name")
String itemName

transient XH xhParent;

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ class HG implements GeiaEntity {
@XmlElement(name = "logistics_support_analysis_control_number_type")
String lcnType

transient HA haParent

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
import com.lmco.spectrum.systemnavigation3d.domain.dto.CA;
import com.lmco.spectrum.systemnavigation3d.domain.dto.XA;
import com.lmco.spectrum.systemnavigation3d.domain.dto.XB;
import com.lmco.spectrum.systemnavigation3d.domain.dto.XH;
import com.lmco.spectrum.systemnavigation3d.domain.dto.CI;
import com.lmco.spectrum.systemnavigation3d.domain.dto.HG;

import java.util.List;

public interface GeiaDataSource {

List<XA> getXAs();
XA getXA(String endItemAcronymCode);
XH getXH(String cageCode);
XB getXB(XA src, String lcn);
CA getCA(XB src, String taskCode);
CI getCI(CA src, String cageCode, String taskProvisionReferenceNumber);

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ public class XMLGeiaDataSource implements GeiaDataSource {
private Map<Class<? extends GeiaEntity>, List<GeiaEntity>> geiaEntityMap;

private List<XA> xaList;
private List<XH> xhList;

public XMLGeiaDataSource(InputStream xmlStream) {
this.xaList = new ArrayList<>();
this.xhList = new ArrayList<>();
this.geiaEntityMap = new HashMap<>();

try {
Expand Down Expand Up @@ -49,17 +51,18 @@ private void processGeiaStd() {
}

xaList.addAll(getEntities(XA.class));
xhList.addAll(getEntities(XH.class));

for(XA xa : xaList) {
pairXAWithChildren(xa);
}

}

private void pairXAWithChildren(XA src) {
getEntities(XB.class)
.stream()
.filter(xb -> xb.getLcnIndentureCode().charAt(0) == 'A' && src.getEndItemAcronymCode().equals(xb.getEndItemAcronymCode()))
.filter(xb -> xb.getLcnIndentureCode().charAt(0) == 'A'
&& src.getEndItemAcronymCode().equals(xb.getEndItemAcronymCode()))
.forEach(xb -> {
pairXBWithChildren(xb);
src.getXbChildren().add(xb);
Expand All @@ -69,15 +72,66 @@ private void pairXAWithChildren(XA src) {
private void pairXBWithChildren(XB src) {
getEntities(XB.class)
.stream()
.filter(xb -> xb.getLcn().startsWith(src.getLcn()) && xb.getLcnIndentureCode().charAt(0)-1 == src.getLcnIndentureCode().charAt(0))
.filter(xb -> xb.getLcn().startsWith(src.getLcn())
&& xb.getLcnIndentureCode().charAt(0)-1 == src.getLcnIndentureCode().charAt(0)
&& xb.getEndItemAcronymCode().equals(src.getEndItemAcronymCode()))
.forEach(xb -> {
pairXBWithChildren(xb);
src.getXbChildren().add(xb);
});
getEntities(CA.class)
.stream()
.filter(ca -> src.getLcn().equals(ca.getLcn()))
.forEach(ca -> src.getCaChildren().add(ca)); // TODO process CA children
.filter(ca -> src.getLcn().equals(ca.getLcn())
&& src.getEndItemAcronymCode().equals(ca.getEndItemAcronymCode()))
.forEach(ca -> {
pairCAWithChildren(ca);
src.getCaChildren().add(ca);
});
}

private void pairCAWithChildren(CA src){
getEntities(CI.class)
.stream()
.filter(ci -> src.getLcn().equals(ci.getLcn())
&& src.getEndItemAcronymCode().equals(ci.getEndItemAcronymCode()))
.forEach(ci -> {
pairCIWithHGChild(ci);
src.getCiChildren().add(ci);
});
}

private void pairCIWithHGChild(CI src){
getEntities(HG.class)
.stream()
.filter(hg -> src.getLcn().equals(hg.getLcn())
&& src.getTaskProvisionCageCode().equals(hg.getCageCode())
&& src.getTaskProvisionReferenceNumber().equals(hg.getReferenceNumber())
&& src.getEndItemAcronymCode().equals(hg.getEndItemAcronymCode()))
.findFirst()
.ifPresent(hg -> {
pairHGWithHAParent(hg);
src.setHgChild(hg);
});
}

private void pairHGWithHAParent(HG src) {
getEntities(HA.class)
.stream()
.filter(ha -> ha.getCageCode().equals(src.getCageCode())
&& ha.getReferenceNumber().equals(src.getReferenceNumber()))
.findFirst()
.ifPresent(ha -> {
pairHAWithXHParent(ha);
src.setHaParent(ha);
});
}

private void pairHAWithXHParent(HA src){
getEntities(XH.class)
.stream()
.filter(xh -> xh.getCageCode().equals(src.getCageCode()))
.findFirst()
.ifPresent(src::setXhParent);
}

@Override
Expand All @@ -90,6 +144,11 @@ public XA getXA(String endItemAcronymCode) {
return xaList.stream().filter(xa -> xa.getEndItemAcronymCode().equals(endItemAcronymCode)).findFirst().orElse(null);
}

@Override
public XH getXH(String cageCode){
return xhList.stream().filter(xh -> xh.getCageCode().equals(cageCode)).findFirst().orElse(null);
}

@Override
public XB getXB(XA src, String lcn) {
return src.getXbChildren().stream().filter(xb -> xb.getLcn().equals(lcn)).findFirst().orElse(null);
Expand All @@ -99,4 +158,13 @@ public XB getXB(XA src, String lcn) {
public CA getCA(XB src, String taskCode) {
return src.getCaChildren().stream().filter(ca -> ca.getTaskCode().equals(taskCode)).findFirst().orElse(null);
}

@Override
public CI getCI(CA src, String cageCode, String taskProvisionReferenceNumber){
return src.getCiChildren()
.stream()
.filter(ci -> ci.getTaskProvisionCageCode().equals(cageCode)
&& ci.getTaskProvisionReferenceNumber().equals(taskProvisionReferenceNumber))
.findFirst().orElse(null);
}
}