Example usage for java.util Calendar HOUR

List of usage examples for java.util Calendar HOUR

Introduction

In this page you can find the example usage for java.util Calendar HOUR.

Prototype

int HOUR

To view the source code for java.util Calendar HOUR.

Click Source Link

Document

Field number for get and set indicating the hour of the morning or afternoon.

Usage

From source file:org.activiti.rest.service.api.runtime.TaskCollectionResourceTest.java

/**
 * Test getting a collection of tasks. GET runtime/tasks
 *///ww w.  j a v  a  2  s .  com
@Deployment
public void testGetTasks() throws Exception {
    try {
        Calendar adhocTaskCreate = Calendar.getInstance();
        adhocTaskCreate.set(Calendar.MILLISECOND, 0);

        Calendar processTaskCreate = Calendar.getInstance();
        processTaskCreate.add(Calendar.HOUR, 2);
        processTaskCreate.set(Calendar.MILLISECOND, 0);

        Calendar inBetweenTaskCreation = Calendar.getInstance();
        inBetweenTaskCreation.add(Calendar.HOUR, 1);

        processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("gonzo");
        adhocTask.setOwner("owner");
        adhocTask.setDelegationState(DelegationState.PENDING);
        adhocTask.setDescription("Description one");
        adhocTask.setName("Name one");
        adhocTask.setDueDate(adhocTaskCreate.getTime());
        adhocTask.setPriority(100);
        adhocTask.setCategory("some-category");
        taskService.saveTask(adhocTask);
        taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);

        processEngineConfiguration.getClock().setCurrentTime(processTaskCreate.getTime());
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
                "myBusinessKey");
        Task processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId())
                .singleResult();
        processTask.setParentTaskId(adhocTask.getId());
        processTask.setPriority(50);
        processTask.setDueDate(processTaskCreate.getTime());
        taskService.saveTask(processTask);

        // Check filter-less to fetch all tasks
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION);
        assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId());

        // Name filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?name=" + encode("Name one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Name like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?nameLike=" + encode("%one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Description filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description="
                + encode("Description one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description="
                + encode("Description two");
        assertEmptyResultsPresentInDataResponse(url);

        // Description like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike="
                + encode("%one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike="
                + encode("%two");
        assertEmptyResultsPresentInDataResponse(url);

        // Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?priority=100";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Mininmum Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?minimumPriority=70";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Maximum Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?maximumPriority=70";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Owner filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=owner";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=kermit";
        assertEmptyResultsPresentInDataResponse(url);

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike=" + encode("%ner");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike="
                + encode("kerm%");
        assertEmptyResultsPresentInDataResponse(url);

        // Assignee filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=gonzo";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=kermit";
        assertEmptyResultsPresentInDataResponse(url);

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike="
                + encode("gon%");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike="
                + encode("kerm%");
        assertEmptyResultsPresentInDataResponse(url);

        // Unassigned filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?unassigned=true";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Delegation state filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?delegationState=pending";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Candidate user filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateUser=kermit";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Candidate group filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateGroup=sales";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Involved user filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?involvedUser=misspiggy";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Process instance filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processInstanceId="
                + processInstance.getId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Execution filtering
        Execution taskExecution = runtimeService.createExecutionQuery().activityId("processTask")
                .singleResult();
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?executionId="
                + taskExecution.getId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Process instance businesskey filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?processInstanceBusinessKey=myBusinessKey";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // CeatedOn filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdOn="
                + getISODateString(adhocTaskCreate.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // CreatedAfter filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdAfter="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, processTask.getId());

        // CreatedBefore filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdBefore="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Subtask exclusion
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?excludeSubTasks=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Task definition key filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?taskDefinitionKey=processTask";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Task definition key like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?taskDefinitionKeyLike="
                + encode("process%");
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Duedate filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueDate="
                + getISODateString(adhocTaskCreate.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Due after filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueAfter="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Due before filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueBefore="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Without tenantId filtering before tenant set
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId());

        // Process definition
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionKey="
                + processInstance.getProcessDefinitionKey();
        assertResultsPresentInDataResponse(url, processTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionId="
                + processInstance.getProcessDefinitionId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Process instance id in list filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processInstanceIdIn="
                + adhocTask.getId() + "," + processInstance.getId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Set tenant on deployment
        managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));

        // Without tenantId filtering after tenant set, only adhoc task
        // should remain
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Tenant id filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantId=myTenant";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Tenant id like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantIdLike="
                + encode("%enant");
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Category filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?category="
                + encode("some-category");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Suspend process-instance to have a supended task
        runtimeService.suspendProcessInstanceById(processInstance.getId());

        // Suspended filering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=false";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Active filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            if (task.getExecutionId() == null) {
                taskService.deleteTask(task.getId(), true);
            }
        }
    }
}

