Example usage for java.util Date setTime

List of usage examples for java.util Date setTime

Introduction

In this page you can find the example usage for java.util Date setTime.

Prototype

public void setTime(long time) 

Source Link

Document

Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT.

Usage

From source file:org.codice.alliance.nsili.client.NsiliClient.java

public void testStandingQueryMgr(ORB orb, POA poa, Query query) throws Exception {
    if (standingQueryMgr != null) {
        System.out.println("----------------------");
        System.out.println("Standing Query Manager Test");

        if (standingQueryMgr != null) {
            Event[] events = standingQueryMgr.get_event_descriptions();
            if (events != null) {
                for (Event event : events) {
                    NamedEventType namedEventType = event.event_type;
                    System.out.println("Event: " + event.event_type.value() + " name: " + event.event_name
                            + " desc: " + event.event_description);
                }//from  ww  w  . j a v a  2 s  .c o  m
            }
        }

        LifeEvent start = new LifeEvent();
        java.util.Date startDate = new java.util.Date();
        start.at(ResultDAGConverter.getAbsTime(startDate));

        LifeEvent end = new LifeEvent();
        long endTime = System.currentTimeMillis() + ONE_YEAR;
        java.util.Date endDate = new java.util.Date();
        endDate.setTime(endTime);
        end.at(ResultDAGConverter.getAbsTime(endDate));

        LifeEvent[] frequency = new LifeEvent[1];
        LifeEvent freqOne = new LifeEvent();
        Time time = new Time((short) 0, (short) 0, 30.0f);
        freqOne.rt(time);
        frequency[0] = freqOne;
        QueryLifeSpan queryLifeSpan = new QueryLifeSpan(start, end, frequency);

        NameValue[] props = new NameValue[0];

        String callbackId = UUID.randomUUID().toString();

        try {
            standingQueryRequest = standingQueryMgr.submit_standing_query(query, getResultAttributes(),
                    getSortableAttributes(), queryLifeSpan, props);

            standingQueryRequest.set_user_info("Alliance");
            standingQueryRequest.set_number_of_hits(200);

            TestNsiliStandingQueryCallback nsiliCallback = new TestNsiliStandingQueryCallback(
                    standingQueryRequest);

            try {
                poa.activate_object_with_id(callbackId.getBytes(Charset.forName(ENCODING)), nsiliCallback);
            } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
                System.err.println("order : Unable to activate callback object, already active.");
            }

            org.omg.CORBA.Object obj = poa.create_reference_with_id(
                    callbackId.getBytes(Charset.forName(ENCODING)), CallbackHelper.id());

            Callback callback = CallbackHelper.narrow(obj);

            String standingQueryCallbackId = standingQueryRequest.register_callback(callback);
            nsiliCallback.setCallbackID(standingQueryCallbackId);
            standingQueryCallbacks.add(nsiliCallback);

            System.out.println("Registered NSILI Callback: " + standingQueryCallbackId);

        } catch (Exception e) {
            System.err.println(
                    "Error submitting standing query: " + NsilCorbaExceptionUtil.getExceptionDetails(e));
            e.printStackTrace(System.err);
            throw (e);
        }

        System.out.println("Standing Query Submitted");
    }
}

From source file:org.xwiki.contrib.mailarchive.timeline.internal.TimeLineGenerator.java

/**
 * {@inheritDoc}/*from   ww  w. ja  va  2 s.c  o  m*/
 * 
 * @see org.xwiki.contrib.mailarchive.timeline.ITimeLineGenerator#compute()
 */
