Example usage for java.util GregorianCalendar get

List of usage examples for java.util GregorianCalendar get

Introduction

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

Prototype

public int get(int field) 

Source Link

Document

Returns the value of the given calendar field.

Usage

From source file:org.motechproject.mobile.omp.manager.intellivr.IntellIVRBean.java

@Transactional
public int getCountIVRCallsInLastDaysWithStatus(int days, IVRCallStatus status) {
    days = days < 0 ? 0 : days;//ww w  .  j  a va 2s  .com
    GregorianCalendar end = new GregorianCalendar();
    GregorianCalendar lastMidnight = new GregorianCalendar(end.get(GregorianCalendar.YEAR),
            end.get(GregorianCalendar.MONTH), end.get(GregorianCalendar.DAY_OF_MONTH));
    Date start = addToDate(lastMidnight.getTime(), GregorianCalendar.DAY_OF_MONTH, (int) (days - 1) * (-1));
    return ivrDao.countIVRCallsCreatedBetweenDatesWithStatus(start, end.getTime(), status);
}

From source file:org.motechproject.mobile.omp.manager.intellivr.IntellIVRBean.java

@Transactional
public List<IVRCallStatusStat> getIVRCallStatusStatsFromLastDays(int days) {
    days = days < 0 ? 0 : days;/*w  w  w  .j a  v a  2s  . c  o m*/
    GregorianCalendar end = new GregorianCalendar();
    GregorianCalendar lastMidnight = new GregorianCalendar(end.get(GregorianCalendar.YEAR),
            end.get(GregorianCalendar.MONTH), end.get(GregorianCalendar.DAY_OF_MONTH));
    Date start = addToDate(lastMidnight.getTime(), GregorianCalendar.DAY_OF_MONTH, (int) (days - 1) * (-1));
    return ivrDao.getIVRCallStatusStatsBetweenDates(start, end.getTime());
}

From source file:org.motechproject.mobile.omp.manager.intellivr.IntellIVRBean.java

@Transactional
public List<IVRCallSession> getIVRCallSessionsInLastDays(int days) {
    days = days < 0 ? 0 : days;/*  w w  w.j  a v  a2s.  c  om*/
    GregorianCalendar end = new GregorianCalendar();
    GregorianCalendar lastMidnight = new GregorianCalendar(end.get(GregorianCalendar.YEAR),
            end.get(GregorianCalendar.MONTH), end.get(GregorianCalendar.DAY_OF_MONTH));
    Date start = addToDate(lastMidnight.getTime(), GregorianCalendar.DAY_OF_MONTH, (int) (days - 1) * (-1));
    return ivrDao.loadIVRCallSessionsCreatedBetweenDates(start, end.getTime());
}

From source file:com.konakart.actions.gateways.CommideaVanguardBaseAction.java

/**
 * Method that manages the VGTOKENREGISTRATIONREQUEST and the VGTOKENREGISTRATIONRESPONSE.
 * /*from   w  w w.j  a  v  a 2s.co m*/
 * @param kkAppEng
 * @param order
 * @param ipnHistory
 * @return Returns "1" or "0" depending on whether the authentication enrollment check request
 *         should be made. i.e. Should be "0" for AMEX cards
 * @throws Exception
 */
