From 80a35922da9c0244e736a87fea3007de92822967 Mon Sep 17 00:00:00 2001 From: talig Date: Thu, 24 May 2018 15:54:53 +0300 Subject: Heal version created based on old-unhealed version Change-Id: I4d50b349988e8e31f46cc9727f84fced84876fea Issue-ID: SDC-1366 Signed-off-by: talig --- .../sdc/healing/impl/HealingManagerImpl.java | 60 +++++++++++++--------- 1 file changed, 37 insertions(+), 23 deletions(-) (limited to 'openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src') diff --git a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java index eb3fd91bcf..e51f427b55 100644 --- a/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java +++ b/openecomp-be/lib/openecomp-healing-lib/openecomp-sdc-healing-core/src/main/java/org/openecomp/sdc/healing/impl/HealingManagerImpl.java @@ -67,7 +67,9 @@ public class HealingManagerImpl implements HealingManager { public Optional healItemVersion(final String itemId, final Version version, final ItemType itemType, final boolean force) { String user = getUser(); - if (!force && !isPrivateHealingNeededByFlags(itemId, version.getId(), user)) { + populateVersionInfo(itemId, version); + + if (!isHealingNeeded(itemId, version, force, user)) { return Optional.empty(); } @@ -102,8 +104,26 @@ public class HealingManagerImpl implements HealingManager { return healVersion; } + private void populateVersionInfo(String itemId, Version version) { + if (version.getStatus() != null) { + return; + } + + Version retrievedVersion = versioningManager.get(itemId, version); + version.setStatus(retrievedVersion.getStatus()); + version.setBaseId(retrievedVersion.getBaseId()); + } + + private boolean isHealingNeeded(String itemId, Version version, boolean force, String user) { + return force || isHealingFlagOn(itemId, version.getId(), user) + .orElse(isHealingFlagOn(itemId, version.getId(), PUBLIC_USER) + .orElse(version.getStatus() == VersionStatus.Draft && version.getBaseId() != null && + isHealingFlagOn(itemId, version.getBaseId(), user) + .orElse(isHealingFlagOn(itemId, version.getBaseId(), PUBLIC_USER) + .orElse(false)))); + } + private Optional getHealVersion(String itemId, Version version) { - version.setStatus(versioningManager.get(itemId, version).getStatus()); return version.getStatus() == VersionStatus.Certified ? createNewVersion(itemId, version.getId()) : Optional.of(version); @@ -124,9 +144,12 @@ public class HealingManagerImpl implements HealingManager { List structureHealersToRun, List dataHealersToRun, String user, boolean force) { + boolean publicFlagOn = isHealingFlagOn(itemId, origVersion.getId(), PUBLIC_USER) + .orElse(origVersion.getBaseId() != null && + isHealingFlagOn(itemId, origVersion.getBaseId(), PUBLIC_USER).orElse(false)); + List failureMessages = - force || origVersion.getStatus() == VersionStatus.Certified || - isPublicHealingNeededByFlag(itemId, origVersion.getId()) + force || origVersion.getStatus() == VersionStatus.Certified || publicFlagOn ? healPublic(itemId, version, origVersion, structureHealersToRun, dataHealersToRun, user) : new LinkedList<>(); @@ -203,17 +226,7 @@ public class HealingManagerImpl implements HealingManager { return failureMessages; } - private boolean isPrivateHealingNeededByFlags(String itemId, String version, String user) { - Optional userHealingFlag = getHealingFlag(itemId, version, user); - return userHealingFlag.orElseGet(() -> isPublicHealingNeededByFlag(itemId, version)); - } - - private boolean isPublicHealingNeededByFlag(String itemId, String versionId) { - Optional publicHealingFlag = getHealingFlag(itemId, versionId, PUBLIC_USER); - return publicHealingFlag.isPresent() && publicHealingFlag.get(); - } - - private Optional getHealingFlag(String itemId, String version, String user) { + private Optional isHealingFlagOn(String itemId, String version, String user) { return healingDao.getItemHealingFlag(user, itemId, version); } @@ -232,13 +245,13 @@ public class HealingManagerImpl implements HealingManager { private List getHealersToRun(Collection healersClassNames, String itemId, Version version, List failureMessages) { return healersClassNames == null - ? Collections.emptyList() - : healersClassNames.stream() - .map(healerClassName -> getHealerInstance(healerClassName, failureMessages)) - .filter(Optional::isPresent) - .map(Optional::get) - .filter(healer -> healer.isHealingNeeded(itemId, version)) - .collect(Collectors.toList()); + ? Collections.emptyList() + : healersClassNames.stream() + .map(healerClassName -> getHealerInstance(healerClassName, failureMessages)) + .filter(Optional::isPresent) + .map(Optional::get) + .filter(healer -> healer.isHealingNeeded(itemId, version)) + .collect(Collectors.toList()); } private Optional getHealerInstance(String healerClassName, List failureMessages) { @@ -255,7 +268,8 @@ public class HealingManagerImpl implements HealingManager { Map healingConfig = FileUtils .readViaInputStream(HEALERS_BY_ENTITY_TYPE_FILE, stream -> JsonUtil.json2Object(stream, Map.class)); - return (Map>) healingConfig.getOrDefault(itemType.name(), Collections.emptyMap()); + return (Map>) healingConfig + .getOrDefault(itemType.name(), Collections.emptyMap()); } private String getUser() { -- cgit 1.2.3-korg