summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
authorshrikantawachar <shrikant.awachar@amdocs.com>2018-12-17 12:26:43 +0530
committershrikantawachar <shrikant.awachar@amdocs.com>2018-12-19 15:08:44 +0530
commitb6e7850484ba61df259e38fd6b59e94c2a7de5b6 (patch)
treeb235bafe42063bea899602c54d8f437c26227c77 /catalog-be/src
parente7cdba9c8a87f6dfd4823214ca64016e69b45a16 (diff)
API for get all interface lifecycle types
API for get all interface lifecycle types Change-Id: I64471c98ff9626ac53562a075a34f506c2e263ab Issue-ID: SDC-1999 Signed-off-by: shrikantawachar <shrikant.awachar@amdocs.com>
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/BaseBusinessLogic.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogic.java13
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java51
-rw-r--r--catalog-be/src/main/resources/config/error-configuration.yaml7
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java23
5 files changed, 100 insertions, 2 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 453564e2f8..02e64334f9 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
@@ -45,6 +45,7 @@ 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.*;
import org.openecomp.sdc.be.model.operations.impl.DaoStatusConverter;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.model.operations.impl.PolicyTypeOperation;
import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
import org.openecomp.sdc.be.model.operations.utils.ComponentValidationUtils;
@@ -129,6 +130,9 @@ public abstract class BaseBusinessLogic {
@Autowired
protected InterfaceOperationBusinessLogic interfaceOperationBusinessLogic;
+ @Autowired
+ protected InterfaceLifecycleOperation interfaceLifecycleOperation;
+
@javax.annotation.Resource
private UserValidations userValidations;
@@ -171,6 +175,10 @@ public abstract class BaseBusinessLogic {
}
+ public void setInterfaceLifecycleOperation(InterfaceLifecycleOperation interfaceLifecycleOperation) {
+ this.interfaceLifecycleOperation = interfaceLifecycleOperation;
+ }
+
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 fed2cac518..a0efddbdda 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
@@ -41,6 +41,7 @@ import java.util.Collections;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
+import java.util.stream.Collectors;
@Component("interfaceOperationBusinessLogic")
public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
@@ -324,4 +325,16 @@ public class InterfaceOperationBusinessLogic extends BaseBusinessLogic {
}
return Either.left( interfaceDefinition);
}
+
+ public Either<Map<String, InterfaceDefinition>, ResponseFormat> getAllInterfaceLifecycleTypes() {
+
+ Either<Map<String, InterfaceDefinition>, StorageOperationStatus> interfaceLifecycleTypes = interfaceLifecycleOperation.getAllInterfaceLifecycleTypes();
+ if(interfaceLifecycleTypes.isRight()) {
+ return Either.right(componentsUtils.getResponseFormat(ActionStatus.INTERFACE_LIFECYCLE_TYPES_NOT_FOUND));
+ }
+ interfaceLifecycleTypes.left().value().values().stream().forEach(
+ id -> id.setOperations(id.getOperations().keySet().stream().collect(Collectors.toMap(key -> key.replaceFirst(id.getUniqueId()+".",""), i -> id.getOperations().get(i)))));
+
+ return Either.left(interfaceLifecycleTypes.left().value());
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
index 8bb93a7d3d..ddb405779d 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesFetchServlet.java
@@ -26,11 +26,13 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import org.openecomp.sdc.be.components.impl.InterfaceOperationBusinessLogic;
import org.openecomp.sdc.be.components.impl.PropertyBusinessLogic;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.dao.api.ActionStatus;
import org.openecomp.sdc.be.impl.WebAppContextWrapper;
import org.openecomp.sdc.be.model.DataTypeDefinition;
+import org.openecomp.sdc.be.model.InterfaceDefinition;
import org.openecomp.sdc.be.model.User;
import org.openecomp.sdc.common.api.Constants;
import org.openecomp.sdc.common.datastructure.Wrapper;
@@ -109,4 +111,53 @@ public class TypesFetchServlet extends AbstractValidationsServlet {
return webApplicationContext.getBean(PropertyBusinessLogic.class);
}
+ @GET
+ @Path("interfaceLifecycleTypes")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @ApiOperation(value = "Get interface lifecycle types", httpMethod = "GET", notes = "Returns interface lifecycle types", response = Response.class)
+ @ApiResponses(value = {
+ @ApiResponse(code = 200, message = "Interface lifecycle types"),
+ @ApiResponse(code = 403, message = "Restricted operation"),
+ @ApiResponse(code = 400, message = "Invalid content / Missing content"),
+ @ApiResponse(code = 404, message = "Interface lifecycle types not found")
+ })
+ public Response getInterfaceLifecycleTypes(@Context final HttpServletRequest request, @HeaderParam(value = Constants.USER_ID_HEADER) String userId) {
+
+ Wrapper<Response> responseWrapper = new Wrapper<>();
+ Wrapper<User> userWrapper = new Wrapper<>();
+ ServletContext context = request.getSession().getServletContext();
+
+ try {
+ validateUserExist(responseWrapper, userWrapper, userId);
+
+ if (responseWrapper.isEmpty()) {
+ String url = request.getMethod() + " " + request.getRequestURI();
+ log.info("Start handle request of {} | modifier id is {}", url, userId);
+
+ InterfaceOperationBusinessLogic businessLogic = getInterfaceOperationBL(context);
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> allInterfaceLifecycleTypes =
+ businessLogic.getAllInterfaceLifecycleTypes();
+
+ if (allInterfaceLifecycleTypes.isRight()) {
+ log.info("Failed to get all interface lifecycle types. Reason - {}",
+ allInterfaceLifecycleTypes.right().value());
+ Response errorResponse = buildErrorResponse(allInterfaceLifecycleTypes.right().value());
+ responseWrapper.setInnerElement(errorResponse);
+
+ } else {
+ String interfaceLifecycleTypeJson = gson.toJson(allInterfaceLifecycleTypes.left().value());
+ Response okResponse = buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK), interfaceLifecycleTypeJson);
+ responseWrapper.setInnerElement(okResponse);
+
+ }
+ }
+
+ return responseWrapper.getInnerElement();
+ } catch (Exception e) {
+ log.debug("get all interface lifecycle types failed with exception", e);
+ ResponseFormat responseFormat = getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR);
+ return buildErrorResponse(responseFormat);
+ }
+ }
}
diff --git a/catalog-be/src/main/resources/config/error-configuration.yaml b/catalog-be/src/main/resources/config/error-configuration.yaml
index aa000f14a7..84213bbe8d 100644
--- a/catalog-be/src/main/resources/config/error-configuration.yaml
+++ b/catalog-be/src/main/resources/config/error-configuration.yaml
@@ -2153,4 +2153,9 @@ errors:
message: "Error: Interface operation output parameter name should not be empty.",
messageId: "SVC4706"
}
-
+#---------SVC4712-----------------------------
+ INTERFACE_LIFECYCLE_TYPES_NOT_FOUND: {
+ code: 404,
+ message: "Error: Interface Lifecycle types not found.",
+ messageId: "SVC4712"
+ } \ No newline at end of file
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
index 4227e5d5cc..f2d8b57dbf 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/impl/InterfaceOperationBusinessLogicTest.java
@@ -70,6 +70,7 @@ import org.openecomp.sdc.be.model.operations.api.IElementOperation;
import org.openecomp.sdc.be.model.operations.api.IPropertyOperation;
import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
import org.openecomp.sdc.be.user.Role;
import org.openecomp.sdc.be.user.UserBusinessLogic;
import org.openecomp.sdc.common.api.ConfigurationSource;
@@ -106,6 +107,7 @@ public class InterfaceOperationBusinessLogicTest {
private final ArtifactCassandraDao artifactCassandraDao = Mockito.mock(ArtifactCassandraDao.class);
private final InterfaceOperation interfaceOperation = Mockito.mock(InterfaceOperation.class);
private final InterfaceOperationValidation operationValidator = Mockito.mock(InterfaceOperationValidation.class);
+ private InterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(InterfaceLifecycleOperation.class);
private final GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
private User user = null;
@@ -192,6 +194,7 @@ public class InterfaceOperationBusinessLogicTest {
bl.setUserValidations(userValidations);
bl.setInterfaceOperation(interfaceOperation);
bl.setInterfaceOperationValidation(operationValidator);
+ bl.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
Resource resourceCsar = createResourceObjectCsar(true);
setCanWorkOnResource(resourceCsar);
Either<Component, StorageOperationStatus> oldResourceRes = Either.left(resourceCsar);
@@ -423,6 +426,24 @@ public class InterfaceOperationBusinessLogicTest {
return resource;
}
+ @Test
+ public void testGetAllInterfaceLifecycleTypes_TypesNotFound() {
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.right(StorageOperationStatus.NOT_FOUND));
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> response = bl.getAllInterfaceLifecycleTypes();
+ Assert.assertTrue(response.isRight());
+ }
-
+ @Test
+ public void testGetAllInterfaceLifecycleTypes_Success() {
+ final String UNIQUE_ID = "UNIQUE_ID";
+ final String TYPE = "UNIQUE_ID";
+ InterfaceDefinition interfaceDefinition = new InterfaceDefinition();
+ interfaceDefinition.setUniqueId(UNIQUE_ID);
+ interfaceDefinition.setType(TYPE);
+ Map<String, InterfaceDefinition> interfaceDefinitionMap = new HashMap<>();
+ interfaceDefinitionMap.put(interfaceDefinition.getUniqueId(), interfaceDefinition);
+ when(interfaceLifecycleOperation.getAllInterfaceLifecycleTypes()).thenReturn(Either.left(interfaceDefinitionMap));
+ Either<Map<String, InterfaceDefinition>, ResponseFormat> response = bl.getAllInterfaceLifecycleTypes();
+ Assert.assertEquals(response.left().value().size(),1);
+ }
} \ No newline at end of file