* ============LICENSE_START=======================================================
* ONAP Policy Model
* ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * 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 jakarta.persistence.Column;
+import jakarta.persistence.ElementCollection;
+import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
-import javax.persistence.Column;
-import javax.persistence.ElementCollection;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
+import org.onap.policy.common.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.common.parameters.annotations.Valid;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfUtils;
-import org.onap.policy.models.base.PfValidationMessage;
-import org.onap.policy.models.base.PfValidationResult;
-import org.onap.policy.models.base.PfValidationResult.ValidationResult;
+import org.onap.policy.models.base.Validated;
+import org.onap.policy.models.base.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConstraint;
import org.onap.policy.models.tosca.authorative.concepts.ToscaSchemaDefinition;
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
-public class JpaToscaSchemaDefinition
+public class JpaToscaSchemaDefinition extends Validated
implements PfAuthorative<ToscaSchemaDefinition>, Serializable, Comparable<JpaToscaSchemaDefinition> {
+ @Serial
private static final long serialVersionUID = 3645882081163287058L;
- // Recurring string constants
- private static final String ENTRY_SCHEMA = "EntrySchema";
-
@Column
+ @VerifyKey
+ @NotNull
private PfConceptKey type;
@Column
+ @NotBlank
private String description;
@ElementCollection
- private List<JpaToscaConstraint> constraints;
+ private List<@NotNull @Valid JpaToscaConstraint> constraints;
/**
* The full constructor creates a {@link JpaToscaSchemaDefinition} object with mandatory fields.
@Override
public ToscaSchemaDefinition toAuthorative() {
- ToscaSchemaDefinition toscaEntrySchema = new ToscaSchemaDefinition();
+ var toscaEntrySchema = new ToscaSchemaDefinition();
toscaEntrySchema.setType(type.getName());
toscaEntrySchema.setTypeVersion(type.getVersion());
description = (description != null ? description.trim() : null);
}
- /**
- * Validate the entry schema.
- *
- * @param resultIn the incoming result
- * @return the ooutput result witht he result of this validation
- */
- public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- if (type == null || type.isNullKey()) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "entry schema type may not be null"));
- }
-
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "entry schema description may not be blank"));
- }
-
- if (constraints != null) {
- for (JpaToscaConstraint constraint : constraints) {
- if (constraint == null) {
- result.addValidationMessage(
- new PfValidationMessage(new PfConceptKey(ENTRY_SCHEMA, PfKey.NULL_KEY_VERSION),
- this.getClass(), ValidationResult.INVALID, "property constraint may not be null "));
- }
- }
- }
-
- return result;
- }
-
@Override
public int compareTo(final JpaToscaSchemaDefinition other) {
if (other == null) {
copy.setDescription(description);
if (constraints != null) {
- final List<JpaToscaConstraint> newConstraints = new ArrayList<>();
- for (final JpaToscaConstraint constraint : constraints) {
- newConstraints.add(constraint); // Constraints are immutable
- }
+ // Constraints are immutable
+ final List<JpaToscaConstraint> newConstraints = new ArrayList<>(constraints);
copy.setConstraints(newConstraints);
}