Example usage for java.util GregorianCalendar getTime

List of usage examples for java.util GregorianCalendar getTime

Introduction

In this page you can find the example usage for java.util GregorianCalendar getTime.

Prototype

public final Date getTime() 

Source Link

Document

Returns a Date object representing this Calendar's time value (millisecond offset from the Epoch").

Usage

From source file:org.oscarehr.PMmodule.web.GenericIntakeEditAction.java

public ActionForward save_all(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String saveWhich) {
    GenericIntakeEditFormBean formBean = (GenericIntakeEditFormBean) form;
    LoggedInInfo loggedInInfo = LoggedInInfo.loggedInInfo.get();

    Intake intake = formBean.getIntake();
    String intakeType = intake.getType();
    Demographic client = formBean.getClient();
    String providerNo = getProviderNo(request);
    Integer nodeId = formBean.getNodeId();
    Integer oldId = null;//from  w ww. j a  v  a  2 s . c  o  m

    /* for repeating elements */
    String[] repeatSizes = request.getParameterValues("repeat_size");
    if (repeatSizes != null) {
        for (String rs : repeatSizes) {
            String[] vals = rs.split("-");
            String rNodeId = vals[0];
            String rSize = vals[1];
            intake.cleanRepeatingAnswers(Integer.parseInt(rNodeId), Integer.parseInt(rSize));
        }
    }
    try {
        try {
            GregorianCalendar cal = new GregorianCalendar(Integer.parseInt(request.getParameter("eff_year")),
                    Integer.parseInt(request.getParameter("eff_month")),
                    Integer.parseInt(request.getParameter("eff_day")));
            client.setEffDate(cal.getTime());
        } catch (Exception e) {
            LOG.debug("date parse exception on eff date", e);
            // that's fine ignore it, probably an invalid date or no date set.
        }

        String anonymous = StringUtils.trimToNull(request.getParameter("anonymous"));
        client.setAnonymous(anonymous);

        //check to see if HIN already exists in the system
        if (client.getDemographicNo() == null) {
            String hin = client.getHin();
            String hcType = client.getHcType();
            if (hin.length() > 0 && clientManager.checkHealthCardExists(hin, hcType)) {
                ActionMessages messages = new ActionMessages();
                messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("hin.duplicate"));
                saveErrors(request, messages);
                return mapping.findForward(EDIT);
            }
        }

        // save client information.
        saveClient(client, providerNo);

        // for RFQ:
        if (OscarProperties.getInstance().isTorontoRFQ()) {
            Integer clientId = client.getDemographicNo();
            if (clientId != null && !"".equals(clientId)) {
                oldId = getCurrentBedCommunityProgramId(client.getDemographicNo());

                // Save 'external' program for RFQ.
                admitExternalProgram(client.getDemographicNo(), providerNo,
                        formBean.getSelectedExternalProgramId());
            }
            // get and set intake location
            // client.setChildren(formBean.getProgramInDomainId());
            Integer intakeLocationId = 0;
            String intakeLocationStr = formBean.getProgramInDomainId();
            if (intakeLocationStr == null || "".equals(intakeLocationStr)) {
                Integer selectedBedCommunityProgramId = formBean.getSelectedBedCommunityProgramId();
                if ("RFQ_admit".equals(saveWhich)) {
                    if (programManager.isBedProgram(selectedBedCommunityProgramId.toString())) {
                        intakeLocationId = selectedBedCommunityProgramId;
                    } else {
                        if (formBean.getProgramInDomainId() != null
                                && formBean.getProgramInDomainId().trim().length() > 0)
                            intakeLocationId = Integer.valueOf(formBean.getProgramInDomainId());
                    }
                }
            } else {
                intakeLocationId = Integer.valueOf(intakeLocationStr);
            }

            intake.setIntakeLocation(intakeLocationId);
        }

        intake.setFacilityId(loggedInInfo.currentFacility.getId());

        String admissionText = null;
        String remoteReferralId = StringUtils.trimToNull(request.getParameter("remoteReferralId"));
        if (remoteReferralId != null) {
            admissionText = getAdmissionText(admissionText, remoteReferralId);
        }

        admitBedCommunityProgram(client.getDemographicNo(), providerNo,
                formBean.getSelectedBedCommunityProgramId(), saveWhich, admissionText);

        if (remoteReferralId != null) {
            // doing this after the admit is about as transactional as this is going to get for now.
            ReferralWs referralWs;
            try {
                referralWs = CaisiIntegratorManager.getReferralWs();
                referralWs.removeReferral(Integer.parseInt(remoteReferralId));
            } catch (Exception e) {
                LOG.error("Unexpected error", e);
            }
        }

        // if (!formBean.getSelectedServiceProgramIds().isEmpty() && "RFQ_admit".endsWith(saveWhich)) {
        //if (!formBean.getSelectedServiceProgramIds().isEmpty()) { //should be able to discharge from all service programs.
        admitServicePrograms(client.getDemographicNo(), providerNo, formBean.getSelectedServiceProgramIds(),
                null);
        //}

        if ("normal".equals(saveWhich) || "appointment".equals(saveWhich)) {
            // normal intake saving . eg. seaton house
            intake.setIntakeStatus("Signed");
            intake.setId(null);
            saveIntake(intake, client.getDemographicNo());
        } else if ("draft".equals(saveWhich)) {
            intake.setIntakeStatus("Draft");
            intake.setId(null);
            saveIntake(intake, client.getDemographicNo());
        } else {
            // RFQ intake saving...
            if ("RFQ_temp".equals(saveWhich)) {
                intake.setIntakeStatus("Unsigned");
                saveUpdateIntake(intake, client.getDemographicNo());
            } else if ("RFQ_admit".equals(saveWhich)) {
                intake.setIntakeStatus("Signed");
                intake.setId(null);
                saveIntake(intake, client.getDemographicNo());
            } else if ("RFQ_notAdmit".equals(saveWhich)) {
                intake.setIntakeStatus("Signed");
                intake.setId(null);
                saveIntake(intake, client.getDemographicNo());
            }
        }
    } catch (ProgramFullException e) {
        ActionMessages messages = new ActionMessages();
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admit.full"));
        saveErrors(request, messages);
    } catch (AdmissionException e) {
        MiscUtils.getLogger().error("Error", e);
        LOG.error("Error", e);

        ActionMessages messages = new ActionMessages();
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("message", e.getMessage()));
        saveErrors(request, messages);
    } catch (ServiceRestrictionException e) {
        ActionMessages messages = new ActionMessages();
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("admit.service_restricted",
                e.getRestriction().getComments(), e.getRestriction().getProvider().getFormattedName()));
        saveErrors(request, messages);
    }

    List<IntakeNodeJavascript> jsLocation = genericIntakeManager
            .getIntakeNodeJavascriptLocation(intake.getNode().getQuestionId());

    setBeanProperties(formBean, intake, client, providerNo,
            Agency.getLocalAgency().areHousingProgramsVisible(intakeType),
            Agency.getLocalAgency().areServiceProgramsVisible(intakeType),
            Agency.getLocalAgency().areExternalProgramsVisible(intakeType),
            getCurrentBedCommunityProgramId(client.getDemographicNo()),
            getCurrentServiceProgramIds(client.getDemographicNo()),
            getCurrentExternalProgramId(client.getDemographicNo()), loggedInInfo.currentFacility.getId(),
            nodeId, jsLocation);

    String oldBedProgramId = String.valueOf(getCurrentBedCommunityProgramId(client.getDemographicNo()));
    request.getSession().setAttribute("intakeCurrentBedCommunityId", oldBedProgramId);

    String remoteFacilityIdStr = StringUtils.trimToNull(request.getParameter("remoteFacilityId"));
    String remoteDemographicIdStr = StringUtils.trimToNull(request.getParameter("remoteDemographicId"));
    if (remoteFacilityIdStr != null && remoteDemographicIdStr != null) {
        try {
            int remoteFacilityId = Integer.parseInt(remoteFacilityIdStr);
            int remoteDemographicId = Integer.parseInt(remoteDemographicIdStr);
            DemographicWs demographicWs = CaisiIntegratorManager.getDemographicWs();

            // link the clients
            demographicWs.linkDemographics(providerNo, client.getDemographicNo(), remoteFacilityId,
                    remoteDemographicId);

            // copy image if exists
            {
                DemographicTransfer demographicTransfer = demographicWs
                        .getDemographicByFacilityIdAndDemographicId(remoteFacilityId, remoteDemographicId);

                if (demographicTransfer.getPhoto() != null) {
                    ClientImage clientImage = new ClientImage();
                    clientImage.setDemographic_no(client.getDemographicNo());
                    clientImage.setImage_data(demographicTransfer.getPhoto());
                    clientImage.setImage_type("jpg");
                    clientImageDAO.saveClientImage(clientImage);
                }
            }
        } catch (MalformedURLException e) {
            LOG.error("Error", e);
        } catch (WebServiceException e) {
            LOG.error("Error", e);
        }
    }
    /*
    GenericIntakeEditFormBean formBean2 = new GenericIntakeEditFormBean();
    request.getSession().setAttribute("genericIntakeEditForm", formBean2);
    */
    if (("RFQ_admit".equals(saveWhich) || "RFQ_notAdmit".equals(saveWhich)) && oldId != null) {
        return clientEdit(mapping, form, request, response);
    } else if (request.getAttribute(Globals.ERROR_KEY) != null) {
        return mapping.findForward(EDIT);
    } else if ("appointment".equals(saveWhich)) {
        ActionForward forward = mapping.findForward(APPT);
        StringBuilder path = new StringBuilder(forward.getPath());
        String fromAppt = request.getParameter("fromAppt");
        String originalPage2 = request.getParameter("originalPage");
        String provider_no2 = request.getParameter("provider_no");
        String bFirstDisp2 = request.getParameter("bFirstDisp");
        String year2 = request.getParameter("year");
        String month2 = request.getParameter("month");
        String day2 = request.getParameter("day");
        String start_time2 = request.getParameter("start_time");
        String end_time2 = request.getParameter("end_time");
        String duration2 = request.getParameter("duration");
        String bufName = client.getDisplayName();
        Integer dem = client.getDemographicNo();
        String bufDoctorNo = client.getProviderNo();
        String bufChart = client.getChartNo();
        String addAppt = "?user_id=" + request.getParameter("creator") + "&provider_no=" + provider_no2
                + "&bFirstDisp=" + bFirstDisp2 + "&appointment_date=" + request.getParameter("appointment_date")
                + "&year=" + year2 + "&month=" + month2 + "&day=" + day2 + "&start_time=" + start_time2
                + "&end_time=" + end_time2 + "&duration=" + duration2 + "&name="
                + URLEncoder.encode(bufName.toString()) + "&chart_no=" + URLEncoder.encode(bufChart.toString())
                + "&bFirstDisp=false&demographic_no=" + dem.toString() + "&messageID="
                + request.getParameter("messageId") + "&doctor_no=" + bufDoctorNo.toString() + "&notes="
                + request.getParameter("notes") + "&reason=" + request.getParameter("reason") + "&location="
                + request.getParameter("location") + "&resources=" + request.getParameter("resources")
                + "&type=" + request.getParameter("apptType") + "&style=" + request.getParameter("style")
                + "&billing=" + request.getParameter("billing") + "&status=" + request.getParameter("status")
                + "&createdatetime=" + request.getParameter("createdatetime") + "&creator="
                + request.getParameter("creator") + "&remarks=" + request.getParameter("remarks");

        path.append(addAppt);
        return new RedirectingActionForward(path.toString());

    } else {
        return clientEdit(mapping, form, request, response);
    }
}

