push addional code
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / vendor-software-products-rest / vendor-software-products-rest-services / src / main / java / org / openecomp / sdcrests / vsp / rest / services / ComponentUploadsImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdcrests.vsp.rest.services;
22
23 import org.apache.cxf.jaxrs.ext.multipart.Attachment;
24 import org.openecomp.sdc.vendorsoftwareproduct.VendorSoftwareProductManager;
25 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MibUploadStatus;
26 import org.openecomp.sdcrests.vendorsoftwareproducts.types.MibUploadStatusDto;
27 import org.openecomp.sdcrests.vsp.rest.ComponentUploads;
28 import org.openecomp.sdcrests.vsp.rest.mapping.MapMibUploadStatusToDto;
29
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.context.annotation.Scope;
32 import org.springframework.stereotype.Service;
33 import org.springframework.validation.annotation.Validated;
34
35 import java.io.InputStream;
36 import javax.inject.Named;
37 import javax.ws.rs.core.Response;
38
39 @Named
40 @Service("componentUploads")
41 @Scope(value = "prototype")
42 @Validated
43 public class ComponentUploadsImpl implements ComponentUploads {
44   @Autowired
45   private VendorSoftwareProductManager vendorSoftwareProductManager;
46
47   @Override
48   public Response uploadTrapMibFile(Attachment attachment, String vspId, String componentId,
49                                     String user) {
50     vendorSoftwareProductManager.uploadComponentMib(attachment.getObject(InputStream.class),
51         attachment.getContentDisposition().getParameter("filename"), vspId, componentId, true,
52         user);
53     return Response.ok().build();
54   }
55
56   @Override
57   public Response deleteTrapMibFile(String vspId, String componentId, String user) {
58     vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, true, user);
59     return Response.ok().build();
60   }
61
62   @Override
63   public Response uploadPollMibFile(Attachment attachment, String vspId, String componentId,
64                                     String user) {
65     vendorSoftwareProductManager.uploadComponentMib(attachment.getObject(InputStream.class),
66         attachment.getContentDisposition().getParameter("filename"), vspId, componentId, false,
67         user);
68     return Response.ok().build();
69   }
70
71   @Override
72   public Response deletePollMibFile(String vspId, String componentId, String user) {
73     vendorSoftwareProductManager.deleteComponentMib(vspId, componentId, false, user);
74     return Response.ok().build();
75   }
76
77   @Override
78   public Response list(String vspId, String componentId, String user) {
79     MibUploadStatus response =
80         vendorSoftwareProductManager.listMibFilenames(vspId, componentId, user);
81
82     MibUploadStatusDto returnEntity =
83         new MapMibUploadStatusToDto().applyMapping(response, MibUploadStatusDto.class);
84     return Response.status(Response.Status.OK).entity(returnEntity).build();
85
86   }
87 }