use of org.sagebionetworks.schema.adapter.JSONObjectAdapter in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityBundle method writeToJSONObject.
@Override
public JSONObjectAdapter writeToJSONObject(JSONObjectAdapter writeTo) throws JSONObjectAdapterException {
if (writeTo == null) {
throw new IllegalArgumentException("JSONObjectAdapter cannot be null");
}
if (entity != null) {
JSONObjectAdapter joa = writeTo.createNew();
entity.writeToJSONObject(joa);
writeTo.put(JSON_ENTITY, joa);
writeTo.put(JSON_ENTITY_TYPE, entityType);
}
if (annotations != null) {
JSONObjectAdapter joa = writeTo.createNew();
annotations.writeToJSONObject(joa);
writeTo.put(JSON_ANNOTATIONS, joa);
}
if (permissions != null) {
JSONObjectAdapter joa = writeTo.createNew();
permissions.writeToJSONObject(joa);
writeTo.put(JSON_PERMISSIONS, joa);
}
if (path != null) {
JSONObjectAdapter joa = writeTo.createNew();
path.writeToJSONObject(joa);
writeTo.put(JSON_PATH, joa);
}
if (referencedBy != null) {
JSONObjectAdapter joa = writeTo.createNew();
referencedBy.writeToJSONObject(joa);
writeTo.put(JSON_REFERENCED_BY, joa);
}
if (hasChildren != null) {
writeTo.put(JSON_HAS_CHILDREN, hasChildren);
}
if (acl != null) {
JSONObjectAdapter joa = writeTo.createNew();
acl.writeToJSONObject(joa);
writeTo.put(JSON_ACL, joa);
}
if (accessRequirements != null) {
JSONArrayAdapter arArray = writeTo.createNewArray();
for (int i = 0; i < accessRequirements.size(); i++) {
JSONObjectAdapter joa = arArray.createNew();
accessRequirements.get(i).writeToJSONObject(joa);
arArray.put(i, joa);
}
writeTo.put(JSON_ACCESS_REQUIREMENTS, arArray);
}
if (unmetAccessRequirements != null) {
JSONArrayAdapter arArray = writeTo.createNewArray();
for (int i = 0; i < unmetAccessRequirements.size(); i++) {
JSONObjectAdapter joa = arArray.createNew();
unmetAccessRequirements.get(i).writeToJSONObject(joa);
arArray.put(i, joa);
}
writeTo.put(JSON_UNMET_ACCESS_REQUIREMENTS, arArray);
}
return writeTo;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapter in project Synapse-Repository-Services by Sage-Bionetworks.
the class Annotations method initializeFromJSONObject.
@Override
public JSONObjectAdapter initializeFromJSONObject(JSONObjectAdapter toInitFrom) throws JSONObjectAdapterException {
if (toInitFrom.has(JSON_ID)) {
this.id = toInitFrom.getString(JSON_ID);
}
if (toInitFrom.has(JSON_URI)) {
this.uri = toInitFrom.getString(JSON_URI);
}
if (toInitFrom.has(JSON_ETAG)) {
this.etag = toInitFrom.getString(JSON_ETAG);
}
if (toInitFrom.has(JSON_CREATION_DATE)) {
this.creationDate = toInitFrom.convertStringToDate(FORMAT.UTC_MILLISEC, toInitFrom.getString(JSON_CREATION_DATE));
}
if (toInitFrom.has(JSON_STRING_ANNOTATIONS)) {
JSONObjectAdapter object = toInitFrom.getJSONObject(JSON_STRING_ANNOTATIONS);
this.stringAnnotations = AdapterCollectionUtils.createMapOfCollection(object, String.class);
}
if (toInitFrom.has(JSON_DOUBLE_ANNOTATIONS)) {
JSONObjectAdapter object = toInitFrom.getJSONObject(JSON_DOUBLE_ANNOTATIONS);
this.doubleAnnotations = AdapterCollectionUtils.createMapOfCollection(object, Double.class);
}
if (toInitFrom.has(JSON_LONG_ANNOTATIONS)) {
JSONObjectAdapter object = toInitFrom.getJSONObject(JSON_LONG_ANNOTATIONS);
this.longAnnotations = AdapterCollectionUtils.createMapOfCollection(object, Long.class);
}
if (toInitFrom.has(JSON_DATE_ANNOTATIONS)) {
JSONObjectAdapter object = toInitFrom.getJSONObject(JSON_DATE_ANNOTATIONS);
this.dateAnnotations = AdapterCollectionUtils.createMapOfCollection(object, Date.class);
}
if (toInitFrom.has(JSON_BLOB_ANNOTATIONS)) {
JSONObjectAdapter object = toInitFrom.getJSONObject(JSON_BLOB_ANNOTATIONS);
this.blobAnnotations = AdapterCollectionUtils.createMapOfCollection(object, byte[].class);
}
return toInitFrom;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapter 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.JSONObjectAdapter in project Synapse-Repository-Services by Sage-Bionetworks.
the class EntityBundleCreate method initializeFromJSONObject.
@Override
public JSONObjectAdapter initializeFromJSONObject(JSONObjectAdapter toInitFrom) throws JSONObjectAdapterException {
if (toInitFrom == null) {
throw new IllegalArgumentException("org.sagebionetworks.schema.adapter.JSONObjectAdapter cannot be null");
}
if (toInitFrom.has(JSON_ENTITY)) {
entityType = toInitFrom.getString(JSON_ENTITY_TYPE);
JSONObjectAdapter joa = (JSONObjectAdapter) toInitFrom.getJSONObject(JSON_ENTITY);
entity = (Entity) autoGenFactory.newInstance(entityType);
entity.initializeFromJSONObject(joa);
}
if (toInitFrom.has(JSON_ANNOTATIONS)) {
JSONObjectAdapter joa = (JSONObjectAdapter) toInitFrom.getJSONObject(JSON_ANNOTATIONS);
if (annotations == null)
annotations = new Annotations();
annotations.initializeFromJSONObject(joa);
}
if (toInitFrom.has(JSON_ACL)) {
JSONObjectAdapter joa = (JSONObjectAdapter) toInitFrom.getJSONObject(JSON_ACL);
if (acl == null)
acl = (AccessControlList) autoGenFactory.newInstance(AccessControlList.class.getName());
acl.initializeFromJSONObject(joa);
}
if (toInitFrom.has(JSON_ACCESS_REQUIREMENT)) {
JSONObjectAdapter joa = (JSONObjectAdapter) toInitFrom.getJSONObject(JSON_ACCESS_REQUIREMENT);
accessRequirement = (AccessRequirement) EntityClassHelper.deserialize(joa);
}
return toInitFrom;
}
use of org.sagebionetworks.schema.adapter.JSONObjectAdapter 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;
}
Aggregations