From source file:org.webical.test.web.component.WeekViewPanelTest.java

public void testWithoutEvents() {

    annotApplicationContextMock.putBean("eventManager", new MockEventManager());

    final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek());

    // Create test page with a WeekViewPanel
    wicketTester.startPage(new ITestPageSource() {
        private static final long serialVersionUID = 1L;

        public Page getTestPage() {
            return new PanelTestPage(new WeekViewPanel(PanelTestPage.PANEL_MARKUP_ID, 7, currentDate) {
                private static final long serialVersionUID = 1L;

                @Override/* w  w  w  . j  a v a 2s.com*/
                public void onAction(IAction action) {
                    /* NOTHING TO DO */ }
            });
        }
    });

    // Basic assertions
    wicketTester.assertRenderedPage(PanelTestPage.class);
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, WeekViewPanel.class);

    // Assert number of days rendered
    GregorianCalendar weekFirstDayCalendar = CalendarUtils.duplicateCalendar(currentDate);
    weekFirstDayCalendar.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the first day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day"
            + weekFirstDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class);

    GregorianCalendar weekLastDayCalendar = CalendarUtils.duplicateCalendar(currentDate);
    weekLastDayCalendar.setTime(CalendarUtils.getLastDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the last day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":weekColumnRepeater:day"
            + weekLastDayCalendar.get(GregorianCalendar.DAY_OF_YEAR), WeekDayPanel.class);

    // Assert the heading label
    DateFormat dateFormat = new SimpleDateFormat("E", getTestSession().getLocale());
    GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate);
    weekCal.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()));
    for (int i = 0; i < 7; ++i) {
        wicketTester.assertLabel(PanelTestPage.PANEL_MARKUP_ID + ":dayHeadingRepeater:headerDay" + i,
                dateFormat.format(weekCal.getTime()));
        weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1);
    }
}

