List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:org.collectionspace.chain.csp.webui.record.RecordCreateUpdate.java
private JSONObject getWorkflowPerm(Storage storage, Record recordForPermResource, String resourceName, String permLevel, String workflowTransition) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, UIException { JSONObject permitem = new JSONObject(); if (permLevel.equals("none")) { return permitem; }//from w ww . j a va 2 s . com JSONArray actions = new JSONArray(); JSONObject permC = permJSON("CREATE"); JSONObject permR = permJSON("READ"); JSONObject permU = permJSON("UPDATE"); JSONObject permD = permJSON("DELETE"); JSONObject permL = permJSON("SEARCH"); actions.put(permR); actions.put(permL); ///cspace-services/authorization/permissions?res=acquisition&actGrp=CRUDL String queryString = "RL"; String permbase = spec.getRecordByWebUrl("permission").getID(); boolean hasRights = false; if (workflowTransition.equals(DELETE_WORKFLOW_TRANSITION)) { // permLevel delete or lock includes this hasRights = permLevel.equals(Generic.DELETE_PERMISSION) || permLevel.equals(Generic.LOCK_PERMISSION); } else if (workflowTransition.equals(LOCK_WORKFLOW_TRANSITION)) { // permLevel lock includes this // UI does not yet support admin of the lock perm, so //hasRights = permLevel.equals(Generic.LOCK_PERMISSION); // Assumes this is only called for records that actually support locking... hasRights = permLevel.equals(Generic.DELETE_PERMISSION) || permLevel.equals(Generic.UPDATE_PERMISSION) || permLevel.equals(Generic.LOCK_PERMISSION); } else { log.warn("RecordCreateUpdate.getWorkflowPerm passed unknown workflowTransition: " + workflowTransition); } if (hasRights) { actions.put(permC); actions.put(permU); actions.put(permD); // They do not really get DELETE rights on a workflow, but that is what the services models by // default, so let's stick with that queryString = "CRUDL"; } // Workflow resources all have leading slashes. String resource = Generic.ResourceNameServices(spec, resourceName) + WORKFLOW_SUB_RESOURCE + workflowTransition; if (!resource.startsWith("/")) resource = "/" + resource; permitem = getPermID(storage, resource, queryString, permbase, actions); return permitem; }
From source file:org.collectionspace.chain.csp.webui.record.RecordCreateUpdate.java
private void assignPermissions(Storage storage, String path, JSONObject data) throws JSONException, ExistException, UnimplementedException, UnderlyingStorageException, UIException { JSONObject fields = data.optJSONObject("fields"); JSONArray permdata = new JSONArray(); JSONObject permcheck = new JSONObject(); if (fields.has("permissions")) { JSONArray permissions = fields.getJSONArray("permissions"); for (int i = 0; i < permissions.length(); i++) { JSONObject perm = permissions.getJSONObject(i); Record recordForPermResource = Generic.RecordNameServices(spec, perm.getString("resourceName")); if (recordForPermResource != null) { if (recordForPermResource.hasSoftDeleteMethod()) { JSONObject permitem = getWorkflowPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission"), DELETE_WORKFLOW_TRANSITION); if (permitem.has("permissionId")) { if (permcheck.has(permitem.getString("resourceName"))) { //ignore as we have duplicate name - eek log.warn(//from w w w .j av a 2 s. c om "RecordCreateUpdate.assignPermissions got duplicate workflow/delete permission for: " + permitem.getString("resourceName")); } else { permcheck.put(permitem.getString("resourceName"), permitem); permdata.put(permitem); } } } if (recordForPermResource.supportsLocking()) { JSONObject permitem = getWorkflowPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission"), LOCK_WORKFLOW_TRANSITION); if (permitem.has("permissionId")) { if (permcheck.has(permitem.getString("resourceName"))) { //ignore as we have duplicate name - eek log.warn( "RecordCreateUpdate.assignPermissions got duplicate workflow/lock permission for: " + permitem.getString("resourceName")); } else { permcheck.put(permitem.getString("resourceName"), permitem); permdata.put(permitem); } } } } JSONObject permitem = getPerm(storage, recordForPermResource, perm.getString("resourceName"), perm.getString("permission")); if (permitem.has("permissionId")) { if (permcheck.has(permitem.getString("resourceName"))) { //ignore as we have duplicate name - eek log.warn("RecordCreateUpdate.assignPermissions got duplicate permission for: " + permitem.getString("resourceName")); } else { permcheck.put(permitem.getString("resourceName"), permitem); permdata.put(permitem); } } } } //log.info("permdata"+permdata.toString()); JSONObject roledata = new JSONObject(); roledata.put("roleName", fields.getString("roleName")); String[] ids = path.split("/"); roledata.put("roleId", ids[ids.length - 1]); JSONObject accountrole = new JSONObject(); JSONObject arfields = new JSONObject(); arfields.put("role", roledata); arfields.put("permission", permdata); accountrole.put("fields", arfields); //log.info("WAAA"+arfields.toString()); if (fields != null) path = storage.autocreateJSON(spec.getRecordByWebUrl("permrole").getID(), arfields, null); }
From source file:net.straylightlabs.archivo.net.MindCommandRecordingFolderItemSearch.java
private static JSONArray buildTemplate() { JSONArray templates = new JSONArray(); JSONObject template;//w ww. j a v a 2 s. c o m // Only get the recording ID template = new JSONObject(); template.put(TYPE, "responseTemplate"); template.put(FIELD_NAME, Collections.singletonList("childRecordingId")); template.put(TYPE_NAME, "recordingFolderItem"); templates.put(template); return templates; }
From source file:com.googlecode.CallerLookup.Main.java
public void saveUserLookupEntries() { try {/*from www. j a v a 2 s .c o m*/ FileOutputStream file = getApplicationContext().openFileOutput(SAVED_FILE, MODE_PRIVATE); JSONArray userLookupEntries = new JSONArray(); for (String lookupEntryName : mUserLookupEntries.keySet()) { try { userLookupEntries.put(mUserLookupEntries.get(lookupEntryName).toJSONObject()); } catch (JSONException e) { e.printStackTrace(); } } OutputStreamWriter content = new OutputStreamWriter(file); content.write(userLookupEntries.toString()); content.flush(); content.close(); file.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void appendToArray(String arrayName, Map<String, Object> values) { try {//www.j a va2 s . com JSONArray array = getOrCreateArray(arrayName); JSONObject next = new JSONObject(values); array.put(next); } catch (JSONException e) { Logging.println("Error adding to JSON array", e); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void appendToArray(String arrayName, String value) { try {/*from w w w. j a va 2 s . c om*/ JSONArray array = getOrCreateArray(arrayName); array.put(value); } catch (JSONException e) { Logging.println("Error adding string to JSON array", e); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void appendToArray(String arrayName, String[] values) { try {//from w ww . j a v a2 s.c om JSONArray array = getOrCreateArray(arrayName); JSONArray next = new JSONArray(); for (String value : values) { next.put(value); } array.put(next); } catch (JSONException e) { Logging.println("Error adding to JSON array", e); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void appendToArray(String arrayName, Map<String, Object>[] values) { try {/*from w w w . java 2 s . co m*/ JSONArray array = getOrCreateArray(arrayName); JSONArray next = new JSONArray(); for (Map<String, Object> value : values) { next.put(new JSONObject(value)); } array.put(next); } catch (JSONException e) { Logging.println("Error adding to JSON array", e); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void addValidationError(String fieldName, String message) { try {/*from www. j ava 2s . co m*/ JSONArray errors = getOrCreateArray(ERROR_LIST); JSONObject error = new JSONObject(); error.put("errortype", "validation"); error.put("field", fieldName); error.put("message", message); errors.put(error); } catch (JSONException e) { Logging.println("Error trying to write out errors with JSON", e); } }
From source file:com.controlj.addon.weather.util.ResponseWriter.java
public void addError(String message) { try {/*from w w w . j a v a 2 s. co m*/ JSONArray errors = getOrCreateArray(ERROR_LIST); JSONObject error = new JSONObject(); error.put("errortype", "general"); error.put("message", message); errors.put(error); } catch (JSONException e) { Logging.println("Error trying to write out errors with JSON", e); } }