summaryrefslogtreecommitdiffstats
path: root/catalog-be/src/main/java/org/openecomp
diff options
context:
space:
mode:
authorFrancis Toth <francis.toth@yoppworks.com>2020-05-31 08:42:14 -0400
committerOfir Sonsino <ofir.sonsino@intl.att.com>2020-06-17 13:02:17 +0000
commit5971be1a797d4ad232257c4bf5dd8c3359b56ede (patch)
tree2674a7ab9600c02dc54df076eb0e73599ba49d74 /catalog-be/src/main/java/org/openecomp
parent67bd4804ca771a5a1d6f2330c0c3573f149bfca1 (diff)
Refactor ArtifactsBusinessLogic::getUpdatedGroupInstances
Signed-off-by: Francis Toth <francis.toth@yoppworks.com> Change-Id: I6d62c1f916aa820f84328d25d2afbc7470397b0d Issue-ID: SDC-2961
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java43
1 files changed, 20 insertions, 23 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
index 60b88cf5cb..d8f85617c0 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/impl/ArtifactsBusinessLogic.java
@@ -27,7 +27,6 @@ import static org.openecomp.sdc.be.dao.api.ActionStatus.MISMATCH_BETWEEN_ARTIFAC
import com.google.common.annotations.VisibleForTesting;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
-import fj.F;
import fj.data.Either;
import io.vavr.control.Option;
import java.io.ByteArrayInputStream;
@@ -69,11 +68,11 @@ import org.openecomp.sdc.be.components.impl.artifact.PayloadTypeEnum;
import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ByResponseFormatComponentException;
import org.openecomp.sdc.be.components.impl.exceptions.ComponentException;
-import org.openecomp.sdc.be.components.utils.ArtifactUtils;
import org.openecomp.sdc.be.components.impl.utils.ComponentUtils;
import org.openecomp.sdc.be.components.lifecycle.LifecycleBusinessLogic;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction;
import org.openecomp.sdc.be.components.lifecycle.LifecycleChangeInfoWithAction.LifecycleChanceActionEnum;
+import org.openecomp.sdc.be.components.utils.ArtifactUtils;
import org.openecomp.sdc.be.components.utils.InterfaceOperationUtils;
import org.openecomp.sdc.be.config.ArtifactConfiguration;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
@@ -1454,27 +1453,25 @@ public class ArtifactsBusinessLogic extends BaseBusinessLogic {
return updatedGroups;
}
- private List<GroupInstance> getUpdatedGroupInstances(String artifactId, ArtifactDefinition foundArtifact, List<GroupInstance> groupInstances) {
- List<GroupInstance> updatedGroupInstances = new ArrayList<>();
- if (CollectionUtils.isNotEmpty(groupInstances)) {
- boolean isUpdated = false;
- for (GroupInstance groupInstance : groupInstances) {
- isUpdated = false;
- if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifacts()) && groupInstance.getGroupInstanceArtifacts().contains(artifactId)) {
- groupInstance.getGroupInstanceArtifacts().remove(artifactId);
- isUpdated = true;
- }
- if (CollectionUtils.isNotEmpty(groupInstance.getGroupInstanceArtifactsUuid()) && groupInstance.getGroupInstanceArtifactsUuid()
- .contains(foundArtifact.getArtifactUUID())) {
- groupInstance.getGroupInstanceArtifactsUuid().remove(foundArtifact.getArtifactUUID());
- isUpdated = true;
- }
- if (isUpdated) {
- updatedGroupInstances.add(groupInstance);
- }
- }
- }
- return updatedGroupInstances;
+ private List<GroupInstance> getUpdatedGroupInstances(
+ String artifactId, ArtifactDefinition foundArtifact, List<GroupInstance> groupInstances
+ ) {
+ if (CollectionUtils.isEmpty(groupInstances)) {
+ return new ArrayList<>();
+ }
+ // TODO: A defensive copy should be created here for groupInstances. Modifying
+ // arguments (aka output arguments) is overall a bad practice as explained in
+ // Clean Code by Robert Martin.
+ // A better approach would be to use Lenses.
+
+ return groupInstances.stream().filter(gi -> {
+ boolean groupInstanceArtifactRemoved = gi.getGroupInstanceArtifacts() != null &&
+ gi.getGroupInstanceArtifacts().remove(artifactId);
+ boolean groupInstanceArtifactUUIDRemoved = gi.getGroupInstanceArtifactsUuid() != null &&
+ gi.getGroupInstanceArtifactsUuid().remove(foundArtifact.getArtifactUUID());
+
+ return groupInstanceArtifactRemoved || groupInstanceArtifactUUIDRemoved;
+ }).collect(Collectors.toList());
}
private ArtifactDataDefinition deleteOrUpdateArtifactOnGraph(Component component, String parentId, String artifactId, NodeTypeEnum parentType, ArtifactDefinition foundArtifact, Boolean cloneIsNeeded) {