Make filters on TOSCA entities generic
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / concepts / ToscaEntity.java
index e588a59..98efd19 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Model
  * ================================================================================
- * Copyright (C) 2019 Nordix Foundation.
+ * Copyright (C) 2019-2021 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -32,6 +32,7 @@ import javax.ws.rs.core.Response;
 import lombok.Data;
 import lombok.NoArgsConstructor;
 import lombok.NonNull;
+import org.onap.policy.models.base.PfKey;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.onap.policy.models.base.PfNameVersion;
 
@@ -43,16 +44,14 @@ import org.onap.policy.models.base.PfNameVersion;
 @Data
 @NoArgsConstructor
 public class ToscaEntity implements PfNameVersion {
-    private String name;
-
-    private String version;
+    private String name = PfKey.NULL_KEY_NAME;
+    private String version = PfKey.NULL_KEY_VERSION;
 
     @ApiModelProperty(name = "derived_from")
     @SerializedName("derived_from")
     private String derivedFrom;
 
     private Map<String, String> metadata;
-
     private String description;
 
     /**
@@ -83,12 +82,22 @@ public class ToscaEntity implements PfNameVersion {
         return new ToscaEntityKey(name, version);
     }
 
+    @Override
+    public String getDefinedName() {
+        return (PfKey.NULL_KEY_NAME.equals(name) ? null : name);
+    }
+
+    @Override
+    public String getDefinedVersion() {
+        return (PfKey.NULL_KEY_VERSION.equals(version) ? null : version);
+    }
+
     /**
      * Convert a list of maps of TOSCA entities into a regular map.
      *
      * @param listOfMapsOfEntities the incoming list of maps of entities
      * @return The entities on a regular map
-     * @throws PfModelException on duplicate entity entries
+     * @throws PfModelRuntimeException on duplicate entity entries
      */
     public static <T extends ToscaEntity> Map<ToscaEntityKey, T> getEntityListMapAsMap(
             List<Map<String, T>> listOfMapsOfEntities) {
@@ -114,7 +123,7 @@ public class ToscaEntity implements PfNameVersion {
      *
      * @param mapOfEntities the incoming list of maps of entities
      * @return The entities on a regular map
-     * @throws PfModelException on duplicate entity entries
+     * @throws PfModelRuntimeException on duplicate entity entries
      */
     public static <T extends ToscaEntity> Map<ToscaEntityKey, T> getEntityMapAsMap(Map<String, T> mapOfEntities) {
         // Declare the return map
@@ -132,4 +141,21 @@ public class ToscaEntity implements PfNameVersion {
         return entityMap;
     }
 
+    /**
+     * Method that should be specialised to return the type of the entity if the entity has a type.
+     *
+     * @return the type of the entity or null if it has no type
+     */
+    public String getType() {
+        return null;
+    }
+
+    /**
+     * Method that should be specialised to return the type version of the entity if the entity has a type.
+     *
+     * @return the type of the entity or null if it has no type
+     */
+    public String getTypeVersion() {
+        return null;
+    }
 }