/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaCapabilityAssignment extends ToscaEntity {
- private Map<String, Object> properties;
+public class ToscaCapabilityAssignment extends ToscaWithObjectProperties {
private Map<String, Object> attributes;
private List<Object> occurrences;
}
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.authorative.concepts;
-import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaCapabilityType extends ToscaEntity {
- private Map<String, ToscaProperty> properties;
+public class ToscaCapabilityType extends ToscaWithToscaProperties {
+
}
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.models.tosca.authorative.concepts;
import java.util.List;
-import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaDataType extends ToscaEntity {
+public class ToscaDataType extends ToscaWithToscaProperties {
private List<ToscaConstraint> constraints;
-
- private Map<String, ToscaProperty> properties;
}
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2020-2021 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaNodeTemplate extends ToscaEntity {
+public class ToscaNodeTemplate extends ToscaWithObjectProperties {
private String type;
- private Map<String, Object> properties;
private List<Map<String, ToscaRequirement>> requirements;
private Map<String, ToscaCapabilityAssignment> capabilities;
this.type = copyObject.type;
- this.properties = (copyObject.properties != null ? new LinkedHashMap<>(copyObject.properties) : null);
this.requirements = (copyObject.requirements != null ? new ArrayList<>(copyObject.requirements) : null);
this.capabilities = (copyObject.capabilities != null ? new LinkedHashMap<>(copyObject.capabilities) : null);
}
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaNodeType extends ToscaEntity {
- private Map<String, ToscaProperty> properties;
+public class ToscaNodeType extends ToscaWithToscaProperties {
private List<Map<String, ToscaRequirement>> requirements;
}
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2021 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
import com.google.gson.annotations.SerializedName;
import io.swagger.annotations.ApiModelProperty;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@ToString(callSuper = true)
-public class ToscaPolicy extends ToscaEntity {
+public class ToscaPolicy extends ToscaWithObjectProperties {
private String type;
@ApiModelProperty(name = "type_version")
@SerializedName("type_version")
private String typeVersion;
- private Map<String, Object> properties;
-
/**
* Copy constructor.
*
this.type = copyObject.type;
this.typeVersion = copyObject.typeVersion;
-
- if (copyObject.properties != null) {
- properties = new LinkedHashMap<>();
- for (final Entry<String, Object> propertyEntry : copyObject.properties.entrySet()) {
- properties.put(propertyEntry.getKey(), propertyEntry.getValue());
- }
- }
}
/**
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019-2020 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.models.tosca.authorative.concepts;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Map.Entry;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaPolicyType extends ToscaEntity {
- private Map<String, ToscaProperty> properties;
+public class ToscaPolicyType extends ToscaWithToscaProperties {
/**
* Copy Constructor.
*/
public ToscaPolicyType(@NonNull ToscaPolicyType copyObject) {
super(copyObject);
-
- if (copyObject.properties != null) {
- properties = new LinkedHashMap<>();
- for (final Entry<String, ToscaProperty> propertyEntry : copyObject.properties.entrySet()) {
- properties.put(propertyEntry.getKey(), propertyEntry.getValue());
- }
- }
}
}
* ONAP Policy Model
* ================================================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.authorative.concepts;
-import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
-public class ToscaRelationshipType extends ToscaEntity {
- private Map<String, ToscaProperty> properties;
+public class ToscaRelationshipType extends ToscaWithToscaProperties {
+
}
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2020 Nordix Foundation.
+ * Modifications Copyright (C) 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.authorative.concepts;
import java.util.List;
-import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@EqualsAndHashCode(callSuper = true)
-public class ToscaRequirement extends ToscaEntity {
+public class ToscaRequirement extends ToscaWithObjectProperties {
private String capability;
private String node;
private String relationship;
private List<Object> occurrences;
- private Map<String, Object> properties;
}
--- /dev/null
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.models.tosca.authorative.concepts;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+import lombok.ToString;
+
+/**
+ * Class to represent TOSCA classes containing property maps whose values are generic
+ * Objects.
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+@ToString
+public class ToscaWithObjectProperties extends ToscaEntity {
+ private Map<String, Object> properties;
+
+ /**
+ * Cop[y constructor.
+ *
+ * @param copyObject object to copy
+ */
+ public ToscaWithObjectProperties(@NonNull ToscaWithObjectProperties copyObject) {
+ super(copyObject);
+
+ if (copyObject.properties != null) {
+ properties = new LinkedHashMap<>(copyObject.properties);
+ }
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP Policy Model
+ * ================================================================================
+ * Copyright (C) 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.
+ * 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.models.tosca.authorative.concepts;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
+import lombok.NonNull;
+
+/**
+ * Class to represent TOSCA classes containing TOSCA properties.
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@NoArgsConstructor
+public class ToscaWithToscaProperties extends ToscaEntity {
+ private Map<String, ToscaProperty> properties;
+
+ /**
+ * Copy Constructor.
+ *
+ * @param copyObject object to copy from
+ */
+ public ToscaWithToscaProperties(@NonNull ToscaWithToscaProperties copyObject) {
+ super(copyObject);
+
+ if (copyObject.properties != null) {
+ properties = new LinkedHashMap<>(copyObject.properties);
+ }
+ }
+}
import lombok.NonNull;
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;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaToscaCapabilityAssignment extends JpaToscaEntityType<ToscaCapabilityAssignment>
- implements PfAuthorative<ToscaCapabilityAssignment> {
+public class JpaToscaCapabilityAssignment extends JpaToscaWithStringProperties<ToscaCapabilityAssignment> {
private static final long serialVersionUID = 1675770231921107988L;
private static final YamlJsonTranslator YAML_JSON_TRANSLATOR = new YamlJsonTranslator();
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull String> properties;
-
@ElementCollection
@Lob
private Map<@NotNull String, @NotNull String> attributes;
*/
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
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) {
package org.onap.policy.models.tosca.simple.concepts;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-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.NoArgsConstructor;
import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
-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.tosca.authorative.concepts.ToscaCapabilityType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* Class to represent the capability type in TOSCA definition.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaCapabilityType extends JpaToscaEntityType<ToscaCapabilityType>
- implements PfAuthorative<ToscaCapabilityType> {
+@NoArgsConstructor
+public class JpaToscaCapabilityType extends JpaToscaWithToscaProperties<ToscaCapabilityType> {
private static final long serialVersionUID = -563659852901842616L;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
- /**
- * The Default Constructor creates a {@link JpaToscaCapabilityType} object with a null key.
- */
- public JpaToscaCapabilityType() {
- this(new PfConceptKey());
- }
-
/**
* The Key Constructor creates a {@link JpaToscaCapabilityType} object with the given concept key.
*
*/
public JpaToscaCapabilityType(final JpaToscaCapabilityType copyConcept) {
super(copyConcept);
- this.properties = copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties);
}
/**
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaCapabilityType(final ToscaCapabilityType authorativeConcept) {
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
public ToscaCapabilityType toAuthorative() {
- ToscaCapabilityType toscaCapabilityType = new ToscaCapabilityType();
- super.setToscaEntity(toscaCapabilityType);
- super.toAuthorative();
-
- toscaCapabilityType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
-
- return toscaCapabilityType;
- }
-
- @Override
- public void fromAuthorative(final ToscaCapabilityType toscaCapabilityType) {
- super.fromAuthorative(toscaCapabilityType);
-
- // Set properties
- if (toscaCapabilityType.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaCapabilityType.getProperties().entrySet()) {
- JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
- jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
- }
-
- @Override
- public List<PfKey> getKeys() {
- final List<PfKey> keyList = super.getKeys();
-
- PfUtils.mapMap(properties, property -> keyList.addAll(property.getKeys()));
-
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- keyList.addAll(property.getKeys());
- }
- }
-
- return keyList;
- }
-
- @Override
- public void clean() {
- super.clean();
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- property.clean();
- }
- }
+ super.setToscaEntity(new ToscaCapabilityType());
+ return super.toAuthorative();
}
@Override
public BeanValidationResult validate(@NonNull String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateKeyVersionNotNull(result, "key", getKey());
-
- return result;
- }
-
- @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 JpaToscaCapabilityType other = (JpaToscaCapabilityType) otherConcept;
- int result = super.compareTo(other);
- if (result != 0) {
- return result;
- }
-
- return PfUtils.compareMaps(properties, other.properties);
- }
-
- /**
- * Get the data types referenced in a capability type.
- *
- * @return the data types referenced in a capability type
- */
- public Collection<PfConceptKey> getReferencedDataTypes() {
- if (properties == null) {
- return CollectionUtils.emptyCollection();
- }
-
- Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
- for (JpaToscaProperty property : properties.values()) {
- referencedDataTypes.add(property.getType());
-
- if (property.getEntrySchema() != null) {
- referencedDataTypes.add(property.getEntrySchema().getType());
- }
- }
-
- referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
-
- return referencedDataTypes;
+ return validateWithKey(fieldName);
}
}
package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
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.NoArgsConstructor;
import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
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.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* Class to represent custom data type in TOSCA definition.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaDataType extends JpaToscaEntityType<ToscaDataType> implements PfAuthorative<ToscaDataType> {
+@NoArgsConstructor
+public class JpaToscaDataType extends JpaToscaWithToscaProperties<ToscaDataType> {
private static final long serialVersionUID = -3922690413436539164L;
@ElementCollection
private List<@NotNull @Valid JpaToscaConstraint> constraints;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
- /**
- * The Default Constructor creates a {@link JpaToscaDataType} object with a null key.
- */
- public JpaToscaDataType() {
- this(new PfConceptKey());
- }
-
/**
* The Key Constructor creates a {@link JpaToscaDataType} object with the given concept key.
*
super(copyConcept);
// Constraints are immutable
this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
- this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
}
/**
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaDataType(final ToscaDataType authorativeConcept) {
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
super.toAuthorative();
toscaDataType.setConstraints(PfUtils.mapList(constraints, JpaToscaConstraint::toAuthorative));
- toscaDataType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
return toscaDataType;
}
super.fromAuthorative(toscaDataType);
constraints = PfUtils.mapList(toscaDataType.getConstraints(), JpaToscaConstraint::newInstance);
-
- if (toscaDataType.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaDataType.getProperties().entrySet()) {
- JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
- jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
- }
-
- @Override
- public List<PfKey> getKeys() {
- final List<PfKey> keyList = super.getKeys();
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- keyList.addAll(property.getKeys());
- }
- }
-
- return keyList;
- }
-
- @Override
- public void clean() {
- super.clean();
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- property.clean();
- }
- }
}
@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 JpaToscaDataType other = (JpaToscaDataType) otherConcept;
- int result = super.compareTo(other);
- if (result != 0) {
- return result;
- }
- result = PfUtils.compareCollections(constraints, other.constraints);
+ int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
}
- return PfUtils.compareMaps(properties, other.properties);
- }
-
- /**
- * Get the data types referenced in a data type.
- *
- * @return the data types referenced in a data type
- */
- public Collection<PfConceptKey> getReferencedDataTypes() {
- if (properties == null) {
- return CollectionUtils.emptyCollection();
- }
-
- Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
- for (JpaToscaProperty property : properties.values()) {
- referencedDataTypes.add(property.getType());
-
- if (property.getEntrySchema() != null) {
- referencedDataTypes.add(property.getEntrySchema().getType());
- }
- }
-
- referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
+ final JpaToscaDataType other = (JpaToscaDataType) otherConcept;
- return referencedDataTypes;
+ return PfUtils.compareCollections(constraints, other.constraints);
}
}
import java.util.Map;
import javax.persistence.CascadeType;
import javax.persistence.Column;
-import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.ws.rs.core.Response;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-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.PfModelRuntimeException;
-import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = false)
-public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate>
- implements PfAuthorative<ToscaNodeTemplate> {
+public class JpaToscaNodeTemplate extends JpaToscaWithStringProperties<ToscaNodeTemplate> {
private static final long serialVersionUID = 1675770231921107988L;
private static final StandardCoder STANDARD_CODER = new StandardCoder();
@NotBlank
private String type;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull String> properties;
-
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@JoinColumn(name = "requirementsName", referencedColumnName = "name")
public JpaToscaNodeTemplate(final JpaToscaNodeTemplate copyConcept) {
super(copyConcept);
this.type = copyConcept.type;
- this.properties = PfUtils.mapMap(copyConcept.properties, String::new);
this.requirements =
(copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
this.capabilities =
toscaNodeTemplate.setType(type);
- toscaNodeTemplate.setProperties(PfUtils.mapMap(properties, property -> {
- try {
- return STANDARD_CODER.decode(property, Object.class);
- } catch (CoderException ce) {
- String errorMessage = "error decoding property JSON value read from database: " + property;
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
- }
- }));
-
if (requirements != null) {
toscaNodeTemplate.setRequirements(requirements.toAuthorative());
}
type = toscaNodeTemplate.getType();
- properties = PfUtils.mapMap(toscaNodeTemplate.getProperties(), property -> {
- try {
- return STANDARD_CODER.encode(property);
- } catch (CoderException ce) {
- String errorMessage = "error encoding property JSON value for database: " + property;
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
- }
- });
-
if (toscaNodeTemplate.getRequirements() != null) {
requirements = new JpaToscaRequirements();
requirements.fromAuthorative(toscaNodeTemplate.getRequirements());
}
}
+ @Override
+ protected Object deserializePropertyValue(String propValue) {
+ try {
+ return STANDARD_CODER.decode(propValue, Object.class);
+ } catch (CoderException ce) {
+ String errorMessage = "error decoding property JSON value read from database: " + propValue;
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
+ }
+
+ @Override
+ protected String serializePropertyValue(Object propValue) {
+ try {
+ return STANDARD_CODER.encode(propValue);
+ } catch (CoderException ce) {
+ String errorMessage = "error encoding property JSON value for database: " + propValue;
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
+ }
+
@Override
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
type = type.trim();
- properties = PfUtils.mapMap(properties, String::trim);
-
if (requirements != null) {
requirements.clean();
}
@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 JpaToscaNodeTemplate other = (JpaToscaNodeTemplate) otherConcept;
- int result = super.compareTo(other);
+ int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
}
- result = type.compareTo(other.type);
- if (result != 0) {
- return result;
- }
+ final JpaToscaNodeTemplate other = (JpaToscaNodeTemplate) otherConcept;
- result = PfUtils.compareMaps(properties, other.properties);
+ result = type.compareTo(other.type);
if (result != 0) {
return result;
}
package org.onap.policy.models.tosca.simple.concepts;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
import javax.persistence.CascadeType;
-import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.NoArgsConstructor;
import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
-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.tosca.authorative.concepts.ToscaNodeType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* Class to represent the node type in TOSCA definition.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implements PfAuthorative<ToscaNodeType> {
+@NoArgsConstructor
+public class JpaToscaNodeType extends JpaToscaWithToscaProperties<ToscaNodeType> {
private static final long serialVersionUID = -563659852901842616L;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
@Valid
private JpaToscaRequirements requirements;
- /**
- * The Default Constructor creates a {@link JpaToscaNodeType} object with a null key.
- */
- public JpaToscaNodeType() {
- this(new PfConceptKey());
- }
-
/**
* The Key Constructor creates a {@link JpaToscaNodeType} object with the given concept key.
*
*/
public JpaToscaNodeType(final JpaToscaNodeType copyConcept) {
super(copyConcept);
- this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
this.requirements =
(copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
}
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaNodeType(final ToscaNodeType authorativeConcept) {
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
super.setToscaEntity(toscaNodeType);
super.toAuthorative();
- toscaNodeType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
-
if (requirements != null) {
toscaNodeType.setRequirements(requirements.toAuthorative());
}
public void fromAuthorative(final ToscaNodeType toscaNodeType) {
super.fromAuthorative(toscaNodeType);
- // Set properties
- if (toscaNodeType.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaNodeType.getProperties().entrySet()) {
- JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
- jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
-
if (toscaNodeType.getRequirements() != null) {
requirements = new JpaToscaRequirements();
requirements.fromAuthorative(toscaNodeType.getRequirements());
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- keyList.addAll(property.getKeys());
- }
- }
-
if (requirements != null) {
keyList.addAll(requirements.getKeys());
}
public void clean() {
super.clean();
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- property.clean();
- }
- }
-
if (requirements != null) {
requirements.clean();
}
@Override
public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateKeyVersionNotNull(result, "key", getKey());
-
- return result;
+ return validateWithKey(fieldName);
}
@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 JpaToscaNodeType other = (JpaToscaNodeType) 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 JpaToscaNodeType other = (JpaToscaNodeType) otherConcept;
return ObjectUtils.compare(requirements, other.requirements);
}
-
- /**
- * Get the data types referenced in a node type.
- *
- * @return the data types referenced in a node type
- */
- public Collection<PfConceptKey> getReferencedDataTypes() {
- if (properties == null) {
- return CollectionUtils.emptyCollection();
- }
-
- Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
- for (JpaToscaProperty property : properties.values()) {
- referencedDataTypes.add(property.getType());
-
- if (property.getEntrySchema() != null) {
- referencedDataTypes.add(property.getEntrySchema().getType());
- }
- }
-
- referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
-
- return referencedDataTypes;
- }
}
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import javax.persistence.AttributeOverride;
import javax.persistence.Column;
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 javax.ws.rs.core.Response;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import org.onap.policy.common.parameters.BeanValidationResult;
-import org.onap.policy.common.parameters.annotations.NotBlank;
import org.onap.policy.common.parameters.annotations.NotNull;
import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-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;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements PfAuthorative<ToscaPolicy> {
+public class JpaToscaPolicy extends JpaToscaWithStringProperties<ToscaPolicy> {
private static final long serialVersionUID = 3265174757061982805L;
// Tags for metadata
@NotNull
private PfConceptKey type;
- @ElementCollection
- @Lob
- private Map<@NotNull @NotBlank String, @NotNull String> properties;
-
@ElementCollection
private List<@NotNull @Valid PfConceptKey> targets;
// @formatter:on
public JpaToscaPolicy(@NonNull final JpaToscaPolicy copyConcept) {
super(copyConcept);
this.type = new PfConceptKey(copyConcept.type);
- this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
}
toscaPolicy.setTypeVersion(null);
}
- toscaPolicy.setProperties(PfUtils.mapMap(properties, property -> {
- try {
- return STANDARD_CODER.decode(property, Object.class);
- } catch (CoderException ce) {
- String errorMessage = "error decoding property JSON value read from database: " + property;
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
- }
- }));
-
return toscaPolicy;
}
+ " in the type_version field");
}
- properties = PfUtils.mapMap(toscaPolicy.getProperties(), property -> {
- try {
- return STANDARD_CODER.encode(property);
- } catch (CoderException ce) {
- String errorMessage = "error encoding property JSON value for database: " + property;
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
- }
- });
-
// Add the property metadata if it doesn't exist already
if (toscaPolicy.getMetadata() == null) {
setMetadata(new LinkedHashMap<>());
getMetadata().put(METADATA_POLICY_VERSION_TAG, getKey().getVersion());
}
+ @Override
+ protected Object deserializePropertyValue(String propValue) {
+ try {
+ return STANDARD_CODER.decode(propValue, Object.class);
+ } catch (CoderException ce) {
+ String errorMessage = "error decoding property JSON value read from database: " + propValue;
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
+ }
+
+ @Override
+ protected String serializePropertyValue(Object propValue) {
+ try {
+ return STANDARD_CODER.encode(propValue);
+ } catch (CoderException ce) {
+ String errorMessage = "error encoding property JSON value for database: " + propValue;
+ throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, ce);
+ }
+ }
+
@Override
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
@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 JpaToscaPolicy other = (JpaToscaPolicy) otherConcept;
- int result = super.compareTo(other);
+ int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
}
- result = type.compareTo(other.type);
- if (result != 0) {
- return result;
- }
+ final JpaToscaPolicy other = (JpaToscaPolicy) otherConcept;
- result = PfUtils.compareMaps(properties, other.properties);
+ result = type.compareTo(other.type);
if (result != 0) {
return result;
}
package org.onap.policy.models.tosca.simple.concepts;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
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.NoArgsConstructor;
import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
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.tosca.authorative.concepts.ToscaPolicyType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaProperty;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* Class to represent the policy type in TOSCA definition.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaPolicyType extends JpaToscaEntityType<ToscaPolicyType> implements PfAuthorative<ToscaPolicyType> {
+@NoArgsConstructor
+public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyType> {
private static final long serialVersionUID = -563659852901842616L;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
@ElementCollection
private List<@NotNull @Valid PfConceptKey> targets;
@ElementCollection
private List<@NotNull @Valid JpaToscaTrigger> triggers;
- /**
- * The Default Constructor creates a {@link JpaToscaPolicyType} object with a null key.
- */
- public JpaToscaPolicyType() {
- this(new PfConceptKey());
- }
-
/**
* The Key Constructor creates a {@link JpaToscaPolicyType} object with the given concept key.
*
*/
public JpaToscaPolicyType(final JpaToscaPolicyType copyConcept) {
super(copyConcept);
- this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
this.triggers = PfUtils.mapList(copyConcept.triggers, JpaToscaTrigger::new);
}
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaPolicyType(final ToscaPolicyType authorativeConcept) {
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
super.setToscaEntity(toscaPolicyType);
super.toAuthorative();
- toscaPolicyType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
+ // TODO need to copy targets & triggers?
return toscaPolicyType;
}
public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
super.fromAuthorative(toscaPolicyType);
- // Set properties
- if (toscaPolicyType.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaPolicyType.getProperties().entrySet()) {
- JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
- jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
+ // TODO need to copy targets & triggers?
}
@Override
public List<PfKey> getKeys() {
final List<PfKey> keyList = super.getKeys();
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- keyList.addAll(property.getKeys());
- }
- }
-
if (targets != null) {
keyList.addAll(targets);
}
public void clean() {
super.clean();
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- property.clean();
- }
- }
-
if (targets != null) {
for (PfConceptKey target : targets) {
target.clean();
}
@Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateKeyVersionNotNull(result, "key", getKey());
-
- return result;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ return validateWithKey(fieldName);
}
@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 JpaToscaPolicyType other = (JpaToscaPolicyType) 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 JpaToscaPolicyType other = (JpaToscaPolicyType) otherConcept;
result = PfUtils.compareCollections(targets, other.targets);
if (result != 0) {
return PfUtils.compareCollections(triggers, other.triggers);
}
-
- /**
- * Get the data types referenced in a policy type.
- *
- * @return the data types referenced in a policy type
- */
- public Collection<PfConceptKey> getReferencedDataTypes() {
- if (properties == null) {
- return CollectionUtils.emptyCollection();
- }
-
- Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
- for (JpaToscaProperty property : properties.values()) {
- referencedDataTypes.add(property.getType());
-
- if (property.getEntrySchema() != null) {
- referencedDataTypes.add(property.getEntrySchema().getType());
- }
- }
-
- referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
-
- return referencedDataTypes;
- }
}
package org.onap.policy.models.tosca.simple.concepts;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-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.NoArgsConstructor;
import lombok.NonNull;
-import org.apache.commons.collections4.CollectionUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
-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.tosca.authorative.concepts.ToscaProperty;
import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
-import org.onap.policy.models.tosca.utils.ToscaUtils;
/**
* Class to represent the relationship type in TOSCA definition.
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaRelationshipType extends JpaToscaEntityType<ToscaRelationshipType>
- implements PfAuthorative<ToscaRelationshipType> {
+@NoArgsConstructor
+public class JpaToscaRelationshipType extends JpaToscaWithToscaProperties<ToscaRelationshipType> {
private static final long serialVersionUID = -563659852901842616L;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull @Valid JpaToscaProperty> properties;
-
- /**
- * The Default Constructor creates a {@link JpaToscaRelationshipType} object with a null key.
- */
- public JpaToscaRelationshipType() {
- this(new PfConceptKey());
- }
-
/**
* The Key Constructor creates a {@link JpaToscaRelationshipType} object with the given concept key.
*
*/
public JpaToscaRelationshipType(final JpaToscaRelationshipType copyConcept) {
super(copyConcept);
- this.properties = PfUtils.mapMap(copyConcept.properties, JpaToscaProperty::new);
}
/**
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaRelationshipType(final ToscaRelationshipType authorativeConcept) {
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
public ToscaRelationshipType toAuthorative() {
- ToscaRelationshipType toscaRelationshipType = new ToscaRelationshipType();
- super.setToscaEntity(toscaRelationshipType);
- super.toAuthorative();
-
- toscaRelationshipType.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
-
- return toscaRelationshipType;
+ super.setToscaEntity(new ToscaRelationshipType());
+ return super.toAuthorative();
}
@Override
- public void fromAuthorative(final ToscaRelationshipType toscaRelationshipType) {
- super.fromAuthorative(toscaRelationshipType);
-
- // Set properties
- if (toscaRelationshipType.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Entry<String, ToscaProperty> toscaPropertyEntry : toscaRelationshipType.getProperties().entrySet()) {
- JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
- jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
- }
-
- @Override
- public List<PfKey> getKeys() {
- final List<PfKey> keyList = super.getKeys();
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- keyList.addAll(property.getKeys());
- }
- }
-
- return keyList;
- }
-
- @Override
- public void clean() {
- super.clean();
-
- if (properties != null) {
- for (JpaToscaProperty property : properties.values()) {
- property.clean();
- }
- }
- }
-
- @Override
- public BeanValidationResult validate(String fieldName) {
- BeanValidationResult result = super.validate(fieldName);
-
- validateKeyVersionNotNull(result, "key", getKey());
-
- return result;
- }
-
- @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 JpaToscaRelationshipType other = (JpaToscaRelationshipType) otherConcept;
- int result = super.compareTo(other);
- if (result != 0) {
- return result;
- }
-
- return PfUtils.compareMaps(properties, other.properties);
- }
-
- /**
- * Get the data types referenced in a relationship type.
- *
- * @return the data types referenced in a relationship type
- */
- public Collection<PfConceptKey> getReferencedDataTypes() {
- if (properties == null) {
- return CollectionUtils.emptyCollection();
- }
-
- Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
-
- for (JpaToscaProperty property : properties.values()) {
- referencedDataTypes.add(property.getType());
-
- if (property.getEntrySchema() != null) {
- referencedDataTypes.add(property.getEntrySchema().getType());
- }
- }
-
- referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
-
- return referencedDataTypes;
+ public BeanValidationResult validate(@NonNull String fieldName) {
+ return validateWithKey(fieldName);
}
}
package org.onap.policy.models.tosca.simple.concepts;
import java.util.ArrayList;
-import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Map;
import javax.persistence.Column;
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.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;
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Data
@EqualsAndHashCode(callSuper = true)
-public class JpaToscaRequirement extends JpaToscaEntityType<ToscaRequirement>
- implements PfAuthorative<ToscaRequirement> {
+public class JpaToscaRequirement extends JpaToscaWithStringProperties<ToscaRequirement> {
private static final long serialVersionUID = 2785481541573683089L;
private static final String AUTHORATIVE_UNBOUNDED_LITERAL = "UNBOUNDED";
private static final Integer JPA_UNBOUNDED_VALUE = -1;
+ private static final YamlJsonTranslator YAML_TRANSLATOR = new YamlJsonTranslator();
@Column
private String capability;
@ElementCollection
private List<@NotNull @PfMin(value = 0, allowed = -1) Integer> occurrences;
- @ElementCollection
- @Lob
- private Map<@NotNull String, @NotNull String> properties;
-
/**
* The Default Constructor creates a {@link JpaToscaRequirement} object with a null key.
*/
this.node = copyConcept.node;
this.relationship = copyConcept.relationship;
this.occurrences = new ArrayList<>(copyConcept.occurrences);
- this.properties = PfUtils.mapMap(copyConcept.properties, String::new);
}
/**
* @param authorativeConcept the authorative concept to copy from
*/
public JpaToscaRequirement(final ToscaRequirement authorativeConcept) {
- super(new PfConceptKey());
- this.fromAuthorative(authorativeConcept);
+ super(authorativeConcept);
}
@Override
toscaRequirement.setOccurrences(occurrencesList);
}
- if (properties != null) {
- Map<String, Object> propertiesMap = new LinkedHashMap<>();
-
- for (Map.Entry<String, String> entry : properties.entrySet()) {
- propertiesMap.put(entry.getKey(), new YamlJsonTranslator().fromYaml(entry.getValue(), Object.class));
- }
-
- toscaRequirement.setProperties(propertiesMap);
- }
-
return toscaRequirement;
}
}
}
}
+ }
- if (toscaRequirement.getProperties() != null) {
- properties = new LinkedHashMap<>();
- for (Map.Entry<String, Object> toscaPropertyEntry : toscaRequirement.getProperties().entrySet()) {
- String jpaProperty = new YamlJsonTranslator().toYaml(toscaPropertyEntry.getValue());
- properties.put(toscaPropertyEntry.getKey(), jpaProperty);
- }
- }
+ @Override
+ protected Object deserializePropertyValue(String propValue) {
+ return YAML_TRANSLATOR.fromYaml(propValue, Object.class);
+ }
+ @Override
+ protected String serializePropertyValue(Object propValue) {
+ return YAML_TRANSLATOR.toYaml(propValue);
}
@Override
capability = capability.trim();
node = node.trim();
relationship = relationship.trim();
-
- properties = PfUtils.mapMap(properties, 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 JpaToscaRequirement other = (JpaToscaRequirement) otherConcept;
- int result = super.compareTo(other);
+ int result = super.compareTo(otherConcept);
if (result != 0) {
return result;
}
+ final JpaToscaRequirement other = (JpaToscaRequirement) otherConcept;
+
result = capability.compareTo(other.capability);
if (result != 0) {
return result;
return result;
}
- result = PfUtils.compareCollections(occurrences, other.occurrences);
- if (result != 0) {
- return result;
- }
-
- return PfUtils.compareMaps(properties, other.properties);
+ return PfUtils.compareCollections(occurrences, other.occurrences);
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.models.tosca.simple.concepts;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import javax.persistence.ElementCollection;
+import javax.persistence.Lob;
+import javax.persistence.MappedSuperclass;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.NotNull;
+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.tosca.authorative.concepts.ToscaWithObjectProperties;
+
+/**
+ * Class to represent JPA TOSCA classes containing property maps whose values are Strings.
+ */
+@MappedSuperclass
+@Data
+@EqualsAndHashCode(callSuper = true)
+public abstract class JpaToscaWithStringProperties<T extends ToscaWithObjectProperties> extends JpaToscaEntityType<T>
+ implements PfAuthorative<T> {
+
+ private static final long serialVersionUID = 2785481541573683089L;
+
+ @ElementCollection
+ @Lob
+ private Map<@NotNull String, @NotNull String> properties;
+
+ /**
+ * The Default Constructor creates a {@link JpaToscaWithStringProperties} object with
+ * a null key.
+ */
+ public JpaToscaWithStringProperties() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link JpaToscaWithStringProperties} object with the
+ * given concept key.
+ *
+ * @param key the key
+ */
+ public JpaToscaWithStringProperties(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public JpaToscaWithStringProperties(@NonNull final JpaToscaWithStringProperties<T> copyConcept) {
+ super(copyConcept);
+ this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
+ }
+
+ /**
+ * Authorative constructor.
+ *
+ * @param authorativeConcept the authorative concept to copy from
+ */
+ public JpaToscaWithStringProperties(final T authorativeConcept) {
+ super(new PfConceptKey());
+ this.fromAuthorative(authorativeConcept);
+ }
+
+ @Override
+ public T toAuthorative() {
+ T tosca = super.toAuthorative();
+
+ tosca.setProperties(PfUtils.mapMap(properties, this::deserializePropertyValue));
+
+ return tosca;
+ }
+
+ @Override
+ public void fromAuthorative(@NonNull final T authorativeConcept) {
+ super.fromAuthorative(authorativeConcept);
+
+ properties = PfUtils.mapMap(authorativeConcept.getProperties(), this::serializePropertyValue);
+ }
+
+ /**
+ * Deserializes a property value.
+ *
+ * @param propValue value to be deserialized
+ * @return the deserialized property value
+ */
+ protected abstract Object deserializePropertyValue(String propValue);
+
+ /**
+ * Serializes a property value.
+ *
+ * @param propValue value to be serialized
+ * @return the serialized property value
+ */
+ protected abstract String serializePropertyValue(Object propValue);
+
+
+ @Override
+ public void clean() {
+ super.clean();
+
+ properties = PfUtils.mapMap(properties, String::trim);
+ }
+
+ /**
+ * Validates the fields of the object, including its key.
+ *
+ * @param fieldName name of the field containing this
+ * @return the result, or {@code null}
+ */
+ protected BeanValidationResult validateWithKey(String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
+
+ validateKeyVersionNotNull(result, "key", getKey());
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ int result = super.compareTo(otherConcept);
+ if (result != 0) {
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ final JpaToscaWithStringProperties<T> other = (JpaToscaWithStringProperties<T>) otherConcept;
+
+ return PfUtils.compareMaps(properties, other.properties);
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 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.
+ * 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.models.tosca.simple.concepts;
+
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+import javax.persistence.ElementCollection;
+import javax.persistence.Lob;
+import javax.persistence.MappedSuperclass;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.NonNull;
+import org.apache.commons.collections4.CollectionUtils;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+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.tosca.authorative.concepts.ToscaProperty;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithToscaProperties;
+import org.onap.policy.models.tosca.utils.ToscaUtils;
+
+/**
+ * Class to represent JPA TOSCA classes containing TOSCA properties.
+ */
+@MappedSuperclass
+@Data
+@EqualsAndHashCode(callSuper = true)
+public abstract class JpaToscaWithToscaProperties<T extends ToscaWithToscaProperties> extends JpaToscaEntityType<T>
+ implements PfAuthorative<T> {
+ private static final long serialVersionUID = -563659852901842616L;
+
+ @ElementCollection
+ @Lob
+ private Map<@NotNull @NotBlank String, @NotNull @Valid JpaToscaProperty> properties;
+
+ /**
+ * The Default Constructor creates a {@link JpaToscaWithToscaProperties} object with a
+ * null key.
+ */
+ public JpaToscaWithToscaProperties() {
+ this(new PfConceptKey());
+ }
+
+ /**
+ * The Key Constructor creates a {@link JpaToscaWithToscaProperties} object with the
+ * given concept key.
+ *
+ * @param key the key
+ */
+ public JpaToscaWithToscaProperties(@NonNull final PfConceptKey key) {
+ super(key);
+ }
+
+ /**
+ * Copy constructor.
+ *
+ * @param copyConcept the concept to copy from
+ */
+ public JpaToscaWithToscaProperties(final JpaToscaWithToscaProperties<T> copyConcept) {
+ super(copyConcept);
+ this.properties = copyConcept.properties == null ? null : new LinkedHashMap<>(copyConcept.properties);
+ }
+
+ /**
+ * Authorative constructor.
+ *
+ * @param authorativeConcept the authorative concept to copy from
+ */
+ public JpaToscaWithToscaProperties(final T authorativeConcept) {
+ this.fromAuthorative(authorativeConcept);
+ }
+
+ @Override
+ public void fromAuthorative(final T authorativeConcept) {
+ super.fromAuthorative(authorativeConcept);
+
+ // Set properties
+ if (authorativeConcept.getProperties() != null) {
+ properties = new LinkedHashMap<>();
+ for (Entry<String, ToscaProperty> toscaPropertyEntry : authorativeConcept.getProperties().entrySet()) {
+ JpaToscaProperty jpaProperty = new JpaToscaProperty(toscaPropertyEntry.getValue());
+ jpaProperty.setKey(new PfReferenceKey(getKey(), toscaPropertyEntry.getKey()));
+ properties.put(toscaPropertyEntry.getKey(), jpaProperty);
+ }
+ }
+ }
+
+ @Override
+ public T toAuthorative() {
+ T tosca = super.toAuthorative();
+
+ tosca.setProperties(PfUtils.mapMap(properties, JpaToscaProperty::toAuthorative));
+
+ return tosca;
+ }
+
+ @Override
+ public List<PfKey> getKeys() {
+ final List<PfKey> keyList = super.getKeys();
+
+ PfUtils.mapMap(properties, property -> keyList.addAll(property.getKeys()));
+
+ return keyList;
+ }
+
+ @Override
+ public void clean() {
+ super.clean();
+
+ if (properties != null) {
+ for (JpaToscaProperty property : properties.values()) {
+ property.clean();
+ }
+ }
+ }
+
+ /**
+ * Validates the fields of the object, including its key.
+ *
+ * @param fieldName name of the field containing this
+ * @return the result, or {@code null}
+ */
+ protected BeanValidationResult validateWithKey(@NonNull String fieldName) {
+ BeanValidationResult result = super.validate(fieldName);
+
+ validateKeyVersionNotNull(result, "key", getKey());
+
+ return result;
+ }
+
+ @Override
+ public int compareTo(final PfConcept otherConcept) {
+ if (this == otherConcept) {
+ return 0;
+ }
+
+ int result = super.compareTo(otherConcept);
+ if (result != 0) {
+ return result;
+ }
+
+ @SuppressWarnings("unchecked")
+ final JpaToscaWithToscaProperties<T> other = (JpaToscaWithToscaProperties<T>) otherConcept;
+
+ return PfUtils.compareMaps(properties, other.properties);
+ }
+
+ /**
+ * Get the referenced data types.
+ *
+ * @return the referenced data types
+ */
+ public Collection<PfConceptKey> getReferencedDataTypes() {
+ if (properties == null) {
+ return CollectionUtils.emptyCollection();
+ }
+
+ Set<PfConceptKey> referencedDataTypes = new LinkedHashSet<>();
+
+ for (JpaToscaProperty property : properties.values()) {
+ referencedDataTypes.add(property.getType());
+
+ if (property.getEntrySchema() != null) {
+ referencedDataTypes.add(property.getEntrySchema().getType());
+ }
+ }
+
+ referencedDataTypes.removeAll(ToscaUtils.getPredefinedDataTypes());
+
+ return referencedDataTypes;
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.authorative.concepts;
+
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+import java.util.Map;
+import org.junit.Test;
+
+public class ToscaWithObjectPropertiesTest {
+
+ @Test
+ public void testCopyConstructor() {
+ ToscaWithObjectProperties tosca = new ToscaWithObjectProperties();
+ assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+
+ tosca.setProperties(Map.of("abc", 10, "def", "world"));
+ assertEquals(tosca, new ToscaWithObjectProperties(tosca));
+
+ assertNotEquals(tosca, new ToscaWithObjectProperties());
+
+ assertThatThrownBy(() -> new ToscaWithObjectProperties(null)).hasMessageContaining("copyObject")
+ .hasMessageContaining("is null");
+ }
+}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 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.
+ * 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.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.models.tosca.simple.concepts;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import java.util.Map;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaWithObjectProperties;
+
+public class JpaToscaWithStringPropertiesTest {
+ private static final String SOME_DESCRIPTION = "some description";
+ private static final String KEY1 = "abc";
+ private static final String KEY2 = "def";
+ private static final String STRING1 = "10";
+ private static final String STRING2 = "20";
+ private static final int INT1 = 10;
+ private static final int INT2 = 20;
+
+ private MyJpa jpa;
+
+ @Before
+ public void setUp() {
+ jpa = new MyJpa();
+ }
+
+ @Test
+ public void testGetKeys() {
+ PfConceptKey key = new PfConceptKey("bye", "9.8.7");
+
+ jpa = new MyJpa(key);
+ jpa.setDescription(SOME_DESCRIPTION);
+ jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
+
+ // properties should be ignored
+ assertThat(jpa.getKeys()).isEqualTo(List.of(key));
+ }
+
+ @Test
+ public void testClean() {
+ jpa.setDescription(" some description ");
+ jpa.setProperties(Map.of(KEY1, "10 ", KEY2, " 20"));
+
+ jpa.clean();
+ assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+ assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
+ }
+
+ @Test
+ public void testToAuthorative() {
+ jpa.setDescription(SOME_DESCRIPTION);
+ jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
+
+ MyTosca tosca = jpa.toAuthorative();
+ assertEquals(SOME_DESCRIPTION, tosca.getDescription());
+ assertThat(tosca.getProperties()).isEqualTo(Map.of(KEY1, INT1, KEY2, INT2));
+ }
+
+ @Test
+ public void testFromAuthorative() {
+ MyTosca tosca = new MyTosca();
+ tosca.setDescription(SOME_DESCRIPTION);
+
+ jpa.fromAuthorative(tosca);
+ assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+ assertThat(jpa.getProperties()).isNull();
+
+ tosca.setProperties(Map.of(KEY1, INT1, KEY2, INT2));
+
+ jpa = new MyJpa();
+ jpa.fromAuthorative(tosca);
+ assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+ assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
+ }
+
+ @Test
+ public void testCompareTo() {
+ jpa.setDescription(SOME_DESCRIPTION);
+ jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
+
+ assertThat(jpa.compareTo(null)).isNegative();
+ assertThat(jpa.compareTo(jpa)).isZero();
+ assertThat(jpa.compareTo(new PfConceptKey())).isNotZero();
+
+ MyJpa jpa2 = new MyJpa();
+ jpa2.setDescription(SOME_DESCRIPTION);
+ jpa2.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
+ assertThat(jpa.compareTo(jpa2)).isZero();
+
+ jpa2.setProperties(Map.of(KEY1, STRING1));
+ assertThat(jpa.compareTo(jpa2)).isNotZero();
+ }
+
+ @Test
+ public void testJpaToscaWithStringProperties() {
+ assertThat(jpa.getProperties()).isNull();
+ assertThat(jpa.getKey().isNullKey()).isTrue();
+
+ }
+
+ @Test
+ public void testJpaToscaWithStringPropertiesPfConceptKey() {
+ PfConceptKey key = new PfConceptKey("hello", "1.2.3");
+
+ jpa = new MyJpa(key);
+ assertEquals(key, jpa.getKey());
+ }
+
+ @Test
+ public void testJpaToscaWithStringPropertiesJpaToscaWithStringPropertiesOfT() {
+ jpa.setDescription(SOME_DESCRIPTION);
+ assertEquals(jpa, new MyJpa(jpa));
+
+ jpa.setProperties(Map.of(KEY1, STRING1, KEY2, STRING2));
+ assertEquals(jpa, new MyJpa(jpa));
+ }
+
+ @Test
+ public void testJpaToscaWithStringPropertiesT() {
+ MyTosca tosca = new MyTosca();
+ tosca.setName("world");
+ tosca.setVersion("3.2.1");
+ tosca.setDescription(SOME_DESCRIPTION);
+ tosca.setProperties(Map.of(KEY1, INT1, KEY2, INT2));
+
+ jpa = new MyJpa(tosca);
+ assertEquals(SOME_DESCRIPTION, jpa.getDescription());
+ assertThat(jpa.getProperties()).isEqualTo(Map.of(KEY1, STRING1, KEY2, STRING2));
+ assertEquals(new PfConceptKey("world", "3.2.1"), jpa.getKey());
+ }
+
+ @Test
+ public void testValidateWithKey() {
+ // null key - should fail
+ jpa.setText("some text");
+ assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
+
+ // valid
+ jpa.setKey(new PfConceptKey("xyz", "2.3.4"));
+ assertThat(jpa.validateWithKey("fieldB").isValid()).isTrue();
+
+ // null text - bean validator should fail
+ jpa.setText(null);
+ assertThat(jpa.validateWithKey("fieldA").isValid()).isFalse();
+ }
+
+ private static class MyTosca extends ToscaWithObjectProperties {
+
+ }
+
+ @NoArgsConstructor
+ protected static class MyJpa extends JpaToscaWithStringProperties<MyTosca> {
+ private static final long serialVersionUID = 1L;
+
+ @NotNull
+ @Getter
+ @Setter
+ private String text;
+
+ public MyJpa(MyJpa jpa) {
+ super(jpa);
+ }
+
+ public MyJpa(PfConceptKey key) {
+ super(key);
+ }
+
+ public MyJpa(MyTosca tosca) {
+ super(tosca);
+ }
+
+ @Override
+ public MyTosca toAuthorative() {
+ this.setToscaEntity(new MyTosca());
+ return super.toAuthorative();
+ }
+
+ @Override
+ protected Object deserializePropertyValue(String propValue) {
+ return Integer.parseInt(propValue);
+ }
+
+ @Override
+ protected String serializePropertyValue(Object propValue) {
+ return propValue.toString();
+ }
+ }
+}
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
.build();
// @formatter:on
- validator.validate(POJO_PACKAGE, new FilterPackageInfo());
+ validator.validate(POJO_PACKAGE,
+ new FilterPackageInfo(),
+ pc -> !pc.getName().startsWith("Test"),
+ pc -> !pc.getName().endsWith("Test"));
}
}