use of org.apache.sling.api.resource.ModifiableValueMap in project acs-aem-commons by Adobe-Consulting-Services.
the class GenericReport method persist.
public void persist(ResourceResolver rr, String path) throws PersistenceException, RepositoryException {
ModifiableValueMap jcrContent = ResourceUtil.getOrCreateResource(rr, path, getResourceType(), null, false).adaptTo(ModifiableValueMap.class);
jcrContent.put("jcr:primaryType", "nt:unstructured");
jcrContent.put("columns", getColumns().toArray(new String[0]));
jcrContent.put("name", name);
rr.commit();
rr.refresh();
JcrUtil.createPath(path + "/rows", "nt:unstructured", rr.adaptTo(Session.class));
int rowCounter = 0;
for (Map<String, Object> row : rows) {
rowCounter++;
ResourceUtil.getOrCreateResource(rr, path + "/rows/row-" + rowCounter, row, null, true);
}
rr.commit();
rr.refresh();
}
use of org.apache.sling.api.resource.ModifiableValueMap in project acs-aem-commons by Adobe-Consulting-Services.
the class ChildrenAsPropertyResource method serialize.
/**
* Serializes all children data as JSON to the resource's propertyName.
*
* @throws InvalidDataFormatException
*/
private void serialize() throws InvalidDataFormatException {
final long start = System.currentTimeMillis();
final ModifiableValueMap modifiableValueMap = this.resource.adaptTo(ModifiableValueMap.class);
JSONObject childrenJSON = new JSONObject();
try {
// Add the new entries to the JSON
for (Resource childResource : this.orderedCache) {
childrenJSON.put(childResource.getName(), this.serializeToJSON(childResource));
}
if (childrenJSON.length() > 0) {
// Persist the JSON back to the Node
modifiableValueMap.put(this.propertyName, childrenJSON.toString());
} else {
// Nothing to persist; delete the property
modifiableValueMap.remove(this.propertyName);
}
log.debug("Persist operation for [ {} ] in [ {} ms ]", this.resource.getPath() + "/" + this.propertyName, System.currentTimeMillis() - start);
} catch (JSONException e) {
throw new InvalidDataFormatException(this.resource, this.propertyName, childrenJSON.toString());
} catch (NoSuchMethodException e) {
throw new InvalidDataFormatException(this.resource, this.propertyName, childrenJSON.toString());
} catch (IllegalAccessException e) {
throw new InvalidDataFormatException(this.resource, this.propertyName, childrenJSON.toString());
} catch (InvocationTargetException e) {
throw new InvalidDataFormatException(this.resource, this.propertyName, childrenJSON.toString());
}
}
use of org.apache.sling.api.resource.ModifiableValueMap in project acs-aem-commons by Adobe-Consulting-Services.
the class BulkWorkflowEngineImpl method deactivate.
@Deactivate
protected final void deactivate(final Map<String, String> args) {
ResourceResolver adminResourceResolver = null;
try {
adminResourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
final Resource root = adminResourceResolver.getResource(BULK_WORKFLOW_MANAGER_PAGE_FOLDER_PATH);
if (root == null) {
return;
}
final ConfigResourceVisitor visitor = new ConfigResourceVisitor();
visitor.accept(root);
final List<Resource> configs = visitor.getConfigs();
for (Resource config : configs) {
ModifiableValueMap properties = config.getChild(Workspace.NN_WORKSPACE).adaptTo(ModifiableValueMap.class);
if (StringUtils.equals(Status.RUNNING.name(), properties.get(Workspace.PN_STATUS, String.class))) {
properties.put(Workspace.PN_STATUS, Status.STOPPED.name());
properties.put(Workspace.PN_SUB_STATUS, SubStatus.DEACTIVATED.name());
}
}
if (root.getResourceResolver().hasChanges()) {
root.getResourceResolver().commit();
}
} catch (LoginException e) {
log.error("Could not obtain resource resolver for finding stopped Bulk Workflow jobs", e);
} catch (PersistenceException e) {
log.error("Could not resume bulk workflow manager configuration", e);
} finally {
if (adminResourceResolver != null) {
adminResourceResolver.close();
}
}
}
use of org.apache.sling.api.resource.ModifiableValueMap in project aem-core-wcm-components by Adobe-Marketing-Cloud.
the class FormActionRpcServletTest method testDoPostWithError.
@Test
void testDoPostWithError() throws ServletException {
MockSlingHttpServletRequest request = context.request();
request.setParameterMap(ImmutableMap.of("text", "hello"));
request.setAttribute("cq.form.id", "new_form");
Resource resource = context.currentResource("/content/container");
ModifiableValueMap modifiableValueMap = resource.adaptTo(ModifiableValueMap.class);
modifiableValueMap.put("formEndPointUrl", "http://localhost:" + wireMockPort + "/form/nonExistingEndpoint");
underTest.doPost(context.request(), context.response());
assertEquals(200, context.response().getStatus());
ValidationInfo validationInfo = ValidationInfo.getValidationInfo(request);
assertNotNull(validationInfo);
}
use of org.apache.sling.api.resource.ModifiableValueMap in project APM by Cognifide.
the class HistoryEntryWriter method writeTo.
public void writeTo(Resource historyLogResource) {
ModifiableValueMap valueMap = historyLogResource.adaptTo(ModifiableValueMap.class);
valueMap.put(HistoryEntryImpl.SCRIPT_NAME, fileName);
valueMap.put(HistoryEntryImpl.SCRIPT_PATH, filePath);
valueMap.put(HistoryEntryImpl.AUTHOR, author);
valueMap.put(HistoryEntryImpl.MODE, mode);
valueMap.put(HistoryEntryImpl.PROGRESS_LOG, progressLog);
valueMap.put(HistoryEntryImpl.INSTANCE_TYPE, instanceType);
valueMap.put(HistoryEntryImpl.INSTANCE_HOSTNAME, instanceHostname);
valueMap.put(HistoryEntryImpl.IS_RUN_SUCCESSFUL, isRunSuccessful);
valueMap.put(HistoryEntryImpl.EXECUTION_TIME, executionTime);
valueMap.put(HistoryEntryImpl.EXECUTOR, executor);
}
Aggregations