Example usage for java.util GregorianCalendar setTime

List of usage examples for java.util GregorianCalendar setTime

Introduction

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

Prototype

public final void setTime(Date date) 

Source Link

Document

Sets this Calendar's time with the given Date.

Usage

From source file:org.caisi.dao.TicklerDAO.java

public int getActiveTicklerCount(String providerNo) {
    ArrayList paramList = new ArrayList();
    //String query = "select count(*) from Tickler t where t.status = 'A' and t.service_date <= ? and (t.task_assigned_to  = '"+ providerNo + "' or t.task_assigned_to='All Providers')";

    GregorianCalendar currentDate = new GregorianCalendar();
    currentDate.setTime(new Date());
    /*paramList.add(currentDate.getTime());
    //paramList.add(new Date());//w w w  .j a  v a  2s . c o  m
    Object params[] = paramList.toArray(new Object[paramList.size()]);
    Long count = (Long) getHibernateTemplate().find(query ,params).get(0);*/

    String query = "select count(*) from tickler t where t.status = 'A' and t.service_date <= ? and (t.task_assigned_to  = '"
            + providerNo + "' or t.task_assigned_to='All Providers')";
    if (org.oscarehr.common.IsPropertiesOn.isMultisitesEnable()) {
        SuperSiteUtil superSiteUtil = SuperSiteUtil.getInstance(providerNo);
        List<Site> sites = superSiteUtil.getSitesWhichUserCanOnlyAccess();
        String siteStr = "";
        if (sites != null && sites.size() > 0) {
            for (Site site : sites) {
                if (siteStr.length() == 0)
                    siteStr = "'" + site.getId() + "'";
                else
                    siteStr = siteStr + ",'" + site.getId() + "'";
            }
            //get tickler which are not assigned to any demographic or which are assigned to demographic
            //enrolled in sites in which provider has only access 
            query = "select count(*) from tickler t "
                    + " left join demographicSite ds on t.demographic_no=ds.demographicId "
                    + " where t.status = 'A' " + " and t.service_date <= ? and  " + " (t.task_assigned_to  = '"
                    + providerNo + "' or t.task_assigned_to='All Providers') "
                    + " and (t.demographic_no is null or t.demographic_no = '' or ds.siteId in (" + siteStr
                    + "))";
        }
    }

    Query hibernateQuery = getSession().createSQLQuery(query);
    hibernateQuery.setDate(0, currentDate.getTime());
    List resultList = hibernateQuery.list();

    int count = 0;

    if (resultList != null && resultList.size() > 0)
        count = Integer.parseInt(resultList.get(0) + "");
    //return count.intValue();
    return count;
}

From source file:edu.lternet.pasta.portal.statistics.GrowthStats.java

private ArrayList<String> buildLabels(GregorianCalendar start, GregorianCalendar end, int scale) {

    ArrayList<String> labels = new ArrayList<String>();

    GregorianCalendar lower = (GregorianCalendar) start.clone();
    GregorianCalendar upper = new GregorianCalendar();
    GregorianCalendar split = new GregorianCalendar();

    while (lower.getTimeInMillis() <= end.getTimeInMillis()) {
        upper.setTime(lower.getTime());
        upper.add(scale, 1);/*from ww w .  j  a v a2  s.  c o m*/
        split.setTime(
                new Date(lower.getTimeInMillis() + (upper.getTimeInMillis() - lower.getTimeInMillis()) / 2));
        /*
        System.out.printf("%s-%s-%s%n", lower.getTime().toString(),
                   split.getTime().toString(),
                   upper.getTime().toString());
         */
        labels.add(getLabel(scale, split));
        lower.setTime(upper.getTime());
    }

    return labels;

}

From source file:gov.nih.nci.cabig.caaers.domain.DateTimeValue.java

/**
 * Instantiates a new date value./*from w ww.  j av  a 2 s  . c o m*/
 *
 * @param date the date
 */
public DateTimeValue(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    this.day = gc.get(Calendar.DAY_OF_MONTH);
    this.month = gc.get(Calendar.MONTH) + 1;
    this.year = gc.get(Calendar.YEAR);
}

From source file:com.konakart.actions.CustomerRegistrationSubmitAction.java

