Search in sources :

Example 6 with ActionManager

use of com.adobe.acs.commons.fam.ActionManager in project acs-aem-commons by Adobe-Consulting-Services.

the class FolderRelocator method validateAllAcls.

private void validateAllAcls(ActionManager step1) {
    TreeFilteringResourceVisitor folderVisitor = new TreeFilteringResourceVisitor();
    folderVisitor.setBreadthFirstMode();
    folderVisitor.setResourceVisitor((resource, level) -> step1.deferredWithResolver(rr -> checkNodeAcls(rr, resource.getPath(), requiredFolderPrivileges)));
    folderVisitor.setLeafVisitor((resource, level) -> step1.deferredWithResolver(rr -> checkNodeAcls(rr, resource.getPath(), requiredNodePrivileges)));
    sourceToDestination.keySet().forEach(sourcePath -> beginStep(step1, sourcePath, folderVisitor));
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) HashMap(java.util.HashMap) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor) StringUtils(org.apache.commons.lang3.StringUtils) Failure(com.adobe.acs.commons.fam.Failure) Level(java.util.logging.Level) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) ActionBatch(com.adobe.acs.commons.fam.actions.ActionBatch) FormField(com.adobe.acs.commons.mcp.form.FormField) PersistenceException(org.apache.sling.api.resource.PersistenceException) Actions(com.adobe.acs.commons.fam.actions.Actions) PathfieldComponent(com.adobe.acs.commons.mcp.form.PathfieldComponent) Session(javax.jcr.Session) Resource(org.apache.sling.api.resource.Resource) RadioComponent(com.adobe.acs.commons.mcp.form.RadioComponent) ActionManager(com.adobe.acs.commons.fam.ActionManager) Logger(java.util.logging.Logger) Serializable(java.io.Serializable) Objects(java.util.Objects) LoginException(org.apache.sling.api.resource.LoginException) List(java.util.List) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) Optional(java.util.Optional) AccessControlManager(javax.jcr.security.AccessControlManager) Pattern(java.util.regex.Pattern) Privilege(javax.jcr.security.Privilege) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)

Example 7 with ActionManager

use of com.adobe.acs.commons.fam.ActionManager in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRelocator method validateAllAcls.

protected void validateAllAcls(ActionManager step1) {
    SimpleFilteringResourceVisitor pageVisitor;
    if (extensiveACLChecks) {
        pageVisitor = new SimpleFilteringResourceVisitor();
        pageVisitor.setLeafVisitor((resource, level) -> step1.deferredWithResolver(rr -> checkNodeAcls(rr, resource.getPath(), requiredPrivileges)));
    } else {
        pageVisitor = new TreeFilteringResourceVisitor(NameConstants.NT_PAGE);
    }
    pageVisitor.setBreadthFirstMode();
    pageVisitor.setResourceVisitor((resource, level) -> step1.deferredWithResolver(rr -> checkNodeAcls(rr, resource.getPath(), requiredPrivileges)));
    beginStep(step1, sourcePath, pageVisitor);
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) ReplicationActionType(com.day.cq.replication.ReplicationActionType) HashMap(java.util.HashMap) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ReplicationStatus(com.day.cq.replication.ReplicationStatus) ManagedProcess(com.adobe.acs.commons.mcp.model.ManagedProcess) RepositoryException(javax.jcr.RepositoryException) ReplicationException(com.day.cq.replication.ReplicationException) Map(java.util.Map) ReferenceSearch(com.day.cq.wcm.commons.ReferenceSearch) FormField(com.adobe.acs.commons.mcp.form.FormField) PersistenceException(org.apache.sling.api.resource.PersistenceException) ReplicationOptions(com.day.cq.replication.ReplicationOptions) Actions(com.adobe.acs.commons.fam.actions.Actions) PathfieldComponent(com.adobe.acs.commons.mcp.form.PathfieldComponent) EnumMap(java.util.EnumMap) Session(javax.jcr.Session) Replicator(com.day.cq.replication.Replicator) Resource(org.apache.sling.api.resource.Resource) RadioComponent(com.adobe.acs.commons.mcp.form.RadioComponent) PageManagerFactory(com.day.cq.wcm.api.PageManagerFactory) ActionManager(com.adobe.acs.commons.fam.ActionManager) Field(java.lang.reflect.Field) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PageManager(com.day.cq.wcm.api.PageManager) LoginException(org.apache.sling.api.resource.LoginException) List(java.util.List) GenericReport(com.adobe.acs.commons.mcp.model.GenericReport) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) NameConstants(com.day.cq.wcm.api.NameConstants) TextfieldComponent(com.adobe.acs.commons.mcp.form.TextfieldComponent) AccessControlManager(javax.jcr.security.AccessControlManager) CheckboxComponent(com.adobe.acs.commons.mcp.form.CheckboxComponent) Pattern(java.util.regex.Pattern) Privilege(javax.jcr.security.Privilege) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor)

