use of org.eclipse.persistence.dynamic.DynamicEntity in project aai-aai-common by onap.
the class StoreNotificationEvent method storeDynamicEvent.
/**
* Store dynamic event.
*
* @param notificationJaxbContext
* the notification jaxb context
* @param notificationVersion
* the notification version
* @param eventHeader
* the event header
* @param obj
* the obj
* @throws AAIException
* the AAI exception
*/
public void storeDynamicEvent(DynamicJAXBContext notificationJaxbContext, String notificationVersion, DynamicEntity eventHeader, DynamicEntity obj) throws AAIException {
if (obj == null) {
throw new AAIException("AAI_7350");
}
DynamicEntity notificationEvent = notificationJaxbContext.getDynamicType("inventory.aai.onap.org." + notificationVersion + ".NotificationEvent").newDynamicEntity();
if (eventHeader.get("id") == null) {
eventHeader.set("id", genDate2() + "-" + UUID.randomUUID().toString());
}
if (eventHeader.get("timestamp") == null) {
eventHeader.set("timestamp", genDate());
}
if (eventHeader.get("entityLink") == null) {
eventHeader.set("entityLink", "UNK");
}
if (eventHeader.get("action") == null) {
eventHeader.set("action", "UNK");
}
if (eventHeader.get("eventType") == null) {
eventHeader.set("eventType", AAIConfig.get("aai.notificationEvent.default.eventType", "UNK"));
}
if (eventHeader.get("domain") == null) {
eventHeader.set("domain", AAIConfig.get("aai.notificationEvent.default.domain", "UNK"));
}
if (eventHeader.get("sourceName") == null) {
eventHeader.set("sourceName", AAIConfig.get("aai.notificationEvent.default.sourceName", "UNK"));
}
if (eventHeader.get("sequenceNumber") == null) {
eventHeader.set("sequenceNumber", AAIConfig.get("aai.notificationEvent.default.sequenceNumber", "UNK"));
}
if (eventHeader.get("severity") == null) {
eventHeader.set("severity", AAIConfig.get("aai.notificationEvent.default.severity", "UNK"));
}
if (eventHeader.get("version") == null) {
eventHeader.set("version", AAIConfig.get("aai.notificationEvent.default.version", "UNK"));
}
if (notificationEvent.get("cambriaPartition") == null) {
notificationEvent.set("cambriaPartition", AAIConstants.UEB_PUB_PARTITION_AAI);
}
notificationEvent.set("eventHeader", eventHeader);
notificationEvent.set("entity", obj);
try {
StringWriter result = new StringWriter();
Marshaller marshaller = notificationJaxbContext.createMarshaller();
marshaller.setProperty(org.eclipse.persistence.jaxb.MarshallerProperties.MEDIA_TYPE, "application/json");
marshaller.setProperty(org.eclipse.persistence.jaxb.MarshallerProperties.JSON_INCLUDE_ROOT, false);
marshaller.setProperty(org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, false);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
marshaller.marshal(notificationEvent, result);
this.sendToDmaapJmsQueue(result.toString());
} catch (Exception e) {
throw new AAIException("AAI_7350", e);
}
}
use of org.eclipse.persistence.dynamic.DynamicEntity in project aai-aai-common by onap.
the class PojoUtilsTest method testGetJsonFromDynamicObject.
@Test
public void testGetJsonFromDynamicObject() throws Exception {
DynamicEntity dynamicEntity = Mockito.mock(DynamicEntity.class);
JAXBContext jaxbContext = Mockito.mock(JAXBContext.class);
JAXBMarshaller marshaller = Mockito.mock(JAXBMarshaller.class);
Mockito.when(jaxbContext.createMarshaller()).thenReturn(marshaller);
String output = pojoUtils.getJsonFromDynamicObject(dynamicEntity, jaxbContext, true);
assertEquals("", output);
}
use of org.eclipse.persistence.dynamic.DynamicEntity in project aai-aai-common by onap.
the class StoreNotificationEventTest method testStoreDynamicEventAAIException.
@Test(expected = Exception.class)
public void testStoreDynamicEventAAIException() throws Exception {
DynamicJAXBContext notificationJaxbContext = nodeIngestor.getContextForVersion(schemaVersions.getEdgeLabelVersion());
DynamicEntity obj = Mockito.mock(DynamicEntity.class);
DynamicEntity eventHeader = Mockito.mock(DynamicEntity.class);
sne.storeDynamicEvent(notificationJaxbContext, "v12", eventHeader, obj);
}
use of org.eclipse.persistence.dynamic.DynamicEntity in project aai-aai-common by onap.
the class NodeIngestorTest method testGetContextForVersion.
@Test
public void testGetContextForVersion() {
DynamicJAXBContext ctx10 = nodeIngestor.getContextForVersion(new SchemaVersion("v10"));
// should work bc Foo is valid in test_network_v10 schema
DynamicEntity foo10 = ctx10.newDynamicEntity("Foo");
foo10.set("fooId", "bar");
assertEquals("bar", foo10.get("fooId"));
// should work bc Bar is valid in test_business_v10 schema
DynamicEntity bar10 = ctx10.newDynamicEntity("Bar");
bar10.set("barId", "bar2");
assertEquals("bar2", bar10.get("barId"));
XSDOutputResolver outputResolver10 = new XSDOutputResolver();
ctx10.generateSchema(outputResolver10);
DynamicJAXBContext ctx11 = nodeIngestor.getContextForVersion(new SchemaVersion("v11"));
// should work bc Foo.quantity is valid in test_network_v11 schema
DynamicEntity foo11 = ctx11.newDynamicEntity("Foo");
foo11.set("quantity", "12");
assertEquals("12", foo11.get("quantity"));
DynamicEntity quux11 = ctx11.newDynamicEntity("Quux");
quux11.set("qManagerName", "some guy");
assertEquals("some guy", quux11.get("qManagerName"));
XSDOutputResolver outputResolver11 = new XSDOutputResolver();
ctx11.generateSchema(outputResolver11);
thrown.expect(IllegalArgumentException.class);
// should fail bc Quux not in v10 test schema
ctx10.newDynamicEntity("Quux");
}
use of org.eclipse.persistence.dynamic.DynamicEntity in project aai-aai-common by onap.
the class MoxyLoader method unmarshal.
/**
* {@inheritDoc}
*/
@Override
public Introspector unmarshal(String type, String json, MediaType mediaType) throws AAIUnmarshallingException {
try {
final Object clazz = objectFromName(type);
final Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
if (mediaType.equals(MediaType.APPLICATION_JSON_TYPE)) {
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, "application/json");
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, true);
}
final DynamicEntity entity = (DynamicEntity) unmarshaller.unmarshal(new StreamSource(new StringReader(json)), clazz.getClass()).getValue();
return IntrospectorFactory.newInstance(ModelType.MOXY, entity);
} catch (JAXBException e) {
AAIException ex = new AAIException("AAI_4007", e);
ErrorLogHelper.logException(ex);
throw new AAIUnmarshallingException("Could not unmarshall: " + e.getMessage(), ex);
} catch (AAIUnknownObjectException e) {
throw new AAIUnmarshallingException("Could not unmarshall: " + e.getMessage(), e);
}
}
Aggregations