/**
 * /*from w  w w. j a  va 2  s.c  o m*/
 * @param mapping
 *            The ActionMapping used to select this instance
 * @param form
 *            The optional ActionForm bean for this request (if any)
 * @param request
 *            The HTTP request we are processing
 * @param response
 *            The HTTP response we are creating
 * 
 */
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) {

    // Create a new object here since it may be used if an exception occurs and so has to be
    // visible.
    CustomerRegistrationIf cr = new CustomerRegistration();
    KKAppEng kkAppEng = null;

    try {
        int custId;
        Date birthDate = null;
        CustomerTag ct = null;

        RegisterCustomerForm localForm = (RegisterCustomerForm) form;

        kkAppEng = this.getKKAppEng(request, response);

        custId = this.loggedIn(request, response, kkAppEng, null);

        // Ensure we are using the correct protocol. Redirect if not.
        ActionForward redirForward = checkSSL(kkAppEng, request, custId, /* forceSSL */true);
        if (redirForward != null) {
            return redirForward;
        }

        // Empty the array of zones so that it isn't presented during the next registration
        // attempt in a drop list.
        kkAppEng.getCustomerMgr().emptyZonesForRegistration();

        // Copy the inputs from the form to the customer registration object
        BeanUtils.copyProperties(cr, form);

        // Set the date
        if (localForm.getBirthDateString() != null && !localForm.getBirthDateString().equals("")) {
            SimpleDateFormat sdf = new SimpleDateFormat(getCatMessage(request, "date.format"));
            birthDate = sdf.parse(localForm.getBirthDateString());
            if (birthDate != null) {
                GregorianCalendar gc = new GregorianCalendar();
                gc.setTime(birthDate);
                cr.setBirthDate(gc);
            }
        }

        // Set the newsletter
        if (localForm.isNewsletterBool()) {
            cr.setNewsletter("1");
        } else {
            cr.setNewsletter("0");
        }

        // Call the engine registration method
        int customerId = kkAppEng.getCustomerMgr().registerCustomer(cr);

        // Send a welcome email
        EmailOptionsIf options = new EmailOptions();
        options.setCountryCode(kkAppEng.getLocale().substring(0, 2));
        options.setTemplateName(com.konakart.bl.EmailMgr.WELCOME_TEMPLATE);
        kkAppEng.getEng().sendWelcomeEmail1(customerId, options);

        // Set this to false if you don't want to login automatically after registration. Note
        // that customer tags won't be set and the reward points won't be allocated.
        if (true) {
            // Now log in the customer
            kkAppEng.getCustomerMgr().login(localForm.getEmailAddr(), localForm.getPassword());
            kkAppEng.nav.set(getCatMessage(request, "header.my.account"), request);

            /*
             * Set customer tags
             */

            // Set the BIRTH_DATE customer tag for this customer
            if (birthDate != null) {
                ct = new CustomerTag();
                ct.setValueAsDate(birthDate);
                ct.setName("BIRTH_DATE");
                kkAppEng.getCustomerTagMgr().insertCustomerTag(ct);
            }

            // Set the COUNTRY_CODE customer tag for this customer
            CountryIf country = kkAppEng.getEng().getCountry(localForm.getCountryId());
            if (country != null && country.getIsoCode3() != null) {
                kkAppEng.getCustomerTagMgr().insertCustomerTag("COUNTRY_CODE", country.getIsoCode3());
            }

            // Set the IS_MALE customer tag for this customer
            ct = new CustomerTag();
            ct.setName("IS_MALE");
            ct.setValueAsBoolean(false);
            if (localForm.getGender() != null && localForm.getGender().equalsIgnoreCase("m")) {
                ct.setValueAsBoolean(true);
            }
            kkAppEng.getCustomerTagMgr().insertCustomerTag(ct);

            // Set reward points if applicable
            if (kkAppEng.getRewardPointMgr().isEnabled()) {
                String pointsStr = kkAppEng.getConfig(ConfigConstants.REGISTRATION_REWARD_POINTS);
                if (pointsStr != null) {
                    int points = 0;
                    try {
                        points = Integer.parseInt(pointsStr);
                        kkAppEng.getRewardPointMgr().addPoints(points, "REG",
                                getCatMessage(request, "reward.points.registration"));
                    } catch (Exception e) {
                        log.warn(
                                "The REGISTRATION_REWARD_POINTS configuration variable has been set with a non numeric value: "
                                        + pointsStr);
                    }
                }
            }

            return mapping.findForward("LoginSubmit");
        }
        // Don't login
        kkAppEng.nav.set(getCatMessage(request, "header.registration.submitted"), request);
        return mapping.findForward("CustomerRegistrationSubmit");

    } catch (Exception e) {
        /*
         * There could be two cases of application error. The user may already exist, in which
         * case we let the customer try again with a different user name. The zone is invalid
         * for the country. If this occurs we populate a drop down list and force the customer
         * to select from this list.
         */

        if (e.getCause() != null
                && e.getCause().getClass().getName().equals("com.konakart.app.KKUserExistsException")) {
            return getForward(mapping, request, e, "com.konakart.app.KKUserExistsException",
                    getCatMessage(request, "register.customer.body.user.exists"), "ApplicationError");
        } else if (e.getCause() != null
                && e.getCause().getClass().getName().equals("com.konakart.app.KKInvalidZoneException")) {
            try {
                if (kkAppEng != null) {
                    kkAppEng.getCustomerMgr().fetchZonesForRegistration(cr.getCountryId());
                }
            } catch (KKException e1) {
                return mapping.findForward(super.handleException(request, e1));
            }
            return getForward(mapping, request, e, "com.konakart.app.KKInvalidZoneException",
                    getCatMessage(request, "register.customer.body.invalid.zone"), "ApplicationError");
        }

        // For the web services case the cause turns out to be an org.apache.axis.AxisFault.
        // However within the message there is a message that says e.g. nested exception is:
        // com.konakart.app.KKPasswordDoesntMatchException so we search for the name of the
        // exception class that is the cause
        if (e.getMessage() != null && e.getMessage().indexOf("com.konakart.app.KKInvalidZoneException") > -1) {
            try {
                if (kkAppEng != null) {
                    kkAppEng.getCustomerMgr().fetchZonesForRegistration(cr.getCountryId());
                }
            } catch (KKException e1) {
                return mapping.findForward(super.handleException(request, e1));
            }
            return getForward(mapping, request, e, "com.konakart.app.KKInvalidZoneException",
                    getCatMessage(request, "register.customer.body.invalid.zone"), "ApplicationError");
        }
        return getForward(mapping, request, e, "com.konakart.app.KKUserExistsException",
                getCatMessage(request, "register.customer.body.user.exists"), "ApplicationError");

    }
}

