Search in sources :

Example 11 with ActionManager

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

the class ActionManagerTest method nullStatsCounterTest.

@Test
public void nullStatsCounterTest() throws LoginException, Exception {
    // Counters don't do tabulate in-thread actions, only deferred actions
    ResourceResolver rr = getMockResolver();
    ActionManager manager = getActionManager();
    assertEquals(0, manager.getAddedCount());
    manager.withResolver(resolver -> {
    });
    assertEquals(0, manager.getAddedCount());
    assertEquals(0, manager.getCompletedCount());
    manager.withResolver(resolver -> {
    });
    assertEquals(0, manager.getAddedCount());
    assertEquals(0, manager.getCompletedCount());
    assertEquals(0, manager.getErrorCount());
    assertEquals(0, manager.getRemainingCount());
    assertTrue(manager.isComplete());
}
Also used : ActionManager(com.adobe.acs.commons.fam.ActionManager) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) Test(org.junit.Test)

Example 12 with ActionManager

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

the class FolderRelocatorTest method getControlledProcessManager.

private ControlledProcessManager getControlledProcessManager() throws LoginException {
    ActionManager am = getActionManager();
    ActionManagerFactory amf = mock(ActionManagerFactoryImpl.class);
    when(amf.createTaskManager(any(), any(), anyInt())).thenReturn(am);
    ControlledProcessManager cpm = mock(ControlledProcessManager.class);
    when(cpm.getActionManagerFactory()).thenReturn(amf);
    return cpm;
}
Also used : ActionManager(com.adobe.acs.commons.fam.ActionManager) ControlledProcessManager(com.adobe.acs.commons.mcp.ControlledProcessManager) ActionManagerFactory(com.adobe.acs.commons.fam.ActionManagerFactory)

Example 13 with ActionManager

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

the class PageRelocatorTest method validateMoveOperation.

@Test
public void validateMoveOperation() throws RepositoryException, LoginException, DeserializeException, PersistenceException {
    ResourceResolver rr = getEnhancedMockResolver(true);
    ProcessInstance instance = new ProcessInstanceImpl(getControlledProcessManager(), tool, "relocator test");
    initInstance(instance, rr);
    ActionManager manager = getActionManager();
    tool.movePages(manager);
    assertTrue("Should be no reported errors", manager.getErrorCount() == 0);
    assertFalse("Should have captured activate requests", tool.replicatorQueue.activateOperations.isEmpty());
    assertFalse("Should have captured deactivate requests", tool.replicatorQueue.deactivateOperations.isEmpty());
    // Our mock doesn't pretend to create target pages at the moment...
    // Resource pageB = rr.getResource("/content/pageB");
    // verify(rr, times(1)).create(eq(pageB), eq("pageA"), any());
    verify(rr, atLeastOnce()).commit();
}
Also used : ActionManager(com.adobe.acs.commons.fam.ActionManager) ProcessInstanceImpl(com.adobe.acs.commons.mcp.impl.ProcessInstanceImpl) ResourceResolver(org.apache.sling.api.resource.ResourceResolver) ProcessInstance(com.adobe.acs.commons.mcp.ProcessInstance) Test(org.junit.Test) ActionManagerTest(com.adobe.acs.commons.fam.impl.ActionManagerTest)

Example 14 with ActionManager

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

the class FolderRelocator method buildTargetFolders.

private void buildTargetFolders(ActionManager step2) {
    TreeFilteringResourceVisitor folderVisitor = new TreeFilteringResourceVisitor();
    folderVisitor.setBreadthFirstMode();
    folderVisitor.setResourceVisitor((res, level) -> {
        String path = res.getPath();
        step2.deferredWithResolver(Actions.retry(5, 100, rr -> buildDestinationFolder(rr, path)));
    });
    sourceToDestination.keySet().forEach(sourcePath -> beginStep(step2, 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 15 with ActionManager

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

the class StatusServlet method addActionManagerTrackedCounts.

private void addActionManagerTrackedCounts(String name, JSONObject json) throws JSONException {
    final ActionManager actionManager = actionManagerFactory.getActionManager(name);
    int failureCount = actionManager.getErrorCount();
    int completeCount = actionManager.getSuccessCount();
    int totalCount = actionManager.getAddedCount();
    int remainingCount = actionManager.getRemainingCount();
    json.put("totalCount", totalCount);
    json.put("completeCount", completeCount);
    json.put("remainingCount", remainingCount);
    json.put("failCount", failureCount);
    json.put("percentComplete", Math.round(((totalCount - remainingCount) / (totalCount * 1F)) * DECIMAL_TO_PERCENT));
}
Also used : ActionManager(com.adobe.acs.commons.fam.ActionManager)

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