Search in sources :

Example 51 with DateTimeFormatter

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;
    }
}
Also used : DateMidnight(org.joda.time.DateMidnight) DateTimeFormatter(org.joda.time.format.DateTimeFormatter)

Example 52 with DateTimeFormatter

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;
}
Also used : DateTimeFormatter(org.joda.time.format.DateTimeFormatter) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 53 with DateTimeFormatter

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;
}
Also used : HashMap(java.util.HashMap) DateMidnight(org.joda.time.DateMidnight) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTimeZone(org.joda.time.DateTimeZone)

Example 54 with DateTimeFormatter

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());
}
Also used : Task(org.activiti.engine.task.Task) Calendar(java.util.Calendar) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) Date(java.util.Date) DateTime(org.joda.time.DateTime) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Job(org.activiti.engine.runtime.Job) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) Deployment(org.activiti.engine.test.Deployment)

Example 55 with DateTimeFormatter

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());
}
Also used : StringEntity(org.apache.http.entity.StringEntity) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Calendar(java.util.Calendar) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition) JsonNode(com.fasterxml.jackson.databind.JsonNode) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) HttpPut(org.apache.http.client.methods.HttpPut) Deployment(org.activiti.engine.test.Deployment)

Aggregations

DateTimeFormatter (org.joda.time.format.DateTimeFormatter)209 DateTime (org.joda.time.DateTime)95 Date (java.util.Date)40 Test (org.junit.Test)25 DateTimeZone (org.joda.time.DateTimeZone)19 ArrayList (java.util.ArrayList)16 HashMap (java.util.HashMap)16 SolrInputDocument (org.apache.solr.common.SolrInputDocument)12 IndexSchema (org.apache.solr.schema.IndexSchema)12 DateTimeFormatterBuilder (org.joda.time.format.DateTimeFormatterBuilder)12 CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)10 IOException (java.io.IOException)9 Calendar (java.util.Calendar)8 Map (java.util.Map)8 DatasetConfigDTO (com.linkedin.thirdeye.datalayer.dto.DatasetConfigDTO)7 FormatDateTimeFormatter (org.elasticsearch.common.joda.FormatDateTimeFormatter)7 Test (org.testng.annotations.Test)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 FilterType (net.opengis.filter.v_1_1_0.FilterType)6 Deployment (org.activiti.engine.test.Deployment)6