/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020 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.
package org.onap.policy.models.base.testconcepts;
+import jakarta.persistence.EmbeddedId;
+import java.io.Serial;
import java.util.List;
-
-import javax.persistence.EmbeddedId;
-
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.parameters.annotations.NotBlank;
+import org.onap.policy.common.parameters.annotations.NotNull;
+import org.onap.policy.models.base.PfAuthorative;
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.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;
@Data
@EqualsAndHashCode(callSuper = false)
-public class DummyPfConcept extends PfConcept {
+public class DummyPfConcept extends PfConcept implements PfAuthorative<DummyAuthorativeConcept> {
+ @Serial
private static final long serialVersionUID = 1L;
+
@EmbeddedId
+ @VerifyKey
+ @NotNull
private PfConceptKey key;
+ @NotBlank
private String description;
+
/**
* The Default Constructor creates a {@link DummyPfConcept} object with a null key.
*/
*/
public DummyPfConcept(final DummyPfConcept copyConcept) {
super(copyConcept);
+ this.key = new PfConceptKey(copyConcept.key);
+ this.description = copyConcept.description;
}
@Override
- public List<PfKey> getKeys() {
- final List<PfKey> keyList = getKey().getKeys();
- return keyList;
+ public DummyAuthorativeConcept toAuthorative() {
+ DummyAuthorativeConcept dac = new DummyAuthorativeConcept();
+ dac.setName(key.getName());
+ dac.setVersion(key.getVersion());
+ dac.setDescription(description);
+
+ return dac;
}
@Override
- public void clean() {
- key.clean();
-
- description = (description != null ? description.trim() : null);
+ public void fromAuthorative(DummyAuthorativeConcept dac) {
+ key.setName(dac.getName());
+ key.setVersion(dac.getVersion());
+ description = dac.getDescription();
}
@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);
+ public List<PfKey> getKeys() {
+ return getKey().getKeys();
+ }
- if (description != null && description.trim().length() == 0) {
- result.addValidationMessage(new PfValidationMessage(key, this.getClass(), ValidationResult.INVALID,
- "property description may not be blank"));
- }
+ @Override
+ public void clean() {
+ key.clean();
- return result;
+ description = (description != null ? description.trim() : null);
}
@Override
return ObjectUtils.compare(description, other.description);
}
-
- @Override
- public PfConcept copyTo(@NonNull PfConcept target) {
- final Object copyObject = target;
- Assertions.instanceOf(copyObject, PfConcept.class);
-
- final DummyPfConcept copy = ((DummyPfConcept) copyObject);
- copy.setKey(new PfConceptKey(key));
- copy.setDescription(description);
-
- return copy;
- }
}