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.vendorlicense.rest.services;
23 import org.openecomp.sdc.vendorlicense.VendorLicenseManager;
24 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
25 import org.openecomp.sdc.vendorlicense.types.VersionedVendorLicenseModel;
26 import org.openecomp.sdc.versioning.dao.types.Version;
27 import org.openecomp.sdcrests.vendorlicense.rest.VendorLicenseModels;
28 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity;
29 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapVersionedVendorLicenseModelToVendorLicenseModelEntityDto;
30 import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelActionRequestDto;
31 import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelEntityDto;
32 import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelRequestDto;
33 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
34 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;
38 import org.springframework.validation.annotation.Validated;
40 import java.util.Collection;
41 import javax.inject.Named;
42 import javax.ws.rs.core.Response;
47 @Service("vendorLicenseModels")
48 @Scope(value = "prototype")
50 public class VendorLicenseModelsImpl implements VendorLicenseModels {
53 private VendorLicenseManager vendorLicenseManager;
56 public Response listLicenseModels(String versionFilter, String user) {
57 Collection<VersionedVendorLicenseModel> versionedVendorLicenseModels =
58 vendorLicenseManager.listVendorLicenseModels(versionFilter, user);
60 GenericCollectionWrapper<VendorLicenseModelEntityDto> results =
61 new GenericCollectionWrapper<>();
62 MapVersionedVendorLicenseModelToVendorLicenseModelEntityDto outputMapper =
63 new MapVersionedVendorLicenseModelToVendorLicenseModelEntityDto();
64 for (VersionedVendorLicenseModel versionedVlm : versionedVendorLicenseModels) {
65 results.add(outputMapper.applyMapping(versionedVlm, VendorLicenseModelEntityDto.class));
68 return Response.ok(results).build();
72 public Response createLicenseModel(VendorLicenseModelRequestDto request, String user) {
73 VendorLicenseModelEntity vendorLicenseModelEntity =
74 new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
75 .applyMapping(request, VendorLicenseModelEntity.class);
76 VendorLicenseModelEntity createdVendorLicenseModel =
77 vendorLicenseManager.createVendorLicenseModel(vendorLicenseModelEntity, user);
78 StringWrapperResponse result = createdVendorLicenseModel != null ? new StringWrapperResponse(
79 createdVendorLicenseModel.getId()) : null;
81 return Response.ok(result).build();
85 public Response updateLicenseModel(VendorLicenseModelRequestDto request, String vlmId,
87 VendorLicenseModelEntity vendorLicenseModelEntity =
88 new MapVendorLicenseModelRequestDtoToVendorLicenseModelEntity()
89 .applyMapping(request, VendorLicenseModelEntity.class);
90 vendorLicenseModelEntity.setId(vlmId);
92 vendorLicenseManager.updateVendorLicenseModel(vendorLicenseModelEntity, user);
93 return Response.ok().build();
97 public Response getLicenseModel(String vlmId, String version, String user) {
98 VersionedVendorLicenseModel versionedVlm =
99 vendorLicenseManager.getVendorLicenseModel(vlmId, Version.valueOf(version), user);
101 VendorLicenseModelEntityDto vlmDto = versionedVlm == null ? null :
102 new MapVersionedVendorLicenseModelToVendorLicenseModelEntityDto()
103 .applyMapping(versionedVlm, VendorLicenseModelEntityDto.class);
104 return Response.ok(vlmDto).build();
108 public Response deleteLicenseModel(String vlmId, String user) {
109 vendorLicenseManager.deleteVendorLicenseModel(vlmId, user);
110 return Response.ok().build();
114 public Response actOnLicenseModel(VendorLicenseModelActionRequestDto request, String vlmId,
117 switch (request.getAction()) {
119 vendorLicenseManager.checkout(vlmId, user);
122 vendorLicenseManager.undoCheckout(vlmId, user);
125 vendorLicenseManager.checkin(vlmId, user);
128 vendorLicenseManager.submit(vlmId, user);
133 return Response.ok().build();