Search in sources :

Example 11 with ScheduledPersistedAction

use of org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction in project alfresco-repository by Alfresco.

the class ScheduledPersistedActionServiceTest method setUp.

@Before
public void setUp() throws Exception {
    actionService = (ActionService) applicationContext.getBean("actionService");
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    transactionService = (TransactionService) applicationContext.getBean("transactionService");
    runtimeActionService = (RuntimeActionService) applicationContext.getBean("actionService");
    service = (ScheduledPersistedActionService) applicationContext.getBean("ScheduledPersistedActionService");
    serviceImpl = (ScheduledPersistedActionServiceImpl) applicationContext.getBean("scheduledPersistedActionService");
    scheduler = (Scheduler) applicationContext.getBean("schedulerFactory");
    bootstrap = (ScheduledPersistedActionServiceBootstrap) applicationContext.getBean("scheduledPersistedActionServiceBootstrap");
    // Set the current security context as admin
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    // Register the test executor, if needed
    SleepActionExecuter.registerIfNeeded(applicationContext);
    // Zap all test schedules
    List<ScheduledPersistedAction> schedules = service.listSchedules();
    for (ScheduledPersistedAction schedule : schedules) {
        service.deleteSchedule(schedule);
    }
    // Persist an action that uses the test executor
    testAction = new TestAction(actionService.createAction(SleepActionExecuter.NAME));
    runtimeActionService.createActionNodeRef(testAction, serviceImpl.SCHEDULED_ACTION_ROOT_NODE_REF, ContentModel.ASSOC_CONTAINS, QName.createQName("TestAction"));
    testAction2 = new TestAction(actionService.createAction(SleepActionExecuter.NAME));
    runtimeActionService.createActionNodeRef(testAction2, serviceImpl.SCHEDULED_ACTION_ROOT_NODE_REF, ContentModel.ASSOC_CONTAINS, QName.createQName("TestAction2"));
    testAction3 = new TestAction(actionService.createAction(SleepActionExecuter.NAME));
    // Finish setup
    txn.commit();
    // By default, we don't want the scheduler to fire while the tests run
    // Certain tests will enable it as required
    scheduler.standby();
}
Also used : UserTransaction(javax.transaction.UserTransaction) ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) Before(org.junit.Before)

Example 12 with ScheduledPersistedAction

use of org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction in project alfresco-repository by Alfresco.

the class ScheduledPersistedActionServiceTest method testLoadFromAction.

@Test
public void testLoadFromAction() throws Exception {
    // Create schedule
    ScheduledPersistedAction schedule1 = service.createSchedule(testAction);
    assertNotNull(schedule1);
    service.saveSchedule(schedule1);
    // retrieve schedule for action which doesn't have schedule
    ScheduledPersistedAction retrieved = service.getSchedule(testAction2);
    assertNull(retrieved);
    // and from one which does
    retrieved = service.getSchedule(testAction);
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getActionNodeRef());
}
Also used : ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 13 with ScheduledPersistedAction

use of org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction in project alfresco-repository by Alfresco.

the class ScheduledPersistedActionServiceTest method testEditing.

/**
 * Ensures that we can create, save, edit, save load, edit, save, load etc, all without problems, and without
 * creating duplicates
 */
@Test
public void testEditing() throws Exception {
    // create and save schedule
    ScheduledPersistedAction schedule = service.createSchedule(testAction);
    assertNotNull(schedule);
    Date now = new Date();
    schedule.setScheduleStart(now);
    schedule.setScheduleIntervalCount(2);
    schedule.setScheduleIntervalPeriod(ScheduledPersistedAction.IntervalPeriod.Day);
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    service.saveSchedule(schedule);
    txn.commit();
    // Load and check it hasn't changed
    txn = transactionService.getUserTransaction();
    txn.begin();
    ScheduledPersistedAction retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    txn.commit();
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getAction().getNodeRef());
    assertEquals(now, retrieved.getScheduleStart());
    assertEquals(new Integer(2), retrieved.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, retrieved.getScheduleIntervalPeriod());
    // Save and re-load without changes
    txn = transactionService.getUserTransaction();
    txn.begin();
    service.saveSchedule(schedule);
    retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    txn.commit();
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getAction().getNodeRef());
    assertEquals(now, retrieved.getScheduleStart());
    assertEquals(new Integer(2), retrieved.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, retrieved.getScheduleIntervalPeriod());
    // Make some small changes
    txn = transactionService.getUserTransaction();
    txn.begin();
    retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    retrieved.setScheduleIntervalCount(3);
    service.saveSchedule(retrieved);
    retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    txn.commit();
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getAction().getNodeRef());
    assertEquals(now, retrieved.getScheduleStart());
    assertEquals(new Integer(3), retrieved.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, retrieved.getScheduleIntervalPeriod());
    // And some more changes
    retrieved.setScheduleIntervalPeriod(ScheduledPersistedAction.IntervalPeriod.Month);
    now = new Date();
    retrieved.setScheduleStart(now);
    txn = transactionService.getUserTransaction();
    txn.begin();
    service.saveSchedule(retrieved);
    retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    txn.commit();
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getAction().getNodeRef());
    assertEquals(now, retrieved.getScheduleStart());
    assertEquals(new Integer(3), retrieved.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Month, retrieved.getScheduleIntervalPeriod());
}
Also used : ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) UserTransaction(javax.transaction.UserTransaction) Date(java.util.Date) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 14 with ScheduledPersistedAction

