Improve the performance of resoures microservice
[aai/aai-common.git] / aai-core / src / main / java / org / onap / aai / introspection / MoxyLoader.java
index 8250455..fa52d62 100644 (file)
@@ -34,6 +34,7 @@ import org.onap.aai.logging.ErrorLogHelper;
 import org.onap.aai.logging.LogFormatTools;
 import org.onap.aai.nodes.NodeIngestor;
 import org.onap.aai.restcore.MediaType;
+import org.onap.aai.schema.enums.ObjectMetadata;
 import org.onap.aai.setup.SchemaVersion;
 import org.onap.aai.workarounds.NamingExceptions;
 import org.springframework.stereotype.Component;
@@ -44,6 +45,7 @@ import java.io.*;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 public class MoxyLoader extends Loader {
 
@@ -52,9 +54,11 @@ public class MoxyLoader extends Loader {
        private Map<String, Introspector> allObjs = null;
 
        private Map<SchemaVersion, MoxyLoader> moxyLoaderFactory;
-       
+
        private NodeIngestor nodeIngestor;
 
+       private Set<String> namedProps;
+
        public MoxyLoader(SchemaVersion version, NodeIngestor nodeIngestor) {
                super(version, ModelType.MOXY);
                this.nodeIngestor = nodeIngestor;
@@ -67,14 +71,14 @@ public class MoxyLoader extends Loader {
        }
        /**
         * {@inheritDoc}
-        * @throws AAIUnknownObjectException 
+        * @throws AAIUnknownObjectException
         */
        @Override
        public Introspector introspectorFromName(String name) throws AAIUnknownObjectException {
 
                return IntrospectorFactory.newInstance(ModelType.MOXY, objectFromName(name));
        }
-       
+
        /**
         * {@inheritDoc}
         */
@@ -93,7 +97,7 @@ public class MoxyLoader extends Loader {
                } else {
                        upperCamel = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, sanitizedName);
                }
-               
+
                try {
                        final DynamicEntity result = jaxbContext.newDynamicEntity(upperCamel);
 
@@ -115,14 +119,14 @@ public class MoxyLoader extends Loader {
                 * We need to have just same JaxbContext for each version
                 */
                jaxbContext = nodeIngestor.getContextForVersion(version);
-               
+
        }
 
        /**
         * {@inheritDoc}
         */
        @Override
-       public Introspector unmarshal(String type, String json, MediaType mediaType) throws AAIUnmarshallingException {         
+       public Introspector unmarshal(String type, String json, MediaType mediaType) throws AAIUnmarshallingException {
                try {
                        final Object clazz = objectFromName(type);
                        final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
@@ -143,7 +147,7 @@ public class MoxyLoader extends Loader {
                        throw new AAIUnmarshallingException("Could not unmarshall: " + e.getMessage(), e);
                }
        }
-       
+
        @Override
        public Map<String, Introspector> getAllObjects() {
                if (this.allObjs != null) {
@@ -163,7 +167,7 @@ public class MoxyLoader extends Loader {
                        return allObjs;
                }
        }
-       
+
        private Set<String> objectsInVersion() {
                 Set<String> result = new HashSet<>();
 
@@ -177,7 +181,21 @@ public class MoxyLoader extends Loader {
                //result.remove("EdgePropNames");
                return result;
        }
-       
+
+       @Override
+       public Set<String> getNamedPropNodes(){
+
+        if(namedProps == null){
+               namedProps = getAllObjects()
+                .entrySet()
+                .stream()
+                .filter(
+                    (entry) -> entry.getValue().getMetadata(ObjectMetadata.NAME_PROPS) != null
+                ).map(entry -> entry.getKey()).collect(Collectors.toSet());
+        }
+
+        return namedProps;
+    }
        public DynamicJAXBContext getJAXBContext() {
                return this.jaxbContext;
        }