-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added structure for GEIA service + data access.
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
Showing
15 changed files
with
141 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/lmco/spectrum/systemnavigation3d/geia/GeiaDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
100 changes: 100 additions & 0 deletions
100
src/main/java/com/lmco/spectrum/systemnavigation3d/geia/XMLGeiaDataSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
24 changes: 7 additions & 17 deletions
24
src/main/java/com/lmco/spectrum/systemnavigation3d/service/GeiaService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters