use of org.sagebionetworks.schema.adapter.JSONObjectAdapterException in project Synapse-Repository-Services by Sage-Bionetworks.
the class BatchResults method initializeFromJSONObject.
@Override
public JSONObjectAdapter initializeFromJSONObject(JSONObjectAdapter adapter) throws JSONObjectAdapterException {
if (adapter == null)
throw new IllegalArgumentException("Adapter cannot be null");
totalNumberOfResults = adapter.getLong("totalNumberOfResults");
if (!adapter.isNull("results")) {
this.results = new ArrayList<T>();
JSONArrayAdapter array = adapter.getJSONArray("results");
for (int i = 0; i < array.length(); i++) {
JSONObjectAdapter childAdapter = array.getJSONObject(i);
try {
T newInstance = (T) factory.newInstance(clazz.getName());
newInstance.initializeFromJSONObject(childAdapter);
this.results.add(newInstance);
} catch (Exception e) {
throw new JSONObjectAdapterException(e);
}
}
}
return adapter;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapterException in project Synapse-Repository-Services by Sage-Bionetworks.
the class PaginatedResults method initializeFromJSONObject.
@Override
public JSONObjectAdapter initializeFromJSONObject(JSONObjectAdapter adapter) throws JSONObjectAdapterException {
if (adapter == null)
throw new IllegalArgumentException("Adapter cannot be null");
totalNumberOfResults = adapter.getLong("totalNumberOfResults");
if (!adapter.isNull("results")) {
this.results = new ArrayList<T>();
JSONArrayAdapter array = adapter.getJSONArray("results");
for (int i = 0; i < array.length(); i++) {
JSONObjectAdapter childAdapter = array.getJSONObject(i);
try {
T newInstance = (T) factory.newInstance(clazz.getName());
newInstance.initializeFromJSONObject(childAdapter);
this.results.add(newInstance);
} catch (Exception e) {
throw new JSONObjectAdapterException(e);
}
}
}
if (!adapter.isNull("paging")) {
JSONObjectAdapter pagingAdapter = adapter.getJSONObject("paging");
this.paging = new HashMap<String, String>();
Iterator<String> it = pagingAdapter.keys();
while (it.hasNext()) {
String key = it.next();
String value = pagingAdapter.getString(key);
this.paging.put(key, value);
}
}
return adapter;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapterException in project Synapse-Repository-Services by Sage-Bionetworks.
the class VariableContentPaginatedResults method initializeFromJSONObject.
@Override
public JSONObjectAdapter initializeFromJSONObject(JSONObjectAdapter adapter) throws JSONObjectAdapterException {
if (adapter == null)
throw new IllegalArgumentException("Adapter cannot be null");
totalNumberOfResults = adapter.getLong("totalNumberOfResults");
if (!adapter.isNull("results")) {
this.results = new ArrayList<T>();
JSONArrayAdapter array = adapter.getJSONArray("results");
for (int i = 0; i < array.length(); i++) {
JSONObjectAdapter childAdapter = array.getJSONObject(i);
try {
this.results.add((T) EntityClassHelper.deserialize(childAdapter));
} catch (Exception e) {
throw new JSONObjectAdapterException(e);
}
}
}
if (!adapter.isNull("paging")) {
JSONObjectAdapter pagingAdapter = adapter.getJSONObject("paging");
this.paging = new HashMap<String, String>();
Iterator<String> it = pagingAdapter.keys();
while (it.hasNext()) {
String key = it.next();
String value = pagingAdapter.getString(key);
this.paging.put(key, value);
}
}
return adapter;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapterException in project Synapse-Repository-Services by Sage-Bionetworks.
the class MessageUtils method createMessage.
/**
* Create an Amazon message from a ChangeMessage. This is used for testing.
* @param message
* @return
*/
public static Message createMessage(ChangeMessage message, String messageId, String receiptHandle) {
if (message == null)
throw new IllegalArgumentException("Message cannot be null");
try {
Message result = new Message().withMessageId(messageId).withReceiptHandle(receiptHandle);
result.setBody(EntityFactory.createJSONStringForEntity(message));
return result;
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
}
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapterException in project Synapse-Repository-Services by Sage-Bionetworks.
the class MessageUtils method extractMessageBody.
/**
* Extract a ChangeMessage from an Amazon Message
* @param message
* @return
*/
public static ChangeMessage extractMessageBody(Message message) {
if (message == null)
throw new IllegalArgumentException("Message cannot be null");
try {
JSONObject object = new JSONObject(message.getBody());
if (object.has("objectId")) {
// This is a message pushed directly to a queue
JSONObjectAdapterImpl adapter = new JSONObjectAdapterImpl(object);
return new ChangeMessage(adapter);
}
if (object.has("TopicArn") && object.has("Message")) {
// This is a message that was pushed to a topic then forwarded to a queue.
JSONObject innerObject = new JSONObject(object.getString("Message"));
JSONObjectAdapterImpl adapter = new JSONObjectAdapterImpl(innerObject);
return new ChangeMessage(adapter);
} else {
throw new IllegalArgumentException("Unknown message type: " + message.getBody());
}
} catch (JSONException e) {
throw new RuntimeException(e);
} catch (JSONObjectAdapterException e) {
throw new RuntimeException(e);
}
}
Aggregations