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();
}
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());
}
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());
}
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());
}
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;
}
Aggregations