From source file:eu.cloudscale.showcase.generate.GenerateMongo.java

@Override
public void populateOrdersAndCC_XACTSTable() {
    GregorianCalendar cal;
    String[] credit_cards = { "VISA", "MASTERCARD", "DISCOVER", "AMEX", "DINERS" };
    int num_card_types = 5;
    String[] ship_types = { "AIR", "UPS", "FEDEX", "SHIP", "COURIER", "MAIL" };
    int num_ship_types = 6;

    String[] status_types = { "PROCESSING", "SHIPPED", "PENDING", "DENIED" };
    int num_status_types = 4;

    // Order variables
    int O_C_ID;//from   ww  w . ja va2  s .co m
    java.sql.Timestamp O_DATE;
    double O_SUB_TOTAL;
    double O_TAX;
    double O_TOTAL;
    String O_SHIP_TYPE;
    java.sql.Timestamp O_SHIP_DATE;
    int O_BILL_ADDR_ID, O_SHIP_ADDR_ID;
    String O_STATUS;

    String CX_TYPE;
    int CX_NUM;
    String CX_NAME;
    java.sql.Date CX_EXPIRY;
    String CX_AUTH_ID;
    int CX_CO_ID;

    System.out.println("Populating ORDERS, ORDER_LINES, CC_XACTS with " + NUM_ORDERS + " orders");

    System.out.print("Complete (in 10,000's): ");

    for (int i = 1; i <= NUM_ORDERS; i++) {
        if (i % 10000 == 0)
            System.out.print(i / 10000 + " ");

        int num_items = getRandomInt(1, 5);
        O_C_ID = getRandomInt(1, NUM_CUSTOMERS);
        cal = new GregorianCalendar();
        cal.add(Calendar.DAY_OF_YEAR, -1 * getRandomInt(1, 60));
        O_DATE = new java.sql.Timestamp(cal.getTime().getTime());
        O_SUB_TOTAL = (double) getRandomInt(1000, 999999) / 100;
        O_TAX = O_SUB_TOTAL * 0.0825;
        O_TOTAL = O_SUB_TOTAL + O_TAX + 3.00 + num_items;
        O_SHIP_TYPE = ship_types[getRandomInt(0, num_ship_types - 1)];
        cal.add(Calendar.DAY_OF_YEAR, getRandomInt(0, 7));
        O_SHIP_DATE = new java.sql.Timestamp(cal.getTime().getTime());

        O_BILL_ADDR_ID = getRandomInt(1, 2 * NUM_CUSTOMERS);
        O_SHIP_ADDR_ID = getRandomInt(1, 2 * NUM_CUSTOMERS);
        O_STATUS = status_types[getRandomInt(0, num_status_types - 1)];

        Orders order = new Orders();

        // Set parameter
        order.setOId(i);
        order.setCustomer(customerDao.findById(O_C_ID));
        order.setODate(new Date(O_DATE.getTime()));
        order.setOSubTotal(O_SUB_TOTAL);
        order.setOTax(O_TAX);
        order.setOTotal(O_TOTAL);
        order.setOShipType(O_SHIP_TYPE);
        order.setOShipDate(O_SHIP_DATE);
        order.setAddressByOBillAddrId(addressDao.findById(O_BILL_ADDR_ID));
        order.setAddressByOShipAddrId(addressDao.findById(O_SHIP_ADDR_ID));
        order.setOStatus(O_STATUS);
        order.setCcXactses(new HashSet<ICcXacts>());
        order.setOrderLines(new HashSet<IOrderLine>());

        for (int j = 1; j <= num_items; j++) {
            int OL_ID = j;
            int OL_O_ID = i;
            int OL_I_ID = getRandomInt(1, NUM_ITEMS);
            int OL_QTY = getRandomInt(1, 300);
            double OL_DISCOUNT = (double) getRandomInt(0, 30) / 100;
            String OL_COMMENTS = getRandomAString(20, 100);

            OrderLine orderLine = new OrderLine();
            orderLine.setOlId(OL_ID);
            orderLine.setItem(itemDao.findById(OL_I_ID));
            orderLine.setOlQty(OL_QTY);
            orderLine.setOlDiscount(OL_DISCOUNT);
            orderLine.setOlComment(OL_COMMENTS);
            orderLine.setOrders(order);

            orderLineDao.shrani(orderLine);

            HashSet<IOrderLine> set = new HashSet<IOrderLine>();
            set.add(orderLine);
            set.addAll(order.getOrderLines());

            order.setOrderLines(set);
            ordersDao.shrani(order);
        }

        CX_TYPE = credit_cards[getRandomInt(0, num_card_types - 1)];
        CX_NUM = getRandomNString(16);
        CX_NAME = getRandomAString(14, 30);
        cal = new GregorianCalendar();
        cal.add(Calendar.DAY_OF_YEAR, getRandomInt(10, 730));
        CX_EXPIRY = new java.sql.Date(cal.getTime().getTime());
        CX_AUTH_ID = getRandomAString(15);
        CX_CO_ID = getRandomInt(1, 92);

        CcXacts ccXacts = new CcXacts();
        ccXacts.setId(i);
        ccXacts.setCountry(countryDao.findById(CX_CO_ID));
        ccXacts.setCxType(CX_TYPE);
        ccXacts.setCxNum(CX_NUM);
        ccXacts.setCxName(CX_NAME);
        ccXacts.setCxExpiry(CX_EXPIRY);
        ccXacts.setCxAuthId(CX_AUTH_ID);
        ccXacts.setCxXactAmt(O_TOTAL);
        ccXacts.setCxXactDate(O_SHIP_DATE);

        ccXacts.setOrders(order);
        ccXactsDao.shrani(ccXacts);

        HashSet<ICcXacts> set = new HashSet<ICcXacts>();
        set.add(ccXacts);
        set.addAll(order.getCcXactses());

        order.setCcXactses(set);

        ordersDao.shrani(order);

    }

    System.out.println("");
}

