From 98f08c1f9b617e670cd4c71321c9152e8f63b18c Mon Sep 17 00:00:00 2001 From: vasraz Date: Wed, 24 May 2023 17:30:41 +0100 Subject: Update external query api with new query params Signed-off-by: Vasyl Razinkov Change-Id: Ib4970d4f57f9e236f520ca1925915d288c9c5236 Issue-ID: SDC-4409 --- .../sdc/be/model/DistributionStatusEnum.java | 14 +++---- .../operations/ToscaOperationFacade.java | 47 ++++++++++++---------- 2 files changed, 32 insertions(+), 29 deletions(-) (limited to 'catalog-model') diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DistributionStatusEnum.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DistributionStatusEnum.java index e81be9f09e..2e521c7b2e 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/DistributionStatusEnum.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/DistributionStatusEnum.java @@ -19,13 +19,14 @@ */ package org.openecomp.sdc.be.model; +import lombok.AllArgsConstructor; +import lombok.Getter; + +@AllArgsConstructor +@Getter public enum DistributionStatusEnum { DISTRIBUTION_NOT_APPROVED("Distribution not approved"), DISTRIBUTED("Distributed"); - private String value; - - private DistributionStatusEnum(String value) { - this.value = value; - } + private final String value; public static DistributionStatusEnum findState(String state) { for (DistributionStatusEnum distributionStatus : DistributionStatusEnum.values()) { @@ -36,7 +37,4 @@ public enum DistributionStatusEnum { return null; } - public String getValue() { - return value; - } } diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java index 42781b21d8..0ed0a7b79d 100644 --- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java +++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaOperationFacade.java @@ -135,6 +135,7 @@ import static java.util.Objects.requireNonNull; import static org.apache.commons.collections.CollectionUtils.isEmpty; import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import static org.janusgraph.core.attribute.Text.REGEX; +import static org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum.TOPOLOGY_TEMPLATE; @org.springframework.stereotype.Component("tosca-operation-facade") public class ToscaOperationFacade { @@ -604,7 +605,7 @@ public class ToscaOperationFacade { public Either getLatestResourceByToscaResourceName(String toscaResourceName) { if (toscaResourceName != null && toscaResourceName.contains("org.openecomp.resource.vf")) { - return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.TOPOLOGY_TEMPLATE, JsonParseFlagEnum.ParseMetadata); + return getLatestResourceByToscaResourceName(toscaResourceName, TOPOLOGY_TEMPLATE, JsonParseFlagEnum.ParseMetadata); } else { return getLatestResourceByToscaResourceName(toscaResourceName, VertexTypeEnum.NODE_TYPE, JsonParseFlagEnum.ParseMetadata); } @@ -861,7 +862,7 @@ public class ToscaOperationFacade { propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); final Either, JanusGraphOperationStatus> getResourceResult - = janusGraphDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch,JsonParseFlagEnum.ParseAll); + = janusGraphDao.getByCriteria(null, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); if (getResourceResult.isRight()) { final JanusGraphOperationStatus status = getResourceResult.right().value(); log.debug("Failed to find resource with systemName {}, version {}. Status is {} ", systemName, version, status); @@ -1647,23 +1648,23 @@ public class ToscaOperationFacade { } public Either, StorageOperationStatus> associateComponentInstanceInterfacesToComponent( - Map> instInterfaces, - String componentId + Map> instInterfaces, + String componentId ) { Either getVertexEither = janusGraphDao.getVertexById( - componentId, - JsonParseFlagEnum.NoParse + componentId, + JsonParseFlagEnum.NoParse ); if (getVertexEither.isRight()) { log.debug( - COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, - componentId, - getVertexEither.right().value() + COULDNT_FETCH_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, + componentId, + getVertexEither.right().value() ); return Either.right( - DaoStatusConverter.convertJanusGraphStatusToStorageStatus( - getVertexEither.right().value() - ) + DaoStatusConverter.convertJanusGraphStatusToStorageStatus( + getVertexEither.right().value() + ) ); } GraphVertex vertex = getVertexEither.left().value(); @@ -1672,15 +1673,15 @@ public class ToscaOperationFacade { for (Map.Entry> entryInstances : instInterfaces.entrySet()) { Map incomingInterfacesMap = entryInstances.getValue().entrySet().stream() - .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); + .collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue())); MapInterfaceDataDefinition interfacesMap = new MapInterfaceDataDefinition(); interfacesMap.setMapToscaDataDefinition(incomingInterfacesMap); instInterfacesMap.put(entryInstances.getKey(), interfacesMap); } } StorageOperationStatus status = topologyTemplateOperation.associateInstInterfacesToComponent( - vertex, - instInterfacesMap + vertex, + instInterfacesMap ); if (StorageOperationStatus.OK == status) { log.debug(COMPONENT_CREATED_SUCCESSFULLY); @@ -2334,7 +2335,7 @@ public class ToscaOperationFacade { } private VertexTypeEnum getVertexTypeEnum(final ResourceTypeEnum resourceType) { - return ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : VertexTypeEnum.TOPOLOGY_TEMPLATE; + return ModelConverter.isAtomicComponent(resourceType) ? VertexTypeEnum.NODE_TYPE : TOPOLOGY_TEMPLATE; } private Map propertiesToMatch(final String normalizedName, final ComponentTypeEnum componentType) { @@ -2406,7 +2407,7 @@ public class ToscaOperationFacade { } if (ComponentTypeEnum.SERVICE == componentTypeEnum || SERVICE.equalsIgnoreCase(internalComponentType) || VF.equalsIgnoreCase( internalComponentType)) { - internalVertexTypes.add(VertexTypeEnum.TOPOLOGY_TEMPLATE); + internalVertexTypes.add(TOPOLOGY_TEMPLATE); } return internalVertexTypes; } @@ -2767,7 +2768,7 @@ public class ToscaOperationFacade { } propertiesToMatch.put(GraphPropertyEnum.COMPONENT_TYPE, ComponentTypeEnum.SERVICE.name()); propertiesNotToMatch.put(GraphPropertyEnum.IS_DELETED, true); - if (distStatus != null && !distStatus.isEmpty()) { + if (CollectionUtils.isNotEmpty(distStatus)) { for (DistributionStatusEnum state : distStatus) { propertiesToMatch.put(GraphPropertyEnum.DISTRIBUTION_STATUS, state.name()); Either, StorageOperationStatus> fetchServicesByCriteria = fetchServicesByCriteria(servicesAll, propertiesToMatch, @@ -2788,8 +2789,12 @@ public class ToscaOperationFacade { Map propertiesToMatch, Map propertiesNotToMatch, String modelName) { - Either, JanusGraphOperationStatus> getRes = janusGraphDao - .getByCriteria(VertexTypeEnum.TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, modelName); + Either, JanusGraphOperationStatus> getRes; + if (StringUtils.isEmpty(modelName)) { + getRes = janusGraphDao.getByCriteria(TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll); + } else { + getRes = janusGraphDao.getByCriteria(TOPOLOGY_TEMPLATE, propertiesToMatch, propertiesNotToMatch, JsonParseFlagEnum.ParseAll, modelName); + } if (getRes.isRight()) { if (getRes.right().value() != JanusGraphOperationStatus.NOT_FOUND) { CommonUtility.addRecordToLog(log, LogLevelEnum.DEBUG, @@ -3441,7 +3446,7 @@ public class ToscaOperationFacade { log.error(COULDNT_FETCH_A_COMPONENT_WITH_AND_UNIQUE_ID_ERROR, componentId, getVertexEither.right().value()); result = Either.right(DaoStatusConverter.convertJanusGraphStatusToStorageStatus(getVertexEither.right().value())); } else { - if (getVertexEither.left().value().getLabel() != VertexTypeEnum.TOPOLOGY_TEMPLATE) { + if (getVertexEither.left().value().getLabel() != TOPOLOGY_TEMPLATE) { log.error("Policy association to component of Tosca type {} is not allowed. ", getVertexEither.left().value().getLabel()); result = Either.right(StorageOperationStatus.BAD_REQUEST); } -- cgit 1.2.3-korg