82d3ae5a61df45dafbf8e9b93ddc66756fc05813
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.versioning.impl;
18
19 import org.openecomp.sdc.common.session.SessionContextProviderFactory;
20 import org.openecomp.sdc.itempermissions.PermissionsServices;
21 import org.openecomp.sdc.notification.services.SubscriptionService;
22 import org.openecomp.sdc.versioning.AsdcItemManager;
23 import org.openecomp.sdc.versioning.dao.ItemDao;
24 import org.openecomp.sdc.versioning.types.Item;
25
26 public class AsdcItemManagerImpl extends ItemManagerImpl implements AsdcItemManager {
27   private static final String CREATE_ITEM = "Create_Item";
28
29   private PermissionsServices permissionsServices;
30   private SubscriptionService subscriptionService;
31
32   public AsdcItemManagerImpl(ItemDao itemDao, PermissionsServices permissionsServices,
33                              SubscriptionService subscriptionService) {
34     super(itemDao);
35
36     this.permissionsServices = permissionsServices;
37     this.subscriptionService = subscriptionService;
38   }
39
40   @Override
41   public Item create(Item item) {
42     Item createdItem = super.create(item);
43
44     String userId = SessionContextProviderFactory.getInstance()
45         .createInterface().get().getUser().getUserId();
46     String itemId = createdItem.getId();
47     permissionsServices.execute(itemId, userId, CREATE_ITEM);
48     subscriptionService.subscribe(userId, itemId);
49
50     return createdItem;
51   }
52
53
54   @Override
55   public void updateOwner(String itemId, String owner) {
56     Item item = get(itemId);
57     if (item == null) {
58       return;
59     }
60     item.setOwner(owner);
61     super.update(item);
62   }
63
64   @Override
65   public void delete(Item item) {
66     super.delete(item);
67   }
68
69
70 }