Search in sources :

Example 1 with UpdateInfo

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);
}
Also used : UpdateInfo(org.eclipse.winery.repository.rest.resources.apiData.UpdateInfo) Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ApiParam(io.swagger.annotations.ApiParam) NamespaceProperties(org.eclipse.winery.repository.backend.filebased.NamespaceProperties) AvailableFeaturesApiData(org.eclipse.winery.repository.rest.resources.apiData.AvailableFeaturesApiData) EncodingUtil(org.eclipse.winery.model.ids.EncodingUtil) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) InvalidParameterException(java.security.InvalidParameterException) Consumes(javax.ws.rs.Consumes) SolutionStrategy(org.eclipse.winery.model.adaptation.problemsolving.SolutionStrategy) VersionSupport(org.eclipse.winery.model.version.VersionSupport) Map(java.util.Map) PlacementUtils(org.eclipse.winery.model.adaptation.placement.PlacementUtils) URI(java.net.URI) TEntityType(org.eclipse.winery.model.tosca.TEntityType) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) Context(javax.ws.rs.core.Context) SolutionInputData(org.eclipse.winery.model.adaptation.problemsolving.SolutionInputData) TopologyAndErrorList(org.eclipse.winery.model.adaptation.enhance.TopologyAndErrorList) Allocation(org.eclipse.winery.repository.targetallocation.Allocation) TNodeType(org.eclipse.winery.model.tosca.TNodeType) Collectors(java.util.stream.Collectors) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) CompositionData(org.eclipse.winery.repository.rest.resources._support.dataadapter.composeadapter.CompositionData) NewVersionListElement(org.eclipse.winery.repository.rest.resources.apiData.NewVersionListElement) Objects(java.util.Objects) List(java.util.List) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) Response(javax.ws.rs.core.Response) IRepository(org.eclipse.winery.repository.backend.IRepository) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) AllocationRequest(org.eclipse.winery.repository.targetallocation.util.AllocationRequest) AbstractComponentInstanceResourceContainingATopology(org.eclipse.winery.repository.rest.resources._support.AbstractComponentInstanceResourceContainingATopology) GET(javax.ws.rs.GET) Splitting(org.eclipse.winery.repository.splitting.Splitting) ServiceTemplateId(org.eclipse.winery.model.ids.definitions.ServiceTemplateId) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) HashMap(java.util.HashMap) EnhancementUtils(org.eclipse.winery.model.adaptation.enhance.EnhancementUtils) TTopologyTemplate(org.eclipse.winery.model.tosca.TTopologyTemplate) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) BackendUtils(org.eclipse.winery.repository.backend.BackendUtils) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Environments(org.eclipse.winery.common.configuration.Environments) HasTags(org.eclipse.winery.model.tosca.HasTags) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) DeploymentTechnologyDescriptor(org.eclipse.winery.model.tosca.DeploymentTechnologyDescriptor) TRelationshipTemplate(org.eclipse.winery.model.tosca.TRelationshipTemplate) PropertyDiffList(org.eclipse.winery.repository.rest.resources.apiData.PropertyDiffList) PUT(javax.ws.rs.PUT) ModelUtilities(org.eclipse.winery.model.tosca.utils.ModelUtilities) Collections(java.util.Collections) SolutionFactory(org.eclipse.winery.model.adaptation.problemsolving.SolutionFactory) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) PropertyDefinitionKV(org.eclipse.winery.model.tosca.extensions.kvproperties.PropertyDefinitionKV) TEntityTemplate(org.eclipse.winery.model.tosca.TEntityTemplate) QName(javax.xml.namespace.QName) TEntityType(org.eclipse.winery.model.tosca.TEntityType) ArrayList(java.util.ArrayList) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) PropertyDiffList(org.eclipse.winery.repository.rest.resources.apiData.PropertyDiffList) IRepository(org.eclipse.winery.repository.backend.IRepository) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiParam (io.swagger.annotations.ApiParam)1 IOException (java.io.IOException)1 URI (java.net.URI)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1