2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.sdc.activityspec.api.rest.services;
19 import org.onap.sdc.activityspec.api.rest.ActivitySpecs;
20 import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecRequestDtoToActivitySpecEntity;
21 import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecCreateResponse;
22 import org.onap.sdc.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecGetResponse;
23 import org.onap.sdc.activityspec.api.rest.mapping.MapItemToListResponseDto;
24 import org.onap.sdc.activityspec.api.rest.types.ActivitySpecActionRequestDto;
25 import org.onap.sdc.activityspec.api.rest.types.ActivitySpecGetResponse;
26 import org.onap.sdc.activityspec.api.rest.types.ActivitySpecListResponseDto;
27 import org.onap.sdc.activityspec.api.rest.types.ActivitySpecRequestDto;
28 import org.onap.sdc.activityspec.api.rest.types.InternalEmptyObject;
29 import org.onap.sdc.activityspec.be.ActivitySpecManager;
30 import org.onap.sdc.activityspec.be.dao.types.ActivitySpecEntity;
31 import org.onap.sdc.activityspec.be.impl.ActivitySpecManagerImpl;
32 import org.onap.sdc.activityspec.api.rest.types.ActivitySpecCreateResponse;
33 import org.onap.sdc.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl;
34 import org.openecomp.core.dao.UniqueValueDaoFactory;
35 import org.openecomp.core.zusammen.api.ZusammenAdaptorFactory;
36 import org.openecomp.sdc.versioning.ItemManagerFactory;
37 import org.openecomp.sdc.versioning.VersioningManagerFactory;
38 import org.openecomp.sdc.versioning.dao.types.Version;
40 import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper;
41 import org.springframework.stereotype.Service;
42 import org.springframework.validation.annotation.Validated;
44 import javax.ws.rs.core.Response;
46 @Service("activitySpecs")
48 public class ActivitySpecsImpl implements ActivitySpecs {
51 private final ActivitySpecManager activitySpecManager =
52 new ActivitySpecManagerImpl(ItemManagerFactory.getInstance().createInterface(),
53 VersioningManagerFactory.getInstance().createInterface(),
54 new ActivitySpecDaoZusammenImpl(ZusammenAdaptorFactory.getInstance()
56 UniqueValueDaoFactory.getInstance().createInterface());
59 public Response createActivitySpec(ActivitySpecRequestDto request) {
60 ActivitySpecEntity activitySpec =
61 new MapActivitySpecRequestDtoToActivitySpecEntity().applyMapping(request, ActivitySpecEntity.class);
63 activitySpec = activitySpecManager.createActivitySpec(activitySpec);
64 ActivitySpecCreateResponse createActivitySpecResponse = new MapActivitySpecToActivitySpecCreateResponse()
65 .applyMapping(activitySpec,
66 ActivitySpecCreateResponse.class);
68 return Response.ok(createActivitySpecResponse).build();
72 public Response getActivitySpec(String activitySpecId, String versionId) {
73 ActivitySpecEntity activitySpec = new ActivitySpecEntity();
74 activitySpec.setId(activitySpecId);
75 activitySpec.setVersion(new Version(versionId));
76 final ActivitySpecEntity retrieved = activitySpecManager.get(activitySpec);
77 ActivitySpecGetResponse getResponse =
78 new MapActivitySpecToActivitySpecGetResponse().applyMapping(retrieved, ActivitySpecGetResponse.class);
79 return Response.ok(getResponse).build();
83 public Response updateActivitySpec(ActivitySpecRequestDto request, String activitySpecId, String versionId) {
84 ActivitySpecEntity activitySpec =
85 new MapActivitySpecRequestDtoToActivitySpecEntity().applyMapping(request, ActivitySpecEntity.class);
87 activitySpec.setId(activitySpecId);
88 activitySpec.setVersion(new Version(versionId));
90 activitySpecManager.update(activitySpec);
92 return Response.ok(new InternalEmptyObject()).build();
96 public Response actOnActivitySpec(ActivitySpecActionRequestDto request, String activitySpecId, String versionId) {
97 activitySpecManager.actOnAction(activitySpecId, versionId, request.getAction());
98 return Response.ok(new InternalEmptyObject()).build();
102 public Response list(String versionStatus) {
104 GenericCollectionWrapper<ActivitySpecListResponseDto> results = new GenericCollectionWrapper<>();
105 MapItemToListResponseDto mapper = new MapItemToListResponseDto();
106 activitySpecManager.list(versionStatus).stream()
107 .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime())).forEach(
108 activitySpecItem -> results.add(
109 mapper.applyMapping(activitySpecItem, ActivitySpecListResponseDto.class)));
111 return Response.ok(results).build();