Add Item Owner to item

Change-Id: I91ce289159057bd5c179c64131d74a24aa83ac9f
Issue-ID: SDC-800
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
index 26bd58d..0448407 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/mapping/MapItemToDto.java
@@ -11,5 +11,6 @@
     target.setType(source.getType());
     target.setName(source.getName());
     target.setDescription(source.getDescription());
+    target.setOwner(source.getOwner());
   }
 }
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
index 1eebf197..3ca77c2 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-types/src/main/java/org/openecomp/sdcrests/item/types/ItemDto.java
@@ -5,6 +5,7 @@
   private String type;
   private String name;
   private String description;
+  private String owner;
 
   public String getId() {
     return id;
@@ -37,4 +38,12 @@
   public void setDescription(String description) {
     this.description = description;
   }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
 }
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
index 2b8e5a3..77152c6 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-license-rest/vendor-license-rest-services/src/main/java/org/openecomp/sdcrests/vendorlicense/rest/services/VendorLicenseModelsImpl.java
@@ -142,6 +142,7 @@
 
     Item item = new Item();
     item.setType(ItemType.vlm.name());
+    item.setOwner(user);
     item.setName(request.getVendorName());
     item.setDescription(request.getDescription());
 
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
index ad45e63..caa0539 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/mapping/MapItemToVspDetailsDto.java
@@ -14,5 +14,6 @@
     target.setVendorId((String) source.getProperties().get(VspItemProperty.VENDOR_ID));
     target.setVendorName((String) source.getProperties().get(VspItemProperty.VENDOR_NAME));
     target.setOnboardingMethod((String) source.getProperties().get(VspItemProperty.ONBOARDING_METHOD));
+    target.setOwner(source.getOwner());
   }
 }
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
index feffb91..b92a431 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/VendorSoftwareProductsImpl.java
@@ -158,6 +158,7 @@
       case Manual:
         Item item = new MapVspDescriptionDtoToItem().applyMapping(vspRequestDto, Item.class);
         item.setType(ItemType.vsp.name());
+        item.setOwner(user);
         item.addProperty(VspItemProperty.ONBOARDING_METHOD, onboardingMethod.name());
 
         UniqueValueUtil.validateUniqueValue(VENDOR_SOFTWARE_PRODUCT_NAME, item.getName());
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
index 5052442..745b930 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-types/src/main/java/org/openecomp/sdcrests/vendorsoftwareproducts/types/VspDetailsDto.java
@@ -35,6 +35,7 @@
   private String candidateOnboardingOrigin;
   private String onboardingOrigin;
   private String networkPackageName;
+  private String owner;
 
   public String getId() {
     return id;
@@ -83,4 +84,12 @@
   public void setNetworkPackageName(String networkPackageName) {
     this.networkPackageName = networkPackageName;
   }
+
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
 }
diff --git a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImpl.java b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImpl.java
index b9fcfcd..726695b 100644
--- a/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImpl.java
+++ b/openecomp-be/backend/openecomp-sdc-item-permissions-manager/src/main/java/org/openecomp/sdc/itempermissions/dao/impl/ItemPermissionsManagerImpl.java
@@ -7,6 +7,7 @@
 import org.openecomp.sdc.common.session.SessionContextProviderFactory;
 import org.openecomp.sdc.itempermissions.ItemPermissionsManager;
 import org.openecomp.sdc.itempermissions.PermissionsServices;
+import org.openecomp.sdc.itempermissions.impl.types.PermissionTypes;
 import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
 import org.openecomp.sdc.logging.api.Logger;
 import org.openecomp.sdc.logging.api.LoggerFactory;
@@ -71,8 +72,20 @@
           .withCategory(ErrorCategory.SECURITY).build());
     }
 
+    if (permission.equals(PermissionTypes.Owner.name()) ){
+      if (addedUsersIds.size() == 1){
+        itemManager.updateOwner(itemId,addedUsersIds.iterator().next());
+    } else {
+        throw new CoreException(new ErrorCode.ErrorCodeBuilder()
+            .withMessage(Messages.PERMISSIONS_OWNER_ERROR.getErrorMessage())
+            .withId(Messages.PERMISSIONS_OWNER_ERROR.getErrorMessage())
+            .withCategory(ErrorCategory.SECURITY).build());
+      }
+    }
+
     permissionsServices
         .updateItemPermissions(itemId, permission, addedUsersIds, removedUsersIds);
