summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/main/java/org/onap
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2021-02-10 16:17:10 -0500
committerJim Hahn <jrh3@att.com>2021-02-10 17:17:34 -0500
commitb7097d21c25a48c9d209548ac8afdc09b1679457 (patch)
treeee7a911622c333818a9ac30f2cae68aee7eb6601 /models-tosca/src/main/java/org/onap
parentf04d89c55ab4dfa94dfed1cc9b65471d1d3140c5 (diff)
More sonars in models
Addressed the following: - make constructors protected - check exception type - too many assertions - remove annotation lists - use "<>" - reduce cognitive complexity - extract constant - multiple method calls in one assert - don't use eq() in verify() - indentation Issue-ID: POLICY-2905 Change-Id: I25bb3951f781250e9cdfe8f5f3b80cb63e129184 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-tosca/src/main/java/org/onap')
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java3
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java2
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java4
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java9
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java9
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java5
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java9
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java106
-rw-r--r--models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java17
9 files changed, 55 insertions, 109 deletions
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
index ef0b6b183..d6f3a6815 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaEntityFilter.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-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.
@@ -55,7 +56,7 @@ public class ToscaEntityFilter<T extends ToscaEntity> implements PfObjectFilter<
// @formatter:off
if (LATEST_VERSION.equals(version)) {
- return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>());
+ return this.latestVersionFilter(returnList, new ToscaEntityComparator<>());
} else {
return returnList;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
index b6ff86b3c..749873a23 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/authorative/concepts/ToscaTypedEntityFilter.java
@@ -67,7 +67,7 @@ public class ToscaTypedEntityFilter<T extends ToscaEntity> implements PfObjectFi
// @formatter:off
if (LATEST_VERSION.equals(version)) {
- return this.latestVersionFilter(returnList, new ToscaEntityComparator<T>());
+ return this.latestVersionFilter(returnList, new ToscaEntityComparator<>());
} else {
return returnList;
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
index 4dfbae74d..f3dbeb030 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaConstraint.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019-2020 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");
@@ -46,7 +46,7 @@ public abstract class JpaToscaConstraint
*
* @param authorativeConcept the authorative concept to copy from
*/
- public JpaToscaConstraint(final ToscaConstraint authorativeConcept) {
+ protected JpaToscaConstraint(final ToscaConstraint authorativeConcept) {
this.fromAuthorative(authorativeConcept);
}
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
index 893cdbe84..2416bab69 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaEntityType.java
@@ -26,7 +26,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.EmbeddedId;
@@ -61,12 +60,8 @@ public class JpaToscaEntityType<T extends ToscaEntity> extends PfConcept impleme
// @formatter:off
@Column
- @AttributeOverrides({
- @AttributeOverride(name = "name",
- column = @Column(name = "derived_from_name")),
- @AttributeOverride(name = "version",
- column = @Column(name = "derived_from_version"))
- })
+ @AttributeOverride(name = "name", column = @Column(name = "derived_from_name"))
+ @AttributeOverride(name = "version", column = @Column(name = "derived_from_version"))
@VerifyKey
private PfConceptKey derivedFrom;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
index 9a07ea187..c28a1aefb 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeTemplate.java
@@ -33,7 +33,6 @@ import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@@ -81,14 +80,14 @@ public class JpaToscaNodeTemplate extends JpaToscaEntityType<ToscaNodeTemplate>
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"),
- @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")})
+ @JoinColumn(name = "requirementsName", referencedColumnName = "name")
+ @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")
@Valid
private JpaToscaRequirements requirements;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns({@JoinColumn(name = "capabilitiesName", referencedColumnName = "name"),
- @JoinColumn(name = "capabilitiesVersion", referencedColumnName = "version")})
+ @JoinColumn(name = "capabilitiesName", referencedColumnName = "name")
+ @JoinColumn(name = "capabilitiesVersion", referencedColumnName = "version")
@Valid
private JpaToscaCapabilityAssignments capabilities;
// @formatter:on
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java
index 5ea21ed77..86be4b318 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaNodeType.java
@@ -35,7 +35,6 @@ import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@@ -76,8 +75,8 @@ public class JpaToscaNodeType extends JpaToscaEntityType<ToscaNodeType> implemen
// formatter:off
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns({@JoinColumn(name = "requirementsName", referencedColumnName = "name"),
- @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")})
+ @JoinColumn(name = "requirementsName", referencedColumnName = "name")
+ @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")
// @formatter:on
@Valid
private JpaToscaRequirements requirements;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
index 0be04353f..11f1199c0 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaPolicy.java
@@ -27,7 +27,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.persistence.AttributeOverride;
-import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
@@ -76,12 +75,8 @@ public class JpaToscaPolicy extends JpaToscaEntityType<ToscaPolicy> implements P
// @formatter:off
@Column
- @AttributeOverrides({
- @AttributeOverride(name = "name",
- column = @Column(name = "type_name")),
- @AttributeOverride(name = "version",
- column = @Column(name = "type_version"))
- })
+ @AttributeOverride(name = "name", column = @Column(name = "type_name"))
+ @AttributeOverride(name = "version", column = @Column(name = "type_version"))
@VerifyKey
@NotNull
private PfConceptKey type;
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
index 594a5c348..0d9060d33 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaServiceTemplate.java
@@ -1,7 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2019-2021 Nordix Foundation.
- * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019-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.
@@ -34,7 +34,6 @@ import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import lombok.Data;
@@ -49,11 +48,6 @@ 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.tosca.authorative.concepts.ToscaCapabilityType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
-import org.onap.policy.models.tosca.authorative.concepts.ToscaRelationshipType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
/**
@@ -84,69 +78,45 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
private String toscaDefinitionsVersion;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "dataTypesName", referencedColumnName = "name"),
- @JoinColumn(name = "dataTypesVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "dataTypesName", referencedColumnName = "name")
+ @JoinColumn(name = "dataTypesVersion", referencedColumnName = "version")
@SerializedName("data_types")
@Valid
private JpaToscaDataTypes dataTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "capabilityTypesName", referencedColumnName = "name"),
- @JoinColumn(name = "capabilityTypesVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "capabilityTypesName", referencedColumnName = "name")
+ @JoinColumn(name = "capabilityTypesVersion", referencedColumnName = "version")
@SerializedName("capability_types")
@Valid
private JpaToscaCapabilityTypes capabilityTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "relationshipTypesName", referencedColumnName = "name"),
- @JoinColumn(name = "relationshipTypesVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "relationshipTypesName", referencedColumnName = "name")
+ @JoinColumn(name = "relationshipTypesVersion", referencedColumnName = "version")
@SerializedName("relationship_types")
@Valid
private JpaToscaRelationshipTypes relationshipTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "nodeTypesName", referencedColumnName = "name"),
- @JoinColumn(name = "nodeTypesVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "nodeTypesName", referencedColumnName = "name")
+ @JoinColumn(name = "nodeTypesVersion", referencedColumnName = "version")
@SerializedName("node_types")
@Valid
private JpaToscaNodeTypes nodeTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "policyTypesName", referencedColumnName = "name"),
- @JoinColumn(name = "policyTypesVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "policyTypesName", referencedColumnName = "name")
+ @JoinColumn(name = "policyTypesVersion", referencedColumnName = "version")
@SerializedName("policy_types")
@Valid
private JpaToscaPolicyTypes policyTypes;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "topologyTemplateParentKeyName", referencedColumnName = "parentKeyName"),
- @JoinColumn(name = "topologyTemplateParentKeyVersion", referencedColumnName = "parentKeyVersion"),
- @JoinColumn(name = "topologyTemplateParentLocalName", referencedColumnName = "parentLocalName"),
- @JoinColumn(name = "topologyTemplateLocalName", referencedColumnName = "localName")
- }
- )
+ @JoinColumn(name = "topologyTemplateParentKeyName", referencedColumnName = "parentKeyName")
+ @JoinColumn(name = "topologyTemplateParentKeyVersion", referencedColumnName = "parentKeyVersion")
+ @JoinColumn(name = "topologyTemplateParentLocalName", referencedColumnName = "parentLocalName")
+ @JoinColumn(name = "topologyTemplateLocalName", referencedColumnName = "localName")
@SerializedName("topology_template")
@Valid
private JpaToscaTopologyTemplate topologyTemplate;
@@ -219,43 +189,23 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
toscaServiceTemplate.setToscaDefinitionsVersion(toscaDefinitionsVersion);
if (dataTypes != null) {
- toscaServiceTemplate.setDataTypes(new LinkedHashMap<>());
- List<Map<String, ToscaDataType>> dataTypeMapList = dataTypes.toAuthorative();
- for (Map<String, ToscaDataType> dataTypeMap : dataTypeMapList) {
- toscaServiceTemplate.getDataTypes().putAll(dataTypeMap);
- }
+ toscaServiceTemplate.setDataTypes(flattenMap(dataTypes.toAuthorative()));
}
if (capabilityTypes != null) {
- toscaServiceTemplate.setCapabilityTypes(new LinkedHashMap<>());
- List<Map<String, ToscaCapabilityType>> capabilityTypeMapList = capabilityTypes.toAuthorative();
- for (Map<String, ToscaCapabilityType> capabilityTypeMap : capabilityTypeMapList) {
- toscaServiceTemplate.getCapabilityTypes().putAll(capabilityTypeMap);
- }
+ toscaServiceTemplate.setCapabilityTypes(flattenMap(capabilityTypes.toAuthorative()));
}
if (relationshipTypes != null) {
- toscaServiceTemplate.setRelationshipTypes(new LinkedHashMap<>());
- List<Map<String, ToscaRelationshipType>> relationshipTypeMapList = relationshipTypes.toAuthorative();
- for (Map<String, ToscaRelationshipType> relationshipTypeMap : relationshipTypeMapList) {
- toscaServiceTemplate.getRelationshipTypes().putAll(relationshipTypeMap);
- }
+ toscaServiceTemplate.setRelationshipTypes(flattenMap(relationshipTypes.toAuthorative()));
}
if (nodeTypes != null) {
- toscaServiceTemplate.setNodeTypes(new LinkedHashMap<>());
- List<Map<String, ToscaNodeType>> nodeTypeMapList = nodeTypes.toAuthorative();
- for (Map<String, ToscaNodeType> nodeTypeMap : nodeTypeMapList) {
- toscaServiceTemplate.getNodeTypes().putAll(nodeTypeMap);
- }
+ toscaServiceTemplate.setNodeTypes(flattenMap(nodeTypes.toAuthorative()));
}
if (policyTypes != null) {
- toscaServiceTemplate.setPolicyTypes(new LinkedHashMap<>());
- List<Map<String, ToscaPolicyType>> policyTypeMapList = policyTypes.toAuthorative();
- for (Map<String, ToscaPolicyType> policyTypeMap : policyTypeMapList) {
- toscaServiceTemplate.getPolicyTypes().putAll(policyTypeMap);
- }
+ toscaServiceTemplate.setPolicyTypes(flattenMap(policyTypes.toAuthorative()));
}
if (topologyTemplate != null) {
@@ -265,6 +215,22 @@ public class JpaToscaServiceTemplate extends JpaToscaEntityType<ToscaServiceTemp
return toscaServiceTemplate;
}
+ /**
+ * Takes a list of maps and flattens it into a single map.
+ *
+ * @param list list to be be flattened
+ * @return a map containing all of the elements from the list of maps
+ */
+ private <V> Map<String, V> flattenMap(List<Map<String, V>> list) {
+ Map<String, V> result = new LinkedHashMap<>();
+
+ for (Map<String, V> map : list) {
+ result.putAll(map);
+ }
+
+ return result;
+ }
+
@Override
public void fromAuthorative(ToscaServiceTemplate toscaServiceTemplate) {
super.fromAuthorative(toscaServiceTemplate);
diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
index 86add360a..b00b14a9e 100644
--- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
+++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaTopologyTemplate.java
@@ -35,7 +35,6 @@ import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
-import javax.persistence.JoinColumns;
import javax.persistence.Lob;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@@ -87,23 +86,15 @@ public class JpaToscaTopologyTemplate extends PfConcept implements PfAuthorative
private Map<@NotNull String, @NotNull @Valid JpaToscaParameter> inputs;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"),
- @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name")
+ @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
@SerializedName("data_types")
@Valid
private JpaToscaNodeTemplates nodeTemplates;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "policyName", referencedColumnName = "name"),
- @JoinColumn(name = "policyVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumn(name = "policyName", referencedColumnName = "name")
+ @JoinColumn(name = "policyVersion", referencedColumnName = "version")
// @formatter:on
@Valid
private JpaToscaPolicies policies;