diff options
Diffstat (limited to 'src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java')
-rw-r--r-- | src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java index ba17423..167a568 100644 --- a/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java +++ b/src/main/java/org/onap/sdc/tosca/parser/elements/queries/EntityQuery.java @@ -1,11 +1,17 @@ package org.onap.sdc.tosca.parser.elements.queries; -import org.apache.commons.lang3.StringUtils; +import org.onap.sdc.tosca.parser.api.IEntityDetails; import org.onap.sdc.tosca.parser.enums.EntityTemplateType; import org.onap.sdc.tosca.parser.enums.SdcTypes; -import org.onap.sdc.toscaparser.api.EntityTemplate; +import org.onap.sdc.tosca.parser.impl.SdcPropertyNames; +import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.ToscaTemplate; +import org.onap.sdc.toscaparser.api.elements.Metadata; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; +import java.util.Objects; /** * This class describes an entity searched and retrieved by SDC Tosca Parser API @@ -13,6 +19,8 @@ import java.util.List; */ public abstract class EntityQuery { + private static final Logger logger = LoggerFactory.getLogger(EntityQuery.class.getName()); + private final EntityTemplateType entityType; private final SdcTypes nodeTemplateType; @@ -37,9 +45,9 @@ public abstract class EntityQuery { this.customizationUUID = customizationUUID; } - public abstract List<EntityTemplate> searchByTopologyTemplate(TopologyTemplateQuery topologyTemplateQuery); + public abstract List<IEntityDetails> getEntitiesFromTopologyTemplate(NodeTemplate nodeTemplate); - public abstract EntityTemplateType getType(); + public abstract List<IEntityDetails> getEntitiesFromService(ToscaTemplate toscaTemplate); public EntityTemplateType getEntityType() { return entityType; @@ -61,8 +69,19 @@ public abstract class EntityQuery { return customizationUUID; } - public boolean searchAllEntities() { - return StringUtils.isEmpty(toscaType) && nodeTemplateType == null; + boolean isSearchCriteriaMatched(Metadata metadata, String toscaType, String uuidKeyName, String cuuidKeyName) { + return Objects.nonNull(metadata) + && isStringMatchingOrNull(metadata.getValue(uuidKeyName), getUUID()) + && isStringMatchingOrNull(metadata.getValue(cuuidKeyName), getCustomizationUUID()) + && isStringMatchingOrNull(toscaType, getToscaType()); + } + + boolean isSearchCriteriaMatched(Metadata metadata, String toscaType) { + return isSearchCriteriaMatched(metadata, toscaType, SdcPropertyNames.PROPERTY_NAME_UUID, SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID); + } + + static boolean isStringMatchingOrNull(String currentUid, String uidInQuery) { + return uidInQuery == null || uidInQuery.equals(currentUid); } public static EntityQueryBuilder newBuilder(EntityTemplateType entityTemplateType) { @@ -73,6 +92,12 @@ public abstract class EntityQuery { return new EntityQueryBuilder(sdcType); } + @Override + public String toString() { + return String.format("EntityType=%s, nodeTemplateType=%s, toscaType=%s, uUID=%s, customizationUUID=%s", + entityType, nodeTemplateType, toscaType, uUID, customizationUUID); + } + public static EntityQueryBuilder newBuilder(String toscaType) { return new EntityQueryBuilder(toscaType); } @@ -97,8 +122,13 @@ public abstract class EntityQuery { case POLICY: entityQuery = new PolicyEntityQuery(); break; + case ALL: + entityQuery = new AllEntitiesQuery(); + break; default: - throw new IllegalArgumentException("Wrong entity query type: " + entityTemplateType); + String wrongTypeMsg = (String.format("Wrong entity query type: %s", entityTemplateType)); + logger.error(wrongTypeMsg); + throw new IllegalArgumentException(wrongTypeMsg); } } |