From source file:org.webical.test.web.component.MonthViewPanelTest.java

/**
 * Test rendering with events./*from  ww w .  j  ava  2s. c  om*/
 * @throws WebicalException
 */
public void testRenderingWithEvents() throws WebicalException {
    log.debug("testRenderingWithEvents");

    String path = null;
    MockCalendarManager mockCalendarManager = (MockCalendarManager) annotApplicationContextMock
            .getBean("calendarManager");
    Calendar calendar1 = mockCalendarManager.getCalendarById("1");

    MockEventManager mockEventManager = new MockEventManager();
    annotApplicationContextMock.putBean("eventManager", mockEventManager);

    GregorianCalendar cal = CalendarUtils.newTodayCalendar(getFirstDayOfWeek());
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    final GregorianCalendar currentDate = CalendarUtils.duplicateCalendar(cal);

    // FIXME mattijs: test fails when run at 23:30 (probably also between 22:00 and 00:00)

    // all events
    List<Event> allEvents = new ArrayList<Event>();

    // Add a normal event
    Event event = new Event();
    event.setUid("e1");
    event.setCalendar(calendar1);
    event.setSummary("Normal Event Description");
    event.setLocation("Normal Event Location");
    event.setDescription("Event e1");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 13);
    cal.set(GregorianCalendar.MINUTE, 30);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a short recurring event, starting yesterday, ending tomorrow
    event = new Event();
    event.setUid("e2");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Yesterday");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e2");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 14);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 10);
    cal.set(GregorianCalendar.MINUTE, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    cal.set(GregorianCalendar.DAY_OF_MONTH, 17);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a long recurring event, starting last month, ending next month
    event = new Event();
    event.setUid("e3");
    event.setCalendar(calendar1);
    event.setSummary("Recurring Event Last Month");
    event.setLocation("Recurring Event Location");
    event.setDescription("Event e3");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 16);
    cal.set(GregorianCalendar.MINUTE, 0);
    cal.add(GregorianCalendar.MONTH, -1);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.HOUR_OF_DAY, 1);
    cal.set(GregorianCalendar.MINUTE, 30);
    cal.add(GregorianCalendar.MONTH, 2);
    event.setDtEnd(cal.getTime());
    RecurrenceUtil.setRecurrenceRule(event,
            new Recurrence(Recurrence.DAILY, 1, CalendarUtils.getEndOfDay(cal.getTime())));
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a (pseudo) all day event, starting 21 00:00 hours, ending 22 00:00 hours
    event = new Event();
    event.setUid("e4");
    event.setCalendar(calendar1);
    event.setSummary("Pseudo All Day Event");
    event.setLocation("All Day Event Location");
    event.setDescription("Starting 21 00:00 hours, ending 22 00:00 hours");
    cal = CalendarUtils.duplicateCalendar(currentDate);
    cal.set(GregorianCalendar.DAY_OF_MONTH, 21);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 0);
    cal.set(GregorianCalendar.MINUTE, 0);
    cal.set(GregorianCalendar.SECOND, 0);
    cal.set(GregorianCalendar.MILLISECOND, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 1);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Add a long event this week starting 23 14.00 hours and ending 25 16.00 hours
    event = new Event();
    event.setUid("e5");
    event.setCalendar(calendar1);
    event.setSummary("Long Event Description");
    event.setLocation("Long Event Location");
    event.setDescription("Event e5");
    cal.set(GregorianCalendar.DAY_OF_MONTH, 23);
    cal.set(GregorianCalendar.HOUR_OF_DAY, 14);
    cal.set(GregorianCalendar.MINUTE, 0);
    event.setDtStart(cal.getTime());
    cal.add(GregorianCalendar.DAY_OF_MONTH, 2);
    cal.add(GregorianCalendar.HOUR_OF_DAY, 2);
    event.setDtEnd(cal.getTime());
    log.debug(
            "Adding event: " + event.getDescription() + " -> " + event.getDtStart() + " - " + event.getDtEnd());
    allEvents.add(event);
    mockEventManager.storeEvent(event);

    // Render test page with a MonthViewPanel
    wicketTester.startPage(new ITestPageSource() {
        private static final long serialVersionUID = 1L;

        public Page getTestPage() {
            MonthViewPanel monthViewPanel = new MonthViewPanel(PanelTestPage.PANEL_MARKUP_ID, 1, currentDate) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onAction(IAction action) {
                    /* NOTHING TO DO */ }
            };
            return new PanelTestPage(monthViewPanel);
        }
    });

    // Basic Assertions
    wicketTester.assertRenderedPage(PanelTestPage.class);
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, MonthViewPanel.class);

    // Assert number of days rendered
    // Set the correct dates to find the first and last day of the month
    GregorianCalendar monthFirstDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthFirstDayDate
            .setTime(CalendarUtils.getFirstDayOfWeekOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the first day in the view
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthFirstDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthFirstDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    wicketTester.assertComponent(path, MonthDayPanel.class);

    GregorianCalendar monthLastDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthLastDayDate.setTime(CalendarUtils.getLastWeekDayOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    // Assert the last day in the view
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthLastDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthLastDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    wicketTester.assertComponent(path, MonthDayPanel.class);

    // Check events
    List<Event> dayEvents = new ArrayList<Event>();

    cal = CalendarUtils.duplicateCalendar(currentDate);

    // Assert events day 13
    cal.set(GregorianCalendar.DAY_OF_MONTH, 13);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    MonthDayPanel monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 14
    cal.set(GregorianCalendar.DAY_OF_MONTH, 14);
    dayEvents.clear();
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 15
    cal.set(GregorianCalendar.DAY_OF_MONTH, 15);
    dayEvents.clear();
    dayEvents.add(allEvents.get(0)); // e1
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    cal.set(GregorianCalendar.DAY_OF_MONTH, 16);
    dayEvents.clear();
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    cal.set(GregorianCalendar.DAY_OF_MONTH, 17);
    dayEvents.clear();
    dayEvents.add(allEvents.get(1)); // e2
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Only long recurring event
    cal.set(GregorianCalendar.DAY_OF_MONTH, 18);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert long recurring event first and last view day
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthFirstDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthFirstDayDate.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage()
            .get(PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
                    + monthLastDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
                    + monthLastDayDate.get(GregorianCalendar.DAY_OF_YEAR));
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 21
    cal.set(GregorianCalendar.DAY_OF_MONTH, 21);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(3)); // e4
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    ListView listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    Iterator<?> lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        Event evt = (Event) item.getModelObject();
        List<?> bhvs = item.getBehaviors();
        if (evt.getUid().equals("e4"))
            assertEquals(1, bhvs.size()); // e4 is an all day event on day 21
        else
            assertEquals(0, bhvs.size());
    }

    // Assert events day 22
    cal.set(GregorianCalendar.DAY_OF_MONTH, 22);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);

    // Assert events day 23
    cal.set(GregorianCalendar.DAY_OF_MONTH, 23);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        List<?> bhvs = item.getBehaviors();
        assertEquals(0, bhvs.size()); // no all day events
    }

    // Assert events day 24
    cal.set(GregorianCalendar.DAY_OF_MONTH, 24);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        Event evt = (Event) item.getModelObject();
        List<?> bhvs = item.getBehaviors();
        if (evt.getUid().equals("e5"))
            assertEquals(1, bhvs.size()); // e5 is an all day event on day 24
        else
            assertEquals(0, bhvs.size());
    }

    // Assert events day 25
    cal.set(GregorianCalendar.DAY_OF_MONTH, 25);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    dayEvents.add(allEvents.get(4)); // e5
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    path = monthDayEventsListView.getPageRelativePath() + ":eventItem";
    wicketTester.assertListView(path, dayEvents);

    listView = (ListView) wicketTester.getComponentFromLastRenderedPage(path);
    lvIt = listView.iterator();
    while (lvIt.hasNext()) {
        ListItem item = (ListItem) lvIt.next();
        List<?> bhvs = item.getBehaviors();
        assertEquals(0, bhvs.size()); // no all day events
    }

    // Assert events day 26
    cal.set(GregorianCalendar.DAY_OF_MONTH, 26);
    dayEvents.clear();
    dayEvents.add(allEvents.get(2)); // e3
    path = PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week" + cal.get(GregorianCalendar.WEEK_OF_YEAR)
            + ":monthDayRepeater:day" + cal.get(GregorianCalendar.DAY_OF_YEAR);
    monthDayEventsListView = (MonthDayPanel) wicketTester.getLastRenderedPage().get(path);
    wicketTester.assertListView(monthDayEventsListView.getPageRelativePath() + ":eventItem", dayEvents);
}

