summaryrefslogtreecommitdiffstats
path: root/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java
diff options
context:
space:
mode:
Diffstat (limited to 'aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java')
-rw-r--r--aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java103
1 files changed, 52 insertions, 51 deletions
diff --git a/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java b/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java
index ecf31253..f0d487e8 100644
--- a/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java
+++ b/aai-core/src/main/java/org/onap/aai/introspection/MoxyStrategy.java
@@ -51,9 +51,10 @@ import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.util.*;
import java.util.Map.Entry;
+import java.util.stream.Collectors;
public class MoxyStrategy extends Introspector {
-
+
private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(MoxyStrategy.class);
private DynamicEntity internalObject = null;
private DynamicType internalType = null;
@@ -67,9 +68,9 @@ public class MoxyStrategy extends Introspector {
private Set<String> requiredProperties = null;
private boolean isInitialized = false;
-
+
private NodeIngestor nodeIngestor;
-
+
protected MoxyStrategy(Object obj) {
super(obj);
/* must look up the correct jaxbcontext for this object */
@@ -81,19 +82,19 @@ public class MoxyStrategy extends Introspector {
jaxbContext = nodeIngestor.getContextForVersion(version);
String simpleName = internalObject.getClass().getName();
internalType = jaxbContext.getDynamicType(simpleName);
-
+
cd = internalType.getDescriptor();
try {
marshaller = jaxbContext.createMarshaller();
-
+
unmarshaller = jaxbContext.createUnmarshaller();
-
+
} catch (JAXBException e) {
}
}
-
+
private void init() {
isInitialized = true;
@@ -104,13 +105,13 @@ public class MoxyStrategy extends Introspector {
}
props = Collections.unmodifiableSet(props);
this.properties = props;
-
+
Set<String> requiredProps = new LinkedHashSet<>();
requiredProps = new LinkedHashSet<>();
for (DatabaseMapping dm : cd.getMappings()) {
- if (dm.getField() instanceof XMLField) {
+ if (dm.getField() instanceof XMLField) {
XMLField x = (XMLField)dm.getField();
- if (x != null) {
+ if (x != null) {
if (x.isRequired()) {
requiredProps.add(this.removeXPathDescriptor(x.getName()));
}
@@ -119,25 +120,25 @@ public class MoxyStrategy extends Introspector {
}
requiredProps = Collections.unmodifiableSet(requiredProps);
this.requiredProperties = requiredProps;
-
+
Set<String> keys = new LinkedHashSet<>();
-
+
for (String name : internalType.getDescriptor().getPrimaryKeyFieldNames()) {
keys.add(this.removeXPathDescriptor(name));
}
keys = Collections.unmodifiableSet(keys);
this.keys = keys;
-
-
+
+
}
-
+
@Override
public boolean hasProperty(String name) {
String convertedName = convertPropertyName(name);
- return internalType.containsProperty(convertedName);
+ return internalType.containsProperty(convertedName);
}
-
+
@Override
public Object get(String name) {
return internalObject.get(name);
@@ -145,7 +146,7 @@ public class MoxyStrategy extends Introspector {
@Override
public void set(String name, Object obj) throws IllegalArgumentException {
-
+
internalObject.set(name, obj);
}
@@ -157,7 +158,7 @@ public class MoxyStrategy extends Introspector {
}
return this.properties;
-
+
}
@Override
@@ -179,7 +180,7 @@ public class MoxyStrategy extends Introspector {
return this.keys;
}
-
+
@Override
public Map<PropertyMetadata, String> getPropertyMetadata(String prop) {
String propName = this.convertPropertyName(prop);
@@ -192,7 +193,7 @@ public class MoxyStrategy extends Introspector {
PropertyMetadata.valueOf(CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, (String)entry.getKey())), (String)entry.getValue());
}
}
-
+
return result;
}
@@ -200,8 +201,8 @@ public class MoxyStrategy extends Introspector {
public String getJavaClassName() {
return internalObject.getClass().getName();
}
-
-
+
+
@Override
public Class<?> getClass(String name) {
@@ -211,7 +212,7 @@ public class MoxyStrategy extends Introspector {
if (internalType.getPropertyType(name) == null) {
if (cd.getMappingForAttributeName(name) instanceof XMLCompositeDirectCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
-
+
} else if (cd.getMappingForAttributeName(name) instanceof XMLCompositeCollectionMapping) {
resultClass = cd.getMappingForAttributeName(name).getContainerPolicy().getContainerClass();
} else {
@@ -243,7 +244,7 @@ public class MoxyStrategy extends Introspector {
resultClass = cd.getMappingForAttributeName(name).getReferenceDescriptor().getJavaClass();
}
}
-
+
return resultClass;
}
@@ -251,20 +252,20 @@ public class MoxyStrategy extends Introspector {
public Object getUnderlyingObject() {
return this.internalObject;
}
-
+
@Override
public String getChildName() {
-
+
String className = internalObject.getClass().getSimpleName();
String lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, className);
-
+
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().iterator().next()).getSimpleName());
}
-
+
return lowerHyphen;
}
-
+
@Override
public String getName() {
String className = internalObject.getClass().getSimpleName();
@@ -273,11 +274,11 @@ public class MoxyStrategy extends Introspector {
if (this.isContainer()) {
lowerHyphen = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN,this.getGenericTypeClass(this.getProperties().get(0)).getSimpleName());
}*/
-
+
return lowerHyphen;
}
-
+
@Override
public String getObjectId() throws UnsupportedEncodingException {
String result = "";
@@ -285,17 +286,17 @@ public class MoxyStrategy extends Introspector {
if (this.isContainer()) {
result += "/" + this.getName();
} else {
-
+
if (container != null) {
result += "/" + container;
}
result += "/" + this.getDbName() + "/" + this.findKey();
-
+
}
-
+
return result;
}
-
+
@Override
protected String findKey() throws UnsupportedEncodingException {
Set<String> keys = null;
@@ -305,10 +306,10 @@ public class MoxyStrategy extends Introspector {
String value = UriUtils.encode(this.getValue(key).toString(), "UTF-8");
results.add(value);
}
-
+
return Joiner.on("/").join(results);
}
-
+
@Override
public String preProcessKey (String key) {
String result = "";
@@ -316,19 +317,19 @@ public class MoxyStrategy extends Introspector {
String[] split = key.split("/");
int i = 0;
for (i = split.length-1; i >= 0; i--) {
-
+
if (jaxbContext.getDynamicType(split[i]) != null) {
break;
-
+
}
-
+
}
result = Joiner.on("/").join(Arrays.copyOfRange(split, 0, i));
-
+
return result;
-
+
}
-
+
@Override
public String marshal(MarshallerProperties properties) {
StringWriter result = new StringWriter();
@@ -339,7 +340,7 @@ public class MoxyStrategy extends Introspector {
marshaller.setProperty(org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, properties.getWrapperAsArrayName());
marshaller.setProperty(org.eclipse.persistence.jaxb.MarshallerProperties.JSON_MARSHAL_EMPTY_COLLECTIONS, false);
}
-
+
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, properties.getFormatted());
marshaller.marshal(this.internalObject, result);
} catch (JAXBException e) {
@@ -348,7 +349,7 @@ public class MoxyStrategy extends Introspector {
return result.toString();
}
-
+
@Override
public Object clone() {
Object result = null;
@@ -358,7 +359,7 @@ public class MoxyStrategy extends Introspector {
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
-
+
result = unmarshaller.unmarshal(new StreamSource(new StringReader(this.marshal(true))), this.internalObject.getClass()).getValue();
} catch (JAXBException e) {
// TODO Auto-generated catch block
@@ -371,21 +372,21 @@ public class MoxyStrategy extends Introspector {
public ModelType getModelType() {
return ModelType.MOXY;
}
-
+
private String removeXPathDescriptor(String name) {
-
+
return name.replaceAll("/text\\(\\)", "");
}
@Override
public String getMetadata(ObjectMetadata name) {
-
+
return (String)cd.getProperty(name.toString());
}
@Override
public SchemaVersion getVersion() {
-
+
return this.version;
}
}