2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdcrests.vsp.rest.services;
23 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
24 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
25 import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity;
26 import org.openecomp.sdc.versioning.dao.types.Version;
27 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ProcessEntityDto;
28 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ProcessRequestDto;
29 import org.openecomp.sdcrests.vsp.rest.ComponentProcesses;
30 import org.openecomp.sdcrests.vsp.rest.mapping.MapProcessEntityToProcessEntityDto;
31 import org.openecomp.sdcrests.vsp.rest.mapping.MapProcessRequestDtoToProcessEntity;
32 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
33 import org.openecomp.sdcrests.wrappers.StringWrapperResponse;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
40 import java.io.InputStream;
41 import java.util.Collection;
42 import javax.inject.Named;
43 import javax.ws.rs.core.Response;
47 @Service("componentProcesses")
48 @Scope(value = "prototype")
49 public class ComponentProcessesImpl implements ComponentProcesses {
51 private VendorSoftwareProductManager vendorSoftwareProductManager;
54 public Response list(String vspId, String componentId, String version, String user) {
55 Collection<ProcessEntity> processes = vendorSoftwareProductManager
56 .listProcesses(vspId, Version.valueOf(version), componentId, user);
58 MapProcessEntityToProcessEntityDto mapper = new MapProcessEntityToProcessEntityDto();
59 GenericCollectionWrapper<ProcessEntityDto> results = new GenericCollectionWrapper<>();
60 for (ProcessEntity process : processes) {
61 results.add(mapper.applyMapping(process, ProcessEntityDto.class));
64 return Response.ok(results).build();
68 public Response deleteList(String vspId, String componentId, String user) {
69 vendorSoftwareProductManager.deleteProcesses(vspId, componentId, user);
70 return Response.ok().build();
74 public Response create(ProcessRequestDto request, String vspId, String componentId, String user) {
75 ProcessEntity process =
76 new MapProcessRequestDtoToProcessEntity().applyMapping(request, ProcessEntity.class);
77 process.setVspId(vspId);
78 process.setComponentId(componentId);
80 ProcessEntity createdProcess = vendorSoftwareProductManager.createProcess(process, user);
82 .ok(createdProcess != null ? new StringWrapperResponse(createdProcess.getId()) : null)
87 public Response get(String vspId, String componentId, String processId, String version,
89 ProcessEntity process = vendorSoftwareProductManager
90 .getProcess(vspId, Version.valueOf(version), componentId, processId, user);
91 ProcessEntityDto result =
92 new MapProcessEntityToProcessEntityDto().applyMapping(process, ProcessEntityDto.class);
93 return Response.ok(result).build();
97 public Response delete(String vspId, String componentId, String processId, String user) {
98 vendorSoftwareProductManager.deleteProcess(vspId, componentId, processId, user);
99 return Response.ok().build();
103 public Response update(ProcessRequestDto request, String vspId, String componentId,
104 String processId, String user) {
105 ProcessEntity processEntity =
106 new MapProcessRequestDtoToProcessEntity().applyMapping(request, ProcessEntity.class);
107 processEntity.setVspId(vspId);
108 processEntity.setComponentId(componentId);
109 processEntity.setId(processId);
111 vendorSoftwareProductManager.updateProcess(processEntity, user);
112 return Response.ok().build();
116 public Response getUploadedFile(String vspId, String componentId, String processId,
117 String version, String user) {
118 File file = vendorSoftwareProductManager
119 .getProcessArtifact(vspId, Version.valueOf(version), componentId, processId, user);
121 Response.ResponseBuilder response = Response.ok(file);
123 return Response.status(Response.Status.NOT_FOUND).build();
125 response.header("Content-Disposition", "attachment; filename=" + file.getName());
126 return response.build();
130 public Response deleteUploadedFile(String vspId, String componentId, String processId,
132 vendorSoftwareProductManager.deleteProcessArtifact(vspId, componentId, processId, user);
133 return Response.ok().build();
137 public Response uploadFile(Attachment attachment, String vspId, String componentId,
138 String processId, String user) {
139 vendorSoftwareProductManager.uploadProcessArtifact(attachment.getObject(InputStream.class),
140 attachment.getContentDisposition().getParameter("filename"), vspId, componentId, processId,
142 return Response.ok().build();