Esempio n. 1
0
  public String upsertTheRemoteDBWithGet(WCHectare hectare) {

    //		upsert/{databaseName}/{id}/{nodeId}/{parcelId}/{status}/{transactionTime}
    //		Calendar.getInstance().getTime()
    //		upsert/farm3/6/1/1/0/2013-09-15%2019:26:12

    resource =
        client.resource(
            WebServicePaths.upsertHectare
                + UserConstants.getSessionUser().getFarm()
                + hectare.getId()
                + "/"
                + hectare.getNodeID()
                + "/"
                + hectare.getParcelID()
                + "/"
                + hectare.getStatus()
                + "/"
                + DateConverter.now().replace(" ", "%20"));

    String webServiceHectareResult = resource.get(String.class);

    System.out.println(webServiceHectareResult);

    return "nice";
  }
 @Test
 public void testConvertNotSupported() throws Exception {
   final Calendar cal = new GregorianCalendar(2005, 0, 16);
   try {
     converter.convert(Object.class, cal.getTime());
     fail("Object.class is not supported");
   } catch (final Exception e) {
     // expected
   }
   try {
     converter.convertToDate(Object.class, cal.getTime(), "");
     fail("Object.class is not supported");
   } catch (final Exception e) {
     // expected
   }
 }
  @Test
  public void testConvertStringToDate() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);
    // test empty time
    Date date = (Date) converter.convert(Date.class, "");
    assertNull(date);
    date = (Date) converter.convert(Date.class, datePart);

    final Calendar cal = new GregorianCalendar();
    cal.setTime(date);
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
 /**
  * Get completed process instances which were finished after the given date and time
  *
  * @return BPMNProcessInstance array if the historic process instance list is not null
  */
 public BPMNProcessInstance[] getCompletedProcessInstances() {
   HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
   HistoricProcessInstanceQuery instanceQuery =
       historyService.createHistoricProcessInstanceQuery();
   List<HistoricProcessInstance> historicProcessInstanceList = null;
   String time =
       readPublishTimeFromRegistry(
           AnalyticsPublisherConstants.PROCESS_RESOURCE_PATH,
           AnalyticsPublisherConstants.LAST_PROCESS_INSTANCE_PUBLISH_TIME);
   if (time == null) {
     if (instanceQuery.finished().list().size() != 0) {
       // if the stored time is null in the registry file then send all completed process
       // instances.
       historicProcessInstanceList =
           instanceQuery.finished().orderByProcessInstanceStartTime().asc().list();
     }
   } else {
     Date timeInDateFormat = DateConverter.convertStringToDate(time);
     int listSize = instanceQuery.finished().startedAfter(timeInDateFormat).list().size();
     if (listSize != 0) {
       /*When using the startedAfter() method it returns the finished objects according to the time stored of
       last completed instance. But if the list length is one then it always return the same object in the
       list twice from the last updated time which stored in the carbon registry.
       (avoid to return same object repeatedly if the list has only one object)*/
       if (listSize == 1) {
         return null;
       }
       // send the process instances which were finished after the given date/time in registry
       historicProcessInstanceList =
           instanceQuery
               .finished()
               .startedAfter(timeInDateFormat)
               .orderByProcessInstanceStartTime()
               .asc()
               .listPage(1, listSize);
     }
   }
   if (historicProcessInstanceList != null) {
     if (log.isDebugEnabled()) {
       log.debug(
           "Write the published time of the last BPMN process instance to the carbon registry..."
               + historicProcessInstanceList.toString());
     }
     /*write the last published time to the registry because lets say as an example when a new process is completed,
     then the attributes belong to that process instance should be published to the DAS and if we are not stored
     the last published time, then all the completed processes which were previously published are also re-published
     to the DAS.*/
     writePublishTimeToRegistry(historicProcessInstanceList);
     // return ProcessInstances set as BPMNProcessInstance array
     return getBPMNProcessInstances(historicProcessInstanceList);
   }
   return null;
 }
  @Test
  public void testConvertStringToTimestamp() throws Exception {
    final Date today = new Date();
    final Calendar todayCalendar = new GregorianCalendar();
    todayCalendar.setTime(today);
    final String datePart = DateUtil.convertDateToString(today);

    final Timestamp time = (Timestamp) converter.convert(Timestamp.class, datePart + " 01:02:03.4");
    final Calendar cal = new GregorianCalendar();
    cal.setTimeInMillis(time.getTime());
    assertEquals(todayCalendar.get(Calendar.YEAR), cal.get(Calendar.YEAR));
    assertEquals(todayCalendar.get(Calendar.MONTH), cal.get(Calendar.MONTH));
    assertEquals(todayCalendar.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH));
  }
 /**
  * Get completed task instances which were finished after the given date and time
  *
  * @return BPMNTaskInstance array if the historic task instance list is not null
  */
 public BPMNTaskInstance[] getCompletedTaskInstances() {
   HistoryService historyService = BPMNServerHolder.getInstance().getEngine().getHistoryService();
   HistoricTaskInstanceQuery instanceQuery = historyService.createHistoricTaskInstanceQuery();
   List<HistoricTaskInstance> historicTaskInstanceList = null;
   String time =
       readPublishTimeFromRegistry(
           AnalyticsPublisherConstants.TASK_RESOURCE_PATH,
           AnalyticsPublisherConstants.LAST_TASK_INSTANCE_END_TIME);
   if (time == null) {
     if (instanceQuery.finished().list().size() != 0) {
       historicTaskInstanceList =
           instanceQuery.finished().orderByHistoricTaskInstanceEndTime().asc().list();
     }
   } else {
     Date dateFormat = DateConverter.convertStringToDate(time);
     int listSize = instanceQuery.finished().taskCompletedAfter(dateFormat).list().size();
     if (listSize != 0) {
       /*When using the startedAfter() method it returns the finished objects according to the time stored of
       last completed instance. But if the list length is one then it always return the same object in the
       list twice from the last updated time which stored in the carbon registry.
       (avoid to return same object repeatedly if the list has only one object)*/
       if (listSize == 1) {
         return null;
       }
       historicTaskInstanceList =
           instanceQuery
               .finished()
               .taskCompletedAfter(dateFormat)
               .orderByHistoricTaskInstanceEndTime()
               .asc()
               .listPage(1, listSize);
     }
   }
   if (historicTaskInstanceList != null) {
     if (log.isDebugEnabled()) {
       log.debug(
           "Write BPMN task instance to the carbon registry..."
               + historicTaskInstanceList.toString());
     }
     writeTaskEndTimeToRegistry(historicTaskInstanceList);
     return getBPMNTaskInstances(historicTaskInstanceList);
   }
   return null;
 }
 @Test
 public void testConvertDateWithNull() throws Exception {
   final String date = (String) converter.convert(String.class, null);
   assertNull(date);
 }
 @Test
 public void testConvertStringToString() throws Exception {
   assertEquals(converter.convert(String.class, "anystring"), "anystring");
 }
 @Test
 public void testConvertDateToString() throws Exception {
   final Calendar cal = new GregorianCalendar(2005, 0, 16);
   final String date = (String) converter.convert(String.class, cal.getTime());
   assertEquals(DateUtil.convertDateToString(cal.getTime()), date);
 }
Esempio n. 10
0
 @Test
 public void testConvertTimestampToString() throws Exception {
   final Timestamp timestamp = Timestamp.valueOf("2005-03-10 01:02:03.4");
   final String time = (String) converter.convert(String.class, timestamp);
   assertEquals(DateUtil.getDateTime(DateUtil.getDateTimePattern(), timestamp), time);
 }