import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
// A map indexed by the property name. Each map entry is the serialized value of the property,
// which can be deserialized into an instance of the type of the property.
- private Map<String, ToscaProperty> propertiesMap = new LinkedHashMap<>();
+ private Map<String, Object> properties = new LinkedHashMap<>();
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
this.orderedState = otherElement.orderedState;
this.toscaServiceTemplateFragment = otherElement.toscaServiceTemplateFragment;
this.description = otherElement.description;
- this.propertiesMap = PfUtils.mapMap(otherElement.propertiesMap, UnaryOperator.identity());
+ this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
}
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation.
+ * Copyright (C) 2021-2022 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
package org.onap.policy.clamp.models.acm.persistence.concepts;
+import java.util.LinkedHashMap;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
+import java.util.function.UnaryOperator;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
+import javax.persistence.Convert;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
+import javax.persistence.Lob;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@Column
private String description;
+ @Lob
+ @NotNull
+ @Valid
+ @Convert(converter = StringToMapConverter.class)
+ private Map<String, Object> properties;
+
/**
* The Default Constructor creates a {@link JpaAutomationCompositionElement} object with a null key.
*/
this.state = copyConcept.state;
this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
+ this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
}
/**
element.setState(state);
element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
element.setDescription(description);
+ element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
return element;
}
this.state = element.getState();
this.orderedState = element.getOrderedState();
this.description = element.getDescription();
+ properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
}
@Override
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.persistence.concepts;
+
+import java.util.HashMap;
+import java.util.Map;
+import javax.persistence.AttributeConverter;
+import javax.persistence.Converter;
+import javax.ws.rs.core.Response;
+import org.onap.policy.common.utils.coder.Coder;
+import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
+import org.onap.policy.models.base.PfModelRuntimeException;
+
+@Converter(autoApply = true)
+public class StringToMapConverter implements AttributeConverter<Map<String, Object>, String> {
+
+ private static final Coder coder = new StandardCoder();
+
+ @Override
+ public String convertToDatabaseColumn(Map<String, Object> map) {
+ try {
+ return map == null ? null : coder.encode(map);
+ } catch (CoderException e) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public Map<String, Object> convertToEntityAttribute(String dbData) {
+ if (dbData == null) {
+ return new HashMap<>();
+ }
+ try {
+ return coder.decode(dbData, Map.class);
+ } catch (CoderException e) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, e.getMessage(), e);
+ }
+ }
+}
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.ParticipantUpdates;
import org.onap.policy.common.utils.coder.CoderException;
+import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
void testCopyConstructor() throws CoderException {
assertThatThrownBy(() -> new AutomationCompositionUpdate(null)).isInstanceOf(NullPointerException.class);
- AutomationCompositionUpdate orig = new AutomationCompositionUpdate();
+ var orig = new AutomationCompositionUpdate();
// verify with all values
- ToscaConceptIdentifier id = new ToscaConceptIdentifier("id", "1.2.3");
+ var id = new ToscaConceptIdentifier("id", "1.2.3");
orig.setAutomationCompositionId(id);
orig.setParticipantId(null);
orig.setMessageId(UUID.randomUUID());
orig.setTimestamp(Instant.ofEpochMilli(3000));
- AutomationCompositionElement acElement = new AutomationCompositionElement();
+ var acElement = new AutomationCompositionElement();
acElement.setId(UUID.randomUUID());
acElement.setDefinition(id);
acElement.setDescription("Description");
acElement.setParticipantId(id);
acElement.setParticipantType(id);
- ToscaProperty property = new ToscaProperty();
+ var property = new ToscaProperty();
property.setName("test");
property.setType("testType");
- Map<String, ToscaProperty> propertiesMap = Map.of("Prop1", property);
- acElement.setPropertiesMap(propertiesMap);
+ var standardCoder = new StandardCoder();
+ var json = standardCoder.encode(property);
+ var propertiesMap = Map.of("Prop1", (Object) json);
+ acElement.setProperties(propertiesMap);
- ParticipantUpdates participantUpdates = new ParticipantUpdates();
+ var participantUpdates = new ParticipantUpdates();
participantUpdates.setParticipantId(id);
participantUpdates.setAutomationCompositionElementList(List.of(acElement));
orig.setParticipantUpdatesList(List.of(participantUpdates));
- AutomationCompositionUpdate other = new AutomationCompositionUpdate(orig);
+ var other = new AutomationCompositionUpdate(orig);
assertEquals(removeVariableFields(orig.toString()), removeVariableFields(other.toString()));
assertSerializable(orig, AutomationCompositionUpdate.class);
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.File;
+import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
testJpaAutomationCompositionElement.fromAuthorative(testAce);
testJpaAutomationCompositionElement.setKey(PfReferenceKey.getNullKey());
testJpaAutomationCompositionElement.fromAuthorative(testAce);
+ testJpaAutomationCompositionElement.setProperties(Map.of("key", "{}"));
return testJpaAutomationCompositionElement;
}
automationCompositionElement.setId(UUID.fromString("a95757ba-b34a-4049-a2a8-46773abcbe5e"));
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantType(new ToscaConceptIdentifier("participantType", "0.0.1"));
+ automationCompositionElement.setProperties(Map.of("key", "{}"));
return automationCompositionElement;
}
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.StringToServiceTemplateConverter</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement</class>
+ <class>org.onap.policy.clamp.models.acm.persistence.concepts.StringToMapConverter</class>
<class>org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant</class>
<properties>
"version": "0.0.1"
},
"state": "UNINITIALISED",
- "orderedState": null
+ "orderedState": null,
+ "properties":{"key":"{}"}
}
package org.onap.policy.clamp.acm.participant.intermediary.handler;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
automationCompositions.setAutomationCompositionList(new ArrayList<>(automationCompositionMap.values()));
return automationCompositions;
}
-
- /**
- * Get properties of a automation composition element.
- *
- * @param id the automation composition element id
- * @return the instance properties
- */
- public Map<String, ToscaProperty> getAcElementInstanceProperties(UUID id) {
- Map<String, ToscaProperty> propertiesMap = new HashMap<>();
- for (var automationComposition : automationCompositionMap.values()) {
- var element = automationComposition.getElements().get(id);
- if (element != null) {
- propertiesMap.putAll(element.getPropertiesMap());
- }
- }
- return propertiesMap;
- }
}
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
updateMsg.setStartPhase(1);
assertDoesNotThrow(() -> ach.handleAutomationCompositionUpdate(updateMsg, acElementDefinitions));
- assertThat(ach.getAcElementInstanceProperties(uuid)).isEmpty();
ach.getAutomationCompositionMap().clear();
updateMsg.setStartPhase(0);