summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
authorpriyanshu <pagarwal@amdocs.com>2018-09-05 18:05:36 +0530
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-09-13 13:00:27 +0000
commitb65c8eeb334a2c579a2dc0241f480d81e9309f9c (patch)
treeb3b3ed06b53703f771da51bec4b40e71b9e1bd1d /catalog-be/src/main/java/org
parentf1e032cf4ae3505eb8acbce56ac978649d6f63d4 (diff)
Interface operation support for service - BE
1. Interface operation support for service 2. Refactored common code of operationspa 3. ONAP Bug fixes VF operations Change-Id: If1c4fd5f17626dbe568ee66ad997eb8ffb772e29 Issue-ID: SDC-1739 Signed-off-by: priyanshu <pagarwal@amdocs.com>
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java11
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java74
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java85
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java10
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java (renamed from catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java)58
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java3
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java52
8 files changed, 152 insertions, 144 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
index e7ae0612f4..fee386ab29 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java
@@ -40,6 +40,7 @@ import org.openecomp.sdc.be.impl.ComponentsUtils;
import org.openecomp.sdc.be.model.*;
import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
import org.openecomp.sdc.be.model.jsontitan.operations.ArtifactsOperations;
+import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
import org.openecomp.sdc.be.model.operations.StorageException;
import org.openecomp.sdc.be.model.operations.api.*;
@@ -122,6 +123,12 @@ public abstract class BaseBusinessLogic {
@Autowired
protected ApplicationDataTypeCache dataTypeCache;
+ @Autowired
+ protected InterfaceOperation interfaceOperation;
+
+ @Autowired
+ protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+
@javax.annotation.Resource
private UserValidations userValidations;
@@ -156,6 +163,10 @@ public abstract class BaseBusinessLogic {
this.propertyOperation = propertyOperation;
}
+ public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
+ this.interfaceOperation = interfaceOperation;
+ }
+
User validateUserNotEmpty(User user, String ecompErrorContext) {
return userValidations.validateUserNotEmpty(user, ecompErrorContext);
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
index 2f4519beb9..792e23af3b 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java
@@ -18,7 +18,7 @@
package org.openecomp.sdc.be.components.impl;
import fj.data.Either;
-import java.util.Arrays;
+import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
@@ -28,9 +28,7 @@ import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
import org.openecomp.sdc.be.model.ArtifactDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.be.model.User;
-import org.openecomp.sdc.be.model.jsontitan.operations.InterfaceOperation;
import org.openecomp.sdc.be.model.jsontitan.utils.InterfaceUtils;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
@@ -55,13 +53,6 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
@Autowired
private InterfaceOperationValidation interfaceOperationValidation;
- @Autowired
- private InterfaceOperation interfaceOperation;
-
- public void setInterfaceOperation(InterfaceOperation interfaceOperation) {
- this.interfaceOperation = interfaceOperation;
- }
-
public void setInterfaceOperationValidation(InterfaceOperationValidation interfaceOperationValidation) {
this.interfaceOperationValidation = interfaceOperationValidation;
}
@@ -74,18 +65,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), DELETE_INTERFACE_OPERATION, true);
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, DELETE_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, DELETE_INTERFACE_OPERATION);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -112,7 +98,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_DELETED));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -126,18 +112,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), GET_INTERFACE_OPERATION, true);
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, GET_INTERFACE_OPERATION);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, GET_INTERFACE_OPERATION);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -158,13 +139,13 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_OPERATION_NOT_FOUND, componentId));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
}
- public Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) {
+ private Either<InterfaceDefinition, ResponseFormat> getInterfaceDefinition(org.openecomp.sdc.be.model.Component component, InterfaceDefinition interfaceDef) {
if (interfaceDef != null){
return Either.left(interfaceDef);
} else {
@@ -195,26 +176,19 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
org.openecomp.sdc.be.model.Component storedComponent = componentEither.left().value();
validateUserExists(user.getUserId(), errorContext, true);
-
- InterfaceUtils.createInputOutput(operation, storedComponent.getInputs(), storedComponent.getInputs());
Either<Boolean, ResponseFormat> interfaceOperationValidationResponseEither = interfaceOperationValidation
- .validateInterfaceOperations(Arrays.asList(operation), storedComponent, isUpdate);
+ .validateInterfaceOperations(Collections.singletonList(operation), storedComponent, isUpdate);
if(interfaceOperationValidationResponseEither.isRight()) {
return Either.right(interfaceOperationValidationResponseEither.right().value());
}
- Either<Boolean, ResponseFormat> lockResult = null;
- if (lock) {
- lockResult = lockComponent(storedComponent.getUniqueId(), storedComponent, errorContext);
- if (lockResult.isRight()) {
- LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, storedComponent.getName(), lockResult.right().value().getFormattedMessage());
- titanDao.rollback();
- return Either.right(lockResult.right().value());
- }
+ Either<Boolean, ResponseFormat> lockResult = lockComponentResult(lock, storedComponent, errorContext);
+ if (lockResult.isRight()) {
+ return Either.right(lockResult.right().value());
}
try {
- Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(((Resource)storedComponent).getInterfaces().values(), storedComponent.getName());
+ Optional<InterfaceDefinition> optionalInterface = InterfaceUtils.getInterfaceDefinitionFromToscaName(storedComponent.getInterfaces().values(), storedComponent.getName());
Either<InterfaceDefinition, ResponseFormat> getInterfaceEither = getInterfaceDefinition(storedComponent, optionalInterface.orElse(null));
if (getInterfaceEither.isRight()) {
return Either.right(getInterfaceEither.right().value());
@@ -250,7 +224,7 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
return Either.right(componentsUtils.getResponseFormat(ActionStatus.GENERAL_ERROR));
}
finally {
- if (lockResult != null && lockResult.isLeft() && lockResult.left().value()) {
+ if (lockResult.isLeft() && lockResult.left().value()) {
graphLockOperation.unlockComponent(storedComponent.getUniqueId(), NodeTypeEnum.getByNameIgnoreCase(storedComponent.getComponentType().getValue()));
}
}
@@ -287,4 +261,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
operation.setUniqueId(UUID.randomUUID().toString());
operation.setImplementation(artifactDefinition);
}
+
+ private Either<Boolean, ResponseFormat> lockComponentResult(boolean lock, org.openecomp.sdc.be.model.Component component, String action){
+ if (lock) {
+ Either<Boolean, ResponseFormat> lockResult = lockComponent(component.getUniqueId(), component, action);
+ if (lockResult.isRight()) {
+ LOGGER.debug(FAILED_TO_LOCK_COMPONENT_RESPONSE_IS, component.getName(), lockResult.right().value().getFormattedMessage());
+ titanDao.rollback();
+ return Either.right(lockResult.right().value());
+ }
+ }
+ return Either.left(true);
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
index affafaed12..8c90501140 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/validation/InterfaceOperationValidation.java
@@ -17,29 +17,33 @@
package org.openecomp.sdc.be.components.validation;
import fj.data.Either;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.elasticsearch.common.Strings;
import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
+import org.openecomp.sdc.be.datatypes.elements.ListDataDefinition;
+import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
+import org.openecomp.sdc.be.model.InputDefinition;
import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.Operation;
-import org.openecomp.sdc.be.model.Resource;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
@Component("interfaceOperationValidation")
public class InterfaceOperationValidation {
@@ -77,6 +81,13 @@ public class InterfaceOperationValidation {
return Either.right(descriptionResponseEither.right().value());
}
+ Either<Boolean, ResponseFormat> inputPropertyExistInComponent = validateInputPropertyExistInComponent(interfaceOperation,
+ component.getInputs(), responseFormatManager);
+ if(inputPropertyExistInComponent.isRight()) {
+ return Either.right(inputPropertyExistInComponent.right().value());
+
+ }
+
Either<Boolean, ResponseFormat> inputParametersResponse = validateInputParameters(interfaceOperation,
responseFormatManager);
if(inputParametersResponse.isRight()) {
@@ -109,14 +120,14 @@ public class InterfaceOperationValidation {
}
Either<Boolean, ResponseFormat> operationTypeUniqueResponse = validateOperationTypeUnique(interfaceOperation,
- component, isUpdate, responseFormatManager );
+ component, isUpdate );
if(operationTypeUniqueResponse.isRight()) {
return Either.right(operationTypeUniqueResponse.right().value());
}
if (!operationTypeUniqueResponse.left().value()) {
LOGGER.error("Interface Operation type {} already in use ", interfaceOperation.getName());
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_ALREADY_IN_USE, interfaceOperation.getName());
+ .INTERFACE_OPERATION_NAME_ALREADY_IN_USE, interfaceOperation.getName());
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -128,7 +139,7 @@ public class InterfaceOperationValidation {
LOGGER.error("Interface Operation type {} is invalid, Operation type should not contain" +
"Special character, space, numbers and should not be greater than 200 characters", operationType);
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_INVALID, operationType);
+ .INTERFACE_OPERATION_NAME_INVALID, operationType);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -139,7 +150,7 @@ public class InterfaceOperationValidation {
if (StringUtils.isEmpty(operationType)) {
LOGGER.error("Interface Operation type is mandatory");
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_TYPE_MANDATORY);
+ .INTERFACE_OPERATION_NAME_MANDATORY);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -150,7 +161,7 @@ public class InterfaceOperationValidation {
if (!Strings.isNullOrEmpty(description) && description.length() > DESCRIPTION_MAX_LENGTH) {
LOGGER.error("Interface Operation description {} is invalid, maximum 200 characters allowed", description);
ResponseFormat errorResponse = responseFormatManager.getResponseFormat(ActionStatus
- .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH);
+ .INTERFACE_OPERATION_DESCRIPTION_MAX_LENGTH, description);
return Either.right(errorResponse);
}
return Either.left(Boolean.TRUE);
@@ -163,14 +174,12 @@ public class InterfaceOperationValidation {
private Either<Boolean, ResponseFormat> validateOperationTypeUnique(
Operation interfaceOperation,
org.openecomp.sdc.be.model.Component component,
- boolean isUpdate,
- ResponseFormatManager responseFormatManager) {
+ boolean isUpdate) {
boolean isOperationTypeUnique = false;
- Map<String, InterfaceDefinition> interfaceDefinitionMap = ((Resource)component).getInterfaces();
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = component.getInterfaces();
if(interfaceDefinitionMap.isEmpty()){
- isOperationTypeUnique = true;
- return Either.left(isOperationTypeUnique);
+ return Either.left(true);
}
Collection<Operation> allOperations = interfaceDefinitionMap.values().stream()
@@ -178,8 +187,7 @@ public class InterfaceOperationValidation {
.map(a -> a.getOperationsMap().values()).flatMap(Collection::stream)
.collect(Collectors.toList());
if(CollectionUtils.isEmpty(allOperations)){
- isOperationTypeUnique = true;
- return Either.left(isOperationTypeUnique);
+ return Either.left(true);
}
Map<String, String> operationTypes = new HashMap<>();
@@ -236,8 +244,6 @@ public class InterfaceOperationValidation {
}
return Either.left(Boolean.TRUE);
}
-
-
private Either<Boolean, Set<String>> isInputParametersUnique(Operation operationDataDefinition) {
Set<String> inputParamNamesSet = new HashSet<>();
Set<String> duplicateParamNamesToReturn = new HashSet<>();
@@ -277,17 +283,32 @@ public class InterfaceOperationValidation {
.anyMatch(inputParam -> inputParam.getName() == null || inputParam.getName().trim().equals(StringUtils.EMPTY));
}
- private boolean validateOperationTypeUniqueForUpdate(Operation interfaceOperation, Map<String, String> operationTypes) {
- boolean isOperationTypeUnique = false;
- Optional<String> id = operationTypes.entrySet().stream().filter(entry -> Objects.equals(entry.getValue(), interfaceOperation.getName()))
- .map(Map.Entry::getKey).findAny();
- if(id.isPresent() && id.get().equalsIgnoreCase(interfaceOperation.getUniqueId())){
- isOperationTypeUnique = true;
+ private Either<Boolean, ResponseFormat> validateInputPropertyExistInComponent(Operation operation,
+ List<InputDefinition> inputs,
+ ResponseFormatManager responseFormatManager) {
+ ListDataDefinition<OperationInputDefinition> inputDefinitionListDataDefinition = operation.getInputs();
+ if (inputDefinitionListDataDefinition == null) {
+ return Either.left(Boolean.TRUE);
+ }
+ List<OperationInputDefinition> inputListToscaDataDefinition = inputDefinitionListDataDefinition.getListToscaDataDefinition();
+
+ for(OperationInputDefinition inputDefinition : inputListToscaDataDefinition ) {
+ if(!validateInputExistsInComponent(inputDefinition, inputs)) {
+ String missingPropertyName = inputDefinition.getInputId().contains(".") ? inputDefinition.getInputId().substring(inputDefinition.getInputId().indexOf(".") + 1) : inputDefinition.getInputId();
+ LOGGER.error("Interface operation input property {} not found in component input properties", missingPropertyName);
+ ResponseFormat inputResponse = responseFormatManager.getResponseFormat(ActionStatus.INTERFACE_OPERATION_INPUT_PROPERTY_NOT_FOUND_IN_COMPONENT, missingPropertyName);
+ return Either.right(inputResponse);
+ }
}
- return isOperationTypeUnique;
+ return Either.left(Boolean.TRUE);
+ }
+
+ private boolean validateInputExistsInComponent(OperationInputDefinition input,
+ List<InputDefinition> inputs) {
+ return inputs.stream().anyMatch(inp -> inp.getUniqueId().equals(input.getInputId()));
}
- protected ResponseFormatManager getResponseFormatManager() {
+ private ResponseFormatManager getResponseFormatManager() {
return ResponseFormatManager.getInstance();
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
index f0cdf3ec70..bdbf20a2b7 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/InterfaceUIDataConverter.java
@@ -40,7 +40,7 @@ public class InterfaceUIDataConverter {
.map(interfaceOperationParamDataDefinition -> new OperationInputDefinition(
interfaceOperationParamDataDefinition.getName(),
interfaceOperationParamDataDefinition.getProperty(),
- interfaceOperationParamDataDefinition.getMandatory(),
+ interfaceOperationParamDataDefinition.getMandatory() == null ? false : interfaceOperationParamDataDefinition.getMandatory(),
interfaceOperationParamDataDefinition.getType()
)).collect(Collectors.toList());
inputList.forEach(inputs::add);
@@ -70,7 +70,6 @@ public class InterfaceUIDataConverter {
}
public static InterfaceOperationDataDefinition convertOperationDataToInterfaceData(Operation operationData){
-
ListDataDefinition<OperationInputDefinition> inputs = operationData.getInputs();
List<InterfaceOperationParamDataDefinition> inputParamList = inputs.getListToscaDataDefinition().stream()
.map(operationInputDefinition -> new InterfaceOperationParamDataDefinition(operationInputDefinition.getName(),
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
index a3731dd9b9..899a7b1cb8 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/datamodel/utils/UiComponentDataConverter.java
@@ -339,6 +339,9 @@ public class UiComponentDataConverter {
UiServiceMetadata metadata = new UiServiceMetadata(service.getCategories(), (ServiceMetadataDataDefinition) service.getComponentMetadataDefinition().getMetadataDataDefinition());
dataTransfer.setMetadata(metadata);
break;
+ case INTERFACES:
+ setInterfaces(service, dataTransfer);
+ break;
default:
setUiTranferDataByFieldName(dataTransfer, service, fieldName);
}
@@ -362,6 +365,13 @@ public class UiComponentDataConverter {
}
}
+ private void setInterfaces(Service service, UiServiceDataTransfer dataTransfer) {
+ if (service.getInterfaces() == null) {
+ dataTransfer.setInterfaces(new HashMap<>());
+ } else {
+ dataTransfer.setInterfaces(service.getInterfaces());
+ }
+ }
public static UiComponentMetadata convertToUiComponentMetadata(Component component) {
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
index 3e43dd7a91..815f9763f9 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/ResourceInterfaceOperationServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/InterfaceOperationServlet.java
@@ -49,21 +49,21 @@ import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.model.Operation;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
-import org.openecomp.sdc.be.ui.model.UiResourceDataTransfer;
+import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.exception.ResponseFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Loggable(prepend = true, value = Loggable.DEBUG, trim = false)
-@Path("/v1/catalog/resources/{resourceId}/interfaceOperations")
+@Path("/v1/catalog/{componentType}/{componentId}/interfaceOperations")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Api(value = "Interface Operation", description = "Interface Operation Servlet")
@Singleton
-public class ResourceInterfaceOperationServlet extends AbstractValidationsServlet {
+public class InterfaceOperationServlet extends AbstractValidationsServlet {
- private static final Logger log = LoggerFactory.getLogger(ResourceInterfaceOperationServlet.class);
+ private static final Logger log = LoggerFactory.getLogger(InterfaceOperationServlet.class);
@POST
@Consumes(MediaType.APPLICATION_JSON)
@@ -76,10 +76,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 409, message = "Interface Operation already exist")})
public Response createInterfaceOperation(
@ApiParam(value = "Interface Operation to create", required = true) String data,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component type") @PathParam("componentType") String componentType,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, resourceId, request, userId, false);
+ return createOrUpdate(data, componentType ,componentId, request, userId, false);
}
@PUT
@@ -92,10 +93,11 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response updateInterfaceOperation(
@ApiParam(value = "Interface Operation to update", required = true) String data,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component type") @PathParam("componentType") String componentType,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return createOrUpdate(data, resourceId, request, userId, true);
+ return createOrUpdate(data, componentType,componentId, request, userId, true);
}
@DELETE
@@ -108,10 +110,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response deleteInterfaceOperation(
@ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return delete(interfaceOperationId, resourceId, request, userId);
+ return delete(interfaceOperationId, componentId, request, userId);
}
@GET
@@ -124,14 +126,14 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
@ApiResponse(code = 400, message = "Invalid content / Missing content")})
public Response getInterfaceOperation(
@ApiParam(value = "Interface Operation Id") @PathParam("interfaceOperationId") String interfaceOperationId,
- @ApiParam(value = "Resource Id") @PathParam("resourceId") String resourceId,
+ @ApiParam(value = "Component Id") @PathParam("componentId") String componentId,
@Context final HttpServletRequest request,
@HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
- return get(interfaceOperationId, resourceId, request, userId);
+ return get(interfaceOperationId, componentId, request, userId);
}
- private Response get (String interfaceOperationId, String resourceId, HttpServletRequest request, String userId){
+ private Response get (String interfaceOperationId, String componentId, HttpServletRequest request, String userId){
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
@@ -140,10 +142,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start get request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
+ Either<Operation, ResponseFormat> actionResponse = businessLogic.getInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
log.error("failed to get interface operation");
return buildErrorResponse(actionResponse.right().value());
@@ -154,13 +156,13 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), result);
}
catch (Exception e) {
- BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Resource interface operations");
- log.error("get resource interface operations failed with exception", e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError("Get Component interface operations");
+ log.error("get component interface operations failed with exception", e);
return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
}
}
- private Response delete (String interfaceOperationId, String resourceId, HttpServletRequest
+ private Response delete (String interfaceOperationId, String componentId, HttpServletRequest
request, String userId){
ServletContext context = request.getSession().getServletContext();
@@ -171,10 +173,10 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start delete request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(resourceIdLower, interfaceOperationId, modifier, true);
+ Either<Operation, ResponseFormat> actionResponse = businessLogic.deleteInterfaceOperation(componentIdLower, interfaceOperationId, modifier, true);
if (actionResponse.isRight()) {
log.error("failed to delete interface operation");
return buildErrorResponse(actionResponse.right().value());
@@ -191,7 +193,7 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
}
- private Response createOrUpdate (String data, String resourceId, HttpServletRequest request, String userId, boolean isUpdate) {
+ private Response createOrUpdate (String data, String componentType, String componentId, HttpServletRequest request, String userId, boolean isUpdate) {
ServletContext context = request.getSession().getServletContext();
String url = request.getMethod() + " " + request.getRequestURI();
@@ -200,15 +202,15 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
log.debug("Start create or update request of {} with modifier id {}", url, userId);
try {
- String resourceIdLower = resourceId.toLowerCase();
+ String componentIdLower = componentId.toLowerCase();
InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
- Operation operation = getMappedOperationData(data, isUpdate, modifier);
+ Operation operation = getMappedOperationData(data, isUpdate, modifier, ComponentTypeEnum.findByParamName(componentType));
Either<Operation, ResponseFormat> actionResponse ;
if (isUpdate) {
- actionResponse = businessLogic.updateInterfaceOperation(resourceIdLower, operation, modifier, true);
+ actionResponse = businessLogic.updateInterfaceOperation(componentIdLower, operation, modifier, true);
} else {
- actionResponse = businessLogic.createInterfaceOperation(resourceIdLower, operation, modifier, true);
+ actionResponse = businessLogic.createInterfaceOperation(componentIdLower, operation, modifier, true);
}
if (actionResponse.isRight()) {
@@ -227,9 +229,9 @@ public class ResourceInterfaceOperationServlet extends AbstractValidationsServle
}
}
- private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user){
- Either<UiResourceDataTransfer, ResponseFormat> uiResourceEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiResourceDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, ComponentTypeEnum.RESOURCE);
- Optional<InterfaceOperationDataDefinition> opDef = uiResourceEither.left().value().getInterfaceOperations().values().stream().findFirst();
+ private Operation getMappedOperationData(String inputJson, boolean isUpdate, User user, ComponentTypeEnum componentTypeEnum){
+ Either<UiComponentDataTransfer, ResponseFormat> uiComponentEither = getComponentsUtils().convertJsonToObjectUsingObjectMapper(inputJson, user, UiComponentDataTransfer.class, AuditingActionEnum.CREATE_RESOURCE, componentTypeEnum);
+ Optional<InterfaceOperationDataDefinition> opDef = uiComponentEither.left().value().getInterfaceOperations().values().stream().findFirst();
InterfaceOperationDataDefinition interfaceOperationDataDefinition = new InterfaceOperationDataDefinition();
if(opDef.isPresent()) {
interfaceOperationDataDefinition = opDef.get();
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
index e5e5f1648a..d62c2c64eb 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/ToscaExportHandler.java
@@ -561,7 +561,7 @@ public class ToscaExportHandler {
List<InputDefinition> inputDef = component.getInputs();
Map<String, ToscaProperty> inputs = new HashMap<>();
-
+ addInterfaceDefinitionElement(component, toscaNodeType);
if (inputDef != null) {
inputDef.forEach(i -> {
ToscaProperty property = propertyConvertor.convertProperty(dataTypes, i, false);
@@ -569,7 +569,6 @@ public class ToscaExportHandler {
});
if (!inputs.isEmpty()) {
toscaNodeType.setProperties(inputs);
- addInterfaceDefinitionElement(component, toscaNodeType);
}
}
return convertReqCapAndTypeName(componentsCache, component, toscaNode, nodeTypes, toscaNodeType, dataTypes);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
index 75a65f95da..5370a7849e 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/tosca/utils/InterfacesOperationsToscaUtil.java
@@ -18,29 +18,25 @@ package org.openecomp.sdc.be.tosca.utils;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+
import org.apache.commons.collections.MapUtils;
import org.openecomp.sdc.be.datatypes.elements.OperationDataDefinition;
import org.openecomp.sdc.be.datatypes.elements.OperationInputDefinition;
import org.openecomp.sdc.be.model.Component;
import org.openecomp.sdc.be.model.InterfaceDefinition;
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.tosca.model.ToscaInterfaceDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaInterfaceNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaLifecycleOperationDefinition;
import org.openecomp.sdc.be.tosca.model.ToscaNodeType;
import org.openecomp.sdc.be.tosca.model.ToscaProperty;
-/**
- * @author KATYR
- * @since March 20, 2018
- */
public class InterfacesOperationsToscaUtil {
@@ -50,7 +46,6 @@ public class InterfacesOperationsToscaUtil {
private static final String DEFAULT = "default";
private static final String DEFAULT_HAS_UNDERSCORE = "_default";
private static final String DOT = ".";
- private static final String DEFAULT_INPUT_TYPE = "string";
private static final String SELF = "SELF";
private static final String GET_PROPERTY = "get_property";
private static final String DEFAULTP = "defaultp";
@@ -65,16 +60,11 @@ public class InterfacesOperationsToscaUtil {
* @return the added element
*/
public static Map<String, Object> addInterfaceTypeElement(Component component) {
- Map<String, Object> toscaInterfaceTypes = new HashMap<>();
- if ((component instanceof Service) || (component instanceof Product)) {
- return null;
- }
-
- final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
- if (MapUtils.isEmpty(interfaces)) {
+ if (component instanceof Product) {
return null;
}
-
+ final Map<String, InterfaceDefinition> interfaces = component.getInterfaces();
+ Map<String, Object> toscaInterfaceTypes = new HashMap<>();
for (InterfaceDefinition interfaceDefinition : interfaces.values()) {
ToscaInterfaceNodeType toscaInterfaceType = new ToscaInterfaceNodeType();
toscaInterfaceType.setDerived_from(DERIVED_FROM_STANDARD_INTERFACE);
@@ -86,8 +76,6 @@ public class InterfacesOperationsToscaUtil {
toscaOperations.put(operationEntry.getValue().getName(),
null); //currently not initializing any of the operations' fields as it is not needed
}
-
-
toscaInterfaceType.setOperations(toscaOperations);
Map<String, Object> interfacesAsMap = getObjectAsMap(toscaInterfaceType);
Map<String, Object> operationsMap = (Map<String, Object>) interfacesAsMap.remove(OPERATIONS_KEY);
@@ -95,7 +83,7 @@ public class InterfacesOperationsToscaUtil {
toscaInterfaceTypes.put(interfaceDefinition.getToscaResourceName(), interfacesAsMap);
}
- return toscaInterfaceTypes;
+ return MapUtils.isNotEmpty(toscaInterfaceTypes) ? toscaInterfaceTypes : null;
}
/**
@@ -105,16 +93,14 @@ public class InterfacesOperationsToscaUtil {
* @param nodeType to which the interfaces element will be added
*/
public static void addInterfaceDefinitionElement(Component component, ToscaNodeType nodeType) {
- Map<String, Object> toscaInterfaceDefinitions = new HashMap<>();
-
- if ((component instanceof Service) || (component instanceof Product)) {
+ if (component instanceof Product) {
return;
}
-
- final Map<String, InterfaceDefinition> interfaces = ((Resource) component).getInterfaces();
+ final Map<String, InterfaceDefinition> interfaces = component.getInterfaces();
if (MapUtils.isEmpty(interfaces)) {
return;
}
+ Map<String, Object> toscaInterfaceDefinitions = new HashMap<>();
for (InterfaceDefinition interfaceDefinition : interfaces.values()) {
ToscaInterfaceDefinition toscaInterfaceDefinition = new ToscaInterfaceDefinition();
final String toscaResourceName = interfaceDefinition.getToscaResourceName();
@@ -133,7 +119,7 @@ public class InterfacesOperationsToscaUtil {
toscaOperation.setImplementation(operationArtifactPath);
}
toscaOperation.setDescription(operationEntry.getValue().getDescription());
- fillToscaOperationInputs(operationEntry.getValue(), toscaOperation, nodeType);
+ fillToscaOperationInputs(operationEntry.getValue(), toscaOperation);
toscaOperations.put(operationEntry.getValue().getName(), toscaOperation);
}
@@ -145,7 +131,9 @@ public class InterfacesOperationsToscaUtil {
interfaceDefAsMap.putAll(operationsMap);
toscaInterfaceDefinitions.put(getLastPartOfName(toscaResourceName), interfaceDefAsMap);
}
- nodeType.setInterfaces(toscaInterfaceDefinitions);
+ if (MapUtils.isNotEmpty(toscaInterfaceDefinitions)) {
+ nodeType.setInterfaces(toscaInterfaceDefinitions);
+ }
}
/***
@@ -180,8 +168,7 @@ public class InterfacesOperationsToscaUtil {
}
private static void fillToscaOperationInputs(OperationDataDefinition operation,
- ToscaLifecycleOperationDefinition toscaOperation,
- ToscaNodeType nodeType) {
+ ToscaLifecycleOperationDefinition toscaOperation) {
if (Objects.isNull(operation.getInputs()) || operation.getInputs().isEmpty()) {
toscaOperation.setInputs(null);
return;
@@ -192,22 +179,15 @@ public class InterfacesOperationsToscaUtil {
ToscaProperty toscaInput = new ToscaProperty();
toscaInput.setDescription(input.getDescription());
String mappedPropertyName = getLastPartOfName(input.getInputId());
- toscaInput.setType(getOperationInputType(mappedPropertyName, nodeType));
+ toscaInput.setType(input.getType());
toscaInput.setDefaultp(createDefaultValue(mappedPropertyName));
+ toscaInput.setRequired(input.isRequired());
toscaInputs.put(input.getName(), toscaInput);
}
toscaOperation.setInputs(toscaInputs);
}
- private static String getOperationInputType(String inputName, ToscaNodeType nodeType) {
- if (nodeType.getProperties() != null
- && nodeType.getProperties().containsKey(inputName)) {
- return nodeType.getProperties().get(inputName).getType();
- }
- return DEFAULT_INPUT_TYPE;
- }
-
private static Map<String, List<String>> createDefaultValue(String propertyName) {
Map<String, List<String>> getPropertyMap = new HashMap<>();
List<String> values = new ArrayList<>();