protected String vgtokenregistrationrequest(KKAppEng kkAppEng, OrderIf order, IpnHistoryIf ipnHistory)
        throws Exception {

    StringBuffer msg = new StringBuffer();
    msg.append(getHeader("VGTOKENREGISTRATIONREQUEST", order, /* sendAttempt */0));

    // Token expiration date formatted to DDMMCCYY (e.g. 14092011)
    long timeInMillis = System.currentTimeMillis();
    Date expiryDate = new Date(timeInMillis + (DAY_IN_MILLIS * 365L));
    GregorianCalendar expiryGC = new GregorianCalendar();
    expiryGC.setTime(expiryDate);
    int day = expiryGC.get(Calendar.DAY_OF_MONTH);
    int month = expiryGC.get(Calendar.MONTH) + 1;
    int year = expiryGC.get(Calendar.YEAR);
    String dayStr = (day < 10) ? "0" + day : "" + day;
    String monthStr = (month < 10) ? "0" + month : "" + month;
    String dateStr = dayStr + monthStr + year;

    String req = "<vgtokenregistrationrequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
            + "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + "xmlns=\"VANGUARD\">" + "<sessionguid>"
            + getSessionId(order.getPaymentDetails().getCustom1()) + "</sessionguid>" + "<purchase>" + "true"
            + "</purchase>" + "<refund>" + "true" + "</refund>" + "<cashback>" + "false" + "</cashback>"
            + "<tokenexpirationdate>" + dateStr + "</tokenexpirationdate>" + "</vgtokenregistrationrequest>";

    msg.append(req);

    msg.append(getFooter());

    if (log.isDebugEnabled()) {
        log.debug("GatewayRequest (VGTOKENREGISTRATIONREQUEST) =\n"
                + RegExpUtils.maskCreditCard(PrettyXmlPrinter.printXml(msg.toString())));
    }

    String gatewayResp = null;
    try {
        gatewayResp = postData(msg, order.getPaymentDetails(), null);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug("Problem posting request to " + order.getPaymentDetails().getRequestUrl() + " : "
                    + e.getMessage());
        }
        throw e;
    }

    if (log.isDebugEnabled()) {
        log.debug("Unformatted GatewayResp (VGTOKENREGISTRATIONRESPONSE) =\n" + gatewayResp);
        try {
            log.debug("Formatted GatewayResp (VGTOKENREGISTRATIONRESPONSE) =\n"
                    + PrettyXmlPrinter.printXml(gatewayResp));
        } catch (Exception e) {
            log.debug("Exception pretty-printing gateway response (VGTOKENREGISTRATIONRESPONSE) : "
                    + e.getMessage());
        }
    }

    // Now process the XML response

    String sessionguid = null;
    String tokenid = null;
    String errorcode = null;
    String errordescription = null;

    if (gatewayResp != null) {
        try {
            DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = builderFactory.newDocumentBuilder();
            ByteArrayInputStream bais = new ByteArrayInputStream(gatewayResp.getBytes());
            Document doc = builder.parse(bais);

            // get the root node
            Node rootnode = doc.getDocumentElement();
            String rootName = rootnode.getNodeName();

            if (rootName != "soap:Envelope") {
                throw new KKException("Unexpected root element in VGTOKENREGISTRATIONRESPONSE: " + rootName);
            }

            // get all elements
            NodeList list = doc.getElementsByTagName("*");
            for (int i = 0; i < list.getLength(); i++) {
                Node node = list.item(i);
                String name = node.getNodeName();
                if (name != null && name.equals("MsgData")) {
                    Text datanode = (Text) node.getFirstChild();
                    String xml = kkAppEng.removeCData(datanode.getData());
                    ByteArrayInputStream bais1 = new ByteArrayInputStream(xml.getBytes());
                    Document doc1 = builder.parse(bais1);
                    NodeList list1 = doc1.getElementsByTagName("*");
                    for (int j = 0; j < list1.getLength(); j++) {
                        Node node1 = list1.item(j);
                        String name1 = node1.getNodeName();
                        if (name1.equals("sessionguid")) {
                            sessionguid = getNodeValue(node1);
                        } else if (name1.equals("errorcode")) {
                            errorcode = getNodeValue(node1);
                        } else if (name1.equals("errordescription")) {
                            errordescription = getNodeValue(node1);
                        } else if (name1.equals("tokenid")) {
                            tokenid = getNodeValue(node1);
                        }
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Commidea VGTOKENREGISTRATIONRESPONSE response data:"
                        + "\n    sessionguid               = " + sessionguid
                        + "\n    errorcode                 = " + errorcode
                        + "\n    errordescription          = " + errordescription
                        + "\n    tokenId                   = " + tokenid);
            }
        } catch (Exception e) {
            // Problems parsing the XML
            if (log.isDebugEnabled()) {
                log.debug("Problems parsing Commidea VGTOKENREGISTRATIONRESPONSE response: " + e.getMessage());
            }
            throw e;
        }
    }

    /*
     * Save the IPN History record
     */
    String codePlusTxt = getResultDescription(
            RET1_DESC + errorcode + ((errordescription == null) ? "" : " : " + errordescription));
    if (errorcode != null && errorcode.equals("0")) {
        ipnHistory.setKonakartResultDescription(RET0_DESC);
        ipnHistory.setKonakartResultId(RET0);
        ipnHistory.setGatewayResult(tokenid);
    } else {
        ipnHistory.setKonakartResultDescription(codePlusTxt);
        ipnHistory.setKonakartResultId(RET1);
        ipnHistory.setGatewayResult("ERROR");
    }

    ipnHistory.setGatewayTransactionId("vgtokenregistrationrequest");
    ipnHistory.setGatewayFullResponse(gatewayResp);
    kkAppEng.getEng().saveIpnHistory(kkAppEng.getSessionId(), ipnHistory);

    return errorcode;
}

From source file:com.southernstorm.tvguide.TvChannelCache.java

/**
 * Expire old entries in the cache.//ww w.j  av a 2 s.  c o  m
 */
