/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2023-2026 OpenInfra Foundation Europe. 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.NoArgsConstructor;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
private UUID id = UUID.randomUUID();
@NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey());
@NonNull
private DeployOrder orderedState = DeployOrder.DEPLOY;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2023-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2023-2026 OpenInfra Foundation Europe. 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.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
-import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
private UUID id = UUID.randomUUID();
@NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey());
private UUID participantId;
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2021-2026 OpenInfra Foundation Europe. 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.NonNull;
import lombok.ToString;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
-import org.onap.policy.models.base.PfConceptKey;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
/**
private UUID id = UUID.randomUUID();
@NonNull
- private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfConceptKey.getNullKey());
+ private ToscaConceptIdentifier definition = new ToscaConceptIdentifier(PfUtils.getNullKey());
@NonNull
private UUID participantId = UUID.randomUUID();
import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.validation.constraints.Pattern;
import java.io.Serial;
-import java.util.List;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
import org.onap.policy.common.utils.validation.Assertions;
import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfKeyImpl;
@Data
this(NULL_KEY_NAME, NULL_KEY_VERSION);
}
- @Override
- @JsonIgnore
- public String getId() {
- return name + ":" + version;
- }
-
/**
* Copy constructor.
*
public PfKeyImpl getKey() {
return this;
}
-
- @Override
- @JsonIgnore
- public List<PfKey> getKeys() {
- return super.getKeys();
- }
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022,2025 OpenInfra Foundation Europe. All rights reserved.
+ * Copyright (C) 2022,2025-2026 OpenInfra Foundation Europe. 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 org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfModelRuntimeException;
import org.onap.policy.models.base.PfNameVersion;
+import org.onap.policy.models.base.PfUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaEntity;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
var authoritiveImpl = mapFunc.apply(incomingConceptEntry.getValue());
// After all that, save the map entry
- conceptMap.put(conceptKey.getId(), authoritiveImpl);
+ conceptMap.put(PfUtils.getId(conceptKey), authoritiveImpl);
}
return conceptMap;
if (StringUtils.isBlank(conceptField) || keyFieldValue.equals(conceptField)) {
return keyFieldValue;
} else {
- throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, "Key " + conceptKey.getId() + " field "
- + keyFieldValue + " does not match the value " + conceptField + " in the concept field");
+ var msg = "Key " + PfUtils.getId(conceptKey) + " field "
+ + keyFieldValue + " does not match the value " + conceptField + " in the concept field";
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, msg);
}
}
private static <A extends DocToscaEntity<?>> Set<String> toSetToscaReferences(Map<String, A> map) {
Set<String> result = new HashSet<>();
for (var entity : map.values()) {
- result.add(entity.getDocConceptKey().getId()); // ref for type
+ result.add(PfUtils.getId(entity.getDocConceptKey())); // ref for type
result.add(entity.getDocConceptKey().getName()); // ref for derived from
}
return result;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaTopologyTemplate;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.models.base.PfUtils;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ToscaServiceTemplateValidation {
final Collection<DocConceptKey> dataTypeKeyCollection, Map<String, Set<String>> references) {
for (DocConceptKey dataTypeKey : dataTypeKeyCollection) {
if (!isTypePresent(dataTypeKey, references.get(DocUtil.REF_DATA_TYPES))) {
- result.addResult("data type", dataTypeKey.getId(), ValidationStatus.INVALID, NOT_FOUND);
+ result.addResult(
+ "data type", PfUtils.getId(dataTypeKey), ValidationStatus.INVALID, NOT_FOUND);
}
}
}
if (reference.isEmpty()) {
return false;
}
- return reference.contains(key.getId());
+ return reference.contains(PfUtils.getId(key));
}
private static String extractDerivedFrom(DocToscaEntity<?> entityType, final BeanValidationResult result) {
return null;
}
if (entityType.getName().equals(parentEntityTypeKey)) {
- result.addResult("entity type", entityType.getDocConceptKey().getId(), ValidationStatus.INVALID,
+ result.addResult("entity type", PfUtils.getId(entityType.getDocConceptKey()), ValidationStatus.INVALID,
"ancestor of itself");
return null;
}
assertThatThrownBy(() -> docConceptKey.setName(null)). isInstanceOf(NullPointerException.class);
assertThatThrownBy(() -> docConceptKey.setVersion(null)). isInstanceOf(NullPointerException.class);
assertEquals("NULL", docConceptKey.getKey().getName());
- assertThat(docConceptKey.getKeys()).hasSize(1);
}
}
import java.io.Serial;
import java.io.Serializable;
-import java.util.List;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.NonNull;
*/
public abstract PfKey getKey();
- /**
- * Gets a list of all keys for this concept and all concepts that are defined or referenced by this concept and its
- * sub-concepts.
- *
- * @return the keys used by this concept and its contained concepts
- */
- public abstract List<PfKey> getKeys();
-
- /**
- * Clean this concept, tidy up any superfluous information such as leading and trailing white space.
- */
- public abstract void clean();
-
- @Override
- public abstract boolean equals(Object otherObject);
-
- @Override
- public abstract String toString();
-
- @Override
- public abstract int hashCode();
-
- /**
- * Gets the ID string of this concept.
- *
- * @return the ID string of this concept
- */
- public String getId() {
- return getKey().getId();
- }
-
/**
* Gets the name of this concept.
*
public String getVersion() {
return getKey().getVersion();
}
-
- /**
- * Checks if this key matches the given key ID.
- *
- * @param id the key ID to match against
- * @return true, if this key matches the ID
- */
- public final boolean matchesId(@NonNull final String id) {
- // Check the ID
- return getId().equals(id);
- }
}
/**
* A concept key uniquely identifies every first order entity in the system. Every first order concept in the system
- * must have an {@link PfConceptKey} to identify it. Concepts that are wholly contained in another concept are
- * identified using a {@link PfReferenceKey} key.
+ * must have an {@link PfConceptKey} to identify it.
*
* <p>Key validation checks that the name and version fields match the NAME_REGEXP and VERSION_REGEXP
* regular expressions respectively.
public void setVersion(@NonNull final String version) {
this.version = Assertions.validateStringParameter(VERSION_TOKEN, version, getVersionRegEx());
}
-
- /**
- * Get a null concept key.
- *
- * @return a null concept key
- */
- public static PfConceptKey getNullKey() {
- return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
- }
}
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019, 2023 Nordix Foundation.
+ * Copyright (C) 2019, 2023,2026 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
super(copyConcept);
}
- @Override
- public abstract String getId();
-
/**
* Return the result of a compatibility check of two keys.
*
* @return the compatibility result of the check
*/
public abstract Compatibility getCompatibility(@NonNull PfKey otherKey);
-
- /**
- * Check if a key equals its null key.
- *
- * @return true, if the key is a null key
- */
- public abstract boolean isNullKey();
}
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2020, 2023 Nordix Foundation.
+ * Copyright (C) 2019-2020, 2023,2026 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
package org.onap.policy.models.base;
import java.io.Serial;
-import java.util.ArrayList;
-import java.util.List;
import lombok.Getter;
import lombok.NonNull;
import lombok.ToString;
return this;
}
- @Override
- public List<PfKey> getKeys() {
- final List<PfKey> keyList = new ArrayList<>();
- keyList.add(getKey());
- return keyList;
- }
-
- @Override
- public String getId() {
- return getName() + ':' + getVersion();
- }
-
- @Override
- public boolean isNullKey() {
- return (PfKey.NULL_KEY_NAME.equals(getName()) && PfKey.NULL_KEY_VERSION.equals(getVersion()));
- }
-
- /**
- * Determines if the name is "null".
- *
- * @return {@code true} if the name is null, {@code false} otherwise
- */
- public boolean isNullName() {
- return PfKey.NULL_KEY_NAME.equals(getName());
- }
-
- /**
- * Determines if the version is "null".
- *
- * @return {@code true} if the version is null, {@code false} otherwise
- */
- public boolean isNullVersion() {
- return PfKey.NULL_KEY_VERSION.equals(getVersion());
- }
-
@Override
public PfKey.Compatibility getCompatibility(@NonNull final PfKey otherKey) {
if (!(otherKey instanceof PfKeyImpl otherConceptKey)) {
return Compatibility.PATCH;
}
- @Override
- public void clean() {
- setName(getName());
- setVersion(getVersion());
- }
-
@Override
public int compareTo(@NonNull final PfConcept otherObj) {
Assertions.argumentNotNull(otherObj, "comparison object may not be null");
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2019-2021, 2023-2024 Nordix Foundation.
+ * Copyright (C) 2019-2021, 2023-2024,2026 OpenInfra Foundation Europe. All rights reserved.
* Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class PfUtils {
+ /**
+ * Gets the ID string of this concept.
+ *
+ * @param key the PfKey object
+ * @return the ID string of this concept
+ */
+ public static String getId(PfKey key) {
+ return key.getName() + ':' + key.getVersion();
+ }
+
+ /**
+ * Determines if the name is "null".
+ *
+ * @param key the PfKeyImpl object
+ * @return {@code true} if the name is null, {@code false} otherwise
+ */
+ public static boolean isNullName(PfKeyImpl key) {
+ return PfKey.NULL_KEY_NAME.equals(key.getName());
+ }
+
+ /**
+ * Determines if the version is "null".
+ *
+ * @param key the PfKeyImpl object
+ * @return {@code true} if the version is null, {@code false} otherwise
+ */
+ public static boolean isNullVersion(PfKeyImpl key) {
+ return PfKey.NULL_KEY_VERSION.equals(key.getVersion());
+ }
+
+ /**
+ * Check if a key equals its null key.
+ *
+ * @param key the PfKey object
+ * @return true, if the key is a null key
+ */
+ public static boolean isNullKey(PfKey key) {
+ return (PfKey.NULL_KEY_NAME.equals(key.getName()) && PfKey.NULL_KEY_VERSION.equals(key.getVersion()));
+ }
+
+ /**
+ * Get a null concept key.
+ *
+ * @return a null concept key
+ */
+ public static PfConceptKey getNullKey() {
+ return new PfConceptKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION);
+ }
+
/**
* Compare two objects using their equals methods, nulls are allowed.
*
import jakarta.validation.ConstraintValidatorContext;
import org.onap.policy.models.base.PfKey;
import org.onap.policy.models.base.PfKeyImpl;
+import org.onap.policy.models.base.PfUtils;
public class VerifyKeyValidator implements ConstraintValidator<VerifyKey, PfKey> {
context.disableDefaultConstraintViolation();
boolean valid = true;
- if (annotation.keyNotNull() && pfkey.isNullKey()) {
+ if (annotation.keyNotNull() && PfUtils.isNullKey(pfkey)) {
context.buildConstraintViolationWithTemplate("is a null key").addConstraintViolation();
return false;
}
- if (pfkey instanceof PfKeyImpl keyimpl) {
- if (annotation.nameNotNull() && keyimpl.isNullName()) {
+ if (pfkey instanceof PfKeyImpl keyImpl) {
+ if (annotation.nameNotNull() && PfUtils.isNullName(keyImpl)) {
context.buildConstraintViolationWithTemplate("is null")
.addPropertyNode("name").addConstraintViolation();
valid = false;
}
- if (annotation.versionNotNull() && keyimpl.isNullVersion()) {
+ if (annotation.versionNotNull() && PfUtils.isNullVersion(keyImpl)) {
context.buildConstraintViolationWithTemplate("is null")
.addPropertyNode("version").addConstraintViolation();
valid = false;
class PfConceptKeyTest {
private static final String VERSION001 = "0.0.1";
- private static final String ID_IS_NULL = "id is marked non-null but is null$";
@Test
void testConceptKey() {
PfConceptKey someKey0 = new PfConceptKey();
- assertEquals(PfConceptKey.getNullKey(), someKey0);
- assertTrue(someKey0.isNullKey());
+ assertEquals(PfUtils.getNullKey(), someKey0);
+ assertTrue(PfUtils.isNullKey(someKey0));
assertEquals("PfConceptKey(name=NULL, version=0.0.0)", someKey0.toString());
PfConceptKey someKey1 = new PfConceptKey("my-name", VERSION001);
PfConceptKey someKey2 = new PfConceptKey(someKey1);
- PfConceptKey someKey3 = new PfConceptKey(someKey1.getId());
+ PfConceptKey someKey3 = new PfConceptKey(PfUtils.getId(someKey1));
assertEquals(someKey1, someKey2);
assertEquals(someKey1, someKey3);
- assertFalse(someKey1.isNullVersion());
- assertFalse(someKey1.isNullName());
+ assertFalse(PfUtils.isNullVersion(someKey1));
+ assertFalse(PfUtils.isNullName(someKey1));
assertEquals("PfConceptKey(name=my-name, version=0.0.1)", someKey1.toString());
assertEquals("my-name", someKey1.getName());
assertEquals(VERSION001, someKey1.getVersion());
-
assertEquals(someKey2, someKey1.getKey());
- assertEquals(1, someKey1.getKeys().size());
-
- PfConcept pfc = new PfConceptKey();
- assertEquals(PfConceptKey.getNullKey().getId(), pfc.getId());
-
- assertTrue(PfConceptKey.getNullKey().matchesId(pfc.getId()));
-
- assertTrue(PfConceptKey.getNullKey().isNullKey());
-
- assertThatThrownBy(() -> PfConceptKey.getNullKey().matchesId(null)).hasMessageMatching(ID_IS_NULL);
+ assertTrue(PfUtils.isNullKey(PfUtils.getNullKey()));
assertThatThrownBy(() -> someKey0.setName(null)).isInstanceOf(NullPointerException.class)
.hasMessageMatching("^name is marked non-null but is null$");
private static final MyKey buildKey1 = new MyKey(NAME, "0.0.3+1");
private static final MyKey buildKey2 = new MyKey(NAME, "0.1.0-1");
private static final MyKey buildKey3 = new MyKey(NAME, "3.0.0-SNAPSHOT");
- private static final MyKey buildKey4 = new MyKey(NAME, "1.0.0-rc.1");
/**
* Sets data in Keys for the tests.
someKey0 = new MyKey();
someKey1 = new MyKey(NAME, VERSION001);
someKey2 = new MyKey(someKey1);
- someKey3 = new MyKey(someKey1.getId());
+ someKey3 = new MyKey(PfUtils.getId(someKey1));
someKey0.setName("zero");
someKey0.setVersion("0.0.2");
assertThatThrownBy(() -> new MyKey((MyKey) null))
.hasMessageMatching("^copyConcept is marked non-null but is null$");
- assertTrue(someKey.isNullKey());
+ assertTrue(PfUtils.isNullKey(someKey));
assertEquals(new MyKey(PfKey.NULL_KEY_NAME, PfKey.NULL_KEY_VERSION), someKey);
MyKey someKey11 = new MyKey(NAME, VERSION001);
MyKey someKey22 = new MyKey(someKey11);
- MyKey someKey33 = new MyKey(someKey11.getId());
+ MyKey someKey33 = new MyKey(PfUtils.getId(someKey11));
assertEquals(someKey11, someKey22);
assertEquals(someKey11, someKey33);
- assertFalse(someKey11.isNullKey());
- assertFalse(someKey11.isNullVersion());
+ assertFalse(PfUtils.isNullKey(someKey11));
+ assertFalse(PfUtils.isNullVersion(someKey11));
assertEquals(someKey22, someKey11.getKey());
- assertEquals(1, someKey11.getKeys().size());
}
@Test
void testCompatibilityConceptKey() {
- assertEquals("name:0.1.2", someKey4.getId());
+ assertEquals("name:0.1.2", PfUtils.getId(someKey4));
assertThatThrownBy(() -> someKey0.getCompatibility(null)).isInstanceOf(NullPointerException.class)
.hasMessageMatching("^otherKey is marked non-null but is null$");
@Test
void testCleanConceptKey() {
- someKey0.clean();
assertNotNull(someKey0.toString());
MyKey someKey7 = new MyKey(someKey1);
MyKey someKey8 = new MyKey();
someKey8.setVersion(VERSION001);
- assertFalse(someKey8.isNullKey());
+ assertFalse(PfUtils.isNullKey(someKey8));
}
@Test