summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src/main/java/org')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java15
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java58
3 files changed, 76 insertions, 5 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
index 474df3f9e5..bfbebf398a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/CommonImportManager.java
@@ -127,7 +127,10 @@ public class CommonImportManager {
private Map<String, Object> convertToFieldMap(String elementTypesYml) {
Map<String, Object> toscaJson = null;
try {
- toscaJson = (Map<String, Object>) new Yaml().load(elementTypesYml);
+ toscaJson = new Yaml().load(elementTypesYml);
+ if (toscaJson.containsKey("data_types")){
+ toscaJson = (Map<String, Object>) toscaJson.get("data_types");
+ }
} catch (Exception e) {
log.debug("Failed to yaml file {}", elementTypesYml, e);
}
@@ -276,11 +279,9 @@ public class CommonImportManager {
eitherResult = handleType(elementType, validator, elementInfoGetter, elementFetcher, elementAdder, elementUpgrader)
.left()
.map(elem -> append(createdElementTypes, elem));
-
if (eitherResult.isRight()) {
break;
}
-
if (!elementTypeItr.hasNext()) {
log.info("all {} were created successfully!!!", elementType);
}
@@ -295,7 +296,6 @@ public class CommonImportManager {
propertyOperation.getJanusGraphGenericDao().rollback();
}
}
-
return eitherResult;
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
index 8139237e38..a7327bf184 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/DataTypeServlet.java
@@ -163,4 +163,19 @@ public class DataTypeServlet extends BeGenericServlet {
return Response.status(Status.CREATED).entity(property).build();
}
+ @GET
+ @Path("{dataTypeName}/models")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Get models for type", method = "GET", summary = "Returns list of models for type", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "200", description = "dataTypeModels"), @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "404", description = "Data type not found")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response getDataTypeModels(@PathParam("dataTypeName") String dataTypeName) {
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.OK),
+ gson.toJson(dataTypeOperation.getAllDataTypeModels(dataTypeName)));
+ }
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
index 786c0338c4..4fcc3c0842 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/TypesUploadServlet.java
@@ -31,7 +31,9 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.servers.Server;
import io.swagger.v3.oas.annotations.tags.Tag;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -49,6 +51,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.glassfish.jersey.media.multipart.FormDataParam;
+import org.jetbrains.annotations.NotNull;
import org.openecomp.sdc.be.components.impl.ArtifactTypeImportManager;
import org.openecomp.sdc.be.components.impl.CapabilityTypeImportManager;
import org.openecomp.sdc.be.components.impl.CategoriesImportManager;
@@ -218,7 +221,7 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
@POST
@Path("/datatypes")
- @Operation(description = "Create Categories from yaml", method = "POST", summary = "Returns created data types", responses = {
+ @Operation(description = "Create Data Types from zip", method = "POST", summary = "Returns created data types", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
@ApiResponse(responseCode = "201", description = "Data types created"),
@ApiResponse(responseCode = "403", description = "Restricted operation"),
@@ -234,6 +237,23 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
@POST
+ @Path("/datatypesyaml")
+ @Operation(description = "Create Data Types from yaml", method = "POST", summary = "Returns created data types", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Data types created"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "409", description = "Data types already exist")})
+ @PermissionAllowed(AafPermission.PermNames.INTERNAL_ALL_VALUE)
+ public Response uploadDataTypesYaml(@Parameter(description = "FileInputStream") @FormDataParam("dataTypesYaml") File file,
+ @Context final HttpServletRequest request, @HeaderParam("USER_ID") String creator,
+ @Parameter(description = "model") @FormDataParam("model") String modelName,
+ @Parameter(description = "includeToModelImport") @FormDataParam("includeToModelImport") boolean includeToModelDefaultImports) {
+ return uploadElementTypeServletLogicYaml(this::createDataTypes, file, request, creator, NodeTypeEnum.DataType.getName(), modelName,
+ includeToModelDefaultImports);
+ }
+
+ @POST
@Path("/grouptypes")
@Operation(description = "Create GroupTypes from yaml", method = "POST", summary = "Returns created group types", responses = {
@ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
@@ -323,6 +343,42 @@ public class TypesUploadServlet extends AbstractValidationsServlet {
}
}
+ private Response uploadElementTypeServletLogicYaml(final ConsumerFourParam<Wrapper<Response>, String, String, Boolean> createElementsMethod,
+ final File file, final HttpServletRequest request, final String creator,
+ final String elementTypeName, final String modelName, final boolean includeToModelDefaultImports) {
+ init();
+ final String userId = initHeaderParam(creator, request, Constants.USER_ID_HEADER);
+ try {
+ final Wrapper<String> yamlStringWrapper = new Wrapper<>();
+ final String url = request.getMethod() + " " + request.getRequestURI();
+ log.debug(START_HANDLE_REQUEST_OF, url);
+ final Wrapper<Response> responseWrapper = doUploadTypeValidations(request, userId, file);
+ if (responseWrapper.isEmpty()) {
+ final String yamlAsString = getFileAsString(file);
+ log.debug("received yaml: {}", yamlAsString);
+ yamlStringWrapper.setInnerElement(yamlAsString);
+ }
+ if (responseWrapper.isEmpty()) {
+ createElementsMethod.accept(responseWrapper, yamlStringWrapper.getInnerElement(), modelName, includeToModelDefaultImports);
+ }
+ return responseWrapper.getInnerElement();
+ } catch (final Exception e) {
+ log.debug(CREATE_FAILED_WITH_EXCEPTION, elementTypeName, e);
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(CREATE + elementTypeName);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+
+ @NotNull
+ private String getFileAsString(File file) throws IOException {
+ FileInputStream fl = new FileInputStream(file);
+ byte[] arr = new byte[(int) file.length()];
+ fl.read(arr);
+ fl.close();
+ final String yamlAsString = new String(arr, StandardCharsets.UTF_8);
+ return yamlAsString;
+ }
+
private Wrapper<Response> doUploadTypeValidations(final HttpServletRequest request, String userId, File file) {
Wrapper<Response> responseWrapper = new Wrapper<>();
Wrapper<User> userWrapper = new Wrapper<>();