From source file:com.bdb.weather.display.stripchart.StripChart.java

/**
 * Adjust the range of the domain axis based on the current time and the span selected by the user.
 * //www  .j ava2  s .co m
 * @param t0 The current time
 */
private void adjustDateAxis(Calendar t0) {
    Calendar now = t0;
    Calendar intercept = (Calendar) now.clone();
    intercept.add(Calendar.HOUR, -span);
    now.add(Calendar.MINUTE, 5);
    dateAxis.setRange(intercept.getTime(), now.getTime());
}

From source file:de.fhbingen.wbs.wpOverview.tabs.AvailabilityGraph.java

/**
 * Set the view to DAY./*from   w ww  .ja v a 2  s  .co m*/
 */
private void setDayView() {

    actualStart = (GregorianCalendar) actualDay.clone();
    actualStart.set(Calendar.HOUR_OF_DAY, 0);
    actualStart.set(Calendar.MINUTE, 0);
    actualStart.add(Calendar.HOUR, -1);

    actualEnd = (GregorianCalendar) actualDay.clone();
    actualEnd.set(Calendar.HOUR_OF_DAY, 23);
    actualEnd.set(Calendar.MINUTE, 59);
    actualEnd.add(Calendar.HOUR, 1);

    actualView = DAY;

    GregorianCalendar helper = (GregorianCalendar) actualEnd.clone();
    helper.add(Calendar.DATE, -1);

    makeChart(new SimpleDateFormat("EEEE, dd.MM.yyyy").format(helper.getTime()));
}

From source file:eu.cloudwave.wp5.feedbackhandler.aggregations.strategies.RequestAggregationStrategyImpl.java

/**
 * Number of expected measurement value groups in the chosen time range based on the chosen aggregation interval
 * //  www  . j a  v a2 s . c o  m
 * Example: time range: 1 day, aggregation interval: hours --> expects you to have 24 value groups, if this is not the
 * case, we have to add groups with 0 values, otherwise the minimum and average value will be wrong
 * 
 * @return number of groups as int
 */
private double getExpectedNumberOfMeasurementValueGroups() {

    // no statement about expected number of measurement value groups because no time range is selected
    if (this.timeRangeFrom == null || this.timeRangeTo == null)
        return 0;

    double expectedCount = 0;

    switch (this.timestampAggregation) {
    case Calendar.SECOND:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / 1000);
        break;
    case Calendar.MINUTE:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60));
        break;
    case Calendar.HOUR:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60));
        break;
    case Calendar.DAY_OF_MONTH:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60 * 24));
        break;
    case Calendar.MONTH:
        expectedCount = Math.floor((this.timeRangeTo - this.timeRangeFrom) / (1000 * 60 * 60 * 24 * 30));
        break;
    }

    return expectedCount;
}

From source file:com.frey.repo.DateUtil.java

/**
 * ??2009-8-7/* w w w.j a  v a 2  s .  c o  m*/
 */
