2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.core.enrichment.types.MonitoringUploadType;
25 import org.openecomp.core.validation.errors.ErrorMessagesFormatBuilder;
26 import org.openecomp.sdc.common.errors.Messages;
27 import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager;
28 import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory;
29 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManager;
30 import org.openecomp.sdc.vendorsoftwareproduct.MonitoringUploadsManagerFactory;
31 import org.openecomp.sdc.vendorsoftwareproduct.types.schemagenerator.MonitoringUploadStatus;
32 import org.openecomp.sdc.versioning.dao.types.Version;
33 import org.openecomp.sdcrests.vendorsoftwareproducts.types.MonitoringUploadStatusDto;
34 import org.openecomp.sdcrests.vsp.rest.ComponentMonitoringUploads;
35 import org.openecomp.sdcrests.vsp.rest.mapping.MapMonitoringUploadStatusToDto;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
39 import javax.inject.Named;
40 import javax.ws.rs.core.Response;
41 import java.io.InputStream;
45 * @since June 26, 2017
49 @Service("componentMonitoringUploads")
50 @Scope(value = "prototype")
52 public class ComponentMonitoringUploadsImpl implements ComponentMonitoringUploads {
53 private MonitoringUploadsManager
54 monitoringUploadsManager = MonitoringUploadsManagerFactory.getInstance().createInterface();
55 private ComponentManager componentManager =
56 ComponentManagerFactory.getInstance().createInterface();
59 public Response upload(Attachment attachment,
60 String vspId, String versionId, String componentId, String type,
61 String user) throws Exception {
63 Version version = new Version(versionId);
64 componentManager.validateComponentExistence(vspId, version, componentId);
66 MonitoringUploadType monitoringUploadType = getMonitoringUploadType(vspId, componentId, type);
67 monitoringUploadsManager.upload(attachment.getObject(InputStream.class),
68 attachment.getContentDisposition().getParameter("filename"), vspId, version, componentId,
69 monitoringUploadType);
70 return Response.ok().build();
73 private MonitoringUploadType getMonitoringUploadType(String vspId, String componentId,
74 String type) throws Exception {
75 MonitoringUploadType monitoringUploadType;
77 monitoringUploadType = MonitoringUploadType.valueOf(type);
78 } catch (IllegalArgumentException exception) {
79 String errorWithParameters = ErrorMessagesFormatBuilder
80 .getErrorWithParameters(Messages.ILLEGAL_MONITORING_ARTIFACT_TYPE.getErrorMessage(),
82 throw new Exception(errorWithParameters, exception);
84 return monitoringUploadType;
88 public Response delete(String vspId, String versionId, String componentId,
89 String type, String user) throws Exception {
91 MonitoringUploadType monitoringUploadType = getMonitoringUploadType(vspId, componentId, type);
93 Version version = new Version(versionId);
94 componentManager.validateComponentExistence(vspId, version, componentId);
95 monitoringUploadsManager.delete(vspId, version, componentId, monitoringUploadType);
96 return Response.ok().build();
100 public Response list(String vspId, String versionId, String componentId,
103 Version version = new Version(versionId);
104 componentManager.validateComponentExistence(vspId, version, componentId);
106 MonitoringUploadStatus response =
107 monitoringUploadsManager.listFilenames(vspId, version, componentId);
109 MonitoringUploadStatusDto returnEntity =
110 new MapMonitoringUploadStatusToDto()
111 .applyMapping(response, MonitoringUploadStatusDto.class);
112 return Response.status(Response.Status.OK).entity(returnEntity).build();