aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl
diff options
context:
space:
mode:
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl')
-rw-r--r--openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java28
1 files changed, 24 insertions, 4 deletions
diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
index e47fbc4a08..711848c4e1 100644
--- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
+++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java
@@ -1,5 +1,6 @@
package org.openecomp.sdc.healing.healers;
+import org.openecomp.sdc.common.errors.SdcRuntimeException;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.healing.interfaces.Healer;
import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
@@ -17,6 +18,8 @@ import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
+import java.util.Optional;
+import java.util.stream.Stream;
/**
* Created by ayalaben on 8/28/2017
@@ -31,9 +34,11 @@ public class OwnerHealer implements Healer {
.createInterface();
public Object heal(String itemId, Version version) {
- Collection<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId);
+ Stream<ItemPermissionsEntity> itemPermissions = permissionsDao.listItemPermissions(itemId)
+ .stream();
- if (itemPermissions.stream().noneMatch(this::isOwnerPermission)) {
+
+ if (itemPermissions.noneMatch(this::isOwnerPermission)) {
String currentUserId =
SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId()
.replace(HEALING_USER_SUFFIX, "");
@@ -46,8 +51,16 @@ public class OwnerHealer implements Healer {
subscribersDao.subscribe(currentUserId,itemId);
return currentUserId;
- }
- return itemPermissions.stream().filter(this::isOwnerPermission).findFirst().get().getUserId();
+ } else if (!itemHasOwnerProperty(itemId)){
+ Optional<ItemPermissionsEntity> ownerOpt = itemPermissions.filter
+ (this::isOwnerPermission).findFirst();
+ if(ownerOpt.isPresent()) {
+ updateItemOwner(itemId, ownerOpt.get().getUserId());
+ } else {
+ throw new SdcRuntimeException("Unexpected error in Owner Healer. Item id: " + itemId);
+ }
+ }
+ return itemPermissions.filter(this::isOwnerPermission).findFirst().get().getUserId();
}
private void updateItemOwner(String itemId,String userId) {
@@ -60,6 +73,13 @@ public class OwnerHealer implements Healer {
}
}
+ private boolean itemHasOwnerProperty(String itemId){
+ Item item = new Item();
+ item.setId(itemId);
+ Item retrievedItem = itemDao.get(item);
+ return Objects.nonNull(retrievedItem) && Objects.nonNull(retrievedItem.getOwner());
+ }
+
private boolean isOwnerPermission(ItemPermissionsEntity permissionsEntity) {
return permissionsEntity.getPermission().equals(PermissionTypes.Owner.name());
}