@Override
public String compute(int maxItems) {
    try {
        config.reloadConfiguration();
    } catch (MailArchiveException e) {
        logger.error("Could not load mail archive configuration", e);
        return null;
    }
    Map<String, IMailingList> mailingLists = config.getMailingLists();
    Map<String, IType> types = config.getMailTypes();

    try {
        this.userStatsUrl = xwiki.getDocument(docResolver.resolve("MailArchive.ViewUserMessages"), context)
                .getURL("view", context);
    } catch (XWikiException e1) {
        logger.warn("Could not retrieve user stats url {}", ExceptionUtils.getRootCauseMessage(e1));
    }

    TreeMap<Long, TimeLineEvent> sortedEvents = new TreeMap<Long, TimeLineEvent>();

    // Set loading user in context (for rights)
    String loadingUser = config.getLoadingUser();
    context.setUserReference(docResolver.resolve(loadingUser));

    try {
        // Search topics
        String xwql = "select doc.fullName, topic.author, topic.subject, topic.topicid, topic.startdate, topic.lastupdatedate from Document doc, doc.object("
                + XWikiPersistence.CLASS_TOPICS + ") as topic order by topic.lastupdatedate desc";
        List<Object[]> result = queryManager.createQuery(xwql, Query.XWQL).setLimit(maxItems).execute();

        for (Object[] item : result) {
            XWikiDocument doc = null;
            try {
                String docurl = (String) item[0];
                String author = (String) item[1];
                String subject = (String) item[2];
                String topicId = (String) item[3];
                Date date = (Date) item[4];
                Date end = (Date) item[5];

                String action = "";

                // Retrieve associated emails
                TreeMap<Long, TopicEventBubble> emails = getTopicMails(topicId, subject);

                if (emails == null || emails.isEmpty()) {
                    // Invalid topic, not emails attached, do not show it
                    logger.warn("Invalid topic, no emails attached " + doc);
                } else {
                    if (date != null && end != null && date.equals(end)) {
                        // Add 10 min just to see the tape
                        end.setTime(end.getTime() + 600000);
                    }

                    doc = xwiki.getDocument(docResolver.resolve(docurl), context);
                    final List<String> tagsList = doc.getTagsList(context);
                    List<String> topicTypes = doc.getListValue(XWikiPersistence.CLASS_TOPICS, "type");

                    // Email type icon
                    List<String> icons = new ArrayList<String>();
                    for (String topicType : topicTypes) {
                        IType type = types.get(topicType);
                        if (type != null && !StringUtils.isEmpty(type.getIcon())) {
                            icons.add(xwiki.getSkinFile("icons/silk/" + type.getIcon() + ".png", context));
                            // http://localhost:8080/xwiki/skins/colibri/icons/silk/bell
                            // http://localhost:8080/xwiki/resources/icons/silk/bell.png

                        }
                    }

                    // Author and avatar
                    final IMAUser wikiUser = mailUtils.parseUser(author, config.isMatchLdap());
                    final String authorAvatar = getAuthorAvatar(wikiUser.getWikiProfile());

                    final TimeLineEvent timelineEvent = new TimeLineEvent();
                    TimeLineEvent additionalEvent = null;
                    timelineEvent.beginDate = date;
                    timelineEvent.title = subject;
                    timelineEvent.icons = icons;
                    timelineEvent.lists = doc.getListValue(XWikiPersistence.CLASS_TOPICS, "list");
                    timelineEvent.author = wikiUser.getDisplayName();
                    timelineEvent.authorAvatar = authorAvatar;
                    timelineEvent.extract = getExtract(topicId);

                    if (emails.size() == 1) {
                        logger.debug("Adding instant event for email '" + subject + "'");
                        // Unique email, we show a punctual email event
                        timelineEvent.url = emails.firstEntry().getValue().link;
                        timelineEvent.action = "New Email ";

                    } else {
                        // For email with specific type icon, and a duration, both a band and a point should be added (so 2 events)
                        // because no icon is displayed for duration events.
                        if (CollectionUtils.isNotEmpty(icons)) {
                            logger.debug(
                                    "Adding additional instant event to display type icon for first email in topic");
                            additionalEvent = new TimeLineEvent(timelineEvent);
                            additionalEvent.url = emails.firstEntry().getValue().link;
                            additionalEvent.action = "New Email ";
                        }

                        // Email thread, we show a topic event (a range)
                        logger.debug("Adding duration event for topic '" + subject + "'");
                        timelineEvent.endDate = end;
                        timelineEvent.url = doc.getURL("view", context);
                        timelineEvent.action = "New Topic ";
                        timelineEvent.messages = emails;
                    }

                    // Add the generated Event to the list
                    if (sortedEvents.containsKey(date.getTime())) {
                        // Avoid having more than 1 event at exactly the same time, because some timeline don't like it
                        date.setTime(date.getTime() + 1);
                    }
                    sortedEvents.put(date.getTime(), timelineEvent);
                    if (additionalEvent != null) {
                        sortedEvents.put(date.getTime() + 1, additionalEvent);
                    }
                }

            } catch (Throwable t) {
                logger.warn("Exception for " + doc, t);
            }

        }

    } catch (Throwable e) {
        logger.warn("could not compute timeline data", e);
    }

    return printEvents(sortedEvents);

}