+
     sendNotifications(itemId, permission, addedUsersIds, removedUsersIds, currentUser);
   }
 
diff --git a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
index 565e60e..038778b 100644
--- a/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
+++ b/openecomp-be/lib/openecomp-common-lib/src/main/java/org/openecomp/sdc/common/errors/Messages.java
@@ -40,6 +40,7 @@
   ZIP_NOT_EXIST("Zip file doesn't exist"),
 
   PERMISSIONS_ERROR("Permissions Error. The user does not have permission to perform this action."),
+  PERMISSIONS_OWNER_ERROR("Permissions Error. Only one owner is allowed."),
 
   ZIP_SHOULD_NOT_CONTAIN_FOLDERS("Zip file should not contain folders"),
   VES_ZIP_SHOULD_CONTAIN_YML_ONLY(
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java
index ee58902..c83ebff 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/ItemManager.java
@@ -17,4 +17,6 @@
   void updateVersionStatus(String itemId, VersionStatus addedVersionStatus,
                            VersionStatus removedVersionStatus);
 
+  void updateOwner(String itemId, String owner);
+
 }
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
index 2a95c05..d572373 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-api/src/main/java/org/openecomp/sdc/versioning/types/Item.java
@@ -11,6 +11,7 @@
   private String id;
   private String type;
   private String name;
+  private String owner;
   private String description;
   private Map<String, Object> properties = new HashMap<>();
   private Map<VersionStatus, Integer> versionStatusCounters = new EnumMap<>(VersionStatus.class);
@@ -41,6 +42,14 @@
     this.name = name;
   }
 
+  public String getOwner() {
+    return owner;
+  }
+
+  public void setOwner(String owner) {
+    this.owner = owner;
+  }
+
   public String getDescription() {
     return description;
   }
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
index 8fdcf71..6352508 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/dao/impl/zusammen/ItemZusammenDaoImpl.java
@@ -70,6 +70,9 @@
       case InfoPropertyName.ITEM_TYPE:
         item.setType((String) propertyValue);
         break;
+      case InfoPropertyName.ITEM_OWNER:
+        item.setOwner((String) propertyValue);
+        break;
       case InfoPropertyName.ITEM_VERSIONS_STATUSES:
         for (Map.Entry<String, Number> statusCounter :
             ((Map<String, Number>) propertyValue).entrySet()) {
@@ -87,6 +90,7 @@
     info.setName(item.getName());
     info.setDescription(item.getDescription());
     info.addProperty(InfoPropertyName.ITEM_TYPE, item.getType());
+    info.addProperty(InfoPropertyName.ITEM_OWNER,item.getOwner());
     info.addProperty(InfoPropertyName.ITEM_VERSIONS_STATUSES, item.getVersionStatusCounters());
     item.getProperties().entrySet()
         .forEach(property -> info.addProperty(property.getKey(), property.getValue()));
@@ -96,6 +100,7 @@
   private static final class InfoPropertyName {
     private static final String ITEM_TYPE = "item_type";
     private static final String ITEM_VERSIONS_STATUSES = "item_versions_statuses";
+    private static final String ITEM_OWNER = "Owner";
 
     private InfoPropertyName() {
       throw new IllegalStateException("Constants class");
diff --git a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
index 7928454..3e85a53 100644
--- a/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-versioning-lib/openecomp-sdc-versioning-core/src/main/java/org/openecomp/sdc/versioning/impl/ItemManagerImpl.java
@@ -65,4 +65,15 @@
     }
     itemDao.update(item);
   }
+
+  @Override
+  public void updateOwner(String itemId, String owner){
+    Item item = get(itemId);
+    if (item == null) {
+      return;
+    }
+
+    item.setOwner(owner);
+    itemDao.update(item);
+  }
 }