From source file:org.oscarehr.web.Cds4ReportUIBean.java

private SingleMultiAdmissions getAdmissionsSortedSingleMulti(GregorianCalendar startDate,
        GregorianCalendar endDate) {
    SingleMultiAdmissions singleMultiAdmissions = new SingleMultiAdmissions();

    LoggedInInfo loggedInInfo = LoggedInInfo.loggedInInfo.get();
    List<CdsClientForm> cdsForms = cdsClientFormDao.findLatestSignedCdsForms(
            loggedInInfo.currentFacility.getId(), "4", startDate.getTime(), endDate.getTime());
    logger.debug("valid cds form count, " + loggedInInfo.currentFacility.getId() + ", 4, " + startDate.getTime()
            + ", " + endDate.getTime() + ", " + cdsForms.size());

    // sort into single and multiple admissions
    for (CdsClientForm form : cdsForms) {
        logger.debug("valid cds form, id=" + form.getId());

        Admission admission = admissionMap.get(form.getAdmissionId());
        if (admission != null) {
            Integer clientId = form.getClientId();

            CdsClientForm existingForm = singleMultiAdmissions.multipleAdmissionsLatestForms.get(clientId);
            // if this person already has multiple admissions
            if (existingForm != null) {
                logger.debug("multiple admissions 3+ forms. formId=" + form.getId() + ", otherFormId="
                        + existingForm.getId());
                singleMultiAdmissions.multipleAdmissionsLatestForms.put(clientId,
                        getNewerForm(existingForm, form));
                singleMultiAdmissions.multipleAdmissionsAllForms.add(form);
            } else // this person either has one previous or no previous admissions
            {//from w w w  .  ja  v a 2s.c om
                existingForm = singleMultiAdmissions.singleAdmissions.get(clientId);
                // this means we have 1 previous admission
                if (existingForm != null) {
                    logger.debug("multiple admissions, 2 forms : formId=" + form.getId() + ", otherFormId="
                            + existingForm.getId());

                    singleMultiAdmissions.multipleAdmissionsLatestForms.put(clientId,
                            getNewerForm(existingForm, form));
                    singleMultiAdmissions.singleAdmissions.remove(clientId);

                    singleMultiAdmissions.multipleAdmissionsAllForms.add(existingForm);
                    singleMultiAdmissions.multipleAdmissionsAllForms.add(form);
                } else // we have no previous admission
                {
                    logger.debug("single admissions : formId=" + form.getId());
                    singleMultiAdmissions.singleAdmissions.put(clientId, form);
                }
            }
        } else {
            logger.debug("cds form missing admission. formId=" + form.getId() + ", admissionId="
                    + form.getAdmissionId());
        }
    }

    // sort single admissions into cohort buckets
    for (CdsClientForm form : singleMultiAdmissions.singleAdmissions.values()) {
        Admission admission = admissionMap.get(form.getAdmissionId());
        int bucket = getCohortBucket(admission);
        singleMultiAdmissions.singleAdmissionCohortBuckets.put(bucket, form);

        logger.debug("cds form id=" + form.getId() + ", admission=" + admission.getId() + ", cohort bucket="
                + bucket);
    }

    // sort multiple admissions into cohort buckets
    for (CdsClientForm form : singleMultiAdmissions.multipleAdmissionsAllForms) {
        Admission admission = admissionMap.get(form.getAdmissionId());
        int bucket = getCohortBucket(admission);
        singleMultiAdmissions.multipleAdmissionCohortBuckets.put(bucket, form);

        logger.debug("cds form id=" + form.getId() + ", admission=" + admission.getId() + ", cohort bucket="
                + bucket);
    }

    return (singleMultiAdmissions);
}

