Added oparent to sdc main
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / conflict-rest / conflict-rest-services / src / main / java / org / openecomp / sdcrests / conflict / rest / services / ConflictsImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.conflict.rest.services;
22
23 import org.openecomp.conflicts.types.Conflict;
24 import org.openecomp.conflicts.types.ConflictResolution;
25 import org.openecomp.conflicts.types.ItemVersionConflict;
26 import org.openecomp.sdc.conflicts.ConflictsManager;
27 import org.openecomp.sdc.conflicts.ConflictsManagerFactory;
28 import org.openecomp.sdc.versioning.dao.types.Version;
29 import org.openecomp.sdcrests.conflict.rest.Conflicts;
30 import org.openecomp.sdcrests.conflict.rest.mapping.MapConflictToDto;
31 import org.openecomp.sdcrests.conflict.rest.mapping.MapDtoToConflictResolution;
32 import org.openecomp.sdcrests.conflict.rest.mapping.MapItemVersionConflictToDto;
33 import org.openecomp.sdcrests.conflict.types.ConflictDto;
34 import org.openecomp.sdcrests.conflict.types.ConflictResolutionDto;
35 import org.openecomp.sdcrests.conflict.types.ItemVersionConflictDto;
36 import org.springframework.context.annotation.Scope;
37 import org.springframework.stereotype.Service;
38
39 import javax.inject.Named;
40 import javax.ws.rs.core.Response;
41
42 @Named
43 @Service("conflicts")
44 @Scope(value = "prototype")
45 public class ConflictsImpl implements Conflicts {
46
47   @Override
48   public Response getConflict(String itemId, String versionId, String user) {
49
50     ConflictsManager conflictsManager = ConflictsManagerFactory.getInstance().createInterface();
51     ItemVersionConflict itemVersionConflict = conflictsManager.getConflict
52         (itemId, new Version(versionId));
53     ItemVersionConflictDto result = (new MapItemVersionConflictToDto()).applyMapping
54         (itemVersionConflict, ItemVersionConflictDto.class);
55     return Response.ok(result).build();
56   }
57
58   @Override
59   public Response getConflict(String itemId, String versionId, String conflictId, String user) {
60     ConflictsManager conflictsManager = ConflictsManagerFactory.getInstance().createInterface();
61     Conflict conflict = conflictsManager.getConflict(itemId, new Version(versionId), conflictId);
62
63     ConflictDto result = new MapConflictToDto().applyMapping(conflict, ConflictDto.class);
64
65     return Response.ok(result).build();
66
67   }
68
69   @Override
70   public Response resolveConflict(ConflictResolutionDto conflictResolution, String itemId,
71                                   String versionId, String conflictId, String user) {
72     ConflictsManager conflictsManager = ConflictsManagerFactory.getInstance().createInterface();
73
74     Version version = new Version(versionId);
75     conflictsManager.resolveConflict(itemId, version, conflictId,
76         new MapDtoToConflictResolution()
77             .applyMapping(conflictResolution, ConflictResolution.class));
78     conflictsManager.finalizeMerge(itemId, version);
79
80     return Response.ok().build();
81   }
82 }