Search in sources :

Example 21 with ScheduleOptions

use of org.apache.sling.commons.scheduler.ScheduleOptions in project acs-aem-commons by Adobe-Consulting-Services.

the class ReviewTaskAssetMoverHandler method handleEvent.

@Override
public void handleEvent(Event event) {
    ResourceResolver resourceResolver = null;
    try {
        resourceResolver = resourceResolverFactory.getServiceResourceResolver(AUTH_INFO);
        final String path = (String) event.getProperty("TaskId");
        final Resource taskResource = resourceResolver.getResource(path);
        if (taskResource != null) {
            final ValueMap taskProperties = taskResource.getValueMap();
            // Perform a fast check to see if this project has the required properties to perform the asset moving
            if (StringUtils.startsWith(taskProperties.get(PN_ON_APPROVE, String.class), PATH_CONTENT_DAM) || StringUtils.startsWith(taskProperties.get(PN_ON_REJECT, String.class), PATH_CONTENT_DAM)) {
                log.debug("Handling event (creating a Job) for Assets Review Task @ [ {} ]", path);
                ScheduleOptions options = scheduler.NOW();
                String jobName = this.getClass().getSimpleName().toString().replace(".", "/") + "/" + path;
                options.name(jobName);
                options.canRunConcurrently(false);
                scheduler.schedule(new ImmediateJob(path), options);
            }
        }
    } catch (LoginException e) {
        log.error("Could not get resource resolver", e);
    } finally {
        // Always close resource resolvers you open
        if (resourceResolver != null) {
            resourceResolver.close();
        }
    }
}
Also used : ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ValueMap(org.apache.sling.api.resource.ValueMap) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Resource(org.apache.sling.api.resource.Resource) LoginException(org.apache.sling.api.resource.LoginException)

Aggregations

ScheduleOptions (org.apache.sling.commons.scheduler.ScheduleOptions)21 Scheduler (org.apache.sling.commons.scheduler.Scheduler)8 Test (org.junit.Test)7 File (java.io.File)4 Date (java.util.Date)3 DistributionQueueProcessor (org.apache.sling.distribution.queue.DistributionQueueProcessor)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LoginException (org.apache.sling.api.resource.LoginException)2 DistributionException (org.apache.sling.distribution.common.DistributionException)2 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)2 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)2 DistributionRequestHandler (org.apache.sling.distribution.trigger.DistributionRequestHandler)2 Workspace (com.adobe.acs.commons.workflow.bulk.execution.model.Workspace)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 FilenameFilter (java.io.FilenameFilter)1 IOException (java.io.IOException)1 Serializable (java.io.Serializable)1 StringReader (java.io.StringReader)1