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;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import java.util.stream.Collectors;
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;
}
/**
* {@inheritDoc}
- * @throws AAIUnknownObjectException
+ * @throws AAIUnknownObjectException
*/
@Override
public Introspector introspectorFromName(String name) throws AAIUnknownObjectException {
return IntrospectorFactory.newInstance(ModelType.MOXY, objectFromName(name));
}
-
+
/**
* {@inheritDoc}
*/
} else {
upperCamel = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, sanitizedName);
}
-
+
try {
final DynamicEntity result = jaxbContext.newDynamicEntity(upperCamel);
* 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();
throw new AAIUnmarshallingException("Could not unmarshall: " + e.getMessage(), e);
}
}
-
+
@Override
public Map<String, Introspector> getAllObjects() {
if (this.allObjs != null) {
return allObjs;
}
}
-
+
private Set<String> objectsInVersion() {
Set<String> result = new HashSet<>();
//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;
}