use of org.joda.time.format.DateTimeFormatter in project OpenClinica by OpenClinica.
the class ArithmeticOpNode method calculateGenericDate.
private String calculateGenericDate(String value1, String value2) {
DateMidnight dm = new DateMidnight(ExpressionTreeHelper.getDate(value1).getTime());
DateTimeFormatter fmt = ISODateTimeFormat.date();
switch(op) {
case PLUS:
{
dm = dm.plusDays(Double.valueOf(value2).intValue());
return fmt.print(dm);
}
case MINUS:
{
dm = dm.minusDays(Double.valueOf(value2).intValue());
return fmt.print(dm);
}
default:
// Bad operator!
return null;
}
}
use of org.joda.time.format.DateTimeFormatter in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isRunTimeValid.
private boolean isRunTimeValid(AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, String runTime) {
boolean isValid = true;
DateTimeFormatter formatter = DateTimeFormat.forPattern("HH:mm");
try {
formatter.parseDateTime(runTime);
if (!runTime.matches("\\d{2}:\\d{2}")) {
ruleSetBeanWrapper.error(createError("OCRERR_0047"));
isValid = false;
}
} catch (Exception e) {
ruleSetBeanWrapper.error(createError("OCRERR_0047"));
isValid = false;
}
return isValid;
}
use of org.joda.time.format.DateTimeFormatter in project OpenClinica by OpenClinica.
the class ExpressionService method getSSDate.
public HashMap<String, String> getSSDate(String ssZoneId, String serverZoneId) {
HashMap<String, String> map = new HashMap<String, String>();
if (ssZoneId == null || ssZoneId.equals(""))
ssZoneId = TimeZone.getDefault().getID();
DateTimeZone ssZone = DateTimeZone.forID(ssZoneId);
DateMidnight dm = new DateMidnight(ssZone);
DateTimeFormatter fmt = ISODateTimeFormat.date();
map.put("ssDate", fmt.print(dm));
map.put("serverZoneId", serverZoneId);
DateTimeZone serverZone = DateTimeZone.forID(serverZoneId);
DateMidnight serverDate = new DateMidnight(serverZone);
map.put("serverDate", fmt.print(serverDate));
return map;
}
use of org.joda.time.format.DateTimeFormatter in project Activiti by Activiti.
the class IntermediateTimerEventRepeatCompatibilityTest method testRepeatWithEnd.
@Deployment
public void testRepeatWithEnd() throws Throwable {
Calendar calendar = Calendar.getInstance();
Date baseTime = calendar.getTime();
//expect to stop boundary jobs after 20 minutes
DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
calendar.setTime(baseTime);
calendar.add(Calendar.HOUR, 2);
//expect to wait after completing task A for 1 hour even I set the end date for 2 hours (the expression will trigger the execution)
DateTime dt = new DateTime(calendar.getTime());
String endDateForIntermediate1 = fmt.print(dt);
calendar.setTime(baseTime);
calendar.add(Calendar.HOUR, 1);
calendar.add(Calendar.MINUTE, 30);
//expect to wait after completing task B for 1 hour and 30 minutes (the end date will be reached, the expression will not be considered)
dt = new DateTime(calendar.getTime());
String endDateForIntermediate2 = fmt.print(dt);
//reset the timer
Calendar nextTimeCal = Calendar.getInstance();
nextTimeCal.setTime(baseTime);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("repeatWithEnd");
runtimeService.setVariable(processInstance.getId(), "EndDateForCatch1", endDateForIntermediate1);
runtimeService.setVariable(processInstance.getId(), "EndDateForCatch2", endDateForIntermediate2);
List<Task> tasks = taskService.createTaskQuery().list();
assertEquals(1, tasks.size());
tasks = taskService.createTaskQuery().list();
assertEquals(1, tasks.size());
Task task = tasks.get(0);
assertEquals("Task A", task.getName());
//Test Timer Catch Intermediate Events after completing Task B (endDate not reached but it will be executed according to the expression)
taskService.complete(task.getId());
try {
waitForJobExecutorToProcessAllJobs(2000, 500);
fail("Expected that job isn't executed because the timer is in t0");
} catch (Exception e) {
// expected
}
//after 1 hour the event must be triggered and the flow will go to the next step
nextTimeCal.add(Calendar.HOUR, 1);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
waitForJobExecutorToProcessAllJobs(2000, 500);
//expect to execute because the time is reached.
List<Job> jobs = managementService.createJobQuery().list();
assertEquals(0, jobs.size());
tasks = taskService.createTaskQuery().list();
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Task C", task.getName());
//Test Timer Catch Intermediate Events after completing Task C
taskService.complete(task.getId());
//after 1H 40 minutes from process start, the timer will trigger because of the endDate
nextTimeCal.add(Calendar.HOUR, 1);
processEngineConfiguration.getClock().setCurrentTime(nextTimeCal.getTime());
waitForJobExecutorToProcessAllJobs(2000, 500);
if (processEngineConfiguration.getHistoryLevel().isAtLeast(HistoryLevel.ACTIVITY)) {
HistoricProcessInstance historicInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();
assertNotNull(historicInstance.getEndTime());
}
//now All the process instances should be completed
List<ProcessInstance> processInstances = runtimeService.createProcessInstanceQuery().list();
assertEquals(0, processInstances.size());
//no jobs
jobs = managementService.createJobQuery().list();
assertEquals(0, jobs.size());
//no tasks
tasks = taskService.createTaskQuery().list();
assertEquals(0, tasks.size());
}
use of org.joda.time.format.DateTimeFormatter in project Activiti by Activiti.
the class ProcessDefinitionResourceTest method testSuspendProcessDefinitionDelayed.
/**
* Test suspending a process definition on a certain date.
* POST repository/process-definitions/{processDefinitionId}
*/
@Deployment(resources = { "org/activiti/rest/service/api/repository/oneTaskProcess.bpmn20.xml" })
public void testSuspendProcessDefinitionDelayed() throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
ObjectNode requestNode = objectMapper.createObjectNode();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR, 2);
// Format the date using ISO date format
DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
String dateString = formatter.print(cal.getTimeInMillis());
requestNode.put("action", "suspend");
requestNode.put("date", dateString);
HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_PROCESS_DEFINITION, processDefinition.getId()));
httpPut.setEntity(new StringEntity(requestNode.toString()));
CloseableHttpResponse response = executeRequest(httpPut, HttpStatus.SC_OK);
// Check "OK" status
JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent());
closeResponse(response);
assertTrue(responseNode.get("suspended").booleanValue());
// Check if process-definition is not yet suspended
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertFalse(processDefinition.isSuspended());
// Force suspension by altering time
cal.add(Calendar.HOUR, 1);
processEngineConfiguration.getClock().setCurrentTime(cal.getTime());
waitForJobExecutorToProcessAllJobs(5000, 100);
// Check if process-definition is suspended
processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertTrue(processDefinition.isSuspended());
}
Aggregations