public static String yesterdayDate3() {

    Calendar cal = Calendar.getInstance();
    cal.setTime(new Date());
    cal.set(Calendar.HOUR, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.DATE, cal.get(Calendar.DATE) - 1);
    return convertDate2String4(cal.getTime());
}

From source file:com.taobao.itest.util.DateConverter.java

/**
 * get GMT Time/* w  w  w  .j  av a 2  s.  c o  m*/
 * 
 * @param calendar
 * @return
 */
public Date getGmtDate(Long time) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time);
    int offset = calendar.get(Calendar.ZONE_OFFSET) / 3600000 + calendar.get(Calendar.DST_OFFSET) / 3600000;
    calendar.add(Calendar.HOUR, -offset);
    Date date = calendar.getTime();

    return date;
}

From source file:edu.wisc.my.stats.query.support.UWDataWareHouseInformationProvider.java

public long getTimeStamp(ResultSet rs, TimeResolution resolution) throws SQLException {
    final Calendar timeStampCal = Calendar.getInstance();
    timeStampCal.clear();/*from   ww w  .  j  av  a2s.  c om*/

    switch (resolution) {
    case MINUTE:
        final int minutes = rs.getInt("MINUTE");
        timeStampCal.set(Calendar.MINUTE, minutes);
    case FIVE_MINUTE:
        if (!timeStampCal.isSet(Calendar.MINUTE)) {
            final int fiveMinutes = rs.getInt("FIVE_MINUTE_INCREMENT");
            timeStampCal.set(Calendar.MINUTE, (fiveMinutes - 1) * 5);
        }
    case HOUR:
        final int hours = rs.getInt("HOUR");
        timeStampCal.set(Calendar.HOUR, hours);
    case DAY:
        final int days = rs.getInt("CALENDAR_DAY_NUMBER");
        timeStampCal.set(Calendar.DAY_OF_MONTH, days);
    case WEEK:
        final int week = rs.getInt("CALENDAR_WEEK_NUMBER");
        timeStampCal.set(Calendar.WEEK_OF_YEAR, week);
    case MONTH:
        final int months = rs.getInt("CALENDAR_MONTH_NUMBER");
        timeStampCal.set(Calendar.MONTH, months - 1); //Dang 0 based months
    case YEAR:
        final int years = rs.getInt("CALENDAR_YEAR_NUMBER");
        timeStampCal.set(Calendar.YEAR, years);
    }

    return timeStampCal.getTimeInMillis();
}

From source file:org.flowable.rest.service.api.runtime.TaskCollectionResourceTest.java

/**
 * Test getting a collection of tasks. GET runtime/tasks
 *//*from ww w . j a  v  a 2 s  . c om*/
