/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.models.tosca.simple.concepts;
import java.util.List;
-
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
+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;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
-
import org.apache.commons.lang3.ObjectUtils;
-import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
@Column(name = "description")
private String description;
- @OneToOne(cascade = CascadeType.ALL)
+ // @formatter:off
+ @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
+ @JoinColumns(
+ {
+ @JoinColumn(name = "policyName", referencedColumnName = "name"),
+ @JoinColumn(name = "policyVersion", referencedColumnName = "version")
+ }
+ )
+ // @formatter:on
private JpaToscaPolicies policies;
/**
}
/**
- * The Key Constructor creates a {@link JpaToscaTopologyTemplate} object with the given concept
- * key.
+ * The Key Constructor creates a {@link JpaToscaTopologyTemplate} object with the given concept key.
*
* @param key the key
*/
*/
public JpaToscaTopologyTemplate(final JpaToscaTopologyTemplate copyConcept) {
super(copyConcept);
+ this.key = new PfReferenceKey(copyConcept.key);
+ this.description = copyConcept.description;
+ this.policies = (copyConcept.policies != null ? new JpaToscaPolicies(copyConcept.policies) : null);
}
/**
@Override
public int compareTo(final PfConcept otherConcept) {
+ int result = compareToWithoutEntities(otherConcept);
+ if (result != 0) {
+ return result;
+ }
+
+ return ObjectUtils.compare(policies, ((JpaToscaTopologyTemplate) otherConcept).policies);
+ }
+
+ /**
+ * Compare this topology template to another topology template, ignoring contained entitites.
+ *
+ * @param otherConcept the other topology template
+ * @return the result of the comparison
+ */
+ public int compareToWithoutEntities(final PfConcept otherConcept) {
if (otherConcept == null) {
return -1;
}
return 0;
}
if (getClass() != otherConcept.getClass()) {
- return this.hashCode() - otherConcept.hashCode();
+ return getClass().getName().compareTo(otherConcept.getClass().getName());
}
final JpaToscaTopologyTemplate other = (JpaToscaTopologyTemplate) otherConcept;
return key.compareTo(other.key);
}
- int result = ObjectUtils.compare(description, other.description);
- if (result != 0) {
- return result;
- }
-
- return ObjectUtils.compare(policies, other.policies);
- }
-
- @Override
- public PfConcept copyTo(@NonNull PfConcept target) {
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, PfConcept.class);
-
- final JpaToscaTopologyTemplate copy = ((JpaToscaTopologyTemplate) copyObject);
- copy.setKey(new PfReferenceKey(key));
- copy.setDescription(description);
- copy.setPolicies(policies != null ? new JpaToscaPolicies(policies) : null);
-
- return copy;
+ return ObjectUtils.compare(description, other.description);
}
}