+ @POST
+ @Path("/resource/import")
+ @Consumes(MediaType.MULTIPART_FORM_DATA)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(description = "Import node types from a TOSCA yaml, along with the types metadata", method = "POST",
+ summary = "Creates node types from a TOSCA yaml file", responses = {
+ @ApiResponse(content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class)))),
+ @ApiResponse(responseCode = "201", description = "Resources created"),
+ @ApiResponse(responseCode = "400", description = "Invalid content / Missing content"),
+ @ApiResponse(responseCode = "403", description = "Restricted operation"),
+ @ApiResponse(responseCode = "409", description = "One of the resources already exists")}
+ )
+ public Response bulkImport(@Parameter(description = "The nodes metadata JSON", required = true)
+ @NotNull @FormDataParam("nodeTypeMetadataJson") final NodeTypesMetadataList nodeTypeMetadata,
+ @Parameter(description = "The node types TOSCA definition yaml", required = true)
+ @NotNull @FormDataParam("nodeTypesYaml") final InputStream nodeTypesYamlInputStream,
+ @Parameter(description = "The model name to associate the node types to")
+ @DefaultValue("true") @FormDataParam("createNewVersion") boolean createNewVersion,
+ @HeaderParam(value = Constants.USER_ID_HEADER) String userId,
+ @Context final HttpServletRequest request) {
+ userId = ValidationUtils.sanitizeInputString(userId);
+ final Either<User, ResponseFormat> userEither = getUser(request, userId);
+ if (userEither.isRight()) {
+ return buildErrorResponse(userEither.right().value());
+ }
+
+ final User user = userEither.left().value();
+
+ final String nodeTypesYamlString;
+ try {
+ nodeTypesYamlString = new String(nodeTypesYamlInputStream.readAllBytes(), StandardCharsets.UTF_8);
+ } catch (final IOException e) {
+ var errorMsg = "Could not read the given node types yaml";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(errorMsg);
+ log.error(errorMsg, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_NODE_TYPES_YAML));
+ }
+
+ try {
+ resourceImportManager.importAllNormativeResource(nodeTypesYamlString, nodeTypeMetadata, user, createNewVersion, false);
+ return buildOkResponse(getComponentsUtils().getResponseFormat(ActionStatus.CREATED), null);
+ } catch (final BusinessException e) {
+ throw e;
+ } catch (final Exception e) {
+ var errorMsg = "Unexpected error while importing the node types";
+ BeEcompErrorManager.getInstance().logBeRestApiGeneralError(errorMsg);
+ log.error(errorMsg, e);
+ return buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.GENERAL_ERROR));
+ }
+ }
+