* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* See the License for the specific language governing permissions and
* limitations under the License.
* ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.introspection;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.google.common.base.CaseFormat;
import com.google.common.base.Joiner;
+
+
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.dynamic.DynamicEntity;
import org.eclipse.persistence.dynamic.DynamicType;
import org.eclipse.persistence.oxm.XMLField;
import org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping;
import org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping;
+import org.onap.aai.config.SpringContextAware;
+import org.onap.aai.nodes.NodeIngestor;
import org.onap.aai.restcore.MediaType;
import org.onap.aai.schema.enums.ObjectMetadata;
import org.onap.aai.schema.enums.PropertyMetadata;
+import org.onap.aai.setup.SchemaVersion;
import org.springframework.web.util.UriUtils;
-
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.bind.Unmarshaller;
public class MoxyStrategy extends Introspector {
+ private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(MoxyStrategy.class);
private DynamicEntity internalObject = null;
private DynamicType internalType = null;
private DynamicJAXBContext jaxbContext = null;
private ClassDescriptor cd = null;
private Marshaller marshaller = null;
private Unmarshaller unmarshaller = null;
- private Version version = null;
+ private SchemaVersion version = null;
private Set<String> properties = null;
private Set<String> keys = null;
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 */
className = MoxyStrategy.class.getSimpleName();
internalObject = (DynamicEntity)obj;
- ModelInjestor injestor = ModelInjestor.getInstance();
- version = injestor.getVersionFromClassName(internalObject.getClass().getName());
- jaxbContext = injestor.getContextForVersion(version);
- super.loader = LoaderFactory.createLoaderForVersion(getModelType(), version);
+ nodeIngestor = SpringContextAware.getBean(NodeIngestor.class);
+ version = nodeIngestor.getVersionFromClassName(internalObject.getClass().getName());
+ super.loader = SpringContextAware.getBean(LoaderFactory.class).createLoaderForVersion(getModelType(), version);
+ 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) {
}
keys = this.getKeys();
List<String> results = new ArrayList<>();
for (String key : keys) {
- if (this.getType(key).toLowerCase().contains("long")) {
- key = ((Long)this.getValue(key)).toString();
- } else {
- key = (String)this.getValue(key);
- }
- key = UriUtils.encode(key, "UTF-8");
-
- results.add(key);
+ String value = UriUtils.encode(this.getValue(key).toString(), "UTF-8");
+ results.add(value);
}
return Joiner.on("/").join(results);
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.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, properties.getFormatted());
marshaller.marshal(this.internalObject, result);
} catch (JAXBException e) {
//e.printStackTrace();
}
@Override
- public Version getVersion() {
+ public SchemaVersion getVersion() {
return this.version;
}