use of org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction in project alfresco-repository by Alfresco.

the class ScheduledPersistedActionServiceTest method testCreateSaveLoad.

@Test
public void testCreateSaveLoad() throws Exception {
    // create and save schedule
    ScheduledPersistedAction schedule = service.createSchedule(testAction);
    assertNotNull(schedule);
    Date now = new Date();
    schedule.setScheduleStart(now);
    schedule.setScheduleIntervalCount(2);
    schedule.setScheduleIntervalPeriod(ScheduledPersistedAction.IntervalPeriod.Day);
    assertNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    service.saveSchedule(schedule);
    assertNotNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    // Load it again, should have the same details still
    ScheduledPersistedAction retrieved = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    assertNotNull(retrieved);
    assertEquals(testAction.getNodeRef(), retrieved.getAction().getNodeRef());
    assertEquals(now, retrieved.getScheduleStart());
    assertEquals(new Integer(2), retrieved.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, retrieved.getScheduleIntervalPeriod());
    assertNotNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    // Load a 2nd copy, won't be any changes
    ScheduledPersistedAction second = serviceImpl.loadPersistentSchedule(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    assertNotNull(second);
    assertEquals(testAction.getNodeRef(), second.getAction().getNodeRef());
    assertEquals(now, second.getScheduleStart());
    assertEquals(new Integer(2), second.getScheduleIntervalCount());
    assertEquals(ScheduledPersistedAction.IntervalPeriod.Day, second.getScheduleIntervalPeriod());
    // Now ensure we can create for an action that didn't have a noderef
    // when we started
    schedule = service.createSchedule(testAction3);
    assertNull(schedule.getActionNodeRef());
    assertNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    runtimeActionService.createActionNodeRef(testAction3, serviceImpl.SCHEDULED_ACTION_ROOT_NODE_REF, ContentModel.ASSOC_CONTAINS, QName.createQName("TestAction3"));
    assertNotNull(schedule.getActionNodeRef());
    assertNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
    service.saveSchedule(schedule);
    assertNotNull(schedule.getActionNodeRef());
    assertNotNull(((ScheduledPersistedActionImpl) schedule).getPersistedAtNodeRef());
}
Also used : ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction) Date(java.util.Date) BaseSpringTest(org.alfresco.util.BaseSpringTest) Test(org.junit.Test)

Example 15 with ScheduledPersistedAction

use of org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction in project alfresco-repository by Alfresco.

the class QuickShareServiceImpl method attachSchedule.

private QuickShareLinkExpiryAction attachSchedule(QuickShareLinkExpiryAction quickShareLinkExpiryAction) {
    if (quickShareLinkExpiryAction.getSchedule() == null) {
        ScheduledPersistedAction schedule = scheduledPersistedActionService.getSchedule(quickShareLinkExpiryAction);
        quickShareLinkExpiryAction.setSchedule(schedule);
    }
    return quickShareLinkExpiryAction;
}
Also used : ScheduledPersistedAction(org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction)

Aggregations

ScheduledPersistedAction (org.alfresco.service.cmr.action.scheduled.ScheduledPersistedAction)16 BaseSpringTest (org.alfresco.util.BaseSpringTest)9 Test (org.junit.Test)9 Date (java.util.Date)6 UserTransaction (javax.transaction.UserTransaction)4 SleepActionExecuter (org.alfresco.repo.action.ActionServiceImplTest.SleepActionExecuter)2 QuickShareLinkExpiryAction (org.alfresco.service.cmr.quickshare.QuickShareLinkExpiryAction)2 NodeRef (org.alfresco.service.cmr.repository.NodeRef)2 ArrayList (java.util.ArrayList)1 ClientAppNotFoundException (org.alfresco.repo.client.config.ClientAppNotFoundException)1 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)1 InvalidSharedIdException (org.alfresco.service.cmr.quickshare.InvalidSharedIdException)1 QuickShareDisabledException (org.alfresco.service.cmr.quickshare.QuickShareDisabledException)1 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)1 InvalidNodeRefException (org.alfresco.service.cmr.repository.InvalidNodeRefException)1 NoSuchPersonException (org.alfresco.service.cmr.security.NoSuchPersonException)1 After (org.junit.After)1 Before (org.junit.Before)1