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.openecomp.activityspec.api.rest.services;
19 import org.openecomp.activityspec.api.rest.ActivitySpecs;
20 import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecRequestDtoToActivitySpecEntity;
21 import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecCreateResponse;
22 import org.openecomp.activityspec.api.rest.mapping.MapActivitySpecToActivitySpecGetResponse;
23 import org.openecomp.activityspec.api.rest.mapping.MapItemToListResponseDto;
24 import org.openecomp.activityspec.api.rest.types.ActivitySpecActionRequestDto;
25 import org.openecomp.activityspec.api.rest.types.ActivitySpecCreateResponse;
26 import org.openecomp.activityspec.api.rest.types.ActivitySpecGetResponse;
27 import org.openecomp.activityspec.api.rest.types.ActivitySpecListResponseDto;
28 import org.openecomp.activityspec.api.rest.types.ActivitySpecRequestDto;
29 import org.openecomp.activityspec.api.rest.types.InternalEmptyObject;
30 import org.openecomp.activityspec.be.ActivitySpecManager;
31 import org.openecomp.activityspec.be.dao.impl.ActivitySpecDaoZusammenImpl;
32 import org.openecomp.activityspec.be.dao.types.ActivitySpecEntity;
33 import org.openecomp.activityspec.be.impl.ActivitySpecManagerImpl;
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.context.annotation.Scope;
42 import org.springframework.stereotype.Service;
43 import org.springframework.validation.annotation.Validated;
45 import javax.ws.rs.core.Response;
47 @Service("activitySpecs")
48 @Scope(value = "singleton")
50 public class ActivitySpecsImpl implements ActivitySpecs {
53 private final ActivitySpecManager activitySpecManager =
54 new ActivitySpecManagerImpl(ItemManagerFactory.getInstance().createInterface(),
55 VersioningManagerFactory.getInstance().createInterface(),
56 new ActivitySpecDaoZusammenImpl(ZusammenAdaptorFactory.getInstance().createInterface()),
57 UniqueValueDaoFactory.getInstance().createInterface());
60 public Response createActivitySpec(ActivitySpecRequestDto request) {
61 ActivitySpecEntity activitySpec = new MapActivitySpecRequestDtoToActivitySpecEntity()
62 .applyMapping(request, ActivitySpecEntity.class);
64 activitySpec = activitySpecManager.createActivitySpec(activitySpec);
65 ActivitySpecCreateResponse createActivitySpecResponse =
66 new MapActivitySpecToActivitySpecCreateResponse().applyMapping(activitySpec,
67 ActivitySpecCreateResponse.class);
69 return Response.ok(createActivitySpecResponse).build();
73 public Response getActivitySpec(String activitySpecId, String versionId) {
74 ActivitySpecEntity activitySpec = new ActivitySpecEntity();
75 activitySpec.setId(activitySpecId);
76 activitySpec.setVersion(new Version(versionId));
77 final ActivitySpecEntity retrieved = activitySpecManager.get(activitySpec);
78 ActivitySpecGetResponse getResponse = new MapActivitySpecToActivitySpecGetResponse()
79 .applyMapping(retrieved, ActivitySpecGetResponse.class);
80 return Response.ok(getResponse).build();
84 public Response updateActivitySpec(ActivitySpecRequestDto request, String activitySpecId,
86 ActivitySpecEntity activitySpec = new MapActivitySpecRequestDtoToActivitySpecEntity()
87 .applyMapping(request, ActivitySpecEntity.class);
89 activitySpec.setId(activitySpecId);
90 activitySpec.setVersion(new Version(versionId));
92 activitySpecManager.update(activitySpec);
94 return Response.ok(new InternalEmptyObject()).build();
98 public Response actOnActivitySpec(ActivitySpecActionRequestDto request, String activitySpecId,
100 activitySpecManager.actOnAction(activitySpecId, versionId, request.getAction());
101 return Response.ok(new InternalEmptyObject()).build();
105 public Response list(String versionStatus) {
107 GenericCollectionWrapper<ActivitySpecListResponseDto> results = new GenericCollectionWrapper<>();
108 MapItemToListResponseDto mapper = new MapItemToListResponseDto();
109 activitySpecManager.list(versionStatus).stream()
110 .sorted((o1, o2) -> o2.getModificationTime().compareTo(o1.getModificationTime()))
111 .forEach(activitySpecItem -> results.add(mapper.applyMapping(activitySpecItem,
112 ActivitySpecListResponseDto.class)));
114 return Response.ok(results).build();