Search in sources :

Example 96 with ModifiableValueMap

use of org.apache.sling.api.resource.ModifiableValueMap in project APM by Cognifide.

the class ModifiableScriptWrapper method setProperty.

public void setProperty(String name, Object value) throws PersistenceException {
    Resource resource = resolver.getResource(script.getPath());
    ModifiableValueMap vm = resource.getChild(JcrConstants.JCR_CONTENT).adaptTo(ModifiableValueMap.class);
    ResourceMixinUtil.addMixin(vm, ScriptContent.CQSM_FILE);
    vm.put(name, convertValue(value));
    resource.getResourceResolver().commit();
}
Also used : Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Example 97 with ModifiableValueMap

use of org.apache.sling.api.resource.ModifiableValueMap in project CQ-Actions by Cognifide.

the class MessageSerializer method saveMessageToResource.

public static void saveMessageToResource(Resource resource, String type, Map<String, String> message) {
    final ModifiableValueMap map = resource.adaptTo(ModifiableValueMap.class);
    map.put("sling:resourceType", type);
    map.putAll(message);
    map.put(ACTION_PROPERTIES, getArray(message.keySet()));
}
Also used : ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Example 98 with ModifiableValueMap

use of org.apache.sling.api.resource.ModifiableValueMap in project CQ-Actions by Cognifide.

the class ReplicationMessageProducer method createActionResource.

private Resource createActionResource(ResourceResolver resolver, String actionType, String relPath) throws PersistenceException {
    final String path = createPath(relPath, config.getActionRoot(), config.getRandomPathPattern());
    final Resource page = ResourceUtil.getOrCreateResource(resolver, path, Collections.singletonMap(JcrConstants.JCR_PRIMARYTYPE, (Object) "cq:Page"), null, false);
    final Map<String, Object> contentMap = new LinkedHashMap<String, Object>();
    contentMap.put(JcrConstants.JCR_PRIMARYTYPE, "cq:PageContent");
    contentMap.put("cq:distribute", false);
    final Resource content = resolver.create(page, JcrConstants.JCR_CONTENT, contentMap);
    resolver.commit();
    final ModifiableValueMap map = content.adaptTo(ModifiableValueMap.class);
    map.put(NameConstants.PN_PAGE_LAST_MOD, Calendar.getInstance());
    map.put(NameConstants.PN_PAGE_LAST_MOD_BY, resolver.getUserID());
    map.put("cq:distribute", true);
    return content;
}
Also used : Resource(org.apache.sling.api.resource.Resource) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap) LinkedHashMap(java.util.LinkedHashMap)

Example 99 with ModifiableValueMap

use of org.apache.sling.api.resource.ModifiableValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class EnsureOakIndexJobHandler method forceRefresh.

/**
 * Forces index refresh for create or updates (that require updating).
 *
 * @param oakIndex the index representing the oak index
 * @throws PersistenceException
 */
public void forceRefresh(@Nonnull final Resource oakIndex) throws PersistenceException {
    final ModifiableValueMap mvm = oakIndex.adaptTo(ModifiableValueMap.class);
    if (mvm == null) {
        String msg = String.format("Cannot adapt {} to a ModifiableValueMap (permissions?)", oakIndex.getPath());
        throw new PersistenceException(msg);
    }
    mvm.put(PN_REINDEX, true);
    log.info("Forcing re-index of [ {} ]", oakIndex.getPath());
}
Also used : PersistenceException(org.apache.sling.api.resource.PersistenceException) ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Example 100 with ModifiableValueMap

use of org.apache.sling.api.resource.ModifiableValueMap in project acs-aem-commons by Adobe-Consulting-Services.

the class EnsureOakIndexJobHandler method disableIndex.

/**
 * Disables an index, so it's no longer updated by Oak.
 *
 * @param oakIndex the index
 * @throws PersistenceException
 */
public void disableIndex(@Nonnull Resource oakIndex) throws PersistenceException {
    final ModifiableValueMap oakIndexProperties = oakIndex.adaptTo(ModifiableValueMap.class);
    oakIndexProperties.put(PN_TYPE, DISABLED);
    log.info("Disabled index at {}", oakIndex.getPath());
}
Also used : ModifiableValueMap(org.apache.sling.api.resource.ModifiableValueMap)

Aggregations

ModifiableValueMap (org.apache.sling.api.resource.ModifiableValueMap)111 Resource (org.apache.sling.api.resource.Resource)74 PersistenceException (org.apache.sling.api.resource.PersistenceException)32 Test (org.junit.Test)28 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)26 HashMap (java.util.HashMap)22 ValueMap (org.apache.sling.api.resource.ValueMap)22 Calendar (java.util.Calendar)13 LoginException (org.apache.sling.api.resource.LoginException)9 ChildResource (org.apache.sling.validation.model.ChildResource)9 Date (java.util.Date)8 HashSet (java.util.HashSet)8 Map (java.util.Map)8 NonExistingResource (org.apache.sling.api.resource.NonExistingResource)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IOException (java.io.IOException)7 ValidationModel (org.apache.sling.validation.model.ValidationModel)7 InputStream (java.io.InputStream)6 Node (javax.jcr.Node)6 RepositoryException (javax.jcr.RepositoryException)6