From source file:com.workplacesystems.queuj.process.ProcessWrapper.java

void updateRunning(final GregorianCalendar runTime) {
    doTransaction(new Callback() {

        @Override//from   w w  w. jav a 2s . c  om
        protected void doAction() {
            getContainingServer().removeProcessFromIndex(ProcessWrapper.this);
            ProcessPersistence<ProcessEntity<K>, K> processHome = getProcessPersistence();
            log.debug("ProcessWrapper.updateRunning called for " + process.getProcessId() + "("
                    + process.getVersion() + ")");
            process.setStatus(Status.RUNNING);
            process.setResultCode(0);

            process.setStartedTimestamp(new Date());
            process.setScheduledTimestamp(runTime.getTime());
            if (isPersistent)
                processHome.update();

            getContainingServer().addProcessToIndex(ProcessWrapper.this);
            _return(ProcessWrapper.this);
        }
    });
}

From source file:org.webical.test.web.component.MonthViewPanelTest.java

/**
 * Test rendering of the panel without events.
 *//*  www . ja  v  a  2  s  . com*/
public void testRenderingWithoutEvents() {
    log.debug("testRenderingWithoutEvents");

    // Add an EventManager
    annotApplicationContextMock.putBean("eventManager", new MockEventManager());

    final GregorianCalendar currentDate = CalendarUtils.newTodayCalendar(getFirstDayOfWeek());

    // render start page with a MonthViewPanel
    wicketTester.startPage(new ITestPageSource() {
        private static final long serialVersionUID = 1L;

        public Page getTestPage() {
            return new PanelTestPage(new MonthViewPanel(PanelTestPage.PANEL_MARKUP_ID, 1, currentDate) {
                private static final long serialVersionUID = 1L;

                @Override
                public void onAction(IAction action) {
                    /* NOTHING TO DO */ }
            });
        }
    });

    // Basic Assertions
    wicketTester.assertRenderedPage(PanelTestPage.class);
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID, MonthViewPanel.class);

    // Weekday headers
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":monthHeaderRepeater", RepeatingView.class);

    DateFormat dateFormat = new SimpleDateFormat("E", getTestSession().getLocale());
    GregorianCalendar weekCal = CalendarUtils.duplicateCalendar(currentDate);
    weekCal.setTime(CalendarUtils.getFirstDayOfWeek(currentDate.getTime(), getFirstDayOfWeek()));
    for (int i = 0; i < 7; ++i) {
        wicketTester.assertLabel(PanelTestPage.PANEL_MARKUP_ID + ":monthHeaderRepeater:headerDay" + i,
                dateFormat.format(weekCal.getTime()));
        weekCal.add(GregorianCalendar.DAY_OF_WEEK, 1);
    }

    // Set the correct dates to find the first and last day of the month
    GregorianCalendar monthFirstDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthFirstDayDate
            .setTime(CalendarUtils.getFirstDayOfWeekOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    log.debug("testRenderingWithoutEvents:monthFirstDayDate " + monthFirstDayDate.getTime());
    // Assert the first day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthFirstDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthFirstDayDate.get(GregorianCalendar.DAY_OF_YEAR), MonthDayPanel.class);

    GregorianCalendar monthLastDayDate = CalendarUtils.duplicateCalendar(currentDate);
    monthLastDayDate.setTime(CalendarUtils.getLastWeekDayOfMonth(currentDate.getTime(), getFirstDayOfWeek()));
    log.debug("testRenderingWithoutEvents:monthLastDayDate " + monthLastDayDate.getTime());
    // Assert the last day in the view
    wicketTester.assertComponent(PanelTestPage.PANEL_MARKUP_ID + ":monthRowRepeater:week"
            + monthLastDayDate.get(GregorianCalendar.WEEK_OF_YEAR) + ":monthDayRepeater:day"
            + monthLastDayDate.get(GregorianCalendar.DAY_OF_YEAR), MonthDayPanel.class);
}

