diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AA.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AA.groovy index 25a5402..177df9b 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AA.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AA.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class AA { +class AA implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AB.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AB.groovy index 931e89d..9c3c436 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AB.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AB.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class AB { +class AB implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AG.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AG.groovy index bfa7c24..759757f 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AG.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/AG.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class AG { +class AG implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CA.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CA.groovy index 4908fb5..6ddf92c 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CA.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CA.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class CA { +class CA implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CI.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CI.groovy index eb06c8e..7d02eed 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CI.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/CI.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class CI { +class CI implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GA.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GA.groovy index 5721eca..f41d7f8 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GA.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GA.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class GA { +class GA implements GeiaEntity { @XmlElement(name = "skill_specialty_code") String skillSpecialityCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XMLModel.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GeiaStdModel.groovy similarity index 98% rename from src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XMLModel.groovy rename to src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GeiaStdModel.groovy index 1bafd22..89c0144 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XMLModel.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/GeiaStdModel.groovy @@ -15,7 +15,7 @@ import javax.xml.bind.annotation.XmlRootElement @EqualsAndHashCode @XmlAccessorType(XmlAccessType.FIELD) @XmlRootElement(name = "GEIA-STD-0007") -class XMLModel { +class GeiaStdModel { @XmlElementWrapper(name = "full_file") @XmlElements([ diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/HA.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/HA.groovy index 486a046..b0e8377 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/HA.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/HA.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class HA { +class HA implements GeiaEntity { @XmlElement(name = "commercial_and_government_entity_code") String cageCode diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XA.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XA.groovy index f02be30..d37984f 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XA.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XA.groovy @@ -15,4 +15,6 @@ class XA implements GeiaEntity { @XmlElement(name = "logistics_support_analysis_control_number_structure") String lcnStructure + transient List xbChildren = new ArrayList<>() + } diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XB.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XB.groovy index 68a9d61..0942404 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XB.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XB.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class XB { +class XB implements GeiaEntity { @XmlElement(name = "end_item_acronym_code") String endItemAcronymCode @@ -30,4 +30,8 @@ class XB { @XmlElement(name = "system_end_item_identifier") String systemEndItemIdentifier + transient List xbChildren = new ArrayList<>() + + transient List caChildren = new ArrayList<>() + } diff --git a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XH.groovy b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XH.groovy index a5841e6..386595c 100644 --- a/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XH.groovy +++ b/src/main/groovy/com/lmco/spectrum/systemnavigation3d/domain/dto/XH.groovy @@ -7,7 +7,7 @@ import javax.xml.bind.annotation.XmlElement @ToString @EqualsAndHashCode -class XH { +class XH implements GeiaEntity { @XmlElement(name = "commercial_and_government_entity_code") String cageCode diff --git a/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/GeiaDataSource.java b/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/GeiaDataSource.java new file mode 100644 index 0000000..03a89c5 --- /dev/null +++ b/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/GeiaDataSource.java @@ -0,0 +1,16 @@ +package com.lmco.spectrum.systemnavigation3d.geia; + +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 java.util.List; + +public interface GeiaDataSource { + + List getXAs(); + XA getXA(String endItemAcronymCode); + XB getXB(XA src, String lcn); + CA getCA(XB src, String taskCode); + +} diff --git a/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/XMLGeiaDataSource.java b/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/XMLGeiaDataSource.java new file mode 100644 index 0000000..1fffefa --- /dev/null +++ b/src/main/java/com/lmco/spectrum/systemnavigation3d/geia/XMLGeiaDataSource.java @@ -0,0 +1,100 @@ +package com.lmco.spectrum.systemnavigation3d.geia; + +import com.lmco.spectrum.systemnavigation3d.domain.dto.*; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class XMLGeiaDataSource implements GeiaDataSource { + + private GeiaStdModel stdModel; + private Map, List> geiaEntityMap; + + private List xaList; + + public XMLGeiaDataSource(InputStream xmlStream) { + this.xaList = new ArrayList<>(); + this.geiaEntityMap = new HashMap<>(); + + try { + JAXBContext jaxbContext = JAXBContext.newInstance(GeiaStdModel.class); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + + stdModel = (GeiaStdModel) unmarshaller.unmarshal(xmlStream); + this.processGeiaStd(); + } catch (JAXBException e) { + e.printStackTrace(); + } + + } + + private void processGeiaStd() { + + for(GeiaEntity entity : stdModel.getGeiaFullFile()) { + if(!geiaEntityMap.containsKey(entity.getClass())) { + geiaEntityMap.put(entity.getClass(), new ArrayList<>()); + } + geiaEntityMap.get(entity.getClass()).add(entity); + } + + geiaEntityMap.get(XA.class).forEach(xa -> xaList.add((XA) xa)); + + for(XA xa : xaList) { + pairXAWithChildren(xa); + } + + } + + private void pairXAWithChildren(XA src) { + geiaEntityMap.get(XB.class) + .stream() + .map(entity -> (XB)entity) + .filter(xb -> xb.getLcnIndentureCode().charAt(0) == 'A' && src.getEndItemAcronymCode().equals(xb.getEndItemAcronymCode())) + .forEach(xb -> { + pairXBWithChildren(xb); + src.getXbChildren().add(xb); + }); + } + + private void pairXBWithChildren(XB src) { + geiaEntityMap.get(XB.class) + .stream() + .map(entity -> (XB)entity) + .filter(xb -> xb.getLcn().startsWith(src.getLcn()) && xb.getLcnIndentureCode().charAt(0)-1 == src.getLcnIndentureCode().charAt(0)) + .forEach(xb -> { + pairXBWithChildren(xb); + src.getXbChildren().add(xb); + }); + geiaEntityMap.get(CA.class) + .stream() + .map(entity -> (CA)entity) + .filter(ca -> src.getLcn().equals(ca.getLcn())) + .forEach(ca -> src.getCaChildren().add(ca)); // TODO process CA children + } + + @Override + public List getXAs() { + return xaList; + } + + @Override + public XA getXA(String endItemAcronymCode) { + return xaList.stream().filter(xa -> xa.getEndItemAcronymCode().equals(endItemAcronymCode)).findFirst().orElse(null); + } + + @Override + public XB getXB(XA src, String lcn) { + return src.getXbChildren().stream().filter(xb -> xb.getLcn().equals(lcn)).findFirst().orElse(null); + } + + @Override + public CA getCA(XB src, String taskCode) { + return src.getCaChildren().stream().filter(ca -> ca.getTaskCode().equals(taskCode)).findFirst().orElse(null); + } +} diff --git a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/GeiaService.java b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/GeiaService.java index 3b189c8..f477361 100644 --- a/src/main/java/com/lmco/spectrum/systemnavigation3d/service/GeiaService.java +++ b/src/main/java/com/lmco/spectrum/systemnavigation3d/service/GeiaService.java @@ -1,33 +1,23 @@ package com.lmco.spectrum.systemnavigation3d.service; -import com.lmco.spectrum.systemnavigation3d.domain.dto.XMLModel; +import com.lmco.spectrum.systemnavigation3d.geia.GeiaDataSource; +import com.lmco.spectrum.systemnavigation3d.geia.XMLGeiaDataSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; -import java.io.File; - @Service public class GeiaService { @Autowired ResourceService resourceService; - public void test() { - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(XMLModel.class); - Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); - - XMLModel temp = (XMLModel) unmarshaller.unmarshal(new File("D:\\Development\\SDP\\files\\test1 (1).xml")); + private GeiaDataSource geiaDataSource; - - } catch (JAXBException e) { - e.printStackTrace(); + public GeiaDataSource getGeiaDataSource() { + if(this.geiaDataSource == null) { + this.geiaDataSource = new XMLGeiaDataSource(resourceService.getFileAsStream("geia/test1.xml")); } - + return geiaDataSource; } } diff --git a/src/test/java/com/lmco/spectrum/systemnavigation3d/Systemnavigation3dApplicationTests.java b/src/test/java/com/lmco/spectrum/systemnavigation3d/Systemnavigation3dApplicationTests.java index 4d5b2ff..1f08089 100644 --- a/src/test/java/com/lmco/spectrum/systemnavigation3d/Systemnavigation3dApplicationTests.java +++ b/src/test/java/com/lmco/spectrum/systemnavigation3d/Systemnavigation3dApplicationTests.java @@ -1,5 +1,6 @@ package com.lmco.spectrum.systemnavigation3d; +import com.lmco.spectrum.systemnavigation3d.geia.GeiaDataSource; import com.lmco.spectrum.systemnavigation3d.service.GeiaService; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -15,9 +16,7 @@ class Systemnavigation3dApplicationTests { @Test void contextLoads() { - - geiaService.test(); - + GeiaDataSource geiaDataSource = geiaService.getGeiaDataSource(); } }