Java Code Examples for javax.xml.datatype.Duration#addTo()

The following examples show how to use javax.xml.datatype.Duration#addTo() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BirtDuration.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
protected Object getValue( Object[] args ) throws BirtException
{
	Duration duration;
	Date date;
	try
	{
		duration = DatatypeFactory.newInstance( )
				.newDuration( args[0].toString( ) );
		date = DataTypeUtil.toDate( args[1] );
	}
	catch ( DatatypeConfigurationException e )
	{
		throw new IllegalArgumentException( Messages.getFormattedString( "error.BirtDuration.literal.invalidArgument",
				args ) );
	}
	duration.addTo( date );
	return date;
}
 
Example 2
Source File: ConfiguredObjectExpressionFactory.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Override
ConfiguredObjectExpression asExpression (final List<Expression> args)
{
    if (args == null || args.size() != 2)
    {
        throw new IllegalArgumentException(DATE_ADD.name() + " requires two arguments.");
    }

    return new ConfiguredObjectExpression()
    {
        @Override
        public Object evaluate(final ConfiguredObject<?> object)
        {
            Object date = args.get(0).evaluate(object);
            Object period = args.get(1).evaluate(object);
            if (!(date instanceof Date) || !(period instanceof String))
            {
                throw new IllegalArgumentException(String.format("%s requires a (Date, String) not a"
                                                                 + " (%s,%s)",
                                                                 DATE_ADD,
                                                                 date.getClass().getSimpleName(),
                                                                 period.getClass().getSimpleName()));
            }
            try
            {
                Date copy = new Date(((Date) date).getTime());
                final Duration duration = DATATYPE_FACTORY.newDuration((String) period);
                duration.addTo(copy);
                return copy;
            }
            catch (IllegalArgumentException e)
            {
                throw new IllegalArgumentException(DATE_ADD + " requires an ISO-8601 format duration.", e);
            }
        }
    };
}
 
Example 3
Source File: AdvancedBusinessCalendar.java    From lemon with Apache License 2.0 5 votes vote down vote up
public Date add(Date date, Duration duration, boolean useBusinessTime) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(date);

    if (!useBusinessTime) {
        duration.addTo(calendar);

        return calendar.getTime();
    }

    // TODO: tenantId
    return workCalendarConnector.add(date, duration, "1");
}
 
Example 4
Source File: DurationUtil.java    From lemon with Apache License 2.0 5 votes vote down vote up
private Date add(Date date, Duration duration) {
    if (!useBusinessTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        duration.addTo(calendar);

        return calendar.getTime();
    }

    return businessCalendar.add(date, duration, useBusinessTime);
}
 
Example 5
Source File: DeadlineHumanTaskListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(TaskInfo taskInfo) {
    String taskDefinitionKey = taskInfo.getCode();

    String processDefinitionId = taskInfo.getProcessDefinitionId();
    List<DeadlineDTO> deadlines = taskDefinitionConnector.findDeadlines(
            taskDefinitionKey, processDefinitionId);

    for (DeadlineDTO deadline : deadlines) {
        try {
            String durationText = deadline.getDuration();

            Date now = new Date();
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(now);

            DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
            Duration duration = datatypeFactory.newDuration(durationText);
            duration.addTo(calendar);

            Date deadlineTime = calendar.getTime();
            TaskDeadline taskDeadline = new TaskDeadline();
            taskDeadline.setTaskInfo(taskInfo);
            taskDeadline.setType(deadline.getType());
            taskDeadline.setDeadlineTime(deadlineTime);
            taskDeadline
                    .setNotificationType(deadline.getNotificationType());
            taskDeadline.setNotificationTemplateCode(deadline
                    .getNotificationTemplateCode());
            taskDeadline.setNotificationReceiver(deadline
                    .getNotificationReceiver());
            taskDeadlineManager.save(taskDeadline);
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
Example 6
Source File: TimeoutNotice.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void processTimeout(DelegateTask delegateTask,
        BpmConfNotice bpmConfNotice) {
    try {
        Date dueDate = delegateTask.getDueDate();
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(dueDate);

        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        Duration duration = datatypeFactory.newDuration("-"
                + bpmConfNotice.getDueDate());
        duration.addTo(calendar);

        Date noticeDate = calendar.getTime();
        Date now = new Date();

        if ((now.getTime() < noticeDate.getTime())
                && ((noticeDate.getTime() - now.getTime()) < (60 * 1000))) {
            UserConnector userConnector = ApplicationContextHelper
                    .getBean(UserConnector.class);
            NotificationConnector notificationConnector = ApplicationContextHelper
                    .getBean(NotificationConnector.class);

            //
            Map<String, Object> data = new HashMap<String, Object>();
            TaskEntity taskEntity = new TaskEntity();
            taskEntity.setId(delegateTask.getId());
            taskEntity.setName(delegateTask.getName());
            taskEntity.setAssigneeWithoutCascade(userConnector.findById(
                    delegateTask.getAssignee()).getDisplayName());
            taskEntity.setVariableLocal("initiator",
                    getInitiator(userConnector, delegateTask));
            //
            data.put("task", taskEntity);
            data.put("initiator",
                    this.getInitiator(userConnector, delegateTask));

            String receiver = bpmConfNotice.getReceiver();

            /*
             * BpmMailTemplate bpmMailTemplate = bpmConfNotice .getBpmMailTemplate(); ExpressionManager
             * expressionManager = Context .getProcessEngineConfiguration().getExpressionManager();
             */
            UserDTO userDto = null;

            if ("任务接收人".equals(receiver)) {
                userDto = userConnector
                        .findById(delegateTask.getAssignee());
            } else if ("流程发起人".equals(receiver)) {
                userDto = userConnector.findById((String) delegateTask
                        .getVariables().get("initiator"));
            } else {
                HistoricProcessInstanceEntity historicProcessInstanceEntity = Context
                        .getCommandContext()
                        .getHistoricProcessInstanceEntityManager()
                        .findHistoricProcessInstance(
                                delegateTask.getProcessInstanceId());
                userDto = userConnector
                        .findById(historicProcessInstanceEntity
                                .getStartUserId());
            }

            /*
             * String subject = expressionManager .createExpression(bpmMailTemplate.getSubject())
             * .getValue(taskEntity).toString();
             * 
             * String content = expressionManager .createExpression(bpmMailTemplate.getContent())
             * .getValue(taskEntity).toString();
             * 
             * this.sendMail(userDto, subject, content); this.sendSiteMessage(userDto, subject, content);
             */
            NotificationDTO notificationDto = new NotificationDTO();
            notificationDto.setReceiver(userDto.getId());
            notificationDto.setReceiverType("userid");
            notificationDto.setTypes(Arrays.asList(bpmConfNotice
                    .getNotificationType().split(",")));
            notificationDto.setData(data);
            notificationDto.setTemplate(bpmConfNotice.getTemplateCode());

            notificationConnector.send(notificationDto,
                    delegateTask.getTenantId());
        }
    } catch (Exception ex) {
        logger.error(ex.getMessage(), ex);
    }
}
 
Example 7
Source File: MockWorkCalendarConnector.java    From lemon with Apache License 2.0 4 votes vote down vote up
public Date add(Date date, Duration duration, String tenantId) {
    duration.addTo(date);

    return date;
}
 
Example 8
Source File: DurationHelper.java    From camunda-bpm-platform with Apache License 2.0 4 votes vote down vote up
private Date add(Date date, Duration duration) {
  Calendar calendar = new GregorianCalendar();
  calendar.setTime(date);
  duration.addTo(calendar);
  return calendar.getTime();
}