X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=models-tosca%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fmodels%2Ftosca%2Fsimple%2Fconcepts%2FJpaToscaModel.java;h=5f72e2ba85fea94d0de65b4e35261e02806c6cf3;hb=e53df8d3f8ab0464b0876bdb339fa91dc9085cd2;hp=a322c167fc821d9daee0bd4e0721938679d116ad;hpb=cc5b96bfd33cd7d91fe6994d348e8d6a0ebb54fa;p=policy%2Fmodels.git diff --git a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java index a322c167f..5f72e2ba8 100644 --- a/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java +++ b/models-tosca/src/main/java/org/onap/policy/models/tosca/simple/concepts/JpaToscaModel.java @@ -1,6 +1,8 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2019-2020,2023 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2022 Bell Canada. 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. @@ -21,30 +23,28 @@ package org.onap.policy.models.tosca.simple.concepts; import java.util.List; - import javax.persistence.CascadeType; 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.onap.policy.common.utils.validation.Assertions; +import org.onap.policy.common.parameters.annotations.Valid; 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.PfModel; import org.onap.policy.models.base.PfModelService; -import org.onap.policy.models.base.PfValidationResult; /** - * A container class for a TOSCA model with multiple service templates. This class is a container - * class that allows a model with many service templates to be constructed that contains a well - * formed overall TOSCA model. + * A container class for a TOSCA model with multiple service templates. This class is a container class that allows a + * model with many service templates to be constructed that contains a well formed overall TOSCA model. * *

Validation runs {@link JpaToscaModel} validation on the model and all its sub concepts. */ @@ -57,20 +57,25 @@ import org.onap.policy.models.base.PfValidationResult; public class JpaToscaModel extends PfModel { private static final long serialVersionUID = 8800599637708309945L; - @OneToOne(cascade = CascadeType.ALL) + @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) + @JoinColumns({ + @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name"), + @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version") + }) + @Valid private JpaToscaServiceTemplates serviceTemplates; /** - * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and - * creates an empty TOSCA model. + * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and creates an empty TOSCA + * model. */ public JpaToscaModel() { this(new PfConceptKey()); } /** - * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and - * creates an empty TOSCA model. + * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and creates an empty TOSCA + * model. * * @param key the TOSCA model key */ @@ -96,6 +101,7 @@ public class JpaToscaModel extends PfModel { */ public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) { super(copyConcept); + this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates); } @Override @@ -118,13 +124,6 @@ public class JpaToscaModel extends PfModel { serviceTemplates.clean(); } - @Override - public PfValidationResult validate(@NonNull final PfValidationResult resultIn) { - PfValidationResult result = super.validate(resultIn); - - return serviceTemplates.validate(result); - } - @Override public int compareTo(final PfConcept otherConcept) { if (otherConcept == null) { @@ -136,25 +135,15 @@ public class JpaToscaModel extends PfModel { } if (getClass() != otherConcept.getClass()) { - return this.hashCode() - otherConcept.hashCode(); + return getClass().getName().compareTo(otherConcept.getClass().getName()); } final JpaToscaModel other = (JpaToscaModel) otherConcept; - if (!super.equals(other)) { - return super.compareTo(other); + int result = super.compareTo(other); + if (result != 0) { + return result; } return serviceTemplates.compareTo(other.serviceTemplates); } - - @Override - public PfConcept copyTo(@NonNull final PfConcept targetObject) { - Assertions.instanceOf(targetObject, JpaToscaModel.class); - - final JpaToscaModel copy = ((JpaToscaModel) targetObject); - super.copyTo(targetObject); - copy.setServiceTemplates(new JpaToscaServiceTemplates(serviceTemplates)); - - return copy; - } }