public void expire() {
    if (httpCacheDir == null)
        return;
    String[] entries = httpCacheDir.list();
    GregorianCalendar today = new GregorianCalendar();
    int todayYear = today.get(Calendar.YEAR);
    int todayMonth = today.get(Calendar.MONTH) + 1;
    int todayDay = today.get(Calendar.DAY_OF_MONTH);
    for (int index = 0; index < entries.length; ++index) {
        // Look for files that end in ".xml.gz" or ".cache".
        String name = entries[index];
        int suffixLength;
        if (name.endsWith(".xml.gz"))
            suffixLength = 7;
        else if (name.endsWith(".cache"))
            suffixLength = 6;
        else
            continue;
        if ((name.length() - suffixLength) < 10)
            continue;

        // Extract the date in the format YYYY-MM-DD from the name
        // and determine if it is less than today.
        int posn = name.length() - suffixLength - 10;
        int year = Utils.parseField(name, posn, 4);
        int month = Utils.parseField(name, posn + 5, 2);
        int day = Utils.parseField(name, posn + 8, 2);
        if (year > todayYear)
            continue;
        if (year == todayYear) {
            if (month > todayMonth)
                continue;
            if (month == todayMonth) {
                if (day >= todayDay)
                    continue;
            }
        }

        // Delete the file as it is older than today.
        File file = new File(httpCacheDir, name);
        if (debug)
            System.out.println("expiring " + file.getPath());
        file.delete();
    }
}

From source file:xc.mst.manager.record.DefaultRecordService.java

@Override
public long getCount(Date fromDate, Date untilDate, Set set, int formatId, int serviceId)
        throws IndexException {
    Date from; // fromDate, or the minimum value for a Date if fromDate is null
    Date until; // toDate, or now if toDate is null

    // If from is null, set it to the minimum possible value
    // Otherwise set it to the same value as fromDate
    if (fromDate == null) {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(new Date(0));
        c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY)
                - ((c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)) / (60 * 60 * 1000)));
        from = c.getTime();//from   w  ww  .  j ava2s. c  om
    } else {
        from = fromDate;
    }

    // If to is null, set it to now
    // Otherwise set it to the same value as toDate
    if (untilDate == null) {
        GregorianCalendar c = new GregorianCalendar();
        c.setTime(new Date());
        c.set(Calendar.HOUR_OF_DAY, c.get(Calendar.HOUR_OF_DAY)
                - ((c.get(Calendar.ZONE_OFFSET) + c.get(Calendar.DST_OFFSET)) / (60 * 60 * 1000)));

        until = c.getTime();
    } else {
        until = untilDate;
    }

    // True if we're getting the count for a specific set, false if we're getting it for all records
    boolean useSet = (set != null);

    // True if we're getting the count for a specific metadataPrefix, false if we're getting it for all records
    boolean useMetadataPrefix = (formatId > 0);

    DateFormat format = DateFormat.getInstance();

    if (log.isDebugEnabled())
        log.debug("Counting the records updated later than " + format.format(from) + " and earlier than "
                + format.format(until) + (useSet ? " with set ID " + set.getSetSpec() : "")
                + (useMetadataPrefix ? " with format ID " + formatId : ""));

    // Create a query to get the Documents for unprocessed records
    SolrQuery query = new SolrQuery();
    StringBuffer queryBuffer = new StringBuffer();
    queryBuffer.append(FIELD_SERVICE_ID).append(":").append(Integer.toString(serviceId));

    if (useSet)
        queryBuffer.append(" AND ").append(FIELD_SET_SPEC).append(":").append(set.getSetSpec());
    if (useMetadataPrefix)
        queryBuffer.append(" AND ").append(FIELD_FORMAT_ID).append(":").append(Integer.toString(formatId));

    queryBuffer.append(" AND ").append(FIELD_DELETED).append(":").append("false");

    query.setQuery(queryBuffer.toString());

    if (from != null && until != null)
        query.addFilterQuery(
                FIELD_UPDATED_AT + ":[" + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(from))
                        + " TO " + (new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'").format(until)) + "]");

    // Get the result of the query
    RecordList records = new RecordList(query, 0);

    if (log.isDebugEnabled())
        log.debug("Found " + records.size() + " records updated later than " + format.format(from)
                + " and earlier than " + format.format(until)
                + (useSet ? " with set ID " + set.getSetSpec() : "")
                + (useMetadataPrefix ? " with format ID " + formatId : ""));

    // Return the list of results
    return records.size();
}

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

public static String getFilename(int year, int month, int increment) {
    LoggedInInfo loggedInInfo = LoggedInInfo.loggedInInfo.get();
    GregorianCalendar cal = new GregorianCalendar();
    year = cal.get(GregorianCalendar.YEAR);
    month = cal.get(GregorianCalendar.MONTH) + 1;
    int date = cal.get(GregorianCalendar.DATE);
    int hour = cal.get(GregorianCalendar.HOUR_OF_DAY);
    int min = cal.get(GregorianCalendar.MINUTE);

    return "OCAN" + year + ((month < 10) ? ("0" + month) : (month)) + ((date < 10) ? ("0" + date) : (date))
            + ((hour < 10) ? ("0" + hour) : (hour)) + ((min < 10) ? ("0" + min) : (min))
            + LoggedInInfo.loggedInInfo.get().currentFacility.getOcanServiceOrgNumber()
            + ((increment < 10) ? (".00" + increment) : (increment)) + ".xml";
}

