/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2020 Nordix Foundation.
- * Modifications Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.tosca.simple.concepts;
+import jakarta.persistence.ElementCollection;
+import jakarta.persistence.Entity;
+import jakarta.persistence.Inheritance;
+import jakarta.persistence.InheritanceType;
+import jakarta.persistence.Lob;
+import jakarta.persistence.Table;
+import java.io.Serial;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
-import javax.persistence.ElementCollection;
-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 lombok.NonNull;
-import org.onap.policy.common.parameters.annotations.Entries;
-import org.onap.policy.common.parameters.annotations.Items;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.utils.coder.YamlJsonTranslator;
-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.PfUtils;
-import org.onap.policy.models.base.validation.annotations.PfItems;
import org.onap.policy.models.base.validation.annotations.PfMin;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabilityAssignment>
- implements PfAuthorative<ToscaCapabilityAssignment> {
+public class JpaToscaCapabilityAssignment extends JpaToscaWithTypeAndStringProperties<ToscaCapabilityAssignment> {
+ @Serial
private static final long serialVersionUID = 1675770231921107988L;
private static final String AUTHORATIVE_UNBOUNDED_LITERAL = "UNBOUNDED";
@ElementCollection
@Lob
- @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
- private Map<String, String> properties;
+ private Map<@NotNull String, @NotNull String> attributes;
@ElementCollection
- @Lob
- @Entries(key = @Items(notNull = {@NotNull}), value = @Items(notNull = {@NotNull}))
- private Map<String, String> attributes;
-
- @ElementCollection
- @PfItems(notNull = {@NotNull}, pfMin = {@PfMin(value = 0, allowed = -1)})
- private List<Integer> occurrences;
+ private List<@NotNull @PfMin(value = 0, allowed = -1) Integer> occurrences;
/**
* The Default Constructor creates a {@link JpaToscaCapabilityAssignment} object with a null key.
*/
public JpaToscaCapabilityAssignment(final JpaToscaCapabilityAssignment copyConcept) {
super(copyConcept);
- this.properties = copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties);
this.attributes = copyConcept.attributes == null ? null : new LinkedHashMap<>(copyConcept.attributes);
this.occurrences = copyConcept.occurrences == null ? null : new ArrayList<>(copyConcept.occurrences);
}
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaCapabilityAssignment(@NonNull final ToscaCapabilityAssignment authorativeConcept) {
- super(new PfConceptKey());
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
public ToscaCapabilityAssignment toAuthorative() {
- ToscaCapabilityAssignment toscaCapabilityAssignment = new ToscaCapabilityAssignment();
+ var toscaCapabilityAssignment = new ToscaCapabilityAssignment();
super.setToscaEntity(toscaCapabilityAssignment);
super.toAuthorative();
- toscaCapabilityAssignment.setProperties(
- PfUtils.mapMap(properties, property -> YAML_JSON_TRANSLATOR.fromYaml(property, Object.class)));
-
toscaCapabilityAssignment.setAttributes(
PfUtils.mapMap(attributes, attribute -> YAML_JSON_TRANSLATOR.fromYaml(attribute, Object.class)));
public void fromAuthorative(ToscaCapabilityAssignment toscaCapabilityAssignment) {
super.fromAuthorative(toscaCapabilityAssignment);
-
- properties = PfUtils.mapMap(toscaCapabilityAssignment.getProperties(), YAML_JSON_TRANSLATOR::toYaml);
attributes = PfUtils.mapMap(toscaCapabilityAssignment.getAttributes(), YAML_JSON_TRANSLATOR::toYaml);
occurrences = PfUtils.mapList(toscaCapabilityAssignment.getOccurrences(), occurrence -> {
});
}
+ @Override
+ protected Object deserializePropertyValue(String propValue) {
+ return YAML_JSON_TRANSLATOR.fromYaml(propValue, Object.class);
+ }
+
+ @Override
+ protected String serializePropertyValue(Object propValue) {
+ return YAML_JSON_TRANSLATOR.toYaml(propValue);
+ }
+
@Override
public void clean() {
super.clean();
- properties = PfUtils.mapMap(properties, String::trim);
attributes = PfUtils.mapMap(attributes, String::trim);
}
@Override
public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
- return -1;
- }
-
if (this == otherConcept) {
return 0;
}
- if (getClass() != otherConcept.getClass()) {
- return getClass().getName().compareTo(otherConcept.getClass().getName());
- }
-
- final JpaToscaCapabilityAssignment other = (JpaToscaCapabilityAssignment) otherConcept;
- int result = super.compareTo(other);
+ int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
}
- result = PfUtils.compareMaps(properties, other.properties);
- if (result != 0) {
- return result;
- }
+ final JpaToscaCapabilityAssignment other = (JpaToscaCapabilityAssignment) otherConcept;
result = PfUtils.compareMaps(attributes, other.attributes);
if (result != 0) {