Skip to content

Commit

Permalink
Added structure for GEIA service + data access.
Browse files Browse the repository at this point in the history
Added GeiaDataSource Interface
Single implementation for this project, XMLGeiaDataSource.
Added transient child lists to XA and XB classes.
Added functions to fill children for XA and XB entities.

Pending: child relationships for the remaining entities
Pending: More data access functions in GeiaDataSource.
  • Loading branch information
dds14002 committed Mar 24, 2020
1 parent b7c2a0f commit c9f106e
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ class XA implements GeiaEntity {
@XmlElement(name = "logistics_support_analysis_control_number_structure")
String lcnStructure

transient List<XB> xbChildren = new ArrayList<>()

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,4 +30,8 @@ class XB {
@XmlElement(name = "system_end_item_identifier")
String systemEndItemIdentifier

transient List<XB> xbChildren = new ArrayList<>()

transient List<CA> caChildren = new ArrayList<>()

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<XA> getXAs();
XA getXA(String endItemAcronymCode);
XB getXB(XA src, String lcn);
CA getCA(XB src, String taskCode);

}
Original file line number Diff line number Diff line change
@@ -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<Class<? extends GeiaEntity>, List<GeiaEntity>> geiaEntityMap;

private List<XA> 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<XA> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -15,9 +16,7 @@ class Systemnavigation3dApplicationTests {

@Test
void contextLoads() {

geiaService.test();

GeiaDataSource geiaDataSource = geiaService.getGeiaDataSource();
}

}

0 comments on commit c9f106e

Please sign in to comment.