Example 8 with ActionManager

use of com.adobe.acs.commons.fam.ActionManager in project acs-aem-commons by Adobe-Consulting-Services.

the class PageRelocator method movePages.

protected void movePages(ActionManager step2) {
    TreeFilteringResourceVisitor pageVisitor = new TreeFilteringResourceVisitor(NameConstants.NT_PAGE);
    pageVisitor.setBreadthFirstMode();
    pageVisitor.setResourceVisitor((resource, level) -> step2.deferredWithResolver(rr -> movePage(rr, resource.getPath())));
    beginStep(step2, sourcePath, pageVisitor);
}
Also used : ResourceResolver(org.apache.sling.api.resource.ResourceResolver) FieldUtils(org.apache.commons.lang.reflect.FieldUtils) ProcessDefinition(com.adobe.acs.commons.mcp.ProcessDefinition) ReplicationActionType(com.day.cq.replication.ReplicationActionType) HashMap(java.util.HashMap) SimpleFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) ReplicationStatus(com.day.cq.replication.ReplicationStatus) ManagedProcess(com.adobe.acs.commons.mcp.model.ManagedProcess) RepositoryException(javax.jcr.RepositoryException) ReplicationException(com.day.cq.replication.ReplicationException) Map(java.util.Map) ReferenceSearch(com.day.cq.wcm.commons.ReferenceSearch) FormField(com.adobe.acs.commons.mcp.form.FormField) PersistenceException(org.apache.sling.api.resource.PersistenceException) ReplicationOptions(com.day.cq.replication.ReplicationOptions) Actions(com.adobe.acs.commons.fam.actions.Actions) PathfieldComponent(com.adobe.acs.commons.mcp.form.PathfieldComponent) EnumMap(java.util.EnumMap) Session(javax.jcr.Session) Replicator(com.day.cq.replication.Replicator) Resource(org.apache.sling.api.resource.Resource) RadioComponent(com.adobe.acs.commons.mcp.form.RadioComponent) PageManagerFactory(com.day.cq.wcm.api.PageManagerFactory) ActionManager(com.adobe.acs.commons.fam.ActionManager) Field(java.lang.reflect.Field) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PageManager(com.day.cq.wcm.api.PageManager) LoginException(org.apache.sling.api.resource.LoginException) List(java.util.List) GenericReport(com.adobe.acs.commons.mcp.model.GenericReport) Stream(java.util.stream.Stream) TreeMap(java.util.TreeMap) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor) NameConstants(com.day.cq.wcm.api.NameConstants) TextfieldComponent(com.adobe.acs.commons.mcp.form.TextfieldComponent) AccessControlManager(javax.jcr.security.AccessControlManager) CheckboxComponent(com.adobe.acs.commons.mcp.form.CheckboxComponent) Pattern(java.util.regex.Pattern) Privilege(javax.jcr.security.Privilege) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) TreeFilteringResourceVisitor(com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)

Example 9 with ActionManager

