/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020,2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2021 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.
import lombok.EqualsAndHashCode;
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.models.base.PfAuthorative;
import org.onap.policy.models.base.PfConcept;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfReferenceKey;
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.validation.annotations.VerifyKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.onap.policy.models.tosca.authorative.concepts.ToscaParameter;
import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
public static final String DEFAULT_LOCAL_NAME = "ToscaTopologyTemplateSimple";
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfReferenceKey key;
@Column(name = "description")
+ @NotBlank
private String description;
// @formatter:off
@ElementCollection
@Lob
- private Map<String, JpaToscaParameter> inputs;
+ private Map<@NotNull String, @NotNull @Valid JpaToscaParameter> inputs;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"),
- @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumns({
+ @JoinColumn(name = "nodeTemplatesName", referencedColumnName = "name"),
+ @JoinColumn(name = "nodeTemplatessVersion", referencedColumnName = "version")
+ })
@SerializedName("data_types")
+ @Valid
private JpaToscaNodeTemplates nodeTemplates;
@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
- @JoinColumns(
- {
- @JoinColumn(name = "policyName", referencedColumnName = "name"),
- @JoinColumn(name = "policyVersion", referencedColumnName = "version")
- }
- )
+ @JoinColumns({
+ @JoinColumn(name = "policyName", referencedColumnName = "name"),
+ @JoinColumn(name = "policyVersion", referencedColumnName = "version")
+
+ })
// @formatter:on
+ @Valid
private JpaToscaPolicies policies;
/**
@Override
public ToscaTopologyTemplate toAuthorative() {
- final ToscaTopologyTemplate toscaTopologyTemplate = new ToscaTopologyTemplate();
+ final var toscaTopologyTemplate = new ToscaTopologyTemplate();
toscaTopologyTemplate.setDescription(description);
if (toscaTopologyTemplate.getInputs() != null) {
inputs = new LinkedHashMap<>();
for (Map.Entry<String, ToscaParameter> toscaInputEntry : toscaTopologyTemplate.getInputs().entrySet()) {
- JpaToscaParameter jpaInput = new JpaToscaParameter(toscaInputEntry.getValue());
+ var jpaInput = new JpaToscaParameter(toscaInputEntry.getValue());
jpaInput.setKey(new PfReferenceKey(getKey(), toscaInputEntry.getKey()));
inputs.put(toscaInputEntry.getKey(), jpaInput);
}
}
}
- @Override
- public PfValidationResult validate(PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- if (key.isNullKey()) {
- result.addValidationMessage(
- new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID, "key is a null key"));
- }
-
- result = key.validate(result);
-
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
-
- if (inputs != null) {
- result = validateInputs(result);
- }
-
-
- if (nodeTemplates != null) {
- result = nodeTemplates.validate(result);
- }
-
- if (policies != null) {
- result = policies.validate(result);
- }
-
- return result;
- }
-
- /**
- * Validate the inputs.
- *
- * @param resultIn The result of validations up to now
- * @return the validation result
- */
- private PfValidationResult validateInputs(final PfValidationResult resultIn) {
- PfValidationResult result = resultIn;
-
- for (JpaToscaParameter input : inputs.values()) {
- if (input == null) {
- result.addValidationMessage(new PfValidationMessage(getKey(), this.getClass(), ValidationResult.INVALID,
- "topology template input may not be null "));
- } else {
- result = input.validate(result);
- }
- }
- return result;
- }
-
@Override
public int compareTo(final PfConcept otherConcept) {
int result = compareToWithoutEntities(otherConcept);