From source file:utils.DBManager.java

public Group fillGroupById(int groupId, boolean users, boolean posts, boolean files) throws SQLException {
    Group ret = new Group();
    ret.setGroupid(groupId);/*from w ww. ja va2s . c o m*/

    String sql = "SELECT ownerid, groupname, creationdate, private FROM groups WHERE groupid=?";
    PreparedStatement stm = con.prepareStatement(sql);
    stm.setInt(1, groupId);
    ResultSet rs = stm.executeQuery();
    if (rs.next()) {
        ret.setOwner(rs.getInt(1));
        ret.setTitle(rs.getString(2));
        ret.setDate(rs.getDate(3));
        ret.setPriva(rs.getInt(4) % 2 == 0);
    }

    if (users) {
        ret.setUsers(this.getMembers(groupId));
    }

    if (posts) {
        ret.setPosts(this.getAllPost(groupId));

        sql = "SELECT date FROM post WHERE groupid=? ORDER BY date LIMIT 1";
        stm = con.prepareStatement(sql);
        stm.setInt(1, groupId);
        rs = stm.executeQuery();
        if (rs.next()) {
            Date d = new Date();
            d.setTime(Long.parseLong(rs.getString(1)));
            ret.setLastPostDate(d);
        }
    }

    if (files) {
        ArrayList<String> file = new ArrayList();
        ArrayList<Post> pstal = this.getAllPost(groupId);
        for (Post post : pstal) {
            file.addAll(this.getAllFileInPost(post.getPostid()));
        }
        ret.setAllFiles(file);
    }
    rs.close();
    stm.close();

    return ret;
}

From source file:org.openconcerto.task.TodoListPanel.java

void initPopUp() {
    TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() {

        @Override//from   www . j ava2  s.com
        public JPopupMenu transformChecked(MouseEvent evt) {
            final JTable table = (JTable) evt.getSource();
            final int modelIndex = TodoListPanel.this.sorter.modelIndex(table.getSelectedRow());
            final JPopupMenu res = new JPopupMenu();

            // Avancer d'un jour
            Action act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        final Date ts = element.getExpectedDate();
                        final Calendar cal = Calendar.getInstance();
                        cal.setTimeInMillis(ts.getTime());
                        cal.add(Calendar.DAY_OF_YEAR, 1);
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                ts.setTime(cal.getTimeInMillis());
                                element.setExpectedDate(ts);
                                element.commitChangesAndWait();
                                table.repaint();
                            }
                        });
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("moveOneDay"));
            res.add(act);

            // Marquer comme ralis
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
                    if (element != null) {
                        element.setDone(true);
                        element.commitChangesAndWait();
                        table.repaint();
                    }
                }
            };
            act.putValue(Action.NAME, TM.tr("markDone"));
            res.add(act);

            // Suppression
            act = new AbstractAction() {
                public void actionPerformed(ActionEvent e) {
                    TodoListPanel.this.model.deleteTaskAtIndex(modelIndex);
                    table.repaint();
                }
            };
            act.putValue(Action.NAME, TM.tr("delete"));
            res.add(act);

            final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex);
            SQLRowValues rowTache = element.getRowValues();

            List<AbstractAction> actions = TacheActionManager.getInstance().getActionsForTaskRow(rowTache);

            for (AbstractAction abstractAction : actions) {
                res.add(abstractAction);
            }

            return res;
        }
    });
}

From source file:netflow.DatabaseProxy.java

