List of usage examples for org.json JSONArray put
public JSONArray put(Object value)
From source file:org.exoplatform.social.addons.storage.RDBMSIdentityStorageImpl.java
private void mapToProfileEntity(Profile profile, IdentityEntity entity) { Map<String, String> entityProperties = entity.getProperties(); if (entityProperties == null) { entityProperties = new HashMap<>(); }/* w ww . ja v a2 s. c o m*/ String providerId = profile.getIdentity().getProviderId(); if (!OrganizationIdentityProvider.NAME.equals(providerId) && !SpaceIdentityProvider.NAME.equals(providerId)) { entityProperties.put(Profile.URL, profile.getUrl()); entityProperties.put(Profile.AVATAR_URL, profile.getAvatarUrl()); } Map<String, Object> properties = profile.getProperties(); for (Map.Entry<String, Object> e : properties.entrySet()) { if (Profile.AVATAR.equalsIgnoreCase(e.getKey())) { AvatarAttachment attachment = (AvatarAttachment) e.getValue(); byte[] bytes = attachment.getImageBytes(); String fileName = attachment.getFileName(); if (fileName == null) { fileName = entity.getRemoteId() + "_avatar"; } try { Long avatarId = entity.getAvatarFileId(); FileItem fileItem; if (avatarId != null) {//update avatar file fileItem = new FileItem(avatarId, fileName, attachment.getMimeType(), socialNameSpace, bytes.length, new Date(), entity.getRemoteId(), false, new ByteArrayInputStream(bytes)); fileService.updateFile(fileItem); } else {//create new avatar file fileItem = new FileItem(null, fileName, attachment.getMimeType(), socialNameSpace, bytes.length, new Date(), entity.getRemoteId(), false, new ByteArrayInputStream(bytes)); fileItem = fileService.writeFile(fileItem); entity.setAvatarFileId(fileItem.getFileInfo().getId()); } } catch (Exception ex) { LOG.warn("Can not store avatar for " + entity.getProviderId() + " " + entity.getRemoteId(), ex); } } else if (Profile.EXPERIENCES.equalsIgnoreCase(e.getKey())) { List<Map<String, String>> exps = (List<Map<String, String>>) e.getValue(); Set<ProfileExperienceEntity> experiences = new HashSet<>(); for (Map<String, String> exp : exps) { ProfileExperienceEntity ex = new ProfileExperienceEntity(); ex.setCompany(exp.get(Profile.EXPERIENCES_COMPANY)); ex.setPosition(exp.get(Profile.EXPERIENCES_POSITION)); ex.setStartDate(exp.get(Profile.EXPERIENCES_START_DATE)); ex.setEndDate(exp.get(Profile.EXPERIENCES_END_DATE)); ex.setSkills(exp.get(Profile.EXPERIENCES_SKILLS)); ex.setDescription(exp.get(Profile.EXPERIENCES_DESCRIPTION)); experiences.add(ex); } entity.setExperiences(experiences); } else if (Profile.CONTACT_IMS.equals(e.getKey()) || Profile.CONTACT_PHONES.equals(e.getKey()) || Profile.CONTACT_URLS.equals(e.getKey())) { List<Map<String, String>> list = (List<Map<String, String>>) e.getValue(); JSONArray arr = new JSONArray(); for (Map<String, String> map : list) { JSONObject json = new JSONObject(map); arr.put(json); } entityProperties.put(e.getKey(), arr.toString()); } else if (!Profile.EXPERIENCES_SKILLS.equals(e.getKey())) { Object val = e.getValue(); if (val != null) { entityProperties.put(e.getKey(), String.valueOf(val)); } } } entity.setProperties(entityProperties); Date created = profile.getCreatedTime() <= 0 ? new Date() : new Date(profile.getCreatedTime()); entity.setCreatedDate(created); }
From source file:com.redoute.datamap.servlet.GetDistinctValueFromTableColumn.java
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS); String table = policy.sanitize(request.getParameter("table")); String colName = policy.sanitize(request.getParameter("colName")); ApplicationContext appContext = WebApplicationContextUtils .getWebApplicationContext(this.getServletContext()); IDatamapService datamapService = appContext.getBean(IDatamapService.class); IPictureService pictureService = appContext.getBean(IPictureService.class); IDatamapLocationTypeService datamapLocationTypeService = appContext .getBean(IDatamapLocationTypeService.class); if (table != null && colName != null) { try {// w w w .jav a 2 s .c o m JSONArray valueList = new JSONArray(); try { if (table.equals("Datamap")) { for (String value : datamapService.findDistinctValuesfromColumn(colName)) { valueList.put(value); } } if (table.equals("Picture")) { for (String value : pictureService.findDistinctValuesfromColumn(colName)) { valueList.put(value); } } if (table.equals("DatamapLocationType")) { for (String value : datamapLocationTypeService.findDistinctValuesfromColumn(colName)) { valueList.put(value); } } } catch (Exception ex) { response.setContentType("text/html"); response.getWriter().print(ex); } response.setContentType("application/json"); response.getWriter().print(valueList.toString()); } catch (Exception e) { Logger.log(GetDistinctValueFromTableColumn.class.getName(), Level.FATAL, "" + e); response.setContentType("text/html"); response.getWriter().print(e.getMessage()); } } }
From source file:com.whizzosoftware.hobson.dto.property.PropertyContainerSetDTO.java
public JSONObject toJSON(PropertyContainerMappingContext context) { JSONObject json = super.toJSON(); if (containers != null && containers.size() > 0) { JSONArray a = new JSONArray(); for (PropertyContainerDTO d : containers) { a.put(d.toJSON()); }/* www . java 2s. c o m*/ json.put(context.getContainersName(), a); } return json; }
From source file:org.wso2.emm.agent.services.PolicyTester.java
@SuppressWarnings("static-access") @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public boolean testPolicy(String code, String data) { if (code.equals(CommonUtilities.OPERATION_CLEAR_PASSWORD)) { ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); JSONObject jobj = new JSONObject(); // data = intent.getStringExtra("data"); try {/*from ww w . j av a 2s . c om*/ Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); devicePolicyManager.resetPassword("", DevicePolicyManager.RESET_PASSWORD_REQUIRE_ENTRY); devicePolicyManager.lockNow(); devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED); jobj.put("status", true); } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED) { jobj.put("status", false); } else { jobj.put("status", true); } } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { jobj.put("code", code); //finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_WIFI)) { boolean wifistatus = false; JSONObject jobjc = new JSONObject(); WiFiConfig config = new WiFiConfig(context); // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("ssid")) { ssid = (String) jobj.get("ssid"); } if (!jobj.isNull("password")) { password = (String) jobj.get("password"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Map<String, String> inparams = new HashMap<String, String>(); inparams.put("code", code); if (IS_ENFORCE) { try { wifistatus = config.saveWEPConfig(ssid, password); jobjc.put("status", true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } try { if (config.readWEPConfig(ssid)) { jobjc.put("status", true); } else { jobjc.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYou are not using company WIFI account, please change your WIFI configuration \n"; } else { usermessage += "You are not using company WIFI account, please change your WIFI configuration \n"; } } jobjc.put("code", code); finalArray.put(jobjc); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_DISABLE_CAMERA)) { ComponentName cameraAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); boolean camFunc = false; // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("enable")) { camFunc = false; } else if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("disable")) { camFunc = true; } else if (!jobj.isNull("function")) { camFunc = Boolean.parseBoolean(jobj.get("function").toString()); } Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); String cammode = "Disabled"; if (camFunc) { cammode = "Disabled"; } else { cammode = "Enabled"; } if (IS_ENFORCE && (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH)) { devicePolicyManager.setCameraDisabled(cameraAdmin, camFunc); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { if (!camFunc) { if (!devicePolicyManager.getCameraDisabled(cameraAdmin)) { jobj.put("status", true); } else { jobj.put("status", false); } } else { if (devicePolicyManager.getCameraDisabled(cameraAdmin)) { jobj.put("status", true); } else { jobj.put("status", false); /*if(usermessage!=null && usermessage!=""){ usermessage+="\nYour camera should be deactivated according to the policy, please deactivate your camera\n"; }else{ usermessage+="Your camera should be deactivated according to the policy, please deactivate your camera \n"; }*/ } } } else { jobj.put("status", false); } jobj.put("code", code); finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_ENCRYPT_STORAGE)) { boolean encryptFunc = true; String pass = ""; JSONParser jp = new JSONParser(); try { JSONObject jobj = new JSONObject(data); if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("encrypt")) { encryptFunc = true; } else if (!jobj.isNull("function") && jobj.get("function").toString().equalsIgnoreCase("decrypt")) { encryptFunc = false; } else if (!jobj.isNull("function")) { encryptFunc = Boolean.parseBoolean(jobj.get("function").toString()); } ComponentName admin = new ComponentName(context, WSO2DeviceAdminReceiver.class); Map<String, String> params = new HashMap<String, String>(); params.put("code", code); if (IS_ENFORCE) { if (encryptFunc && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setStorageEncryption(admin, encryptFunc); Intent intent = new Intent(DevicePolicyManager.ACTION_START_ENCRYPTION); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent); } } } else if (!encryptFunc && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVE || devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_ACTIVATING) { if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { devicePolicyManager.setStorageEncryption(admin, encryptFunc); } } } } if (devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED) { params.put("status", "200"); } else { params.put("status", "400"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { jobj.put("code", code); if (encryptFunc) { if (devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED && devicePolicyManager .getStorageEncryptionStatus() != devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { jobj.put("status", true); } else { jobj.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour device should be encrypted according to the policy, please enable device encryption through device settings\n"; } else { usermessage += "Your device should be encrypted according to the policy, please enable device encryption through device settings \n"; } } } else { if (devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_UNSUPPORTED || devicePolicyManager .getStorageEncryptionStatus() == devicePolicyManager.ENCRYPTION_STATUS_INACTIVE) { jobj.put("status", true); } else { jobj.put("status", false); } } finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_MUTE)) { try { Map<String, String> params = new HashMap<String, String>(); params.put("code", code); params.put("status", "200"); if (IS_ENFORCE) { muteDevice(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } JSONObject jobj = new JSONObject(); try { jobj.put("code", code); if (isMuted()) { jobj.put("status", true); } else { jobj.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour phone should be muted according to the policy, please mute your phone \n"; } else { usermessage += "Your phone should be muted according to the policy, please mute your phone \n"; } } finalArray.put(jobj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_PASSWORD_POLICY)) { ComponentName demoDeviceAdmin = new ComponentName(context, WSO2DeviceAdminReceiver.class); JSONObject jobjx = new JSONObject(); int attempts, length, history, specialChars; String alphanumeric, complex; boolean b_alphanumeric = false, b_complex = false, is_comply = true, comply_fac1 = true, comply_fac2 = true, comply_fac3 = true, comply_fac4 = true, comply_fac5 = true, comply_fac6 = true, comply_fac7 = true; long timout; Map<String, String> inparams = new HashMap<String, String>(); // data = intent.getStringExtra("data"); JSONParser jp = new JSONParser(); try { JSONObject jobjpass = new JSONObject(); jobjpass.put("code", CommonUtilities.OPERATION_CHANGE_LOCK_CODE); if (devicePolicyManager.isActivePasswordSufficient()) { is_comply = true; //finalArray.put(jobjpass); } else { is_comply = false; } JSONObject jobj = new JSONObject(data); if (!jobj.isNull("maxFailedAttempts") && jobj.get("maxFailedAttempts") != null) { attempts = Integer.parseInt((String) jobj.get("maxFailedAttempts")); if (IS_ENFORCE) { devicePolicyManager.setMaximumFailedPasswordsForWipe(demoDeviceAdmin, attempts); comply_fac1 = true; } else { if (devicePolicyManager.getMaximumFailedPasswordsForWipe(demoDeviceAdmin) != attempts) { comply_fac1 = false; } else { comply_fac1 = true; } } } if (!jobj.isNull("minLength") && jobj.get("minLength") != null) { length = Integer.parseInt((String) jobj.get("minLength")); if (IS_ENFORCE) { devicePolicyManager.setPasswordMinimumLength(demoDeviceAdmin, length); comply_fac2 = true; } else { if (devicePolicyManager.getPasswordMinimumLength(demoDeviceAdmin) != length) { comply_fac2 = false; } else { comply_fac2 = true; } } } if (!jobj.isNull("pinHistory") && jobj.get("pinHistory") != null) { history = Integer.parseInt((String) jobj.get("pinHistory")); if (IS_ENFORCE) { devicePolicyManager.setPasswordHistoryLength(demoDeviceAdmin, history); comply_fac3 = true; } else { if (devicePolicyManager.getPasswordHistoryLength(demoDeviceAdmin) != history) { comply_fac3 = false; } else { comply_fac3 = true; } } } if (!jobj.isNull("minComplexChars") && jobj.get("minComplexChars") != null) { specialChars = Integer.parseInt((String) jobj.get("minComplexChars")); if (IS_ENFORCE) { devicePolicyManager.setPasswordMinimumSymbols(demoDeviceAdmin, specialChars); comply_fac4 = true; } else { if (devicePolicyManager.getPasswordMinimumSymbols(demoDeviceAdmin) != specialChars) { comply_fac4 = false; } else { comply_fac4 = true; } } } if (!jobj.isNull("requireAlphanumeric") && jobj.get("requireAlphanumeric") != null) { if (jobj.get("requireAlphanumeric") instanceof String) { alphanumeric = (String) jobj.get("requireAlphanumeric").toString(); if (alphanumeric.equals("true")) { b_alphanumeric = true; } else { b_alphanumeric = false; } } else if (jobj.get("requireAlphanumeric") instanceof Boolean) { b_alphanumeric = jobj.getBoolean("requireAlphanumeric"); } if (b_alphanumeric) { if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC); comply_fac5 = true; } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) { comply_fac5 = false; } else { comply_fac5 = true; } } } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC) { comply_fac5 = false; } else { comply_fac5 = true; } } } if (!jobj.isNull("allowSimple") && jobj.get("allowSimple") != null) { if (jobj.get("allowSimple") instanceof String) { complex = (String) jobj.get("allowSimple").toString(); if (complex.equals("true")) { b_complex = true; } else { b_complex = false; } } else if (jobj.get("allowSimple") instanceof Boolean) { b_complex = jobj.getBoolean("allowSimple"); } if (!b_complex) { if (IS_ENFORCE) { devicePolicyManager.setPasswordQuality(demoDeviceAdmin, DevicePolicyManager.PASSWORD_QUALITY_COMPLEX); comply_fac6 = true; } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) != DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { comply_fac6 = false; } else { comply_fac6 = true; } } } else { if (devicePolicyManager.getPasswordQuality( demoDeviceAdmin) == DevicePolicyManager.PASSWORD_QUALITY_COMPLEX) { comply_fac6 = false; } else { comply_fac6 = true; } } } if (!jobj.isNull("maxPINAgeInDays") && jobj.get("maxPINAgeInDays") != null) { int daysOfExp = Integer.parseInt((String) jobj.get("maxPINAgeInDays")); timout = (long) (daysOfExp * 24 * 60 * 60 * 1000); if (IS_ENFORCE) { devicePolicyManager.setPasswordExpirationTimeout(demoDeviceAdmin, timout); comply_fac7 = true; } else { if (devicePolicyManager.getPasswordExpirationTimeout(demoDeviceAdmin) != timout) { comply_fac7 = false; } else { comply_fac7 = true; } } } if (!is_comply || !comply_fac1 || !comply_fac2 || !comply_fac3 || !comply_fac4 || !comply_fac5 || !comply_fac6 || !comply_fac7) { jobjx.put("status", false); if (usermessage != null && usermessage != "") { usermessage += "\nYour screen lock password doesn't meet current policy requirement. Please reset your passcode \n"; } else { usermessage += "Your screen lock password doesn't meet current policy requirement. Please reset your passcode \n"; } } else { jobjx.put("status", true); } inparams.put("code", code); inparams.put("status", "200"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } try { jobjx.put("code", code); finalArray.put(jobjx); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } else if (code.equals(CommonUtilities.OPERATION_BLACKLIST_APPS)) { ArrayList<PInfo> apps = appList.getInstalledApps(false); /* * false = * no system * packages */ JSONArray jsonArray = new JSONArray(); int max = apps.size(); Boolean flag = true; try { JSONObject appObj = new JSONObject(data); String identity = (String) appObj.get("identity"); for (int j = 0; j < max; j++) { JSONObject jsonObj = new JSONObject(); try { jsonObj.put("name", apps.get(j).appname); jsonObj.put("package", apps.get(j).pname); if (identity.trim().equals(apps.get(j).pname)) { jsonObj.put("notviolated", false); flag = false; jsonObj.put("package", apps.get(j).pname); if (apps.get(j).appname != null) { appcount++; apz = appcount + ". " + apps.get(j).appname; } if (apz != null || !apz.trim().equals("")) { if (usermessage != null && usermessage != "") { if (appcount > 1) { usermessage += "\n" + apz; } else { usermessage += "\nFollowing apps are blacklisted by your MDM Admin, please remove them \n\n" + apz; } } else { if (appcount > 1) { usermessage += "\n" + apz; } else { usermessage += "Following apps are blacklisted by your MDM Admin, please remove them \n\n" + apz; } } } } else { jsonObj.put("notviolated", true); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } jsonArray.put(jsonObj); } } catch (Exception ex) { ex.printStackTrace(); } /* * for(int i=0;i<apps.length;i++){ jsonArray.add(apps[i]); } */ JSONObject appsObj = new JSONObject(); try { //appsObj.put("data", jsonArray); appsObj.put("status", flag); appsObj.put("code", code); finalArray.put(appsObj); } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } return true; }
From source file:com.sencha.gxt.examples.resources.server.JsonTreeServlet.java
private String generateJson(Folder folder) throws Exception { JSONObject root = new JSONObject(); JSONArray records = new JSONArray(); root.put("records", records); for (int i = 0, len = folder.getSubFolders().size(); i < len; i++) { Folder sub = folder.getSubFolders().get(i); JSONObject f = new JSONObject(); f.put("folder", true); f.put("name", sub.getName()); f.put("id", sub.getId()); records.put(f); }//w ww . ja v a2 s . c o m for (int i = 0, len = folder.getChildren().size(); i < len; i++) { Music m = folder.getChildren().get(i); JSONObject f = new JSONObject(); f.put("folder", false); f.put("name", m.getName()); f.put("id", m.getId()); records.put(f); } return root.toString(); }
From source file:br.ufc.mdcc.mpos.net.profile.model.Network.java
public static String arrayToString(long... vlrs) { JSONArray jsonArray = new JSONArray(); if (vlrs != null) { for (long vlr : vlrs) { jsonArray.put(vlr); }/*from w w w .j a v a 2 s . c o m*/ } return jsonArray.toString(); }
From source file:net.alastairwyse.oraclepermissiongenerator.datainterfacelayer.RestRemoteDataModelProxy.java
@Override public void AddObjectPermissionSet(String objectName, String objectType, String objectOwner, boolean addFlag, boolean removeFlag, ArrayList<RoleToPermissionMap> objectPermissions, AuthenticationContext authenticationContext, TrackingData trackingData) throws Exception { JSONArray permissions = new JSONArray(); for (RoleToPermissionMap currentRoleToPermissionMap : objectPermissions) { JSONObject currentRoleToPermissionMapJsonObject = new JSONObject(); currentRoleToPermissionMapJsonObject.put("Role", currentRoleToPermissionMap.getRole()); currentRoleToPermissionMapJsonObject.put("Permission", currentRoleToPermissionMap.getPermission()); permissions.put(currentRoleToPermissionMapJsonObject); }/* w ww. j ava 2 s .c o m*/ JSONObject parameters = new JSONObject(); parameters.put("objectName", objectName); parameters.put("objectType", objectType); parameters.put("objectOwner", objectOwner); parameters.put("addFlag", addFlag); parameters.put("removeFlag", removeFlag); parameters.put("objectPermissions", permissions); MakePostRequest(parameters.toString(), "Objects", new ArrayList<RestQueryParameter>(), authenticationContext, trackingData); }
From source file:org.apache.giraph.graph.BspServiceMaster.java
/** * Save the supplied aggregator values.//from w w w. j av a2 s . c om * * @param superstep superstep for which to save values */ private void saveAggregatorValues(long superstep) { Map<String, Aggregator<Writable>> aggregatorMap = getAggregatorMap(); if (aggregatorMap.size() > 0) { String mergedAggregatorPath = getMergedAggregatorPath(getApplicationAttempt(), superstep); byte[] zkData = null; JSONArray aggregatorArray = new JSONArray(); for (Map.Entry<String, Aggregator<Writable>> entry : aggregatorMap.entrySet()) { try { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutput output = new DataOutputStream(outputStream); entry.getValue().getAggregatedValue().write(output); JSONObject aggregatorObj = new JSONObject(); aggregatorObj.put(AGGREGATOR_NAME_KEY, entry.getKey()); aggregatorObj.put(AGGREGATOR_VALUE_KEY, Base64.encodeBytes(outputStream.toByteArray())); aggregatorArray.put(aggregatorObj); if (LOG.isInfoEnabled()) { LOG.info("saveAggregatorValues: " + "Trying to add aggregatorObj " + aggregatorObj + "(" + entry.getValue().getAggregatedValue() + ") to merged aggregator path " + mergedAggregatorPath); } } catch (IOException e) { throw new IllegalStateException("saveAggregatorValues: " + "IllegalStateException", e); } catch (JSONException e) { throw new IllegalStateException("saveAggregatorValues: JSONException", e); } } try { zkData = aggregatorArray.toString().getBytes(); getZkExt().createExt(mergedAggregatorPath, zkData, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT, true); } catch (KeeperException.NodeExistsException e) { LOG.warn("saveAggregatorValues: " + mergedAggregatorPath + " already exists!"); } catch (KeeperException e) { throw new IllegalStateException("saveAggregatorValues: KeeperException", e); } catch (InterruptedException e) { throw new IllegalStateException("saveAggregatorValues: IllegalStateException", e); } if (LOG.isInfoEnabled()) { LOG.info("saveAggregatorValues: Finished " + "loading " + mergedAggregatorPath + " with aggregator values " + aggregatorArray); } } }
From source file:org.nuxeo.connect.data.PackageDescriptor.java
@JSONExportMethod(name = "conflicts") protected JSONArray getConflictsAsJSON() { JSONArray deps = new JSONArray(); for (PackageDependency dep : getConflicts()) { deps.put(dep.toString()); }//from w w w. j av a 2s .c o m return deps; }
From source file:org.nuxeo.connect.data.PackageDescriptor.java
@JSONExportMethod(name = "dependencies") protected JSONArray getDependenciesAsJSON() { JSONArray deps = new JSONArray(); for (PackageDependency dep : getDependencies()) { deps.put(dep.toString()); }// w w w . ja v a 2 s .co m return deps; }