From source file:gov.nih.nci.cabig.caaers.domain.DateValue.java

/**
 * Instantiates a new date value./*from   w ww  .  j a va  2 s  . co  m*/
 *
 * @param date the date
 */
public DateValue(Date date) {
    GregorianCalendar gc = new GregorianCalendar();
    gc.setTime(date);
    this.day = gc.get(Calendar.DAY_OF_MONTH);
    this.month = gc.get(Calendar.MONTH) + 1;
    this.year = gc.get(Calendar.YEAR);
}

From source file:jenkins.plugins.coverity.DefectFilters.java

public XMLGregorianCalendar getXMLCutOffDate() {
    GregorianCalendar calender = new GregorianCalendar();
    calender.setTime(cutOffDate);
    try {/* w  ww .  j av  a  2  s.  c o m*/
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(calender);
    } catch (Exception e) {

    }
    return null;
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 *  ?2009-08-01//from w  w  w. j a v a 2 s. co m
 */
public static String addMonth(String strdate) {

    Date date = new Date(); // ??

    String dateresult = null; // 
    // ??
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    // ?
    GregorianCalendar gc = new GregorianCalendar();

    try {
        date = df.parse(strdate); // ?
    } catch (ParseException e) {
        e.printStackTrace();
    }

    gc.setTime(date); // gc?

    gc.add(2, 1); // 2?1?(,)
    // ?
    gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE));
    // ?
    dateresult = df.format(gc.getTime());

    return dateresult;
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * ? ?2009-08-01//  ww  w. j  a v a  2 s  .c  o m
 */
public static String subMonth(String strdate) {

    Date date = new Date(); // ??

    String dateresult = null; // 
    // ??
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    // ?
    GregorianCalendar gc = new GregorianCalendar();

    try {
        date = df.parse(strdate); // ?
    } catch (ParseException e) {
        e.printStackTrace();
    }

    gc.setTime(date); // gc?

    gc.add(2, -1); // 2?1?(,)
    // ?
    gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE));
    // ?
    dateresult = df.format(gc.getTime());

    return dateresult;
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 * ? ?2009-08-01//from w w w  .j  a va  2 s .co m
 */
public static String subDay(String strdate) {

    Date date = new Date(); // ??

    String dateresult = null; // 
    // ??
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    // ?
    GregorianCalendar gc = new GregorianCalendar();

    try {
        date = df.parse(strdate); // ?
    } catch (ParseException e) {
        e.printStackTrace();
    }

    gc.setTime(date); // gc?

    gc.add(5, -1); // 2?1?(....5)
    // ?
    gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE));
    // ?
    dateresult = df.format(gc.getTime());

    return dateresult;
}

From source file:com.eryansky.common.utils.DateUtil.java

/**
 *  ?2009-08-01//from w w w.j  a v  a2s  .c o  m
 */
public static String addDay(String strdate) {

    Date date = new Date(); // ??

    String dateresult = null; // 
    // ??
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    // ?
    GregorianCalendar gc = new GregorianCalendar();

    try {
        date = df.parse(strdate); // ?
    } catch (ParseException e) {
        e.printStackTrace();
    }

    gc.setTime(date); // gc?

    gc.add(5, 1); // 2?1?(....5)
    // ?
    gc.set(gc.get(gc.YEAR), gc.get(gc.MONTH), gc.get(gc.DATE));
    // ?
    dateresult = df.format(gc.getTime());

    return dateresult;
}