use of javax.json.JsonObject in project sling by apache.
the class VersionInfoServletTest method testHarrayVersionsList.
public void testHarrayVersionsList() throws Exception {
// No need to test everything in detail, just verify that the output
// is reformatted with the harray option
createConfiguration("V");
waitForSlingStartup();
waitUntilSlingIsStable();
final JsonObject versions = JsonUtil.parseObject(getContent(createVersionableNode() + ".V.harray.json", CONTENT_TYPE_JSON));
assertTrue("Expecting children array", versions.containsKey("__children__"));
assertEquals("Expecting versions object", "versions", versions.getJsonArray("__children__").getJsonObject(0).getString("__name__"));
}
use of javax.json.JsonObject in project sling by apache.
the class AccessPrivilegesInfoTest method testGrantedWriteForGroup.
/*
* group testuser granted read / granted write
*/
@Test
public void testGrantedWriteForGroup() throws IOException, JsonException {
testGroupId = H.createTestGroup();
testUserId = H.createTestUser();
testFolderUrl = H.createTestFolder();
Credentials adminCreds = new UsernamePasswordCredentials("admin", "admin");
//add testUserId to testGroup
String groupPostUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/group/" + testGroupId + ".update.html";
List<NameValuePair> groupPostParams = new ArrayList<NameValuePair>();
groupPostParams.add(new NameValuePair(":member", testUserId));
H.assertAuthenticatedPostStatus(adminCreds, groupPostUrl, HttpServletResponse.SC_OK, groupPostParams, null);
//assign some privileges
String postUrl = testFolderUrl + ".modifyAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testGroupId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:write", "granted"));
postParams.add(new NameValuePair("privilege@jcr:readAccessControl", "granted"));
postParams.add(new NameValuePair("privilege@jcr:modifyAccessControl", "granted"));
H.assertAuthenticatedPostStatus(adminCreds, postUrl, HttpServletResponse.SC_OK, postParams, null);
String getUrl = testFolderUrl + ".privileges-info.json";
//fetch the JSON for the test page to verify the settings.
Credentials testUserCreds = new UsernamePasswordCredentials(testUserId, "testPwd");
String json = H.getAuthenticatedContent(testUserCreds, getUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObj = JsonUtil.parseObject(json);
assertEquals(true, jsonObj.getBoolean("canAddChildren"));
assertEquals(true, jsonObj.getBoolean("canDeleteChildren"));
//the parent node must also have jcr:removeChildren granted for 'canDelete' to be true
assertEquals(false, jsonObj.getBoolean("canDelete"));
assertEquals(true, jsonObj.getBoolean("canModifyProperties"));
assertEquals(true, jsonObj.getBoolean("canReadAccessControl"));
assertEquals(true, jsonObj.getBoolean("canModifyAccessControl"));
//add a child node to verify the 'canDelete' use case
String childFolderUrl = H.getTestClient().createNode(testFolderUrl + "/testFolder" + random.nextInt() + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
String childPostUrl = childFolderUrl + ".modifyAce.html";
postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("principalId", testGroupId));
postParams.add(new NameValuePair("privilege@jcr:read", "granted"));
postParams.add(new NameValuePair("privilege@jcr:removeNode", "granted"));
H.assertAuthenticatedPostStatus(adminCreds, childPostUrl, HttpServletResponse.SC_OK, postParams, null);
String childGetUrl = childFolderUrl + ".privileges-info.json";
String childJson = H.getAuthenticatedContent(testUserCreds, childGetUrl, HttpTest.CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(childJson);
JsonObject childJsonObj = JsonUtil.parseObject(childJson);
assertEquals(true, childJsonObj.getBoolean("canDelete"));
}
use of javax.json.JsonObject in project sling by apache.
the class SimpleDistributionQueueProvider method enableQueueProcessing.
public void enableQueueProcessing(@Nonnull DistributionQueueProcessor queueProcessor, String... queueNames) {
if (checkpoint) {
// recover from checkpoints
log.debug("recovering from checkpoints if needed");
for (final String queueName : queueNames) {
log.debug("recovering for queue {}", queueName);
DistributionQueue queue = getQueue(queueName);
FilenameFilter filenameFilter = new FilenameFilter() {
@Override
public boolean accept(File file, String name) {
return name.equals(queueName + "-checkpoint");
}
};
for (File qf : checkpointDirectory.listFiles(filenameFilter)) {
log.info("recovering from checkpoint {}", qf);
try {
LineIterator lineIterator = IOUtils.lineIterator(new FileReader(qf));
while (lineIterator.hasNext()) {
String s = lineIterator.nextLine();
String[] split = s.split(" ");
String id = split[0];
String infoString = split[1];
Map<String, Object> info = new HashMap<String, Object>();
JsonReader reader = Json.createReader(new StringReader(infoString));
JsonObject jsonObject = reader.readObject();
for (Map.Entry<String, JsonValue> entry : jsonObject.entrySet()) {
if (entry.getValue().getValueType().equals(JsonValue.ValueType.ARRAY)) {
JsonArray value = jsonObject.getJsonArray(entry.getKey());
String[] a = new String[value.size()];
for (int i = 0; i < a.length; i++) {
a[i] = value.getString(i);
}
info.put(entry.getKey(), a);
} else if (JsonValue.NULL.equals(entry.getValue())) {
info.put(entry.getKey(), null);
} else {
info.put(entry.getKey(), ((JsonString) entry.getValue()).getString());
}
}
queue.add(new DistributionQueueItem(id, info));
}
log.info("recovered {} items from queue {}", queue.getStatus().getItemsCount(), queueName);
} catch (FileNotFoundException e) {
log.warn("could not read checkpoint file {}", qf.getAbsolutePath());
} catch (JsonException e) {
log.warn("could not parse info from checkpoint file {}", qf.getAbsolutePath());
}
}
}
// enable checkpointing
for (String queueName : queueNames) {
ScheduleOptions options = scheduler.NOW(-1, 15).canRunConcurrently(false).name(getJobName(queueName + "-checkpoint"));
scheduler.schedule(new SimpleDistributionQueueCheckpoint(getQueue(queueName), checkpointDirectory), options);
}
}
// enable processing
for (String queueName : queueNames) {
ScheduleOptions options = scheduler.NOW(-1, 1).canRunConcurrently(false).name(getJobName(queueName));
scheduler.schedule(new SimpleDistributionQueueProcessor(getQueue(queueName), queueProcessor), options);
}
}
use of javax.json.JsonObject in project sling by apache.
the class DistributionUtils method getQueueItems.
public static List<Map<String, Object>> getQueueItems(SlingInstance instance, String queueUrl) throws IOException, JsonException {
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
JsonObject json = getResource(instance, queueUrl + ".infinity");
Iterator<String> keys = json.keySet().iterator();
while (keys.hasNext()) {
String key = keys.next();
JsonObject queueItem;
Object item = json.get(key);
if (item instanceof JsonObject) {
queueItem = (JsonObject) item;
} else if (item instanceof JsonString) {
try {
queueItem = Json.createReader(new StringReader(((JsonString) item).getString())).readObject();
} catch (JsonException ex) {
queueItem = null;
}
} else {
queueItem = null;
}
if (queueItem != null && queueItem.containsKey("id")) {
Map<String, Object> itemProperties = new HashMap<String, Object>();
itemProperties.put("id", queueItem.getString("id"));
itemProperties.put("paths", JsonUtil.unbox(queueItem.get("paths")));
itemProperties.put("action", JsonUtil.unbox(queueItem.get("action")));
itemProperties.put("userid", JsonUtil.unbox(queueItem.get("userid")));
itemProperties.put("attempts", JsonUtil.unbox(queueItem.get("attempts")));
itemProperties.put("time", JsonUtil.unbox(queueItem.get("time")));
itemProperties.put("state", JsonUtil.unbox(queueItem.get("state")));
result.add(itemProperties);
}
}
return result;
}
use of javax.json.JsonObject in project sling by apache.
the class DistributionUtils method getQueues.
public static Map<String, Map<String, Object>> getQueues(SlingInstance instance, String agentName) throws IOException, JsonException {
Map<String, Map<String, Object>> result = new HashMap<String, Map<String, Object>>();
JsonObject json = getResource(instance, queueUrl(agentName) + ".infinity");
JsonArray items = json.getJsonArray("items");
for (int i = 0; i < items.size(); i++) {
String queueName = items.getString(i);
Map<String, Object> queueProperties = new HashMap<String, Object>();
JsonObject queue = json.getJsonObject(queueName);
queueProperties.put("empty", queue.getBoolean("empty"));
queueProperties.put("itemsCount", queue.getInt("itemsCount"));
result.put(queueName, queueProperties);
}
return result;
}
Aggregations