@Deployment
public void testGetTasks() throws Exception {
    try {
        Calendar adhocTaskCreate = Calendar.getInstance();
        adhocTaskCreate.set(Calendar.MILLISECOND, 0);

        Calendar processTaskCreate = Calendar.getInstance();
        processTaskCreate.add(Calendar.HOUR, 2);
        processTaskCreate.set(Calendar.MILLISECOND, 0);

        Calendar inBetweenTaskCreation = Calendar.getInstance();
        inBetweenTaskCreation.add(Calendar.HOUR, 1);

        processEngineConfiguration.getClock().setCurrentTime(adhocTaskCreate.getTime());
        Task adhocTask = taskService.newTask();
        adhocTask.setAssignee("gonzo");
        adhocTask.setOwner("owner");
        adhocTask.setDelegationState(DelegationState.PENDING);
        adhocTask.setDescription("Description one");
        adhocTask.setName("Name one");
        adhocTask.setDueDate(adhocTaskCreate.getTime());
        adhocTask.setPriority(100);
        adhocTask.setCategory("some-category");
        taskService.saveTask(adhocTask);
        taskService.addUserIdentityLink(adhocTask.getId(), "misspiggy", IdentityLinkType.PARTICIPANT);

        processEngineConfiguration.getClock().setCurrentTime(processTaskCreate.getTime());
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("oneTaskProcess",
                "myBusinessKey");
        Task processTask = taskService.createTaskQuery().processInstanceId(processInstance.getId())
                .singleResult();
        processTask.setParentTaskId(adhocTask.getId());
        processTask.setPriority(50);
        processTask.setDueDate(processTaskCreate.getTime());
        taskService.saveTask(processTask);
        runtimeService.setVariable(processInstance.getId(), "variable", "globaltest");
        taskService.setVariableLocal(processTask.getId(), "localVariable", "localtest");

        // Check filter-less to fetch all tasks
        String url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION);
        assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId());

        // Name filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?name=" + encode("Name one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Name like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?nameLike=" + encode("%one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Description filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description="
                + encode("Description one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?description="
                + encode("Description two");
        assertEmptyResultsPresentInDataResponse(url);

        // Description like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike="
                + encode("%one");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?descriptionLike="
                + encode("%two");
        assertEmptyResultsPresentInDataResponse(url);

        // Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?priority=100";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Mininmum Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?minimumPriority=70";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Maximum Priority filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?maximumPriority=70";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Owner filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=owner";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?owner=kermit";
        assertEmptyResultsPresentInDataResponse(url);

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike=" + encode("%ner");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?ownerLike="
                + encode("kerm%");
        assertEmptyResultsPresentInDataResponse(url);

        // Assignee filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=gonzo";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assignee=kermit";
        assertEmptyResultsPresentInDataResponse(url);

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike="
                + encode("gon%");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?assigneeLike="
                + encode("kerm%");
        assertEmptyResultsPresentInDataResponse(url);

        // Unassigned filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?unassigned=true";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Delegation state filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?delegationState=pending";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Candidate user filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateUser=kermit";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Candidate group filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?candidateGroup=sales";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Involved user filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?involvedUser=misspiggy";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Process instance filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processInstanceId="
                + processInstance.getId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Execution filtering
        Execution taskExecution = runtimeService.createExecutionQuery().activityId("processTask")
                .singleResult();
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?executionId="
                + taskExecution.getId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Process instance businesskey filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?processInstanceBusinessKey=myBusinessKey";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // CreatedOn filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdOn="
                + getISODateString(adhocTaskCreate.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // CreatedAfter filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdAfter="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, processTask.getId());

        // CreatedBefore filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?createdBefore="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Subtask exclusion
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?excludeSubTasks=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Task definition key filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?taskDefinitionKey=processTask";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Task definition key like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?taskDefinitionKeyLike="
                + encode("process%");
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Duedate filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueDate="
                + getISODateString(adhocTaskCreate.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Due after filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueAfter="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Due before filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?dueBefore="
                + getISODateString(inBetweenTaskCreation.getTime());
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Without tenantId filtering before tenant set
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId(), processTask.getId());

        // Process definition
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionKey="
                + processInstance.getProcessDefinitionKey();
        assertResultsPresentInDataResponse(url, processTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?processDefinitionId="
                + processInstance.getProcessDefinitionId();
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Set tenant on deployment
        managementService.executeCommand(new ChangeDeploymentTenantIdCmd(deploymentId, "myTenant"));

        // Without tenantId filtering after tenant set, only adhoc task
        // should remain
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?withoutTenantId=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Tenant id filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantId=myTenant";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Tenant id like filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?tenantIdLike="
                + encode("%enant");
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Category filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?category="
                + encode("some-category");
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        // Suspend process-instance to have a suspended task
        runtimeService.suspendProcessInstanceById(processInstance.getId());

        // Suspended filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=false";
        assertResultsPresentInDataResponse(url, processTask.getId());

        // Active filtering
        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION) + "?active=true";
        assertResultsPresentInDataResponse(url, adhocTask.getId());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?includeTaskLocalVariables=true";
        CloseableHttpResponse response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

        // Check status and size
        JsonNode dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
        closeResponse(response);
        Assert.assertEquals(2, dataNode.size());

        Map<String, JsonNode> taskNodeMap = new HashMap<>();
        for (JsonNode taskNode : dataNode) {
            taskNodeMap.put(taskNode.get("id").asText(), taskNode);
        }

        Assert.assertTrue(taskNodeMap.containsKey(processTask.getId()));
        JsonNode processTaskNode = taskNodeMap.get(processTask.getId());
        JsonNode variablesNode = processTaskNode.get("variables");
        assertEquals(1, variablesNode.size());
        JsonNode variableNode = variablesNode.get(0);
        assertEquals("localVariable", variableNode.get("name").asText());
        assertEquals("local", variableNode.get("scope").asText());
        assertEquals("localtest", variableNode.get("value").asText());

        url = RestUrls.createRelativeResourceUrl(RestUrls.URL_TASK_COLLECTION)
                + "?includeTaskLocalVariables=true&includeProcessVariables=true";
        response = executeRequest(new HttpGet(SERVER_URL_PREFIX + url), HttpStatus.SC_OK);

        // Check status and size
        dataNode = objectMapper.readTree(response.getEntity().getContent()).get("data");
        closeResponse(response);
        Assert.assertEquals(2, dataNode.size());

        taskNodeMap = new HashMap<>();
        for (JsonNode taskNode : dataNode) {
            taskNodeMap.put(taskNode.get("id").asText(), taskNode);
        }

        Assert.assertTrue(taskNodeMap.containsKey(processTask.getId()));
        processTaskNode = taskNodeMap.get(processTask.getId());
        variablesNode = processTaskNode.get("variables");
        assertEquals(2, variablesNode.size());
        Map<String, JsonNode> variableMap = new HashMap<>();
        for (JsonNode variableResponseNode : variablesNode) {
            variableMap.put(variableResponseNode.get("name").asText(), variableResponseNode);
        }

        variableNode = variableMap.get("localVariable");
        assertEquals("localVariable", variableNode.get("name").asText());
        assertEquals("local", variableNode.get("scope").asText());
        assertEquals("localtest", variableNode.get("value").asText());

        variableNode = variableMap.get("variable");
        assertEquals("variable", variableNode.get("name").asText());
        assertEquals("global", variableNode.get("scope").asText());
        assertEquals("globaltest", variableNode.get("value").asText());

    } finally {
        // Clean adhoc-tasks even if test fails
        List<Task> tasks = taskService.createTaskQuery().list();
        for (Task task : tasks) {
            if (task.getExecutionId() == null) {
                taskService.deleteTask(task.getId(), true);
            }
        }
    }
}