From source file:com.collabnet.ccf.pi.qc.v90.QCHandler.java

/**
 * Gets the value of the field in a suitable data type.
 * /*from   w  ww.jav  a  2 s . c o  m*/
 */
public String getProperFieldValue(GenericArtifactField thisField, String targetSystemTimezone) {

    String fieldValue = null;
    GenericArtifactField.FieldValueTypeValue fieldValueTypeValue = thisField.getFieldValueType();
    switch (fieldValueTypeValue) {
    case DATE: {
        GregorianCalendar gcal = (GregorianCalendar) thisField.getFieldValue();
        if (gcal != null) {
            Date targetTimezoneDate = gcal.getTime();
            if (DateUtil.isAbsoluteDateInTimezone(targetTimezoneDate, DateUtil.GMT_TIME_ZONE_STRING)) {
                targetTimezoneDate = DateUtil.convertGMTToTimezoneAbsoluteDate(targetTimezoneDate,
                        TimeZone.getDefault().getDisplayName(false, TimeZone.SHORT));
            }
            fieldValue = DateUtil.formatQCDate(targetTimezoneDate);
        }
        break;
    }
    case DATETIME: {
        Date targetTimezoneDate = (Date) thisField.getFieldValue();
        if (targetTimezoneDate != null) {
            fieldValue = DateUtil.formatQCDate(targetTimezoneDate);
        }
        break;
    }

    }
    return fieldValue;

}

