From e90fadeec27e0249bb64da08d817fa1c475630fa Mon Sep 17 00:00:00 2001 From: Sirisha_Manchikanti Date: Wed, 27 Oct 2021 08:24:48 +0100 Subject: Move code to common, avoid duplication This commit moves duplicate code from runtime and participant to common Issue-ID: POLICY-3542 Signed-off-by: Sirisha_Manchikanti Change-Id: Ia7cea1d2c88031c72af77338e242f8981e536c21 --- .../simulator/main/rest/TestListenerUtils.java | 71 ++-------------------- 1 file changed, 4 insertions(+), 67 deletions(-) (limited to 'participant/participant-impl/participant-impl-simulator/src/test/java') diff --git a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java index bd3316abb..c9848248e 100644 --- a/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java +++ b/participant/participant-impl/participant-impl-simulator/src/test/java/org/onap/policy/clamp/controlloop/participant/simulator/main/rest/TestListenerUtils.java @@ -33,9 +33,9 @@ import java.util.Set; import java.util.UUID; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.onap.policy.clamp.controlloop.common.utils.CommonUtils; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement; -import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElementDefinition; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState; import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantDefinition; @@ -166,39 +166,12 @@ public final class TestListenerUtils { List participantUpdates = new ArrayList<>(); for (ControlLoopElement element : elements.values()) { - prepareParticipantUpdateForControlLoop(element, participantUpdates); + CommonUtils.prepareParticipantUpdate(element, participantUpdates); } clUpdateMsg.setParticipantUpdatesList(participantUpdates); return clUpdateMsg; } - private static void prepareParticipantUpdateForControlLoop(ControlLoopElement clElement, - List participantUpdates) { - if (participantUpdates.isEmpty()) { - participantUpdates.add(getControlLoopElementList(clElement)); - } else { - boolean participantExists = false; - for (ParticipantUpdates participantUpdate : participantUpdates) { - if (participantUpdate.getParticipantId().equals(clElement.getParticipantId())) { - participantUpdate.getControlLoopElementList().add(clElement); - participantExists = true; - } - } - if (!participantExists) { - participantUpdates.add(getControlLoopElementList(clElement)); - } - } - } - - private static ParticipantUpdates getControlLoopElementList(ControlLoopElement clElement) { - ParticipantUpdates participantUpdate = new ParticipantUpdates(); - List controlLoopElementList = new ArrayList<>(); - participantUpdate.setParticipantId(clElement.getParticipantId()); - controlLoopElementList.add(clElement); - participantUpdate.setControlLoopElementList(controlLoopElementList); - return participantUpdate; - } - /** * Method to create participantUpdateMsg. * @@ -226,8 +199,8 @@ public final class TestListenerUtils { toscaServiceTemplate)) { var clParticipantType = ParticipantUtils.findParticipantType(toscaInputEntry.getValue().getProperties()); - prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), - toscaInputEntry.getValue(), participantDefinitionUpdates); + CommonUtils.prepareParticipantDefinitionUpdate(clParticipantType, toscaInputEntry.getKey(), + toscaInputEntry.getValue(), participantDefinitionUpdates, null); } } @@ -235,42 +208,6 @@ public final class TestListenerUtils { return participantUpdateMsg; } - private static void prepareParticipantDefinitionUpdate(ToscaConceptIdentifier clParticipantType, String entryKey, - ToscaNodeTemplate entryValue, List participantDefinitionUpdates) { - - var clDefinition = new ControlLoopElementDefinition(); - clDefinition.setClElementDefinitionId(new ToscaConceptIdentifier(entryKey, entryValue.getVersion())); - clDefinition.setControlLoopElementToscaNodeTemplate(entryValue); - List controlLoopElementDefinitionList = new ArrayList<>(); - - if (participantDefinitionUpdates.isEmpty()) { - participantDefinitionUpdates - .add(getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } else { - boolean participantExists = false; - for (ParticipantDefinition participantDefinitionUpdate : participantDefinitionUpdates) { - if (participantDefinitionUpdate.getParticipantType().equals(clParticipantType)) { - participantDefinitionUpdate.getControlLoopElementDefinitionList().add(clDefinition); - participantExists = true; - } - } - if (!participantExists) { - participantDefinitionUpdates.add( - getParticipantDefinition(clDefinition, clParticipantType, controlLoopElementDefinitionList)); - } - } - } - - private static ParticipantDefinition getParticipantDefinition(ControlLoopElementDefinition clDefinition, - ToscaConceptIdentifier clParticipantType, - List controlLoopElementDefinitionList) { - ParticipantDefinition participantDefinition = new ParticipantDefinition(); - participantDefinition.setParticipantType(clParticipantType); - controlLoopElementDefinitionList.add(clDefinition); - participantDefinition.setControlLoopElementDefinitionList(controlLoopElementDefinitionList); - return participantDefinition; - } - /** * Method to create ControlLoopUpdate using the arguments passed. * -- cgit 1.2.3-korg