in SdmxStructureParser/src/main/java/org/sdmxsource/sdmx/structureparser/builder/sdmxbeans/impl/SdmxObjectsJsonV1Builder.java [177:318]
private void processDatastructures(JsonNode dataStructures, SdmxBeansImpl beans) throws JsonProcessingException {
if (dataStructures == null || beans == null)
return;
for (JsonNode dataStructure : dataStructures) {
DataStructureDTO dataStructureDto = objectMapper.treeToValue(dataStructure, DataStructureDTO.class);
DataStructureMutableBean structureMutableObject = new DataStructureMutableBeanImpl();
for (Map.Entry<String, String> name : dataStructureDto.names.entrySet())
structureMutableObject.addName(name.getKey(), name.getValue());
if (dataStructureDto.description != null) {
for (Map.Entry<String, String> description : dataStructureDto.descriptions.entrySet())
structureMutableObject.addDescription(description.getKey(), description.getValue());
}
structureMutableObject.setId(dataStructureDto.id);
structureMutableObject.setAgencyId(dataStructureDto.agencyID);
structureMutableObject.setVersion(dataStructureDto.version);
if (dataStructureDto.validFrom != null)
structureMutableObject.setStartDate(Date.from(dataStructureDto.validFrom));
if (dataStructureDto.validTo != null)
structureMutableObject.setEndDate(Date.from(dataStructureDto.validTo));
structureMutableObject.setFinalStructure(TERTIARY_BOOL.parseBoolean(dataStructureDto.isFinal));
SdmxObjectsJsonV1Builder.addAnnotations(dataStructureDto.annotations, structureMutableObject);
if (dataStructureDto.dataStructureComponents != null) {
if (dataStructureDto.dataStructureComponents.attributeList != null &&
dataStructureDto.dataStructureComponents.attributeList.attributes != null) {
for (DataStructureDTO.Attribute attributeDto : dataStructureDto.dataStructureComponents.attributeList.attributes) {
AttributeMutableBean attribute = new AttributeMutableBeanImpl();
attribute.setId(attributeDto.id);
attribute.setAssignmentStatus(attributeDto.assignmentStatus);
attribute.setConceptRef(this.setConceptRef(attributeDto.conceptIdentity));
if (attributeDto.conceptRoles != null) {
for (String conceptRole : attributeDto.conceptRoles)
attribute.addConceptRole(this.setConceptRole(conceptRole));
}
attribute.setRepresentation(this.setRepresentation(attributeDto.localRepresentation, true));
if (attributeDto.attributeRelationship != null) {
if (attributeDto.attributeRelationship.primaryMeasure != null &&
attributeDto.attributeRelationship.primaryMeasure.length() != 0) {
attribute.setPrimaryMeasureReference(attributeDto.attributeRelationship.primaryMeasure);
attribute.setAttachmentLevel(ATTRIBUTE_ATTACHMENT_LEVEL.OBSERVATION);
} else if (attributeDto.attributeRelationship.attachmentGroups != null &&
attributeDto.attributeRelationship.attachmentGroups.length != 0) {
attribute.setAttachmentGroup(attributeDto.attributeRelationship.attachmentGroups[0]);
attribute.setAttachmentLevel(ATTRIBUTE_ATTACHMENT_LEVEL.GROUP);
} else if (attributeDto.attributeRelationship.dimensions != null) {
attribute.setAttachmentLevel(ATTRIBUTE_ATTACHMENT_LEVEL.DIMENSION_GROUP);
for (String dimension : attributeDto.attributeRelationship.dimensions)
attribute.getDimensionReferences().add(dimension);
} else
attribute.setAttachmentLevel(ATTRIBUTE_ATTACHMENT_LEVEL.DATA_SET);
}
SdmxObjectsJsonV1Builder.addAnnotations(attributeDto.annotations, attribute);
structureMutableObject.addAttribute(attribute);
}
}
if (dataStructureDto.dataStructureComponents.dimensionList != null) {
Map<Integer, DimensionMutableBean> dictionary = new HashMap<>(); // TODO: @MS map with boxed Integer keys - super bad!
if (dataStructureDto.dataStructureComponents.dimensionList.dimensions != null) {
for (DataStructureDTO.Dimension dimension : dataStructureDto.dataStructureComponents.dimensionList.dimensions) {
DimensionMutableBean dimensionMutableObject = new DimensionMutableBeanImpl();
dimensionMutableObject.setId(dimension.id);
if (dimension.conceptRoles != null) {
for (String conceptRole : dimension.conceptRoles)
dimensionMutableObject.getConceptRole().add(this.setConceptRole(conceptRole));
}
dimensionMutableObject.setConceptRef(this.setConceptRef(dimension.conceptIdentity));
dimensionMutableObject.setRepresentation(this.setRepresentation(dimension.localRepresentation, true));
if (dimensionMutableObject.getId().equalsIgnoreCase("FREQ"))
dimensionMutableObject.setFrequencyDimension(true);
SdmxObjectsJsonV1Builder.addAnnotations(dimension.annotations, dimensionMutableObject);
int position = dimension.position;
while (dictionary.containsKey(position))
++position;
dictionary.put(position, dimensionMutableObject);
}
}
if (dataStructureDto.dataStructureComponents.dimensionList.measureDimensions != null) {
for (DataStructureDTO.Measuredimension measureDimension : dataStructureDto.dataStructureComponents.dimensionList.measureDimensions) {
DimensionMutableBean dimensionMutableObject = new DimensionMutableBeanImpl();
dimensionMutableObject.setId(measureDimension.id);
if (measureDimension.conceptRoles != null) {
for (String conceptRole : measureDimension.conceptRoles)
dimensionMutableObject.getConceptRole().add(this.setConceptRole(conceptRole));
}
dimensionMutableObject.setMeasureDimension(true);
dimensionMutableObject.setConceptRef(this.setConceptRef(measureDimension.conceptIdentity));
dimensionMutableObject.setRepresentation(this.setRepresentation(measureDimension.localRepresentation, false));
SdmxObjectsJsonV1Builder.addAnnotations(measureDimension.annotations, dimensionMutableObject);
int position = measureDimension.position;
while (dictionary.containsKey(position))
++position;
dictionary.put(position, dimensionMutableObject);
}
}
if (dataStructureDto.dataStructureComponents.dimensionList.timeDimensions != null) {
for (DataStructureDTO.Timedimension timeDimension : dataStructureDto.dataStructureComponents.dimensionList.timeDimensions) {
DimensionMutableBean dimensionMutableObject = new DimensionMutableBeanImpl();
dimensionMutableObject.setId(timeDimension.id);
if (timeDimension.conceptRoles != null) {
for (String conceptRole : timeDimension.conceptRoles)
dimensionMutableObject.getConceptRole().add(this.setConceptRole(conceptRole));
}
dimensionMutableObject.setTimeDimension(true);
dimensionMutableObject.setConceptRef(this.setConceptRef(timeDimension.conceptIdentity));
dimensionMutableObject.setRepresentation(this.setRepresentation(timeDimension.localRepresentation, true));
SdmxObjectsJsonV1Builder.addAnnotations(timeDimension.annotations, dimensionMutableObject);
int position = timeDimension.position;
while (dictionary.containsKey(position))
++position;
dictionary.put(position, dimensionMutableObject);
}
}
List<Integer> list = dictionary.keySet().stream().sorted().collect(Collectors.toList());
for (Integer key : list)
structureMutableObject.addDimension(dictionary.get(key));
}
if (dataStructureDto.dataStructureComponents.measureList != null && dataStructureDto.dataStructureComponents.measureList.primaryMeasure != null) {
PrimaryMeasureMutableBean primaryMeasure = new PrimaryMeasureMutableBeanImpl();
primaryMeasure.setConceptRef(this.setConceptRef(dataStructureDto.dataStructureComponents.measureList.primaryMeasure.conceptIdentity));
primaryMeasure.setRepresentation(this.setRepresentation(dataStructureDto.dataStructureComponents.measureList.primaryMeasure.localRepresentation, true));
structureMutableObject.setPrimaryMeasure(primaryMeasure);
SdmxObjectsJsonV1Builder.addAnnotations(dataStructureDto.dataStructureComponents.measureList.primaryMeasure.annotations, structureMutableObject.getMeasureList().getPrimaryMeasure());
}
if (dataStructureDto.dataStructureComponents.groups != null) {
for (DataStructureDTO.Group groupDto : dataStructureDto.dataStructureComponents.groups) {
GroupMutableBean group = new GroupMutableBeanImpl();
group.setId(groupDto.id);
for (String groupDimension : groupDto.groupDimensions)
group.getDimensionRef().add(groupDimension);
structureMutableObject.addGroup(group);
}
}
}
beans.addDataStructure(structureMutableObject.getImmutableInstance());
}
}