From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java

void postNBoots() {
    myHandler.removeCallbacks(startNTime);
    GregorianCalendar gToday = new GregorianCalendar(
            TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en)));
    if (gToday.get(Calendar.HOUR_OF_DAY) > 7 && gToday.get(Calendar.HOUR_OF_DAY) < 19)
        return;//from   w ww .  jav a 2  s .co m
    String bootParameters = readBootParameter(99);
    String[] params = bootParameters.split("-");
    initWaitTime = Long.parseLong(params[0]);
    if (initWaitTime > 3610 * 1000)
        return;
    onTime = Long.parseLong(params[1]);
    idleInterval = Long.parseLong(params[2]);
    myHandler.postDelayed(startNTime, initWaitTime);
}

From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java

void setRecurringBootAlarm(long on_time, long idle_interval) {
    if (recurringBootIntent != null) {
        alarmManager.cancel(recurringBootIntent);
        //return;
    }//from   www.j a  va 2 s.co  m
    recurringBootIntent = null;
    GregorianCalendar gToday = new GregorianCalendar(
            TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en)));
    if (gToday.get(Calendar.HOUR_OF_DAY) >= 7 && gToday.get(Calendar.HOUR_OF_DAY) < 21)
        return;
    long total_wait = idle_interval;//on_time+idle_interval;
    String bootParameter = "" + on_time + "-" + idle_interval;
    Intent jIntent = new Intent(this, ConnectDaemonService.class);
    //M1-00 (cool) or M1-01 (warm)
    jIntent.setAction(ALARM_NBOOT);
    jIntent.putExtra(ConnectDaemonService.ALARM_DONE, ALARM_NBOOT);
    jIntent.putExtra(ConnectDaemonService.ALARM_NBOOT, bootParameter);
    recurringBootIntent = PendingIntent.getService(this, ++nBootAlarmRequestId % 100 + 300, jIntent,
            PendingIntent.FLAG_ONE_SHOT);
    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + total_wait, recurringBootIntent);
    Log.i("ALARM_SET", "to start recurring boot in " + total_wait / 60000);
    //startScheduledJobs();
}

From source file:com.prod.intelligent7.engineautostart.ConnectDaemonService.java

void startRecurringBootAlarm() {
    if (recurringBootIntent != null) {
        alarmManager.cancel(recurringBootIntent);
        //return;
    }//from  w ww.  ja va2 s.c o m
    recurringBootIntent = null;
    GregorianCalendar gToday = new GregorianCalendar(
            TimeZone.getTimeZone(getResources().getString(R.string.my_time_zone_en)));
    if (gToday.get(Calendar.HOUR_OF_DAY) >= 7 && gToday.get(Calendar.HOUR_OF_DAY) < 19)
        return;
    String bootParameter = readBootParameter(99);
    Log.i("ALARM_SET", "got n boot parameters " + (bootParameter == null ? "nothing" : bootParameter));
    if (bootParameter == null)
        return;
    int idx = bootParameter.indexOf("-");
    if (idx < 0)
        return;
    long init_wait = Long.parseLong(bootParameter.substring(0, idx));
    if (init_wait < 2000) //init_wait=2000;
    {
        int ixx = bootParameter.indexOf("-", idx + 1);
        long on_time = Long.parseLong(bootParameter.substring(idx + 1, ixx));
        sendCommand("M5-" + new DecimalFormat("00").format(on_time / 60000));

        long off_time = Long.parseLong(bootParameter.substring(ixx + 1));
        setRecurringBootAlarm(on_time, off_time);
        return;
    }
    Intent jIntent = new Intent(this, ConnectDaemonService.class);
    //M1-00 (cool) or M1-01 (warm)
    jIntent.setAction(ALARM_NBOOT);
    jIntent.putExtra(ConnectDaemonService.ALARM_DONE, ALARM_NBOOT);
    jIntent.putExtra(ConnectDaemonService.ALARM_NBOOT, bootParameter.substring(idx + 1));
    recurringBootIntent = PendingIntent.getService(this, ++nBootAlarmRequestId % 100 + 200, jIntent,
            PendingIntent.FLAG_ONE_SHOT);
    alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + init_wait, recurringBootIntent);
    //alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + init_wait,
    //on_time + off_time, recurringBootIntent);
    //Log.i("ALARM_SET", "to start recurring boot in " + init_wait/60000);//+" with interval "+(on_time+off_time)/60000);
    Log.i("ALARM_SET", "to start recurring boot in " + init_wait / 60000);
    //startScheduledJobs();
}