public java.util.Date getMaxDate() {
    java.util.Date result = null;
    String sql = getQuery("max.date.get");
    try {//from  w ww  . j  ava 2 s  . c om
        PreparedStatement pstmt = con.prepareStatement(sql);
        result = doWithStatement(pstmt, new ResultSetProcessor<Date>() {
            @Override
            public Date process(ResultSet rs) throws SQLException {
                java.util.Date result = null;
                if (rs.next()) {
                    Timestamp t = rs.getTimestamp(1);
                    if (t != null) {
                        result = new java.util.Date();
                        result.setTime(t.getTime());
                    }
                }
                return result;
            }
        });
    } catch (SQLException e) {
        log.error(e);
        e.printStackTrace();
    }
    return result;
}

From source file:org.etudes.mneme.impl.QuestionServiceImpl.java

/**
 * {@inheritDoc}// w w  w.  j av a2s.c  om
 */
public void clearStaleMintQuestions() {
    if (M_log.isDebugEnabled())
        M_log.debug("clearStaleMintQuestions");

    // give it a day
    Date stale = new Date();
    stale.setTime(stale.getTime() - (1000l * 60l * 60l * 24l));

    List<String> ids = this.storage.clearStaleMintQuestions(stale);

    // generate events for any deleted
    for (String id : ids) {
        eventTrackingService.post(
                eventTrackingService.newEvent(MnemeService.QUESTION_DELETE, getQuestionReference(id), true));
    }
}

From source file:org.sakaiproject.evaluation.beans.EvalBeanUtils.java

/**
 * Sets all the system defaults for this evaluation object
 * and ensures all required fields are correctly set,
 * use this whenever you create a new evaluation <br/>
 * This is guaranteed to be non-destructive (i.e. it will not replace existing values
 * but it will fixup any required fields which are nulls to default values),
 * will force null due date to be non-null but will respect the {@link EvalEvaluation#useDueDate} flag
 * //from www .  j  a  v a2  s  .com
 * @param eval an {@link EvalEvaluation} object (can be persisted or new)
 * @param evaluationType a type constant of EvalConstants#EVALUATION_TYPE_*,
 * if left null then {@link EvalConstants#EVALUATION_TYPE_EVALUATION} is used
 */