From source file:no.met.jtimeseries.MeteogramWrapper.java

/**
 * Get the nearest full hour where UTC hour % snapTo == 0
 * @param date Date to adapt/*from   w ww.  j  av a 2 s .co  m*/
 * @param snapTo Hour to snap to
 * @return
 */
private static Date adapt(Date date, int snapTo) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
    cal.setTime(date);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    int offset = (snapTo - (cal.get(Calendar.HOUR) % snapTo));
    cal.add(Calendar.HOUR, offset);

    return cal.getTime();
}

From source file:com.glaf.core.util.CalendarUtils.java

/**
 * ??//from  w w w . j  ava  2 s . c  om
 * 
 * @return
 */
public static Date getWorkDate(Date date) {
    initWorkDayEnv();
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);

    int nowtime = cal.get(Calendar.HOUR) * 100 + cal.get(Calendar.MINUTE);
    if (startTime > endTime) { // ? 23:30 ~ 13:30
        switch (mode) {
        case 0: // 0?
            break;
        case 1: // 1??
            if (nowtime > startTime && nowtime <= 2359)
                date = getDateAfter(date, 1);
            break;
        }
    } else { // ? 7:30 ~ 16:30
        switch (mode) {
        case 0: // 0?
            if (nowtime >= 0 && nowtime < startTime)
                date = getDateBefore(date, 1);
            break;
        case 1: // 1??
            break;
        }
    }
    return date;
}