From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java

private void parse_tIME_chunk(final PNGChunk chunk) {
    final int year = chunk.getInt2(0);
    final int month = chunk.getInt1(2) - 1;
    final int day = chunk.getInt1(3);
    final int hour = chunk.getInt1(4);
    final int minute = chunk.getInt1(5);
    final int second = chunk.getInt1(6);

    final TimeZone gmt = TimeZone.getTimeZone("GMT");

    final GregorianCalendar cal = new GregorianCalendar(gmt);
    cal.set(year, month, day, hour, minute, second);
    final Date date = cal.getTime();

    if (this.encodeParam != null) {
        this.encodeParam.setModificationTime(date);
    }/*  w  ww  . java  2  s. co m*/
    if (this.emitProperties) {
        this.properties.put("timestamp", date);
    }
}

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

/**
 * {@inheritDoc}/*  ww w  . j a v  a2  s.c om*/
 */
public void applyBaseDateTx(String context, int days) {
    if (context == null)
        throw new IllegalArgumentException("applyBaseDateTx: context is null");
    if (days == 0)
        return;

    try {
        // security check
        securityService.secure(sessionManager.getCurrentSessionUserId(), MnemeService.MANAGE_PERMISSION,
                context);

        // do this the slow way (i.e. not all in SQL) to avoid the y2038 bug and assure proper gradebook integration
        // see Etudes Jira MN-1125

        // get all assessments
        List<Assessment> assessments = getContextAssessments(context, AssessmentsSort.odate_a, Boolean.FALSE);

        GregorianCalendar gc = new GregorianCalendar();

        // for each one, apply the base date change
        for (Assessment assessment : assessments) {
            if (assessment.getDates().getAcceptUntilDate() != null) {
                gc.setTime(assessment.getDates().getAcceptUntilDate());
                gc.add(Calendar.DATE, days);
                assessment.getDates().setAcceptUntilDate(gc.getTime());
            }

            if (assessment.getDates().getDueDate() != null) {
                gc.setTime(assessment.getDates().getDueDate());
                gc.add(Calendar.DATE, days);
                assessment.getDates().setDueDate(gc.getTime());
            }

            if (assessment.getDates().getOpenDate() != null) {
                gc.setTime(assessment.getDates().getOpenDate());
                gc.add(Calendar.DATE, days);
                assessment.getDates().setOpenDate(gc.getTime());
            }

            if (assessment.getReview().getDate() != null) {
                gc.setTime(assessment.getReview().getDate());
                gc.add(Calendar.DATE, days);
                assessment.getReview().setDate(gc.getTime());
            }

            // save
            try {
                saveAssessment(assessment);
            } catch (AssessmentPermissionException e) {
                M_log.warn("applyBaseDateTx: " + assessment.getId() + " exception: " + e.toString());
            } catch (AssessmentPolicyException e) {
                M_log.warn("applyBaseDateTx: " + assessment.getId() + " exception: " + e.toString());
            }
        }
    } catch (AssessmentPermissionException e) {
        throw new RuntimeException("applyBaseDateTx: security check failed: " + e.toString());
    }
}