use of com.adobe.acs.commons.fam.ActionManager in project acs-aem-commons by Adobe-Consulting-Services.

the class StatusServlet method doGet.

@Override
@SuppressWarnings({ "squid:S3776", "squid:S1192" })
protected final void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
    SimpleDateFormat sdf = new SimpleDateFormat("EEE, d MMM yyyy hh:mm:ss aaa");
    response.setContentType("application/json");
    response.setCharacterEncoding("UTF-8");
    Config config = request.getResource().adaptTo(Config.class);
    Workspace workspace = config.getWorkspace();
    final JSONObject json = new JSONObject();
    try {
        json.put("initialized", workspace.isInitialized());
        json.put("status", workspace.getStatus());
        if (workspace.getSubStatus() != null) {
            json.put("subStatus", workspace.getSubStatus());
        }
        json.put("runnerType", config.getRunnerType());
        json.put("queryType", config.getQueryType());
        json.put("queryStatement", config.getQueryStatement());
        json.put("workflowModel", StringUtils.removeEnd(config.getWorkflowModelId(), "/jcr:content/model"));
        json.put("batchSize", config.getBatchSize());
        json.put("autoThrottle", config.isAutoThrottle());
        json.put("purgeWorkflow", config.isPurgeWorkflow());
        json.put("interval", config.getInterval());
        json.put("retryCount", config.getRetryCount());
        json.put("timeout", config.getTimeout());
        json.put("throttle", config.getThrottle());
        json.put("message", workspace.getMessage());
        if (config.isUserEventData()) {
            json.put("userEventData", config.getUserEventData());
        }
        ActionManager actionManager = actionManagerFactory.getActionManager(workspace.getActionManagerName());
        if (actionManager != null && !Status.COMPLETED.equals(workspace.getStatus())) {
            // If Complete, then look to JCR for final accounts as ActionManager may be gone
            addActionManagerTrackedCounts(workspace.getActionManagerName(), json);
            for (com.adobe.acs.commons.fam.Failure failure : actionManager.getFailureList()) {
                JSONObject failureJSON = new JSONObject();
                failureJSON.put(Failure.PN_PAYLOAD_PATH, failure.getNodePath());
                failureJSON.put(Failure.PN_FAILED_AT, sdf.format(failure.getTime().getTime()));
                json.accumulate("failures", failureJSON);
            }
        } else {
            addWorkspaceTrackedCounts(workspace, json);
            // Failures
            for (Failure failure : workspace.getFailures()) {
                json.accumulate("failures", failure.toJSON());
            }
        }
        // Times
        if (workspace.getStartedAt() != null) {
            json.put("startedAt", sdf.format(workspace.getStartedAt().getTime()));
            json.put("timeTakenInMillis", (Calendar.getInstance().getTime().getTime() - workspace.getStartedAt().getTime().getTime()));
        }
        if (workspace.getStoppedAt() != null) {
            json.put("stoppedAt", sdf.format(workspace.getStoppedAt().getTime()));
            json.put("timeTakenInMillis", (workspace.getStoppedAt().getTime().getTime() - workspace.getStartedAt().getTime().getTime()));
        }
        if (workspace.getCompletedAt() != null) {
            json.put("completedAt", sdf.format(workspace.getCompletedAt().getTime()));
            json.put("timeTakenInMillis", (workspace.getCompletedAt().getTime().getTime() - workspace.getStartedAt().getTime().getTime()));
        }
        if (AEMWorkflowRunnerImpl.class.getName().equals(config.getRunnerType())) {
            for (Payload payload : config.getWorkspace().getActivePayloads()) {
                json.accumulate("activePayloads", payload.toJSON());
            }
        }
        json.put("systemStats", getSystemStats());
        response.getWriter().write(json.toString());
    } catch (JSONException e) {
        log.error("Could not collect Bulk Workflow status due to: {}", e);
        JSONErrorUtil.sendJSONError(response, SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not collect Bulk Workflow status.", e.getMessage());
    }
}
Also used : Config(com.adobe.acs.commons.workflow.bulk.execution.model.Config) JSONException(org.apache.sling.commons.json.JSONException) AEMWorkflowRunnerImpl(com.adobe.acs.commons.workflow.bulk.execution.impl.runners.AEMWorkflowRunnerImpl) ActionManager(com.adobe.acs.commons.fam.ActionManager) JSONObject(org.apache.sling.commons.json.JSONObject) Payload(com.adobe.acs.commons.workflow.bulk.execution.model.Payload) SimpleDateFormat(java.text.SimpleDateFormat) Failure(com.adobe.acs.commons.workflow.bulk.execution.model.Failure) Workspace(com.adobe.acs.commons.workflow.bulk.execution.model.Workspace)

