summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java165
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java39
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java3
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverterTest.java452
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServletTest.java2
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java105
-rw-r--r--catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java4
-rw-r--r--common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnum.java17
-rw-r--r--common-be/src/test/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnumTest.java2
11 files changed, 381 insertions, 413 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
index 0d43082dc4..bd8b2cb2d9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverter.java
@@ -19,17 +19,22 @@
*/
package org.openecomp.sdc.be.ecomp.converters;
-import fj.data.Either;
+import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Stream;
+
+import fj.data.Either;
import org.apache.commons.collections.MapUtils;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.distribution.servlet.DistributionCatalogServlet;
import org.openecomp.sdc.be.externalapi.servlet.representation.ArtifactMetadata;
import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetDetailedMetadata;
@@ -46,6 +51,7 @@ import org.openecomp.sdc.be.model.Service;
import org.openecomp.sdc.be.model.category.CategoryDefinition;
import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.common.log.enums.EcompLoggerErrorCode;
import org.openecomp.sdc.common.log.wrappers.Logger;
import org.openecomp.sdc.exception.ResponseFormat;
import org.springframework.beans.factory.annotation.Autowired;
@@ -53,7 +59,7 @@ import org.springframework.beans.factory.annotation.Autowired;
@org.springframework.stereotype.Component("asset-metadata-utils")
public class AssetMetadataConverter {
- private static final Logger log = Logger.getLogger(DistributionCatalogServlet.class);
+ private static final Logger log = Logger.getLogger(AssetMetadataConverter.class);
@Autowired
protected ToscaOperationFacade toscaOperationFacade;
@Autowired
@@ -63,13 +69,13 @@ public class AssetMetadataConverter {
* Relative asset’s URL. Should be used in REST GET API to download the asset’s CSAR. https://{serverBaseURL}/{csarPath} can be obtained from (HttpServletRequest)request.getServerName()
*/
public Either<List<? extends AssetMetadata>, ResponseFormat> convertToAssetMetadata(List<? extends Component> componentList, String serverBaseURL,
- boolean detailed) {
- if (componentList == null || componentList.isEmpty()) {
+ boolean detailed, final List<String> additionalMetadataKeysToInclude) {
+ if (CollectionUtils.isEmpty(componentList)) {
return Either.left(new LinkedList<>());
}
List<AssetMetadata> retResList = new LinkedList<>();
for (Component curr : componentList) {
- Either<? extends AssetMetadata, ResponseFormat> resMetaData = convertToSingleAssetMetadata(curr, serverBaseURL, detailed);
+ Either<? extends AssetMetadata, ResponseFormat> resMetaData = convertToSingleAssetMetadata(curr, serverBaseURL, detailed, additionalMetadataKeysToInclude);
if (resMetaData.isRight()) {
return Either.right(resMetaData.right().value());
}
@@ -79,9 +85,10 @@ public class AssetMetadataConverter {
}
public <T extends Component> Either<? extends AssetMetadata, ResponseFormat> convertToSingleAssetMetadata(T component, String serverBaseURL,
- boolean detailed) {
+ boolean detailed,
+ final List<String> additionalMetadataKeysToInclude) {
ComponentTypeEnum componentType = component.getComponentType();
- Either<? extends AssetMetadata, ResponseFormat> resMetaData = convertToMetadata(componentType, serverBaseURL, detailed, component);
+ Either<? extends AssetMetadata, ResponseFormat> resMetaData = convertToMetadata(componentType, serverBaseURL, detailed, component, additionalMetadataKeysToInclude);
if (resMetaData.isRight()) {
return Either.right(resMetaData.right().value());
} else {
@@ -90,49 +97,46 @@ public class AssetMetadataConverter {
}
private Either<? extends AssetMetadata, ResponseFormat> convertToMetadata(ComponentTypeEnum componentType, String serverBaseURL, boolean detailed,
- Component curr) {
+ Component curr,
+ final List<String> additionalMetadataKeysToInclude) {
switch (componentType) {
case RESOURCE:
- return generateResourceMeatdata(serverBaseURL, detailed, curr);
+ return generateResourceMetadata(serverBaseURL, detailed, curr);
case SERVICE:
- return generateServiceMetadata(serverBaseURL, detailed, curr);
+ return generateServiceMetadata(serverBaseURL, detailed, curr, additionalMetadataKeysToInclude);
default:
- ResponseFormat responseFormat = componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_INVALID_CATEGORY);
- return Either.right(responseFormat);
+ return Either.right(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_INVALID_CATEGORY));
}
}
- private Either<? extends AssetMetadata, ResponseFormat> generateResourceMeatdata(String serverBaseURL, boolean detailed, Component curr) {
- AssetMetadata metaData;
- metaData = createMetadaObject(detailed, curr.getComponentType());
- metaData = convertToResourceMetadata((ResourceAssetMetadata) metaData, (Resource) curr, serverBaseURL, detailed);
+ private Either<? extends AssetMetadata, ResponseFormat> generateResourceMetadata(String serverBaseURL, boolean detailed, Component curr) {
+ AssetMetadata metaData = createMetadaObject(detailed, curr.getComponentType(), false);
+ convertToResourceMetadata((ResourceAssetMetadata) metaData, (Resource) curr, serverBaseURL, detailed);
if (detailed) {
- Either<ResourceAssetDetailedMetadata, StorageOperationStatus> converted = convertToResourceDetailedMetadata(
- (ResourceAssetDetailedMetadata) metaData, (Resource) curr, serverBaseURL);
+ Either<ResourceAssetDetailedMetadata, StorageOperationStatus> converted = convertToResourceDetailedMetadata((ResourceAssetDetailedMetadata) metaData, (Resource) curr);
if (converted.isRight()) {
ActionStatus storageResponse = componentsUtils.convertFromStorageResponse(converted.right().value(), ComponentTypeEnum.RESOURCE);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(storageResponse);
- return Either.right(responseFormat);
+ return Either.right(componentsUtils.getResponseFormat(storageResponse));
}
}
return Either.left(metaData);
}
- private AssetMetadata createMetadaObject(boolean detailed, ComponentTypeEnum type) {
+ private AssetMetadata createMetadaObject(boolean detailed, ComponentTypeEnum type, boolean additionalMetadataKeysToInclude) {
AssetMetadata metaData = null;
switch (type) {
case SERVICE:
- if (!detailed) {
- metaData = new ServiceAssetMetadata();
- } else {
+ if (detailed && !additionalMetadataKeysToInclude) {
metaData = new ServiceAssetDetailedMetadata();
+ } else {
+ metaData = new ServiceAssetMetadata();
}
break;
case RESOURCE:
- if (!detailed) {
- metaData = new ResourceAssetMetadata();
- } else {
+ if (detailed) {
metaData = new ResourceAssetDetailedMetadata();
+ } else {
+ metaData = new ResourceAssetMetadata();
}
break;
default:
@@ -141,39 +145,37 @@ public class AssetMetadataConverter {
return metaData;
}
- private Either<? extends AssetMetadata, ResponseFormat> generateServiceMetadata(String serverBaseURL, boolean detailed, Component curr) {
- AssetMetadata metaData = createMetadaObject(detailed, curr.getComponentType());
- metaData = convertToServiceAssetMetadata((ServiceAssetMetadata) metaData, (Service) curr, serverBaseURL, detailed);
+ private Either<? extends AssetMetadata, ResponseFormat> generateServiceMetadata(String serverBaseURL, boolean detailed, Component curr, final List<String> additionalMetadataKeysToInclude) {
+ AssetMetadata metaData = createMetadaObject(detailed, curr.getComponentType(), CollectionUtils.isNotEmpty(additionalMetadataKeysToInclude));
+ convertToServiceAssetMetadata((ServiceAssetMetadata) metaData, (Service) curr, serverBaseURL, detailed, additionalMetadataKeysToInclude);
if (detailed) {
Either<ServiceAssetDetailedMetadata, StorageOperationStatus> converted = convertToServiceDetailedMetadata(
- (ServiceAssetDetailedMetadata) metaData, (Service) curr);
+ (ServiceAssetDetailedMetadata) metaData, (Service) curr);
if (converted.isRight()) {
ActionStatus storageResponse = componentsUtils.convertFromStorageResponse(converted.right().value(), ComponentTypeEnum.RESOURCE);
- ResponseFormat responseFormat = componentsUtils.getResponseFormat(storageResponse);
- return Either.right(responseFormat);
+ return Either.right(componentsUtils.getResponseFormat(storageResponse));
}
}
return Either.left(metaData);
}
- private <U extends AssetMetadata, T extends Component> U convertToAsset(U asset, T component, String serverBaseURL, boolean detailed) {
+ private <U extends AssetMetadata, T extends Component> void convertToAsset(U asset, T component, String serverBaseURL, boolean detailed) {
asset.setUuid(component.getUUID());
asset.setInvariantUUID(component.getInvariantUUID());
asset.setName(component.getName());
asset.setVersion(component.getVersion());
- if (!detailed) {
- asset.setToscaModelURL(serverBaseURL + "/" + component.getUUID() + "/toscaModel");
- } else {
- String toscaModelUrl = (new String(serverBaseURL)).replace("metadata", "toscaModel");
+ if (detailed) {
+ String toscaModelUrl = serverBaseURL.replace("metadata", "toscaModel");
asset.setToscaModelURL(toscaModelUrl);
+ } else {
+ asset.setToscaModelURL(serverBaseURL + "/" + component.getUUID() + "/toscaModel");
}
- return asset;
}
- private <T extends ResourceAssetMetadata> T convertToResourceMetadata(T assetToPopulate, Resource resource, String serverBaseURL,
- boolean detailed) {
- assetToPopulate = convertToAsset(assetToPopulate, resource, serverBaseURL, detailed);
- if (resource.getCategories() != null && !resource.getCategories().isEmpty()) {
+ private <T extends ResourceAssetMetadata> void convertToResourceMetadata(T assetToPopulate, Resource resource, String serverBaseURL,
+ boolean detailed) {
+ convertToAsset(assetToPopulate, resource, serverBaseURL, detailed);
+ if (CollectionUtils.isNotEmpty(resource.getCategories())) {
CategoryDefinition categoryDefinition = resource.getCategories().get(0);
assetToPopulate.setCategory(categoryDefinition.getName());
assetToPopulate.setSubCategory(categoryDefinition.getSubcategories().get(0).getName());
@@ -181,36 +183,62 @@ public class AssetMetadataConverter {
assetToPopulate.setResourceType(resource.getResourceType().name());
assetToPopulate.setLifecycleState(resource.getLifecycleState().name());
assetToPopulate.setLastUpdaterUserId(resource.getLastUpdaterUserId());
- return (T) assetToPopulate;
}
- private <T extends ServiceAssetMetadata> T convertToServiceAssetMetadata(T assetToPopulate, Service service, String serverBaseURL,
- boolean detailed) {
- assetToPopulate = convertToAsset(assetToPopulate, service, serverBaseURL, detailed);
- if (service.getCategories() != null && !service.getCategories().isEmpty()) {
+ private <T extends ServiceAssetMetadata> void convertToServiceAssetMetadata(T assetToPopulate, Service service, String serverBaseURL,
+ boolean detailed,
+ final List<String> additionalMetadataKeysToInclude) {
+ convertToAsset(assetToPopulate, service, serverBaseURL, detailed);
+ if (CollectionUtils.isNotEmpty(service.getCategories())) {
CategoryDefinition categoryDefinition = service.getCategories().get(0);
assetToPopulate.setCategory(categoryDefinition.getName());
}
assetToPopulate.setLifecycleState(service.getLifecycleState().name());
assetToPopulate.setLastUpdaterUserId(service.getLastUpdaterUserId());
assetToPopulate.setDistributionStatus(service.getDistributionStatus().name());
- return (T) assetToPopulate;
+ if (CollectionUtils.isNotEmpty(additionalMetadataKeysToInclude)) {
+ setAdditionalRequestedMetadata((ServiceAssetMetadata) assetToPopulate, service, additionalMetadataKeysToInclude);
+ }
+ }
+
+ private void setAdditionalRequestedMetadata(ServiceAssetMetadata assetToPopulate, Service service, List<String> additionalMetadataKeysToInclude) {
+ final Map<String, String> additionalRequestedMetadata = new HashMap<>();
+ for (final String key : additionalMetadataKeysToInclude) {
+ Object value = null;
+ try {
+ Optional<Method> optionalMethod = Stream.of(service.getClass().getMethods()).filter(method -> method.getName().toLowerCase().equals("get" + key.toLowerCase())).findAny();
+ if (optionalMethod.isPresent()) {
+ value = optionalMethod.get().invoke(service);
+ }
+ } catch (final Exception e) {
+ log.warn(EcompLoggerErrorCode.DATA_ERROR, AssetMetadataConverter.class.getSimpleName(), "No such field '{}'", key);
+ }
+ if (value == null) {
+ value = service.getCategorySpecificMetadata().get(key);
+ }
+ if (value != null) {
+ additionalRequestedMetadata.put(key, value.toString());
+ }
+ }
+
+ if (MapUtils.isNotEmpty(additionalRequestedMetadata)) {
+ assetToPopulate.setAdditionalRequestedMetadata(additionalRequestedMetadata);
+ }
}
private <T extends ResourceAssetDetailedMetadata> Either<T, StorageOperationStatus> convertToResourceDetailedMetadata(T assetToPopulate,
- Resource resource,
- String serverBaseURL) {
+ Resource resource) {
List<ComponentInstance> componentInstances = resource.getComponentInstances();
if (componentInstances != null) {
Either<List<ResourceInstanceMetadata>, StorageOperationStatus> resourceInstanceMetadata = convertToResourceInstanceMetadata(
- componentInstances, ComponentTypeEnum.RESOURCE_PARAM_NAME, resource.getUUID());
+ componentInstances, ComponentTypeEnum.RESOURCE_PARAM_NAME, resource.getUUID());
if (resourceInstanceMetadata.isRight()) {
return Either.right(resourceInstanceMetadata.right().value());
}
assetToPopulate.setResources(resourceInstanceMetadata.left().value());
}
Map<String, ArtifactDefinition> deploymentArtifacts = resource.getDeploymentArtifacts();
- assetToPopulate = populateResourceWithArtifacts(assetToPopulate, resource, deploymentArtifacts);
+ populateResourceWithArtifacts(assetToPopulate, resource, deploymentArtifacts);
assetToPopulate.setLastUpdaterFullName(resource.getLastUpdaterFullName());
assetToPopulate.setToscaResourceName(resource.getToscaResourceName());
assetToPopulate.setDescription(resource.getDescription());
@@ -222,40 +250,38 @@ public class AssetMetadataConverter {
List<ComponentInstance> componentInstances = service.getComponentInstances();
if (componentInstances != null) {
Either<List<ResourceInstanceMetadata>, StorageOperationStatus> resourceInstanceMetadata = convertToResourceInstanceMetadata(
- componentInstances, ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUUID());
+ componentInstances, ComponentTypeEnum.SERVICE_PARAM_NAME, service.getUUID());
if (resourceInstanceMetadata.isRight()) {
return Either.right(resourceInstanceMetadata.right().value());
}
assetToPopulate.setResources(resourceInstanceMetadata.left().value());
}
Map<String, ArtifactDefinition> deploymentArtifacts = service.getDeploymentArtifacts();
- assetToPopulate = populateServiceWithArtifacts(assetToPopulate, service, deploymentArtifacts);
+ populateServiceWithArtifacts(assetToPopulate, service, deploymentArtifacts);
assetToPopulate.setLastUpdaterFullName(service.getLastUpdaterFullName());
return Either.left(assetToPopulate);
}
- private <T extends ResourceAssetDetailedMetadata> T populateResourceWithArtifacts(T asset, Resource resource,
- Map<String, ArtifactDefinition> artifacts) {
+ private <T extends ResourceAssetDetailedMetadata> void populateResourceWithArtifacts(T asset, Resource resource,
+ Map<String, ArtifactDefinition> artifacts) {
List<ArtifactMetadata> artifactMetaList = populateAssetWithArtifacts(resource, artifacts);
asset.setArtifacts(artifactMetaList);
- return asset;
}
- private <T extends ServiceAssetDetailedMetadata> T populateServiceWithArtifacts(T asset, Service service,
- Map<String, ArtifactDefinition> artifacts) {
+ private <T extends ServiceAssetDetailedMetadata> void populateServiceWithArtifacts(T asset, Service service,
+ Map<String, ArtifactDefinition> artifacts) {
List<ArtifactMetadata> artifactMetaList = populateAssetWithArtifacts(service, artifacts);
asset.setArtifacts(artifactMetaList);
- return asset;
}
private List<ArtifactMetadata> populateAssetWithArtifacts(Component component, Map<String, ArtifactDefinition> artifacts) {
List<ArtifactMetadata> artifactMetaList = new LinkedList<>();
- if (artifacts != null) {
+ if (MapUtils.isNotEmpty(artifacts)) {
Collection<ArtifactDefinition> artefactDefList = artifacts.values();
for (ArtifactDefinition artifactDefinition : artefactDefList) {
- if (artifactDefinition.getEsId() != null && !artifactDefinition.getEsId().isEmpty()) {
+ if (StringUtils.isNotBlank(artifactDefinition.getEsId())) {
ArtifactMetadata convertedArtifactMetadata = convertToArtifactMetadata(artifactDefinition,
- ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUUID(), null);
+ ComponentTypeEnum.findParamByType(component.getComponentType()), component.getUUID(), null);
artifactMetaList.add(convertedArtifactMetadata);
}
}
@@ -270,11 +296,10 @@ public class AssetMetadataConverter {
ArtifactMetadata metadata = new ArtifactMetadata();
metadata.setArtifactName(artifact.getArtifactName());
metadata.setArtifactType(artifact.getArtifactType());
- if (resourceInstanceName == null || resourceInstanceName.isEmpty()) {
+ if (StringUtils.isBlank(resourceInstanceName)) {
metadata.setArtifactURL(String.format(COMPONENT_ARTIFACT_URL, componentType, componentUUID, artifact.getArtifactUUID()));
} else {
- metadata.setArtifactURL(
- String.format(RESOURCE_INSTANCE_ARTIFACT_URL, componentType, componentUUID, resourceInstanceName, artifact.getArtifactUUID()));
+ metadata.setArtifactURL(String.format(RESOURCE_INSTANCE_ARTIFACT_URL, componentType, componentUUID, resourceInstanceName, artifact.getArtifactUUID()));
}
metadata.setArtifactDescription(artifact.getDescription());
metadata.setArtifactTimeout(artifact.getTimeout() != null && artifact.getTimeout() > 0 ? artifact.getTimeout() : null);
@@ -288,7 +313,7 @@ public class AssetMetadataConverter {
}
private Either<List<ResourceInstanceMetadata>, StorageOperationStatus> convertToResourceInstanceMetadata(
- List<ComponentInstance> componentInstances, String componentType, String componentUUID) {
+ List<ComponentInstance> componentInstances, String componentType, String componentUUID) {
List<ResourceInstanceMetadata> retList = new LinkedList<>();
Map<String, ImmutablePair<String, String>> uuidDuplicatesMap = new HashMap<>();
for (ComponentInstance componentInstance : componentInstances) {
@@ -322,7 +347,7 @@ public class AssetMetadataConverter {
Collection<ArtifactDefinition> values = componentInstance.getDeploymentArtifacts().values();
for (ArtifactDefinition artifactDefinition : values) {
ArtifactMetadata converted = convertToArtifactMetadata(artifactDefinition, componentType, componentUUID,
- componentInstance.getNormalizedName());
+ componentInstance.getNormalizedName());
artifactMetaList.add(converted);
}
metadata.setArtifacts(artifactMetaList);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
index cce2f12343..e5b2a94584 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServlet.java
@@ -96,23 +96,23 @@ import org.springframework.stereotype.Controller;
public class AssetsDataServlet extends AbstractValidationsServlet {
private static final Logger log = Logger.getLogger(AssetsDataServlet.class);
- private final ElementBusinessLogic elementBusinessLogic;
+ private final ElementBusinessLogic elementBL;
private final AssetMetadataConverter assetMetadataConverter;
- private final ServiceBusinessLogic serviceBusinessLogic;
- private final ResourceBusinessLogic resourceBusinessLogic;
+ private final ServiceBusinessLogic serviceBL;
+ private final ResourceBusinessLogic resourceBL;
@Context
private HttpServletRequest request;
@Inject
public AssetsDataServlet(ComponentInstanceBusinessLogic componentInstanceBL, ComponentsUtils componentsUtils, ServletUtils servletUtils,
- ResourceImportManager resourceImportManager, ElementBusinessLogic elementBusinessLogic,
- AssetMetadataConverter assetMetadataConverter, ServiceBusinessLogic serviceBusinessLogic,
- ResourceBusinessLogic resourceBusinessLogic) {
+ ResourceImportManager resourceImportManager, ElementBusinessLogic elementBL,
+ AssetMetadataConverter assetMetadataConverter, ServiceBusinessLogic serviceBL,
+ ResourceBusinessLogic resourceBL) {
super(componentInstanceBL, componentsUtils, servletUtils, resourceImportManager);
- this.elementBusinessLogic = elementBusinessLogic;
+ this.elementBL = elementBL;
this.assetMetadataConverter = assetMetadataConverter;
- this.serviceBusinessLogic = serviceBusinessLogic;
- this.resourceBusinessLogic = resourceBusinessLogic;
+ this.serviceBL = serviceBL;
+ this.resourceBL = resourceBL;
}
@GET
@@ -132,10 +132,13 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
@Parameter(description = "Determines the format of the body of the response") @HeaderParam(value = Constants.ACCEPT_HEADER) String accept,
@Parameter(description = "The username and password", required = true) @HeaderParam(value = Constants.AUTHORIZATION_HEADER) String authorization,
@Parameter(description = "The requested asset type", schema = @Schema(allowableValues = {"resources", "services"}), required = true) @PathParam("assetType") final String assetType,
+
@Parameter(description = "The category to filter the result set on") @QueryParam("category") String category,
@Parameter(description = "The sub category to filter the result set on. Only applicable when assetType = resources") @QueryParam("subCategory") String subCategory,
@Parameter(description = "The distribution status to filter the result set on") @QueryParam("distributionStatus") String distributionStatus,
@Parameter(description = "The resource type to filter the result set on. Only applicable when assetType = resources") @QueryParam("resourceType") String resourceType,
+ @Parameter(description = "Additional metadata keys to include in the response, not all keys are supported.\nSupported keys: lastUpdateDate, creationDate, description, uniqueId and category specific metadata keys")
+ @QueryParam("include") List<String> additionalMetadataKeysToInclude,
@Parameter(description = "The version(s) to filter the result set on\n" +
"Syntax: /services?version=(highestMatchingVersionOnly|lessThan|greaterThan|equals)(:=)(value)",
examples = {
@@ -202,17 +205,16 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
}
filters.put(FilterKeyEnum.RESOURCE_TYPE, resourceTypeEnum.name());
}
- Either<List<? extends Component>, ResponseFormat> assetTypeData
- = elementBusinessLogic.getFilteredCatalogComponents(assetType, filters, query);
- if (assetTypeData.isRight()) {
+ final Either<List<? extends Component>, ResponseFormat> componentList = elementBL.getFilteredCatalogComponents(assetType, filters, query);
+ if (componentList.isRight()) {
log.debug("getAssetList: Asset Fetching Failed");
- responseFormat = assetTypeData.right().value();
+ responseFormat = componentList.right().value();
getComponentsUtils().auditExternalGetAssetList(responseFormat, auditingActionEnum, distributionData, requestId);
return buildErrorResponse(responseFormat);
} else {
log.debug("getAssetList: Asset Fetching Success");
Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter
- .convertToAssetMetadata(assetTypeData.left().value(), requestURI, false);
+ .convertToAssetMetadata(componentList.left().value(), requestURI, false, additionalMetadataKeysToInclude);
if (resMetadata.isRight()) {
log.debug("getAssetList: Asset conversion Failed");
responseFormat = resMetadata.right().value();
@@ -276,8 +278,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
return buildErrorResponse(responseFormat);
}
try {
- Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBusinessLogic
- .getCatalogComponentsByUuidAndAssetType(assetType, uuid);
+ final Either<List<? extends Component>, ResponseFormat> assetTypeData = elementBL.getCatalogComponentsByUuidAndAssetType(assetType, uuid);
if (assetTypeData.isRight()) {
log.debug("getAssetList: Asset Fetching Failed");
responseFormat = assetTypeData.right().value();
@@ -287,7 +288,7 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
resourceCommonInfo.setResourceName(assetTypeData.left().value().iterator().next().getName());
log.debug("getAssetList: Asset Fetching Success");
Either<List<? extends AssetMetadata>, ResponseFormat> resMetadata = assetMetadataConverter
- .convertToAssetMetadata(assetTypeData.left().value(), requestURI, true);
+ .convertToAssetMetadata(assetTypeData.left().value(), requestURI, true, null);
if (resMetadata.isRight()) {
log.debug("getAssetList: Asset conversion Failed");
responseFormat = resMetadata.right().value();
@@ -307,10 +308,10 @@ public class AssetsDataServlet extends AbstractValidationsServlet {
private ComponentBusinessLogic getComponentBLByType(ComponentTypeEnum componentTypeEnum) {
if (componentTypeEnum.equals(RESOURCE)) {
- return resourceBusinessLogic;
+ return resourceBL;
} else {
// Implementation is the same for any ComponentBusinessLogic
- return serviceBusinessLogic;
+ return serviceBL;
}
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
index b0ec4e5727..6d94ff6471 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/CrudExternalServlet.java
@@ -434,7 +434,7 @@ public class CrudExternalServlet extends AbstractValidationsServlet {
ResponseFormat responseFormat;
Response response;
Either<? extends AssetMetadata, ResponseFormat> resMetadata = assetMetadataUtils
- .convertToSingleAssetMetadata(resource, request.getRequestURL().toString(), true);
+ .convertToSingleAssetMetadata(resource, request.getRequestURL().toString(), true, null);
if (resMetadata.isRight()) {
log.debug("Asset conversion Failed");
responseFormat = resMetadata.right().value();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java
index 1610eceeca..ce606501b0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetDetailedMetadata.java
@@ -19,10 +19,11 @@
*/
package org.openecomp.sdc.be.externalapi.servlet.representation;
-import java.util.List;
import lombok.Getter;
import lombok.Setter;
+import java.util.List;
+
@Getter
@Setter
public class ServiceAssetDetailedMetadata extends ServiceAssetMetadata {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java
index ee3978c961..f97207f40d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/externalapi/servlet/representation/ServiceAssetMetadata.java
@@ -22,6 +22,8 @@ package org.openecomp.sdc.be.externalapi.servlet.representation;
import lombok.Getter;
import lombok.Setter;
+import java.util.Map;
+
@Getter
@Setter
public class ServiceAssetMetadata extends AssetMetadata {
@@ -30,4 +32,5 @@ public class ServiceAssetMetadata extends AssetMetadata {
private String lifecycleState;
private String lastUpdaterUserId;
private String distributionStatus;
+ private Map<String, String> additionalRequestedMetadata;
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverterTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverterTest.java
index f89d899e00..e591832a47 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverterTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/ecomp/converters/AssetMetadataConverterTest.java
@@ -7,9 +7,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,279 +20,213 @@
package org.openecomp.sdc.be.ecomp.converters;
-import static org.assertj.core.api.Assertions.assertThat;
-
import fj.data.Either;
-import mockit.Deencapsulation;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Spy;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ArtifactMetadata;
+import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
import org.openecomp.sdc.be.externalapi.servlet.representation.AssetMetadata;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetDetailedMetadata;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceAssetMetadata;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ResourceInstanceMetadata;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetDetailedMetadata;
-import org.openecomp.sdc.be.externalapi.servlet.representation.ServiceAssetMetadata;
+import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.ComponentInstance;
import org.openecomp.sdc.be.model.DistributionStatusEnum;
import org.openecomp.sdc.be.model.LifecycleStateEnum;
+import org.openecomp.sdc.be.model.Product;
import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.Service;
-import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
+import org.openecomp.sdc.be.model.category.CategoryDefinition;
+import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
import org.openecomp.sdc.exception.ResponseFormat;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-public class AssetMetadataConverterTest {
-
- private AssetMetadataConverter createTestSubject() {
- return new AssetMetadataConverter();
- }
-
- @Test
- public void testConvertToAssetMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- List<? extends Component> componentList = null;
- String serverBaseURL = "";
- boolean detailed = false;
- Either<List<? extends AssetMetadata>, ResponseFormat> result;
-
- // test 1
- testSubject = createTestSubject();
- componentList = null;
- result = testSubject.convertToAssetMetadata(componentList, serverBaseURL, detailed);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testConvertToSingleAssetMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- Resource component = new Resource();
- String serverBaseURL = "";
- boolean detailed = false;
- Either<? extends AssetMetadata, ResponseFormat> result;
- component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- component.setComponentType(ComponentTypeEnum.RESOURCE);
- // default test
- testSubject = createTestSubject();
- result = testSubject.convertToSingleAssetMetadata(component, serverBaseURL, detailed);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testConvertToMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- String serverBaseURL = "";
- boolean detailed = false;
- Resource curr = new Resource();
- Either<? extends AssetMetadata, ResponseFormat> result;
- curr.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- curr.setComponentType(ComponentTypeEnum.RESOURCE);
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToMetadata", ComponentTypeEnum.RESOURCE, serverBaseURL,
- detailed, curr);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testGenerateResourceMeatdata() throws Exception {
- AssetMetadataConverter testSubject;
- String serverBaseURL = "";
- Resource curr = new Resource();
- Either<? extends AssetMetadata, ResponseFormat> result;
- curr.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
- curr.setComponentType(ComponentTypeEnum.RESOURCE);
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "generateResourceMeatdata", serverBaseURL, true, curr);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testCreateMetadaObject() throws Exception {
- AssetMetadataConverter testSubject;
- AssetMetadata result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "createMetadaObject", true, ComponentTypeEnum.RESOURCE);
- assertThat(result).isInstanceOf(AssetMetadata.class);
- }
-
- @Test
- public void testGenerateServiceMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- String serverBaseURL = "";
- boolean detailed = false;
- Service curr = new Service();
- curr.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- curr.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED);
-
- Either<? extends AssetMetadata, ResponseFormat> result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "generateServiceMetadata", serverBaseURL, detailed, curr);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testConvertToAsset() throws Exception {
- AssetMetadataConverter testSubject;
- ResourceAssetMetadata asset = new ResourceAssetMetadata();
- Resource component = new Resource();
- String serverBaseURL = "";
- ResourceAssetMetadata result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToAsset", asset, component, serverBaseURL, true);
- assertThat(result).isInstanceOf(ResourceAssetMetadata.class);
- }
-
- @Test
- public void testConvertToResourceMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- ResourceAssetMetadata assetToPopulate = new ResourceAssetMetadata();
- Resource resource = new Resource();
- String serverBaseURL = "";
- boolean detailed = false;
- ResourceAssetMetadata result;
- resource.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToResourceMetadata", assetToPopulate, resource,
- serverBaseURL, true);
- assertThat(result).isInstanceOf(ResourceAssetMetadata.class);
- }
-
- @Test
- public void testConvertToServiceAssetMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- ServiceAssetMetadata assetToPopulate = new ServiceAssetMetadata();
- Service service = new Service();
- service.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED);
- String serverBaseURL = "";
- boolean detailed = false;
- ServiceAssetMetadata result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToServiceAssetMetadata", assetToPopulate, service,
- serverBaseURL, true);
- assertThat(result).isInstanceOf(ServiceAssetMetadata.class);
- }
-
- @Test
- public void testConvertToResourceDetailedMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- ResourceAssetDetailedMetadata assetToPopulate = new ResourceAssetDetailedMetadata();
- Resource resource = new Resource();
- String serverBaseURL = "";
- Either<ResourceAssetDetailedMetadata, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToResourceDetailedMetadata", assetToPopulate, resource,
- serverBaseURL);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testConvertToServiceDetailedMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- ServiceAssetDetailedMetadata assetToPopulate = new ServiceAssetDetailedMetadata();
- Service service = new Service();
- Either<ServiceAssetDetailedMetadata, StorageOperationStatus> result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToServiceDetailedMetadata", assetToPopulate, service);
- assertThat(result.isLeft()).isTrue();
- }
-
- @Test
- public void testPopulateResourceWithArtifacts() throws Exception {
- AssetMetadataConverter testSubject;
- ResourceAssetDetailedMetadata asset = new ResourceAssetDetailedMetadata();
- Resource resource = new Resource();
- Map<String, ArtifactDefinition> artifacts = new HashMap<>();
- ResourceAssetDetailedMetadata result;
-
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "populateResourceWithArtifacts", asset, resource, artifacts);
- assertThat(result).isInstanceOf(ResourceAssetDetailedMetadata.class);
- }
-
- @Test
- public void testPopulateServiceWithArtifacts() throws Exception {
- AssetMetadataConverter testSubject;
- ServiceAssetDetailedMetadata asset = new ServiceAssetDetailedMetadata();
- Service service = new Service();
- Map<String, ArtifactDefinition> artifacts = new HashMap<>();
- ServiceAssetDetailedMetadata result;
- service.setLifecycleState(LifecycleStateEnum.CERTIFIED);
- service.setDistributionStatus(DistributionStatusEnum.DISTRIBUTED);
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "populateServiceWithArtifacts",
- asset, Service.class, artifacts);
- assertThat(result).isInstanceOf(ServiceAssetDetailedMetadata.class);
- }
-
- @Test
- public void testPopulateAssetWithArtifacts() throws Exception {
- AssetMetadataConverter testSubject;
- Resource component = new Resource();
- Map<String, ArtifactDefinition> artifacts = new HashMap<>();
- List<ArtifactMetadata> result;
-
- // test 1
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "populateAssetWithArtifacts", component, artifacts);
- assertThat(result).isNull();
- }
-
- @Test
- public void testConvertToArtifactMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- ArtifactDefinition artifact = new ArtifactDefinition();
- artifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
- String componentType = "";
- String componentUUID = "";
- String resourceInstanceName = "";
- ArtifactMetadata result;
-
- // test 1
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToArtifactMetadata", artifact, componentType,
- componentUUID, resourceInstanceName);
- assertThat(result).isInstanceOf(ArtifactMetadata.class);
- }
-
- @Test
- public void testConvertToResourceInstanceMetadata() throws Exception {
- AssetMetadataConverter testSubject;
- List<ComponentInstance> componentInstances = new LinkedList<>();
- String componentType = "";
- String componentUUID = "";
- Either<List<ResourceInstanceMetadata>, StorageOperationStatus> result;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+@ExtendWith(MockitoExtension.class)
+class AssetMetadataConverterTest {
+
+ @InjectMocks
+ @Spy
+ private AssetMetadataConverter testSubject;
+ @Mock
+ private ComponentsUtils componentsUtils;
+ @Mock
+ private ToscaOperationFacade toscaOperationFacade;
+
+ @BeforeEach
+ void setUp() {
+ MockitoAnnotations.openMocks(this);
+ }
+
+ @Test
+ void testConvertToAssetMetadata_emptyComponentList() throws Exception {
+ List<? extends Component> componentList = null;
+ String serverBaseURL = "";
+ boolean detailed = false;
+ Either<List<? extends AssetMetadata>, ResponseFormat> result;
+
+ result = testSubject.convertToAssetMetadata(componentList, serverBaseURL, detailed, null);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ void testConvertToAssetMetadata_withComponentList_Service_without_additionalMetadataKeysToInclude() throws Exception {
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setEsId("mock");
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
+ deploymentArtifacts.put("mock", artifactDefinition);
+ Service component = new Service();
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setComponentType(ComponentTypeEnum.SERVICE);
+ component.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setComponentUid("mock");
+ componentInstance.setOriginType(OriginTypeEnum.VFC);
+ componentInstance.setDeploymentArtifacts(deploymentArtifacts);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+ component.setDeploymentArtifacts(deploymentArtifacts);
+ component.setCategories(Collections.singletonList(new CategoryDefinition()));
+ Map<String, String> categorySpecificMetadata = new HashMap<>();
+ categorySpecificMetadata.put("mock_key", "mock_value");
+ component.setCategorySpecificMetadata(categorySpecificMetadata);
+ String serverBaseURL = "";
+ boolean detailed = true;
+
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
+
+ Either<List<? extends AssetMetadata>, ResponseFormat> result;
+ result = testSubject.convertToAssetMetadata(Collections.singletonList(component), serverBaseURL, detailed, null);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ void testConvertToAssetMetadata_withComponentList_Service_with_additionalMetadataKeysToInclude() throws Exception {
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setEsId("mock");
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
+ deploymentArtifacts.put("mock", artifactDefinition);
+ Service component = new Service();
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setComponentType(ComponentTypeEnum.SERVICE);
+ component.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setComponentUid("mock");
+ componentInstance.setOriginType(OriginTypeEnum.VFC);
+ componentInstance.setDeploymentArtifacts(deploymentArtifacts);
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+ component.setDeploymentArtifacts(deploymentArtifacts);
+ component.setCategories(Collections.singletonList(new CategoryDefinition()));
+ Map<String, String> categorySpecificMetadata = new HashMap<>();
+ categorySpecificMetadata.put("mock_key", "mock_value");
+ component.setCategorySpecificMetadata(categorySpecificMetadata);
+ String serverBaseURL = "";
+ boolean detailed = false;
+
+ Either<List<? extends AssetMetadata>, ResponseFormat> result;
+ List<String> additionalMetadataKeysToInclude = new ArrayList<>();
+ additionalMetadataKeysToInclude.add("description");
+ additionalMetadataKeysToInclude.add("mock_key");
+ result = testSubject.convertToAssetMetadata(Collections.singletonList(component), serverBaseURL, detailed, additionalMetadataKeysToInclude);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ void testConvertToAssetMetadata_withComponentList_Resource() throws Exception {
+ ArtifactDefinition artifactDefinition = new ArtifactDefinition();
+ artifactDefinition.setEsId("mock");
+ artifactDefinition.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
+ Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
+ deploymentArtifacts.put("mock", artifactDefinition);
+ Resource component = new Resource();
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setComponentType(ComponentTypeEnum.RESOURCE);
+ ComponentInstance componentInstance = new ComponentInstance();
+ componentInstance.setComponentUid("mock");
+ componentInstance.setOriginType(OriginTypeEnum.VFC);
+ componentInstance.setDeploymentArtifacts(deploymentArtifacts);
+ componentInstance.setNormalizedName("mock");
+ component.setComponentInstances(Collections.singletonList(componentInstance));
+ component.setDeploymentArtifacts(deploymentArtifacts);
+ CategoryDefinition categoryDefinition = new CategoryDefinition();
+ categoryDefinition.setSubcategories(Collections.singletonList(new SubCategoryDefinition()));
+ component.setCategories(Collections.singletonList(categoryDefinition));
+ Map<String, String> categorySpecificMetadata = new HashMap<>();
+ categorySpecificMetadata.put("mock_key", "mock_value");
+ component.setCategorySpecificMetadata(categorySpecificMetadata);
+ String serverBaseURL = "";
+ boolean detailed = true;
+
+ when(toscaOperationFacade.getToscaElement(anyString())).thenReturn(Either.left(new Resource()));
+
+ Either<List<? extends AssetMetadata>, ResponseFormat> result;
+ List<String> additionalMetadataKeysToInclude = new ArrayList<>();
+ additionalMetadataKeysToInclude.add("description");
+ additionalMetadataKeysToInclude.add("mock_key");
+// additionalMetadataKeysToInclude.add("NoSuchElementException");
+ result = testSubject.convertToAssetMetadata(Collections.singletonList(component), serverBaseURL, detailed, additionalMetadataKeysToInclude);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ void testConvertToSingleAssetMetadata_Resource() throws Exception {
+
+ Resource component = new Resource();
+ String serverBaseURL = "";
+ boolean detailed = false;
+ Either<? extends AssetMetadata, ResponseFormat> result;
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setComponentType(ComponentTypeEnum.RESOURCE);
+
+ result = testSubject.convertToSingleAssetMetadata(component, serverBaseURL, detailed, null);
+ assertTrue(result.isLeft());
+ }
+
+ @Test
+ void testConvertToSingleAssetMetadata_Product() throws Exception {
+
+ Product component = new Product();
+ String serverBaseURL = "";
+ boolean detailed = false;
+ Either<? extends AssetMetadata, ResponseFormat> result;
+ component.setComponentType(ComponentTypeEnum.PRODUCT);
+
+ when(componentsUtils.getResponseFormatAdditionalProperty(ActionStatus.COMPONENT_INVALID_CATEGORY)).thenReturn(new ResponseFormat());
+
+ result = testSubject.convertToSingleAssetMetadata(component, serverBaseURL, detailed, null);
+ assertTrue(result.isRight());
+ }
+
+ @Test
+ void testConvertToSingleAssetMetadata_Service() throws Exception {
+
+ Service component = new Service();
+ String serverBaseURL = "";
+ boolean detailed = false;
+ Either<? extends AssetMetadata, ResponseFormat> result;
+ component.setLifecycleState(LifecycleStateEnum.NOT_CERTIFIED_CHECKIN);
+ component.setComponentType(ComponentTypeEnum.SERVICE);
+ component.setDistributionStatus(DistributionStatusEnum.DISTRIBUTION_NOT_APPROVED);
+
+ result = testSubject.convertToSingleAssetMetadata(component, serverBaseURL, detailed, null);
+ assertTrue(result.isLeft());
+ }
- // default test
- testSubject = createTestSubject();
- result = Deencapsulation.invoke(testSubject, "convertToResourceInstanceMetadata",
- new Object[] { componentInstances, componentType, componentUUID });
- assertThat(result.isLeft()).isTrue();
- }
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServletTest.java
index 87cb31f39b..6c70d68dcc 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AbstractTemplateServletTest.java
@@ -152,7 +152,7 @@ class AbstractTemplateServletTest extends JerseyTest {
Mockito.doReturn(Either.left(resourceAssetMetadata)).when(assetMetadataConverter)
.convertToSingleAssetMetadata(Mockito.eq(resource), Mockito.anyString(),
- Mockito.eq(true));
+ Mockito.eq(true), Mockito.eq(null));
String appConfigDir = "src/test/abstract/config";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java
index d11022a886..5452e29fa7 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/externalapi/servlet/AssetsDataServletTest.java
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
-import fj.data.Either;
import java.util.Arrays;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
@@ -34,6 +33,8 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
+
+import fj.data.Either;
import org.apache.http.HttpStatus;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.server.ResourceConfig;
@@ -97,7 +98,7 @@ class AssetsDataServletTest extends JerseyTest {
private static final LifecycleBusinessLogic lifecycleBusinessLogic = Mockito.mock(LifecycleBusinessLogic.class);
private static final UserBusinessLogic userBusinessLogic = Mockito.mock(UserBusinessLogic.class);
private static final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito
- .mock(ComponentInstanceBusinessLogic.class);
+ .mock(ComponentInstanceBusinessLogic.class);
@BeforeAll
@@ -110,7 +111,7 @@ class AssetsDataServletTest extends JerseyTest {
when(session.getServletContext()).thenReturn(servletContext);
when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR))
- .thenReturn(webAppContextWrapper);
+ .thenReturn(webAppContextWrapper);
when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webApplicationContext);
when(webApplicationContext.getBean(ServletUtils.class)).thenReturn(servletUtils);
@@ -123,8 +124,8 @@ class AssetsDataServletTest extends JerseyTest {
when(resource.getSystemName()).thenReturn("mockvfcmt");
Either<Resource, ResponseFormat> eitherRet = Either.left(resource);
when(componentsUtils
- .convertJsonToObjectUsingObjectMapper(Mockito.any(), Mockito.any(), Mockito.eq(Resource.class),
- Mockito.any(), Mockito.eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherRet);
+ .convertJsonToObjectUsingObjectMapper(Mockito.any(), Mockito.any(), Mockito.eq(Resource.class),
+ Mockito.any(), Mockito.eq(ComponentTypeEnum.RESOURCE))).thenReturn(eitherRet);
when(webApplicationContext.getBean(ResourceImportManager.class)).thenReturn(resourceImportManager);
when(webApplicationContext.getBean(ElementBusinessLogic.class)).thenReturn(elementBusinessLogic);
@@ -132,20 +133,20 @@ class AssetsDataServletTest extends JerseyTest {
when(subCategoryDefinition.getName()).thenReturn("Monitoring Template");
when(categoryDefinition.getSubcategories()).thenReturn(Arrays.asList(subCategoryDefinition));
when(elementBusinessLogic.getAllResourceCategories())
- .thenReturn(Either.left(Arrays.asList(categoryDefinition)));
+ .thenReturn(Either.left(Arrays.asList(categoryDefinition)));
when(resourceBusinessLogic
- .createResource(Mockito.eq(resource), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
- .thenReturn(resource);
+ .createResource(Mockito.eq(resource), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any()))
+ .thenReturn(resource);
when(webApplicationContext.getBean(AssetMetadataConverter.class)).thenReturn(assetMetadataConverter);
when(request.isUserInRole(anyString())).thenReturn(true);
Mockito.doReturn(Either.left(resourceAssetMetadata)).when(assetMetadataConverter)
- .convertToSingleAssetMetadata(Mockito.eq(resource), Mockito.anyString(),
- Mockito.eq(true));
+ .convertToSingleAssetMetadata(Mockito.eq(resource), Mockito.anyString(),
+ Mockito.eq(true), Mockito.eq(null));
String appConfigDir = "src/test/resources/config/catalog-be";
ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(),
- appConfigDir);
+ appConfigDir);
ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
org.openecomp.sdc.be.config.Configuration configuration = new org.openecomp.sdc.be.config.Configuration();
@@ -166,21 +167,21 @@ class AssetsDataServletTest extends JerseyTest {
private static void mockResponseFormat() {
when(componentsUtils.getResponseFormat(Mockito.any(ActionStatus.class), Mockito.any(String[].class)))
- .thenAnswer((Answer<ResponseFormat>) invocation -> {
- ResponseFormat ret;
- final ActionStatus actionStatus = invocation.getArgument(0);
- switch (actionStatus) {
- case CREATED: {
- ret = new ResponseFormat(HttpStatus.SC_CREATED);
- break;
+ .thenAnswer((Answer<ResponseFormat>) invocation -> {
+ ResponseFormat ret;
+ final ActionStatus actionStatus = invocation.getArgument(0);
+ switch (actionStatus) {
+ case CREATED: {
+ ret = new ResponseFormat(HttpStatus.SC_CREATED);
+ break;
+ }
+ default: {
+ ret = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ break;
+ }
}
- default: {
- ret = new ResponseFormat(HttpStatus.SC_INTERNAL_SERVER_ERROR);
- break;
- }
- }
- return ret;
- });
+ return ret;
+ });
}
@@ -188,27 +189,27 @@ class AssetsDataServletTest extends JerseyTest {
void createVfcmtHappyScenario() {
final JSONObject createRequest = buildCreateJsonRequest();
Response response = target().path("/v1/catalog/resources").request(MediaType.APPLICATION_JSON)
- .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, "mockXEcompInstanceId")
- .header(Constants.USER_ID_HEADER, "mockAttID")
- .post(Entity.json(createRequest.toJSONString()), Response.class);
+ .header(Constants.X_ECOMP_INSTANCE_ID_HEADER, "mockXEcompInstanceId")
+ .header(Constants.USER_ID_HEADER, "mockAttID")
+ .post(Entity.json(createRequest.toJSONString()), Response.class);
assertEquals(HttpStatus.SC_CREATED, response.getStatus());
}
private static final String BASIC_CREATE_REQUEST = "{\r\n" +
- " \"name\": \"VFCMT_1\",\r\n" +
- " \"description\": \"VFCMT Description\",\r\n" +
- " \"resourceType\" : \"VFCMT\",\r\n" +
- " \"category\": \"Template\",\r\n" +
- " \"subcategory\": \"Monitoring Template\",\r\n" +
- " \"vendorName\" : \"DCAE\",\r\n" +
- " \"vendorRelease\" : \"1.0\",\r\n" +
- " \"tags\": [\r\n" +
- " \"VFCMT_1\"\r\n" +
- " ],\r\n" +
- " \"icon\" : \"defaulticon\",\r\n" +
- " \"contactId\": \"cs0008\"\r\n" +
- "}";
+ " \"name\": \"VFCMT_1\",\r\n" +
+ " \"description\": \"VFCMT Description\",\r\n" +
+ " \"resourceType\" : \"VFCMT\",\r\n" +
+ " \"category\": \"Template\",\r\n" +
+ " \"subcategory\": \"Monitoring Template\",\r\n" +
+ " \"vendorName\" : \"DCAE\",\r\n" +
+ " \"vendorRelease\" : \"1.0\",\r\n" +
+ " \"tags\": [\r\n" +
+ " \"VFCMT_1\"\r\n" +
+ " ],\r\n" +
+ " \"icon\" : \"defaulticon\",\r\n" +
+ " \"contactId\": \"cs0008\"\r\n" +
+ "}";
private JSONObject buildCreateJsonRequest() {
@@ -222,16 +223,16 @@ class AssetsDataServletTest extends JerseyTest {
ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
forceSet(TestProperties.CONTAINER_PORT, "0");
return new ResourceConfig()
- .register(new CrudExternalServlet(componentInstanceBusinessLogic, componentsUtils,
- servletUtils, resourceImportManager, elementBusinessLogic, assetMetadataConverter,
- lifecycleBusinessLogic, resourceBusinessLogic, serviceBusinessLogic))
- .register(new AbstractBinder() {
-
- @Override
- protected void configure() {
- bind(request).to(HttpServletRequest.class);
- }
- })
- .property("contextConfig", context);
+ .register(new CrudExternalServlet(componentInstanceBusinessLogic, componentsUtils,
+ servletUtils, resourceImportManager, elementBusinessLogic, assetMetadataConverter,
+ lifecycleBusinessLogic, resourceBusinessLogic, serviceBusinessLogic))
+ .register(new AbstractBinder() {
+
+ @Override
+ protected void configure() {
+ bind(request).to(HttpServletRequest.class);
+ }
+ })
+ .property("contextConfig", context);
}
}
diff --git a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
index 327ece3da7..13729bf0b1 100644
--- a/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
+++ b/catalog-model/src/main/java/org/openecomp/sdc/be/model/jsonjanusgraph/operations/ToscaElementOperation.java
@@ -1415,7 +1415,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
return isAddToCatalog;
}
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType,
+ private Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestComponents(ComponentTypeEnum componentType,
List<ResourceTypeEnum> excludeTypes,
JsonParseFlagEnum parseFlag) {
Map<GraphPropertyEnum, Object> propertiesToMatch = new EnumMap<>(GraphPropertyEnum.class);
@@ -1432,7 +1432,7 @@ public abstract class ToscaElementOperation extends BaseOperation {
}
// highest + (certified && !highest)
- public Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType,
+ private Either<List<GraphVertex>, JanusGraphOperationStatus> getListOfHighestAndAllCertifiedComponents(ComponentTypeEnum componentType,
List<ResourceTypeEnum> excludeTypes) {
long startFetchAllStates = System.currentTimeMillis();
Either<List<GraphVertex>, JanusGraphOperationStatus> highestNodes = getListOfHighestComponents(componentType, excludeTypes,
diff --git a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnum.java b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnum.java
index 3ba4ca62cd..522e4e6259 100644
--- a/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnum.java
+++ b/common-be/src/main/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnum.java
@@ -17,6 +17,7 @@ package org.openecomp.sdc.be.datatypes.enums;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+
import lombok.AllArgsConstructor;
import lombok.Getter;
@@ -28,19 +29,21 @@ public enum FilterKeyEnum {
CATEGORY("category"),
VERSION("version"),
METADATA("metadata"),
+ INCLUDE("include"),
DISTRIBUTION_STATUS("distributionStatus"),
NAME_FRAGMENT("nameFragment");
private final String name;
private static final List<String> RESOURCES_FILTERED = Arrays.asList(
- RESOURCE_TYPE.getName(),
- SUB_CATEGORY.getName(),
- CATEGORY.getName());
+ RESOURCE_TYPE.getName(),
+ SUB_CATEGORY.getName(),
+ CATEGORY.getName());
private static final List<String> SERVICES_FILTERED = Arrays.asList(
- CATEGORY.getName(),
- DISTRIBUTION_STATUS.getName(),
- VERSION.getName(),
- METADATA.getName());
+ CATEGORY.getName(),
+ DISTRIBUTION_STATUS.getName(),
+ VERSION.getName(),
+ INCLUDE.getName(),
+ METADATA.getName());
public static List<String> getValidFiltersByAssetType(ComponentTypeEnum assetType) {
if (assetType == null) {
diff --git a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnumTest.java b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnumTest.java
index b08a32fc05..dc0bd1ddc7 100644
--- a/common-be/src/test/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnumTest.java
+++ b/common-be/src/test/java/org/openecomp/sdc/be/datatypes/enums/FilterKeyEnumTest.java
@@ -44,7 +44,7 @@ class FilterKeyEnumTest {
assertFalse(result.contains(VERSION.getName()));
result = FilterKeyEnum.getValidFiltersByAssetType(ComponentTypeEnum.SERVICE);
assertNotNull(result);
- assertEquals(4, result.size());
+ assertEquals(5, result.size());
assertTrue(result.contains(CATEGORY.getName()));
assertFalse(result.contains(RESOURCE_TYPE.getName()));
result = FilterKeyEnum.getValidFiltersByAssetType(ComponentTypeEnum.SERVICE_INSTANCE);