JPA concepts for TOSCA
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaTrigger.java
index 0a32701..10a9d2f 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP Policy Model
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 Nordix Foundation.
  * ================================================================================
  * 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 com.google.gson.annotations.SerializedName;
-
 import java.time.Duration;
 import java.util.List;
-
 import javax.persistence.Column;
 import javax.persistence.EmbeddedId;
 import javax.persistence.Entity;
 import javax.persistence.Inheritance;
 import javax.persistence.InheritanceType;
 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.common.utils.validation.ParameterValidationUtils;
 import org.onap.policy.models.base.PfConcept;
 import org.onap.policy.models.base.PfKey;
@@ -137,6 +132,18 @@ public class JpaToscaTrigger extends PfConcept {
      */
     public JpaToscaTrigger(final JpaToscaTrigger copyConcept) {
         super(copyConcept);
+        this.key = new PfReferenceKey(copyConcept.key);
+        this.description = copyConcept.description;
+        this.eventType = copyConcept.eventType;
+        this.schedule = (copyConcept.schedule != null ? new JpaToscaTimeInterval(copyConcept.schedule) : null);
+        this.targetFilter =
+                (copyConcept.targetFilter != null ? new JpaToscaEventFilter(copyConcept.targetFilter) : null);
+        this.condition = copyConcept.condition;
+        this.constraint = copyConcept.constraint;
+        this.period = copyConcept.period;
+        this.evaluations = copyConcept.evaluations;
+        this.method = copyConcept.method;
+        this.action = copyConcept.action;
     }
 
     @Override
@@ -148,12 +155,6 @@ public class JpaToscaTrigger extends PfConcept {
         if (targetFilter != null) {
             keyList.addAll(targetFilter.getKeys());
         }
-        if (condition != null) {
-            keyList.addAll(condition.getKeys());
-        }
-        if (constraint != null) {
-            keyList.addAll(constraint.getKeys());
-        }
         return keyList;
     }
 
@@ -170,12 +171,6 @@ public class JpaToscaTrigger extends PfConcept {
         if (targetFilter != null) {
             targetFilter.clean();
         }
-        if (condition != null) {
-            condition.clean();
-        }
-        if (constraint != null) {
-            constraint.clean();
-        }
 
         method = (method != null ? method.trim() : method);
         action = action.trim();
@@ -233,8 +228,6 @@ public class JpaToscaTrigger extends PfConcept {
 
         result = (schedule != null ? schedule.validate(result) : result);
         result = (targetFilter != null ? targetFilter.validate(result) : result);
-        result = (condition != null ? condition.validate(result) : result);
-        result = (constraint != null ? constraint.validate(result) : result);
 
         return result;
     }
@@ -248,20 +241,20 @@ public class JpaToscaTrigger extends PfConcept {
             return 0;
         }
         if (getClass() != otherConcept.getClass()) {
-            return this.hashCode() - otherConcept.hashCode();
+            return getClass().getName().compareTo(otherConcept.getClass().getName());
         }
 
         final JpaToscaTrigger other = (JpaToscaTrigger) otherConcept;
-        if (!key.equals(other.key)) {
-            return key.compareTo(other.key);
+        int result = key.compareTo(other.key);
+        if (result != 0) {
+            return result;
         }
 
         return compareFields(other);
     }
 
     /**
-     * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty
-     * object.
+     * Compare the fields of this ToscaTrigger object with the fields of the other ToscaProperty object.
      *
      * @param other the other ToscaTrigger object
      */
@@ -312,24 +305,4 @@ public class JpaToscaTrigger extends PfConcept {
 
         return ObjectUtils.compare(action, other.action);
     }
-
-    @Override
-    public PfConcept copyTo(@NonNull final PfConcept target) {
-        Assertions.instanceOf(target, JpaToscaTrigger.class);
-
-        final JpaToscaTrigger copy = ((JpaToscaTrigger) target);
-        copy.setKey(new PfReferenceKey(key));
-        copy.setDescription(description);
-        copy.setEventType(eventType);
-        copy.setSchedule(schedule != null ? new JpaToscaTimeInterval(schedule) : null);
-        copy.setTargetFilter(targetFilter != null ? new JpaToscaEventFilter(targetFilter) : null);
-        copy.setCondition(condition);
-        copy.setConstraint(constraint);
-        copy.setPeriod(period);
-        copy.setEvaluations(evaluations);
-        copy.setMethod(method);
-        copy.setAction(action);
-
-        return copy;
-    }
 }