Example 10 with ActionManager

use of com.adobe.acs.commons.fam.ActionManager in project acs-aem-commons by Adobe-Consulting-Services.

the class ActionManagerTest method deferredStatsCounterErrorTest.

@Test
public void deferredStatsCounterErrorTest() throws LoginException, Exception {
    ResourceResolver rr = getMockResolver();
    ActionManager manager = getActionManager();
    assertEquals(0, manager.getAddedCount());
    manager.deferredWithResolver(resolver -> {
        throw new Exception("Bad things");
    });
    assertEquals(1, manager.getAddedCount());
    assertEquals(1, manager.getCompletedCount());
    manager.deferredWithResolver(resolver -> {
        throw new Exception("Bad things");
    });
    assertEquals(2, manager.getAddedCount());
    assertEquals(2, manager.getCompletedCount());
    assertEquals(2, manager.getErrorCount());
    manager.deferredWithResolver(resolver -> {
        throw new NullPointerException("Bad things");
    });
    assertEquals(3, manager.getAddedCount());
    assertEquals(3, manager.getCompletedCount());
    assertEquals(3, manager.getErrorCount());
    manager.deferredWithResolver(resolver -> {
        throw new PersistenceException("Bad things");
    });
    assertEquals(4, manager.getAddedCount());
    assertEquals(4, manager.getCompletedCount());
    assertEquals(4, manager.getErrorCount());
    assertNotNull(manager.getFailureList());
    assertEquals(4, manager.getFailures().size());
    assertEquals(0, manager.getSuccessCount());
    assertEquals(0, manager.getRemainingCount());
    assertTrue(manager.isComplete());
}
Also used : ActionManager(com.adobe.acs.commons.fam.ActionManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) PersistenceException(org.apache.sling.api.resource.PersistenceException) LoginException(org.apache.sling.api.resource.LoginException) PersistenceException(org.apache.sling.api.resource.PersistenceException) Test(org.junit.Test)

Aggregations

ActionManager (com.adobe.acs.commons.fam.ActionManager)15 ResourceResolver (org.apache.sling.api.resource.ResourceResolver)9 ProcessInstance (com.adobe.acs.commons.mcp.ProcessInstance)5 LoginException (org.apache.sling.api.resource.LoginException)5 PersistenceException (org.apache.sling.api.resource.PersistenceException)5 Actions (com.adobe.acs.commons.fam.actions.Actions)4 ProcessDefinition (com.adobe.acs.commons.mcp.ProcessDefinition)4 FormField (com.adobe.acs.commons.mcp.form.FormField)4 PathfieldComponent (com.adobe.acs.commons.mcp.form.PathfieldComponent)4 RadioComponent (com.adobe.acs.commons.mcp.form.RadioComponent)4 SimpleFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.SimpleFilteringResourceVisitor)4 TreeFilteringResourceVisitor (com.adobe.acs.commons.util.visitors.TreeFilteringResourceVisitor)4 HashMap (java.util.HashMap)4 List (java.util.List)4 Map (java.util.Map)4 Level (java.util.logging.Level)4 Logger (java.util.logging.Logger)4 Pattern (java.util.regex.Pattern)4 RepositoryException (javax.jcr.RepositoryException)4 Session (javax.jcr.Session)4