diff options
author | ayalaben <ayala.benzvi@amdocs.com> | 2018-01-22 12:22:32 +0200 |
---|---|---|
committer | ayalaben <ayala.benzvi@amdocs.com> | 2018-01-22 14:19:57 +0200 |
commit | 09cc405325d939d486b3b0f251311ce41e3b9ab5 (patch) | |
tree | b6c478f573d70052ba8d9624ea51614251335b23 /openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main | |
parent | 10c74ee2fbccabd7a109c91ed47c8e11d61d411e (diff) |
Owner healer - owner in tile
Change-Id: Ia9bea13d4e6e78e6222e9565074137c58d167eb6
Issue-ID: SDC-946
Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main')
-rw-r--r-- | openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-impl/src/main/java/org/openecomp/sdc/healing/healers/OwnerHealer.java | 28 |
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()); } |