public void setEvaluationDefaults(EvalEvaluation eval, String evaluationType) {

    // set the type to the default to ensure not null
    if (eval.getType() == null) {
        eval.setType(EvalConstants.EVALUATION_TYPE_EVALUATION);
    }

    // set to the supplied type if supplied and do any special settings if needed based on the type
    if (evaluationType != null) {
        eval.setType(evaluationType);
    }

    // only do these for new evals
    if (eval.getId() == null) {
        if (eval.getState() == null) {
            eval.setState(EvalConstants.EVALUATION_STATE_PARTIAL);
        }
    }

    // make sure the dates are set
    Calendar calendar = new GregorianCalendar();
    Date now = new Date();

    // if default start hour is set, use it for start time (must be tomorrow as eval cannot start in the past).
    Integer hour = (Integer) settings.get(EvalSettings.EVAL_DEFAULT_START_HOUR);
    if (hour != null) {
        // add 1 day to make it tomorrow
        now.setTime(now.getTime() + 86400000L);
        // set desired hour
        now.setHours(hour);
        now.setMinutes(0);
        now.setSeconds(0);
    }

    calendar.setTime(now);
    if (eval.getStartDate() == null) {
        eval.setStartDate(now);
        LOG.debug("Setting start date to default of: " + eval.getStartDate());
    } else {
        calendar.setTime(eval.getStartDate());
    }

    if (eval.useDueDate != null && !eval.useDueDate) {
        // allow evals which are open forever
        eval.setDueDate(null);
        eval.setStopDate(null);
        eval.setViewDate(null);
    } else {
        // using the due date
        calendar.add(Calendar.DATE, 1); // +1 day
        if (eval.getDueDate() == null) {
            // default the due date to the end of the start date + 1 day
            Date endOfDay = EvalUtils.getEndOfDayDate(calendar.getTime());
            eval.setDueDate(endOfDay);
            LOG.debug("Setting due date to default of: " + eval.getDueDate());
        } else {
            calendar.setTime(eval.getDueDate());
        }

        boolean useStopDate;
        if (eval.useStopDate != null && !eval.useStopDate) {
            useStopDate = false;
        } else {
            useStopDate = (Boolean) settings.get(EvalSettings.EVAL_USE_STOP_DATE);
        }
        if (useStopDate) {
            // assign stop date to equal due date for now
            if (eval.getStopDate() == null) {
                eval.setStopDate(eval.getDueDate());
                LOG.debug("Setting stop date to default of: " + eval.getStopDate());
            }
        } else {
            eval.setStopDate(null);
        }

        boolean useViewDate;
        if (eval.useViewDate != null && !eval.useViewDate) {
            useViewDate = false;
        } else {
            useViewDate = (Boolean) settings.get(EvalSettings.EVAL_USE_VIEW_DATE);
        }
        if (useViewDate) {
            // assign default view date
            calendar.add(Calendar.DATE, 1);
            if (eval.getViewDate() == null) {
                // default the view date to the today + 2
                eval.setViewDate(calendar.getTime());
                LOG.debug("Setting view date to default of: " + eval.getViewDate());
            }
        } else {
            eval.setViewDate(null);
        }
    }

    // handle the view dates default
    Boolean useSameViewDates = (Boolean) settings.get(EvalSettings.EVAL_USE_SAME_VIEW_DATES);
    Date sharedDate = eval.getViewDate() == null ? eval.getDueDate() : eval.getViewDate();
    if (eval.getStudentsDate() == null || useSameViewDates) {
        eval.setStudentsDate(sharedDate);
    }
    if (eval.getInstructorsDate() == null || useSameViewDates) {
        eval.setInstructorsDate(sharedDate);
    }

    // results viewable settings
    Date studentsDate;
    Boolean studentsView = (Boolean) settings.get(EvalSettings.STUDENT_ALLOWED_VIEW_RESULTS);
    if (studentsView != null) {
        eval.setStudentViewResults(studentsView);
    }

    Date instructorsDate;
    Boolean instructorsView = (Boolean) settings.get(EvalSettings.INSTRUCTOR_ALLOWED_VIEW_RESULTS);
    if (instructorsView != null) {
        eval.setInstructorViewResults(instructorsView);
    }

    // Added by EVALSYS-1063. Modified by EVALSYS-1176.
    // Will modify the value of EvalEvaluation.instructorViewAllResults property iff current value is null.
    // Will use value of EvalSettings.INSTRUCTOR_ALLOWED_VIEW_ALL_RESULTS setting if available, false otherwise.
    Boolean instructorsAllView = eval.getInstructorViewAllResults();
    if (instructorsAllView == null) {
        Boolean instructorsAllViewSetting = (Boolean) settings
                .get(EvalSettings.INSTRUCTOR_ALLOWED_VIEW_ALL_RESULTS);
        if (instructorsAllViewSetting == null) {
            eval.setInstructorViewAllResults(Boolean.FALSE);
        } else {
            eval.setInstructorViewAllResults(instructorsAllViewSetting);
        }
    }

    // Section awareness default controlled by sakai.property
    if (eval.getSectionAwareness() == null || !eval.getSectionAwareness()) {
        eval.setSectionAwareness(EVALSYS_SECTION_AWARE_DEFAULT);
    }

    // Results sharing default controlled by sakai.property
    if (eval.getResultsSharing() == null) {
        if (!EvalConstants.SHARING_VISIBLE.equals(EVALSYS_RESULTS_SHARING_DEFAULT)
                && !EvalConstants.SHARING_PRIVATE.equals(EVALSYS_RESULTS_SHARING_DEFAULT)
                && !EvalConstants.SHARING_PUBLIC.equals(EVALSYS_RESULTS_SHARING_DEFAULT)) {
            eval.setResultsSharing(EvalConstants.SHARING_VISIBLE);
        } else {
            eval.setResultsSharing(EVALSYS_RESULTS_SHARING_DEFAULT);
        }
    }

    // Instructors view results default controlled by sakai.property
    if ((Boolean) eval.getInstructorViewResults() == null) {
        eval.setInstructorViewResults(EVALSYS_INSTRUCTOR_VIEW_RESPONSES_DEFAULT);
    }
    if (eval.getInstructorViewAllResults() == null) {
        eval.setInstructorViewAllResults(EVALSYS_INSTRUCTOR_VIEW_RESPONSES_DEFAULT);
    }

    if (EvalConstants.SHARING_PRIVATE.equals(eval.getResultsSharing())) {
        eval.setStudentViewResults(false);
        eval.setInstructorViewResults(false);
        eval.setInstructorViewAllResults(false);
    } else if (EvalConstants.SHARING_PUBLIC.equals(eval.getResultsSharing())) {
        eval.setStudentViewResults(true);
        eval.setInstructorViewResults(true);
        eval.setInstructorViewAllResults(true);
        studentsDate = eval.getViewDate();
        eval.setStudentsDate(studentsDate);
        instructorsDate = eval.getViewDate();
        eval.setInstructorsDate(instructorsDate);
    }

    // student completion settings
    if (eval.getBlankResponsesAllowed() == null) {
        Boolean blankAllowed = (Boolean) settings.get(EvalSettings.STUDENT_ALLOWED_LEAVE_UNANSWERED);
        if (blankAllowed == null) {
            blankAllowed = false;
        }
        eval.setBlankResponsesAllowed(blankAllowed);
    }

    if (eval.getModifyResponsesAllowed() == null) {
        Boolean modifyAllowed = (Boolean) settings.get(EvalSettings.STUDENT_MODIFY_RESPONSES);
        if (modifyAllowed == null) {
            modifyAllowed = false;
        }
        eval.setModifyResponsesAllowed(modifyAllowed);
    }

    if (eval.getUnregisteredAllowed() == null) {
        eval.setUnregisteredAllowed(Boolean.FALSE);
    }

    if (eval.getAllRolesParticipate() == null) {
        Boolean allRolesParticipate = (Boolean) settings.get(EvalSettings.ALLOW_ALL_SITE_ROLES_TO_RESPOND);
        if (allRolesParticipate == null) {
            allRolesParticipate = false;
        }
        eval.setAllRolesParticipate(allRolesParticipate);
    }

    // fix up the reminder days to the default
    if (eval.getReminderDays() == null) {
        Integer reminderDays = 1;
        Integer defaultReminderDays = (Integer) settings.get(EvalSettings.DEFAULT_EMAIL_REMINDER_FREQUENCY);
        if (defaultReminderDays != null) {
            reminderDays = defaultReminderDays;
        }
        eval.setReminderDays(reminderDays);
    }

    // set the reminder email address to the default
    if (eval.getReminderFromEmail() == null) {
        // email from address control
        String from = (String) settings.get(EvalSettings.FROM_EMAIL_ADDRESS);
        // https://bugs.caret.cam.ac.uk/browse/CTL-1525 - default to admin address if option set
        Boolean useAdminEmail = (Boolean) settings.get(EvalSettings.USE_ADMIN_AS_FROM_EMAIL);
        if (useAdminEmail) {
            // try to get the email address for the owner (eval admin)
            EvalUser owner = commonLogic.getEvalUserById(commonLogic.getCurrentUserId());
            if (owner != null && owner.email != null && !"".equals(owner.email)) {
                from = owner.email;
            }
        }
        eval.setReminderFromEmail(from);
    }

    // admin settings
    if (eval.getInstructorOpt() == null) {
        String instOpt = (String) settings.get(EvalSettings.INSTRUCTOR_MUST_USE_EVALS_FROM_ABOVE);
        if (instOpt == null) {
            instOpt = EvalConstants.INSTRUCTOR_REQUIRED;
        }
        eval.setInstructorOpt(instOpt);
    }
}

