use of org.eclipse.winery.repository.rest.resources.apiData.UpdateInfo in project winery by eclipse.
the class TopologyTemplateResource method computeDi.
@POST
@Path("kvcomparison")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public PropertyDiffList computeDi(UpdateInfo updateInfo) {
List<String> resolvedProperties = new ArrayList<>();
List<String> removedProperties = new ArrayList<>();
List<String> newProperties = new ArrayList<>();
Optional<TEntityTemplate> foundTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream().filter(template -> template.getId().equals(updateInfo.getNodeTemplateId())).filter(template -> template.getProperties() != null).findFirst();
if (foundTemplate.isPresent() && Objects.nonNull(foundTemplate.get().getProperties()) && Objects.nonNull(ModelUtilities.getPropertiesKV(foundTemplate.get()))) {
HashMap<String, String> oldKvs = ModelUtilities.getPropertiesKV(foundTemplate.get());
QName qNameType = QName.valueOf(updateInfo.getNewComponentType());
IRepository repository = RepositoryFactory.getRepository();
TEntityType newNodeTypeVersion = repository.getElement(new NodeTypeId(qNameType));
if (Objects.nonNull(newNodeTypeVersion) && Objects.nonNull(newNodeTypeVersion.getWinerysPropertiesDefinition())) {
List<PropertyDefinitionKV> newKvs = newNodeTypeVersion.getWinerysPropertiesDefinition().getPropertyDefinitions();
resolvedProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
removedProperties = oldKvs.keySet().stream().filter(keys -> !newKvs.stream().map(newProp -> newProp.getKey().toLowerCase()).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
newProperties = newKvs.stream().map(PropertyDefinitionKV::getKey).filter(keys -> !oldKvs.keySet().stream().map(String::toLowerCase).collect(Collectors.toList()).contains(keys.toLowerCase())).collect(Collectors.toList());
}
}
return new PropertyDiffList(resolvedProperties, removedProperties, newProperties);
}
Aggregations