/*-
* ============LICENSE_START=======================================================
- * 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, 2023 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.util.LinkedList;
+import jakarta.persistence.ElementCollection;
+import java.io.Serial;
+import java.util.ArrayList;
import java.util.List;
-import javax.persistence.ElementCollection;
-import javax.ws.rs.core.Response;
-
-import lombok.Data;
import lombok.EqualsAndHashCode;
+import lombok.Getter;
import lombok.NonNull;
-
-import org.onap.policy.models.base.PfConcept;
-import org.onap.policy.models.base.PfModelRuntimeException;
-import org.onap.policy.models.base.PfReferenceKey;
+import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
/**
* This class represents valid_values TOSCA constraint.
* @author Chenfei Gao (cgao@research.att.com)
*/
@EqualsAndHashCode(callSuper = false)
-@Data
+@ToString
public class JpaToscaConstraintValidValues extends JpaToscaConstraint {
- private static final long serialVersionUID = 3152323457560746844L;
+ @Serial
+ private static final long serialVersionUID = -5060193250508635456L;
- @SerializedName("valid_values")
- @NonNull
@ElementCollection
- private final List<String> validValues;
-
- /**
- * The Default Constructor creates a {@link JpaToscaConstraintValidValues} object with a null key.
- */
- public JpaToscaConstraintValidValues() {
- this(new PfReferenceKey());
- }
+ @Getter
+ private List<String> validValues;
/**
- * The Key Constructor creates a {@link JpaToscaConstraintValidValues} object with the given concept key.
- *
- * @param key the key of the constraint
- */
- public JpaToscaConstraintValidValues(final PfReferenceKey key) {
- super(key);
- validValues = new LinkedList<>();
- }
-
- /**
- * The Key Constructor creates a {@link JpaToscaConstraintLogical} object with the given concept key
- * and valid values list.
- *
- * @param key the key of the constraint
- * @param validValues the valid values list of the constraint
+ * Constructor to set the valid values.
*
+ * @param validValues the valid values that are allowed
*/
- public JpaToscaConstraintValidValues(final PfReferenceKey key, @NonNull final List<String> validValues) {
- super(key);
+ public JpaToscaConstraintValidValues(@NonNull final List<String> validValues) {
this.validValues = validValues;
}
/**
- * Copy constructor.
+ * Authorative constructor.
*
- * @param copyConcept the concept to copy from
+ * @param authorativeConcept the authorative concept to copy from
*/
- public JpaToscaConstraintValidValues(@NonNull final JpaToscaConstraintValidValues copyConcept) {
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ public JpaToscaConstraintValidValues(final ToscaConstraint authorativeConcept) {
+ /*
+ * The following will call invoke fromAuthorative() which will populate the class fields.
+ */
+ super(authorativeConcept);
}
@Override
- public int compareTo(final PfConcept otherConcept) {
- if (otherConcept == null) {
- return -1;
- }
- if (this == otherConcept) {
- return 0;
- }
- if (getClass() != otherConcept.getClass()) {
- return this.hashCode() - otherConcept.hashCode();
- }
+ public ToscaConstraint toAuthorative() {
+ var toscaConstraint = new ToscaConstraint();
- final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConcept;
+ toscaConstraint.setValidValues(validValues);
- int result = super.compareTo(other);
- if (result != 0) {
- return result;
- }
+ return toscaConstraint;
+ }
- if (validValues.equals(other.validValues)) {
- return 0;
+ @Override
+ public void fromAuthorative(final ToscaConstraint toscaConstraint) {
+ validValues = new ArrayList<>();
+ if (toscaConstraint.getValidValues() != null) {
+ validValues.addAll(toscaConstraint.getValidValues());
}
- return -1;
}
@Override
- public PfConcept copyTo(@NonNull final PfConcept target) {
- throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "cannot copy an immutable constraint");
+ public int compareTo(@NonNull JpaToscaConstraint otherConstraint) {
+ if (this == otherConstraint) {
+ return 0;
+ }
+ if (getClass() != otherConstraint.getClass()) {
+ return getClass().getName().compareTo(otherConstraint.getClass().getName());
+ }
+
+ final JpaToscaConstraintValidValues other = (JpaToscaConstraintValidValues) otherConstraint;
+
+ return PfUtils.compareObjects(validValues, other.validValues);
}
}