From source file:org.codice.alliance.nsili.client.SampleNsiliClient.java

public void testStandingQueryMgr() throws Exception {
    if (standingQueryMgr != null) {
        LOGGER.info("----------------------");
        LOGGER.info("Standing Query Manager Test");

        Event[] events = standingQueryMgr.get_event_descriptions();
        if (events != null) {
            Arrays.stream(events).forEach(event -> LOGGER.info("Event: {}\n Name: {}\n Desc: {}",
                    event.event_type.value(), event.event_name, event.event_description));
        }/*from w  w w.  ja  v a  2 s .  c  o m*/

        LifeEvent start = new LifeEvent();
        java.util.Date startDate = new java.util.Date();
        start.at(ResultDAGConverter.getAbsTime(startDate));

        LifeEvent end = new LifeEvent();
        final long ONE_YEAR_IN_MS = TimeUnit.DAYS.toMillis(365);
        long endTime = System.currentTimeMillis() + ONE_YEAR_IN_MS;
        java.util.Date endDate = new java.util.Date();
        endDate.setTime(endTime);
        end.at(ResultDAGConverter.getAbsTime(endDate));

        LifeEvent[] frequency = new LifeEvent[1];
        LifeEvent freqOne = new LifeEvent();
        Time time = new Time((short) 0, (short) 0, 30.0f);
        freqOne.rt(time);
        frequency[0] = freqOne;
        QueryLifeSpan queryLifeSpan = new QueryLifeSpan(start, end, frequency);

        NameValue[] props = new NameValue[0];

        String callbackId = UUID.randomUUID().toString();

        try {
            standingQueryRequest = standingQueryMgr.submit_standing_query(STANDING_ALL_QUERY,
                    getResultAttributes(), getSortableAttributes(), queryLifeSpan, props);

            standingQueryRequest.set_user_info(ALLIANCE);
            standingQueryRequest.set_number_of_hits(200);

            TestNsiliStandingQueryCallback nsiliCallback = new TestNsiliStandingQueryCallback(
                    standingQueryRequest);

            final String ENCODING = "ISO-8859-1";
            try {
                poa.activate_object_with_id(callbackId.getBytes(Charset.forName(ENCODING)), nsiliCallback);
            } catch (ServantAlreadyActive | ObjectAlreadyActive | WrongPolicy e) {
                LOGGER.error("Order : Unable to activate callback object, already active : {}",
                        NsilCorbaExceptionUtil.getExceptionDetails(e), e);
            }

            org.omg.CORBA.Object obj = poa.create_reference_with_id(
                    callbackId.getBytes(Charset.forName(ENCODING)), CallbackHelper.id());

            Callback callback = CallbackHelper.narrow(obj);

            String standingQueryCallbackId = standingQueryRequest.register_callback(callback);
            nsiliCallback.setCallbackID(standingQueryCallbackId);
            standingQueryCallbacks.add(nsiliCallback);

            LOGGER.info("Registered NSILI Callback: {}", standingQueryCallbackId);
            LOGGER.info("Standing Query Submitted");
        } catch (Exception e) {
            LOGGER.debug("Error submitting standing query: ", NsilCorbaExceptionUtil.getExceptionDetails(e));
            throw (e);
        }
    } else {
        LOGGER.info("StandingQueryMgr is not initialized, unable to test");
    }
}

From source file:org.yes.cart.shoppingcart.impl.DeliveryTimeEstimationVisitorImpl.java

protected void skipDatesExclusions(final CarrierSla sla, final Calendar date,
        final Map<Date, Date> exclusions) {

    if (!exclusions.isEmpty()) {

        final TreeSet<Date> startDates = new TreeSet<Date>(exclusions.keySet());

        while (true) {
            final Date thisDate = date.getTime();
            final Date beforeOfEqual = startDates.floor(thisDate);
            if (beforeOfEqual == null) {
                return; // no exclusions before
            } else if (beforeOfEqual.before(thisDate)) {
                final Date rangeEnd = exclusions.get(beforeOfEqual);
                // Two cases here:
                // 1) Single date - same as beforeOfEqual
                // 2) Range - need to make sure it is before this date
                if (thisDate.after(rangeEnd)) {
                    return; // This date is after the min in exclusions
                } else {
                    thisDate.setTime(rangeEnd.getTime());
                    date.add(Calendar.DAY_OF_YEAR, 1);
                    skipWeekdayExclusions(sla, date);
                }//from  w w  w. jav  a2s .com
            } else {
                // equal, so need to move next day and check weekdays
                date.add(Calendar.DAY_OF_YEAR, 1);
                skipWeekdayExclusions(sla, date);
            }
        }

    }

}

From source file:com.markuspage.android.atimetracker.Tasks.java

private String getRangeName() {
    if (adapter.currentRangeStart == -1) {
        return "all";
    }//from   w w  w.  ja v a 2 s .  co  m
    SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd");
    Date d = new Date();
    d.setTime(adapter.currentRangeStart);
    return f.format(d);
}