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.openmrs.api.PatientServiceTest.java

/**
 * @see PatientService#mergePatients(Patient,Patient)
 * @verifies audit prior date of birth estimated
 *///from w  w w  .j av a2 s  . c o m
@Test
public void mergePatients_shouldAuditPriorDateOfBirthEstimated() throws Exception {
    //retrieve preferred patient and set a date of birth
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    Patient preferred = patientService.getPatient(999);
    preferred.setBirthdate(cDate.getTime());
    preferred.setBirthdateEstimated(true);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertTrue("prior estimated date of birth was not audited",
            audit.getPersonMergeLogData().isPriorDateOfBirthEstimated());
}

From source file:org.openmrs.api.PatientServiceTest.java

/**
 * @see PatientService#mergePatients(Patient,Patient)
 * @verifies audit prior date of death estimated
 *///w w w  .  j a va  2  s .c  o  m
@Test
public void mergePatients_shouldAuditPriorDateOfDeathEstimated() throws Exception {
    //retrieve preferred patient and set a date of death
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    Patient preferred = patientService.getPatient(999);
    preferred.setDeathDate(cDate.getTime());
    preferred.setDeathdateEstimated(true);
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertTrue("prior estimated date of death was not audited",
            audit.getPersonMergeLogData().getPriorDateOfDeathEstimated());
}

From source file:com.advdb.footballclub.FootBallClub.java

private void generateFactMatch(int opponentIndex, GregorianCalendar cal, int competitionKy, Session session) {

    int randomDay = randomWithRange(1, 3);
    cal.add(Calendar.DATE, randomDay);
    //Random tactic
    String hqlDT = "from DimTactic dt";
    List resultDT = session.createQuery(hqlDT).list();
    int tacticIndex = randomWithRange(0, resultDT.size());

    //Random player
    String hqlDP = "from DimPlayer dp";
    List resultDP = session.createQuery(hqlDP).list();
    HashMap<Integer, FactMatch> playerMap = new HashMap<Integer, FactMatch>();

    FactMeasure matchMeasure = new FactMeasure();
    matchMeasure.setHalfTimeGoals(randomWithRange(0, 2));
    matchMeasure.setFullTimeGoals(// w  w w.  j av a2s  .  co m
            randomWithRange(matchMeasure.getHalfTimeGoals(), matchMeasure.getHalfTimeGoals() + 2));
    matchMeasure.setShot(randomWithRange(10, 25));
    matchMeasure.setFoul(randomWithRange(2, 10));
    matchMeasure.setCornner(randomWithRange(5, 15));
    matchMeasure.setYellowCard(randomWithRange(0, 5));

    int playerIndex;
    do {
        playerIndex = randBetween(0, resultDP.size());
        if (!playerMap.containsKey(playerIndex)) {

            FactMeasure m = new FactMeasure();
            m.setHalfTimeGoals(randomWithRange(0, matchMeasure.getHalfTimeGoals()));
            matchMeasure.setHalfTimeGoals(matchMeasure.getHalfTimeGoals() - m.getHalfTimeGoals());

            m.setFullTimeGoals(randomWithRange(m.getHalfTimeGoals(), matchMeasure.getFullTimeGoals()));
            matchMeasure.setFullTimeGoals(matchMeasure.getFullTimeGoals() - m.getFullTimeGoals());

            if (matchMeasure.getShot() != 0) {
                m.setShot(randomWithRange(m.getFullTimeGoals(), matchMeasure.getShot() / 2));
                matchMeasure.setShot(matchMeasure.getShot() - m.getShot());
                m.setOnTarget(randomWithRange(m.getFullTimeGoals(), m.getShot()));
                m.setOffTarget(m.getShot() - m.getOnTarget());
            }
            m.setFoul(randomWithRange(0, matchMeasure.getFoul()));
            matchMeasure.setFoul(matchMeasure.getFoul() - m.getFoul());

            int cornnerWeight = 0;
            if (matchMeasure.getCornner() != 0) {
                cornnerWeight = randomWithRange(1, matchMeasure.getCornner());
            }
            m.setCornner(randomWithRangeAndWeight(0, matchMeasure.getCornner(), cornnerWeight));
            matchMeasure.setCornner(matchMeasure.getCornner() - m.getCornner());

            if (matchMeasure.getYellowCard() != 0 && matchMeasure.getYellowCard() >= 2) {
                m.setYellowCard(randomWithRangeAndWeight(0, matchMeasure.getYellowCard(),
                        matchMeasure.getYellowCard() - 2));
                matchMeasure.setYellowCard(matchMeasure.getYellowCard() - m.getYellowCard());
                if (m.getYellowCard() == 2) {
                    m.setRedCard(1);
                    matchMeasure.setRedCard(matchMeasure.getRedCard() - 1);
                }

            }
            createDate(session, cal);
            FactMatch factMatch = new FactMatch(competitionKy, cal.getTime(), opponentIndex, tacticIndex,
                    playerIndex, m.getFullTimeGoals(), m.getHalfTimeGoals(), m.getShot(), m.getOnTarget(),
                    m.getOffTarget(), m.getCornner(), m.getFoul(), m.getYellowCard(), m.getRedCard());

            playerMap.put(playerIndex, factMatch);
            session.save(factMatch);

        }
    } while (playerMap.size() != 13);
}

From source file:org.openmrs.api.PatientServiceTest.java

/**
 * @see PatientService#mergePatients(Patient,Patient)
 * @verifies audit prior date of birth// www .j  a  v  a  2  s.  c o  m
 */
@Test
public void mergePatients_shouldAuditPriorDateOfBirth() throws Exception {
    //retrieve preferred patient and set a date of birth
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    //milliseconds are not serialized into the database. they will be ignored in the test
    cDate.set(Calendar.MILLISECOND, 0);
    Patient preferred = patientService.getPatient(999);
    preferred.setBirthdate(cDate.getTime());
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertEquals("prior date of birth was not audited", cDate.getTime(),
            audit.getPersonMergeLogData().getPriorDateOfBirth());
}

From source file:org.openmrs.api.PatientServiceTest.java

/**
 * @see PatientService#mergePatients(Patient,Patient)
 * @verifies audit prior date of death//from   www.  j ava2 s. co m
 */
@Test
public void mergePatients_shouldAuditPriorDateOfDeath() throws Exception {
    //retrieve preferred patient and set a date of birth
    GregorianCalendar cDate = new GregorianCalendar();
    cDate.setTime(new Date());
    //milliseconds are not serialized into the database. they will be ignored in the test
    cDate.set(Calendar.MILLISECOND, 0);
    Patient preferred = patientService.getPatient(999);
    preferred.setDeathDate(cDate.getTime());
    preferred.setDead(true);
    preferred.setCauseOfDeath(Context.getConceptService().getConcept(3));
    preferred.addName(new PersonName("givenName", "middleName", "familyName"));
    patientService.savePatient(preferred);
    Patient notPreferred = patientService.getPatient(7);
    voidOrders(Collections.singleton(notPreferred));
    PersonMergeLog audit = mergeAndRetrieveAudit(preferred, notPreferred);
    Assert.assertEquals("prior date of death was not audited", cDate.getTime(),
            audit.getPersonMergeLogData().getPriorDateOfDeath());

}

From source file:eionet.util.Util.java

/**
 * A method for calculating time difference in MILLISECONDS, between a date-time specified in input parameters and the current
 * date-time. <BR>/*from w ww  .  j a v  a 2 s  .co  m*/
 * This should be useful for calculating sleep time for code that has a certain schedule for execution.
 *
 * @param hour
 *            An integer from 0 to 23. If less than 0 or more than 23, then the closest next hour to current hour is taken.
 * @param date
 *            An integer from 1 to 31. If less than 1 or more than 31, then the closest next date to current date is taken.
 * @param month
 *            An integer from Calendar.JANUARY to Calendar.DECEMBER. If out of those bounds, the closest next month to current
 *            month is taken.
 * @param wday
 *            An integer from 1 to 7. If out of those bounds, the closest next weekday to weekday month is taken.
 * @param zone
 *            A String specifying the time-zone in which the calculations should be done. Please see Java documentation an
 *            allowable time-zones and formats.
 * @return Time difference in milliseconds.
 */
public static long timeDiff(int hour, int date, int month, int wday, String zone) {

    GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone(zone));
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MILLISECOND, 0);

    cal.setFirstDayOfWeek(Calendar.MONDAY);

    /*
     * here we force the hour to be one of the defualts if (hour < 0) hour = 0; if (hour > 23) hour = 23;
     */
    int cur_hour = cal.get(Calendar.HOUR);

    if (cal.get(Calendar.AM_PM) == Calendar.PM) {
        cur_hour = 12 + cur_hour;
    }

    // here we assume that every full hour is accepted
    /*
     * if (hour < 0 || hour > 23) { hour = cur_hour>=23 ? 0 : cur_hour + 1; }
     */

    if (wday >= 1 && wday <= 7) {

        int cur_wday = cal.get(Calendar.DAY_OF_WEEK);
        if (hour < 0 || hour > 23) {
            if (cur_wday != wday) {
                hour = 0;
            } else {
                hour = cur_hour >= 23 ? 0 : cur_hour + 1;
            }
        }

        int amount = wday - cur_wday;
        if (amount < 0) {
            amount = 7 + amount;
        }
        if (amount == 0 && cur_hour >= hour) {
            amount = 7;
        }
        cal.add(Calendar.DAY_OF_WEEK, amount);
    } else if (month >= Calendar.JANUARY && month <= Calendar.DECEMBER) { // do something about when every date is accepted
        if (date < 1) {
            date = 1;
        }
        if (date > 31) {
            date = 31;
        }
        int cur_month = cal.get(Calendar.MONTH);
        int amount = month - cur_month;
        if (amount < 0) {
            amount = 12 + amount;
        }
        if (amount == 0) {
            if (cal.get(Calendar.DATE) > date) {
                amount = 12;
            } else if (cal.get(Calendar.DATE) == date) {
                if (cur_hour >= hour) {
                    amount = 12;
                }
            }
        }
        // cal.set(Calendar.DATE, date);
        cal.add(Calendar.MONTH, amount);
        if (date > cal.getActualMaximum(Calendar.DATE)) {
            date = cal.getActualMaximum(Calendar.DATE);
        }
        cal.set(Calendar.DATE, date);
    } else if (date >= 1 && date <= 31) {
        int cur_date = cal.get(Calendar.DATE);
        if (cur_date > date) {
            cal.add(Calendar.MONTH, 1);
        } else if (cur_date == date) {
            if (cur_hour >= hour) {
                cal.add(Calendar.MONTH, 1);
            }
        }
        cal.set(Calendar.DATE, date);
    } else {
        if (hour < 0 || hour > 23) {
            hour = cur_hour >= 23 ? 0 : cur_hour + 1;
        }
        if (cur_hour >= hour) {
            cal.add(Calendar.DATE, 1);
        }
    }

    if (hour >= 12) {
        cal.set(Calendar.HOUR, hour - 12);
        cal.set(Calendar.AM_PM, Calendar.PM);
    } else {
        cal.set(Calendar.HOUR, hour);
        cal.set(Calendar.AM_PM, Calendar.AM);
    }

    Date nextDate = cal.getTime();
    Date currDate = new Date();

    long nextTime = cal.getTime().getTime();
    long currTime = (new Date()).getTime();

    return nextTime - currTime;
}

From source file:org.exoplatform.services.cms.actions.impl.BaseActionPlugin.java

private void scheduleActionActivationJob(String srcWorkspace, String srcPath, String actionName,
        String actionType, String actionExecutable, Map mappings) throws Exception {
    JobSchedulerService schedulerService = WCMCoreUtils.getService(JobSchedulerService.class);
    ActionServiceContainer actionContainer = WCMCoreUtils.getService(ActionServiceContainer.class);

    Session session = getSystemSession(srcWorkspace);
    Node srcNode = (Node) session.getItem(srcPath);
    Node actionNode = actionContainer.getAction(srcNode, actionName);
    if (!actionNode.isNodeType(SCHEDULABLE_INFO_MIXIN)) {
        actionNode.addMixin(SCHEDULABLE_INFO_MIXIN);
    }/*from  w w  w .j ava2  s  .co  m*/
    Class activationJob = createActivationJob();
    String jobName = JOB_NAME_PREFIX.concat(actionName);
    String jobGroup = actionType;
    String userId = session.getUserID();
    String scheduleType = null, repeatCount = null, timeInterval = null, cronExpress = null;
    GregorianCalendar startTime = new GregorianCalendar();
    GregorianCalendar endTime = null;
    if (mappings.containsKey("/node/exo:scheduleType")) {
        scheduleType = (String) ((JcrInputProperty) mappings.get("/node/exo:scheduleType")).getValue();
        mappings.remove("/node/exo:scheduleType");
    }
    if (mappings.containsKey("/node/exo:startTime")) {
        startTime = (GregorianCalendar) ((JcrInputProperty) mappings.get("/node/exo:startTime")).getValue();
        mappings.remove("/node/exo:startTime");
    }
    if (mappings.containsKey("/node/exo:endTime")) {
        endTime = (GregorianCalendar) ((JcrInputProperty) mappings.get("/node/exo:endTime")).getValue();
        mappings.remove("/node/exo:endTime");
    }
    if (mappings.containsKey("/node/exo:repeatCount")) {
        repeatCount = (String) ((JcrInputProperty) mappings.get("/node/exo:repeatCount")).getValue();
        mappings.remove("/node/exo:repeatCount");
    }
    if (mappings.containsKey("/node/exo:timeInterval")) {
        timeInterval = (String) ((JcrInputProperty) mappings.get("/node/exo:timeInterval")).getValue();
        mappings.remove("/node/exo:timeInterval");
    }
    if (mappings.containsKey("/node/exo:cronExpression")) {
        cronExpress = (String) ((JcrInputProperty) mappings.get("/node/exo:cronExpression")).getValue();
        mappings.remove("/node/exo:cronExpression");
    }
    actionNode.setProperty(JOB_NAME_PROP, jobName);
    actionNode.setProperty(JOB_GROUP_PROP, jobGroup);

    actionNode.setProperty(JOB_CLASS_PROP, activationJob.getName());
    actionNode.setProperty(SCHEDULED_INITIATOR, userId);
    actionNode.setProperty(SCHEDULE_TYPE_PROP, scheduleType);
    actionNode.save();
    Map<String, Object> variables = new HashMap<String, Object>();
    variables.put(initiatorVar, userId);
    variables.put(actionNameVar, actionName);
    variables.put(executableVar, actionExecutable);
    variables.put(srcWorkspaceVar, srcWorkspace);
    variables.put(srcPathVar, srcPath);
    variables.put(nodePath, srcPath);
    Map<String, Object> executionVariables = getExecutionVariables(mappings);
    JobDataMap jdatamap = new JobDataMap();
    jdatamap.putAll(variables);
    jdatamap.putAll(executionVariables);
    JobInfo jinfo = new JobInfo(jobName, jobGroup, activationJob);
    if (scheduleType.equals(CRON_JOB)) {
        actionNode.setProperty(CRON_EXPRESSION_PROP, cronExpress);
        actionNode.save();
        schedulerService.addCronJob(jinfo, cronExpress, jdatamap);
    } else {
        int repeatNum = Integer.parseInt(repeatCount);
        long period = Long.parseLong(timeInterval);
        actionNode.setProperty(START_TIME_PROP, startTime);
        if (endTime != null) {
            actionNode.setProperty(END_TIME_PROP, endTime);
        }
        actionNode.setProperty(TIME_INTERVAL_PROP, period);
        actionNode.setProperty(REPEAT_COUNT_PROP, repeatNum);
        actionNode.save();
        PeriodInfo pinfo;
        if (endTime != null) {
            pinfo = new PeriodInfo(startTime.getTime(), endTime.getTime(), repeatNum, period);
        } else {
            pinfo = new PeriodInfo(repeatNum, period);
        }
        schedulerService.addPeriodJob(jinfo, pinfo, jdatamap);
    }
    session.save();
    session.logout();
}

From source file:fr.paris.lutece.plugins.plu.web.PluJspBean.java

/**
 * Apply a Plu and return to the Plu manage
 * @param request the Http request/*from w  ww  . j  ava2s  . c  o m*/
 * @throws ParseException ParseException
 * @return HTML
 */
public String doApplicablePlu(HttpServletRequest request) throws ParseException {
    int nIdPlu = Integer.parseInt(request.getParameter(PARAMETER_PLU_ID));
    Plu plu = _pluServices.findByPrimaryKey(nIdPlu);
    Date dateApplicationPlu = stringToDate(request.getParameter(PARAMETER_DATE_APPLICATION), "dd/MM/yyyy");

    Etat etat = _etatServices.findByPrimaryKey(1);

    plu.setEtat(etat);
    plu.setDa(dateApplicationPlu);
    _pluServices.update(plu);

    // Set the date application of the VA in state 1
    List<Version> versionState1 = _versionServices.findVersionState(1, nIdPlu);
    for (Version version : versionState1) {
        version.setD2(dateApplicationPlu);
        _versionServices.update(version);
    }

    GregorianCalendar dayBeforeApplication = new GregorianCalendar();
    dayBeforeApplication.setTime(dateApplicationPlu);
    dayBeforeApplication.add(Calendar.DATE, -1);

    // Set the date archive of the VA in state 3
    List<Version> versionState3 = _versionServices.selectArchive();
    for (Version version : versionState3) {
        version.setD4(dayBeforeApplication.getTime());
        version.setArchive('N');
        _versionServices.update(version);
    }

    Plu plu2 = new Plu();
    _pluServices.create(plu2);

    plu2 = _pluServices.findPluWork();

    //all the folder of the previous working PLU : call this PLUAPP
    List<Folder> folderList = _folderServices.findByPluId(nIdPlu);
    Map<Integer, Integer> mapIdOldIdNew = new Hashtable<Integer, Integer>();

    for (Folder folder : folderList) {
        Folder folder2 = new Folder();
        //for each folder of PLUAPP, clone this in folder2
        folder2.setPlu(plu2.getId());

        if (mapIdOldIdNew.containsKey(folder.getParentFolder())) {
            folder2.setParentFolder(mapIdOldIdNew.get(folder.getParentFolder()));
        } else {
            folder2.setParentFolder(folder.getParentFolder());
        }

        folder2.setTitle(folder.getTitle());
        folder2.setDescription(folder.getDescription());
        folder2.setNomImage(folder.getNomImage());
        folder2.setImg(folder.getImg());
        folder2.setHtml(folder.getHtml());
        folder2.setHtmlImpression(folder.getHtmlImpression());

        _folderServices.create(folder2);

        folder2 = _folderServices.findLastFolder();
        mapIdOldIdNew.put(folder.getId(), folder2.getId());

        List<FolderVersion> folderVersionList = _folderVersionServices.findByFolder(folder);

        for (FolderVersion folderVersion : folderVersionList) {
            FolderVersion folderVersion2 = new FolderVersion();
            folderVersion2.setVersion(folderVersion.getVersion());
            folderVersion2.setFolder(folder2);
            _folderVersionServices.create(folderVersion2);
        }
    }

    return JSP_REDIRECT_TO_MANAGE_PLU;
}

From source file:ffsutils.TaskUtils.java

public static ArrayList<Tasks> getTaskByMeComp(Connection conn, UserAccount Username, String onlyUser)
        throws SQLException {
    System.out.println("getTaskByMeComp " + onlyUser);
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    GregorianCalendar cal121 = new GregorianCalendar();
    cal121.setTime(date);/*from  w  w w  .  j  a  v  a  2 s  . co  m*/
    cal121.add(Calendar.DATE, 3);
    Date days3 = cal121.getTime();

    String year = Integer.toString(cal.get(Calendar.YEAR));
    String month = Integer.toString(cal.get(Calendar.MONTH) + 1);
    String day = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    String hour = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
    String minute = Integer.toString(cal.get(Calendar.MINUTE));

    String sql = "";
    if (onlyUser == null) {
        onlyUser = "";
    }
    if (onlyUser.equals(null) | onlyUser.length() < 4) {
        sql = "select * from " + Username.getcompany()
                + ".tasks where (taskfrom = ?) and (taskstat = 'Completed')";
    } else {
        sql = "select * from " + Username.getcompany()
                + ".tasks where (taskfrom = ?) and (taskstat = 'Completed') and ((taskto1 ='" + onlyUser
                + "') or (taskto2 ='" + onlyUser + "') or (taskto3 ='" + onlyUser + "') or (taskto4 ='"
                + onlyUser + "') or (taskto5 ='" + onlyUser + "') or (taskto6 ='" + onlyUser
                + "') or (taskto7 ='" + onlyUser + "') or (taskto8 ='" + onlyUser + "') or (taskto9 ='"
                + onlyUser + "') or (taskto10 ='" + onlyUser + "') or (taskto11 ='" + onlyUser
                + "') or (taskto12 ='" + onlyUser + "') or (taskto13 ='" + onlyUser + "') or (taskto14 ='"
                + onlyUser + "') or (taskto15 ='" + onlyUser + "'))";
    }
    PreparedStatement pstm = conn.prepareStatement(sql);
    pstm.setString(1, Username.getUserName());

    ResultSet rs = pstm.executeQuery();
    ArrayList<Tasks> list = new ArrayList<Tasks>();
    while (rs.next()) {
        Date date1 = new Date();
        Calendar cal1 = new GregorianCalendar();
        if (rs.getTimestamp("revdate") == null) {
            cal1.setTime(rs.getTimestamp("startdate"));
        } else {
            cal1.setTime(rs.getTimestamp("revdate"));
        }
        String year1 = Integer.toString(cal1.get(Calendar.YEAR));
        String month1 = Integer.toString(cal1.get(Calendar.MONTH) + 1);
        String day1 = Integer.toString(cal1.get(Calendar.DAY_OF_MONTH));
        String hour1 = Integer.toString(cal1.get(Calendar.HOUR_OF_DAY));
        String minute1 = Integer.toString(cal1.get(Calendar.MINUTE));
        if (hour1.length() == 1) {
            hour1 = "0" + hour1;
        }
        if (minute1.length() == 1) {
            minute1 = "0" + minute1;
        }
        if (month1.length() == 1) {
            month1 = "0" + month1;
        }
        if (day1.length() == 1) {
            day1 = "0" + day1;
        }
        Date date2 = new Date();
        Calendar cal2 = new GregorianCalendar();

        cal2.setTime(rs.getTimestamp("enddate"));
        String year2 = Integer.toString(cal2.get(Calendar.YEAR));
        String month2 = Integer.toString(cal2.get(Calendar.MONTH) + 1);
        String day2 = Integer.toString(cal2.get(Calendar.DAY_OF_MONTH));
        String hour2 = Integer.toString(cal2.get(Calendar.HOUR_OF_DAY));
        String minute2 = Integer.toString(cal2.get(Calendar.MINUTE));
        if (hour2.length() == 1) {
            hour2 = "0" + hour2;
        }
        if (minute2.length() == 1) {
            minute2 = "0" + minute2;
        }
        if (month2.length() == 1) {
            month2 = "0" + month2;
        }
        if (day2.length() == 1) {
            day2 = "0" + day2;
        }
        Date date3 = new Date();
        Calendar cal3 = new GregorianCalendar();

        cal3.setTime(rs.getTimestamp("startdate"));
        String year3 = Integer.toString(cal3.get(Calendar.YEAR));
        String month3 = Integer.toString(cal3.get(Calendar.MONTH) + 1);
        String day3 = Integer.toString(cal3.get(Calendar.DAY_OF_MONTH));
        String hour3 = Integer.toString(cal3.get(Calendar.HOUR_OF_DAY));
        String minute3 = Integer.toString(cal3.get(Calendar.MINUTE));
        if (hour3.length() == 1) {
            hour3 = "0" + hour3;
        }
        if (minute3.length() == 1) {
            minute3 = "0" + minute3;
        }
        if (month3.length() == 1) {
            month3 = "0" + month3;
        }
        if (day3.length() == 1) {
            day3 = "0" + day3;
        }
        String tranid = rs.getString("tranid");
        String taskfrom = rs.getString("taskfrom");
        String description = rs.getString("description");
        String revdate = year1 + "-" + month1 + "-" + day1 + " " + hour1 + ":" + minute1;
        String enddate = year2 + "-" + month2 + "-" + day2 + " " + hour2 + ":" + minute2;
        String taskstat;
        if (rs.getString("taskstat") == null) {
            taskstat = "Not Started";
        } else {
            taskstat = rs.getString("taskstat");
        }
        //String taskstat = rs.getString("taskstat");
        String startdate = year3 + "-" + month3 + "-" + day3 + " " + hour3 + ":" + minute3;
        Tasks task = new Tasks();
        task.setTranid(tranid);
        task.setTaskfrom(taskfrom);
        task.setDescription(description);
        task.setRevdate(revdate);
        task.setEnddate(enddate);
        task.setTaskstat(taskstat);
        task.setStartdate(startdate);
        task.setTaskto1(rs.getString("taskto1"));
        String color1 = "";
        if (date.after(rs.getTimestamp("revdate"))) {
            color1 = "red";
        }
        if (color1 == "" && days3.after(rs.getTimestamp("revdate"))) {
            color1 = "orange";
        }
        if (color1 == "") {
            color1 = "green";
        }
        task.setlinkup1(color1);
        String color2 = "black";
        if ((Username.equals(rs.getString("taskto1")) && (!"Y".equals(rs.getString("newt1"))))
                || (Username.equals(rs.getString("taskto2")) && (!"Y".equals(rs.getString("newt2"))))
                || (Username.equals(rs.getString("taskto3")) && (!"Y".equals(rs.getString("newt3"))))
                || (Username.equals(rs.getString("taskto4")) && (!"Y".equals(rs.getString("newt4"))))
                || (Username.equals(rs.getString("taskto5")) && (!"Y".equals(rs.getString("newt5"))))
                || (Username.equals(rs.getString("taskto6")) && (!"Y".equals(rs.getString("newt6"))))
                || (Username.equals(rs.getString("taskto7")) && (!"Y".equals(rs.getString("newt7"))))
                || (Username.equals(rs.getString("taskto8")) && (!"Y".equals(rs.getString("newt8"))))
                || (Username.equals(rs.getString("taskto9")) && (!"Y".equals(rs.getString("newt9"))))
                || (Username.equals(rs.getString("taskto10")) && (!"Y".equals(rs.getString("newt10"))))
                || (Username.equals(rs.getString("taskto11")) && (!"Y".equals(rs.getString("newt11"))))
                || (Username.equals(rs.getString("taskto12")) && (!"Y".equals(rs.getString("newt12"))))
                || (Username.equals(rs.getString("taskto13")) && (!"Y".equals(rs.getString("newt13"))))
                || (Username.equals(rs.getString("taskto14")) && (!"Y".equals(rs.getString("newt14"))))
                || (Username.equals(rs.getString("taskto15")) && (!"Y".equals(rs.getString("newt15"))))) {
            color2 = "green";
        }
        task.setlinkup2(color2);

        list.add(task);

    }

    return list;
}

From source file:ffsutils.TaskUtils.java

public static ArrayList<Tasks> getTaskByMe(Connection conn, UserAccount Username, String onlyUser)
        throws SQLException {

    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    GregorianCalendar cal121 = new GregorianCalendar();
    cal121.setTime(date);/* w  w  w.j a va  2s. com*/
    cal121.add(Calendar.DATE, 3);
    Date days3 = cal121.getTime();

    String year = Integer.toString(cal.get(Calendar.YEAR));
    String month = Integer.toString(cal.get(Calendar.MONTH) + 1);
    String day = Integer.toString(cal.get(Calendar.DAY_OF_MONTH));
    String hour = Integer.toString(cal.get(Calendar.HOUR_OF_DAY));
    String minute = Integer.toString(cal.get(Calendar.MINUTE));

    String sql = "";
    if (onlyUser == null) {
        onlyUser = "";
    }
    if (onlyUser.equals(null) | onlyUser.length() < 4) {
        sql = "select * from " + Username.getcompany()
                + ".tasks where (taskfrom = ?) and ((taskstat <> 'Completed') or (taskstat is NULL))";
    } else {
        sql = "select * from " + Username.getcompany()
                + ".tasks where ((taskfrom = ?) and ((taskstat <> 'Completed') or (taskstat is NULL)) ) and ((taskto1 = '"
                + onlyUser + "') or (taskto2 = '" + onlyUser + "') or (taskto3 = '" + onlyUser
                + "') or (taskto4 = '" + onlyUser + "') or (taskto5 = '" + onlyUser + "') or (taskto6 = '"
                + onlyUser + "') or (taskto7 = '" + onlyUser + "') or (taskto8 = '" + onlyUser
                + "') or (taskto9 = '" + onlyUser + "') or (taskto10 = '" + onlyUser + "') or (taskto11 = '"
                + onlyUser + "') or (taskto12 = '" + onlyUser + "') or (taskto13 = '" + onlyUser
                + "') or (taskto14 = '" + onlyUser + "') or (taskto15 = '" + onlyUser + "')) ";
    }

    PreparedStatement pstm = conn.prepareStatement(sql);
    pstm.setString(1, Username.getUserName());

    ResultSet rs = pstm.executeQuery();
    ArrayList<Tasks> list = new ArrayList<Tasks>();
    while (rs.next()) {
        Date date1 = new Date();
        Calendar cal1 = new GregorianCalendar();
        if (rs.getTimestamp("revdate") == null) {
            cal1.setTime(rs.getTimestamp("enddate"));
        } else {
            cal1.setTime(rs.getTimestamp("revdate"));
        }
        // cal1.setTime(rs.getTimestamp("revdate"));
        String year1 = Integer.toString(cal1.get(Calendar.YEAR));
        String month1 = Integer.toString(cal1.get(Calendar.MONTH) + 1);
        String day1 = Integer.toString(cal1.get(Calendar.DAY_OF_MONTH));
        String hour1 = Integer.toString(cal1.get(Calendar.HOUR_OF_DAY));
        String minute1 = Integer.toString(cal1.get(Calendar.MINUTE));
        if (hour1.length() == 1) {
            hour1 = "0" + hour1;
        }
        if (minute1.length() == 1) {
            minute1 = "0" + minute1;
        }
        if (month1.length() == 1) {
            month1 = "0" + month1;
        }
        if (day1.length() == 1) {
            day1 = "0" + day1;
        }
        Date date2 = new Date();
        Calendar cal2 = new GregorianCalendar();

        cal2.setTime(rs.getTimestamp("enddate"));
        String year2 = Integer.toString(cal2.get(Calendar.YEAR));
        String month2 = Integer.toString(cal2.get(Calendar.MONTH) + 1);
        String day2 = Integer.toString(cal2.get(Calendar.DAY_OF_MONTH));
        String hour2 = Integer.toString(cal2.get(Calendar.HOUR_OF_DAY));
        String minute2 = Integer.toString(cal2.get(Calendar.MINUTE));
        if (hour2.length() == 1) {
            hour2 = "0" + hour2;
        }
        if (minute2.length() == 1) {
            minute2 = "0" + minute2;
        }
        if (month2.length() == 1) {
            month2 = "0" + month2;
        }
        if (day2.length() == 1) {
            day2 = "0" + day2;
        }
        Date date3 = new Date();
        Calendar cal3 = new GregorianCalendar();

        cal3.setTime(rs.getTimestamp("startdate"));
        String year3 = Integer.toString(cal3.get(Calendar.YEAR));
        String month3 = Integer.toString(cal3.get(Calendar.MONTH) + 1);
        String day3 = Integer.toString(cal3.get(Calendar.DAY_OF_MONTH));
        String hour3 = Integer.toString(cal3.get(Calendar.HOUR_OF_DAY));
        String minute3 = Integer.toString(cal3.get(Calendar.MINUTE));
        if (hour3.length() == 1) {
            hour3 = "0" + hour3;
        }
        if (minute3.length() == 1) {
            minute3 = "0" + minute3;
        }
        if (month3.length() == 1) {
            month3 = "0" + month3;
        }
        if (day3.length() == 1) {
            day3 = "0" + day3;
        }
        String tranid = rs.getString("tranid");
        String taskfrom = rs.getString("taskfrom");
        String description = rs.getString("description");
        String revdate = year1 + "-" + month1 + "-" + day1 + " " + hour1 + ":" + minute1;
        String enddate = year2 + "-" + month2 + "-" + day2 + " " + hour2 + ":" + minute2;
        String taskstat;
        if (rs.getString("taskstat") == null) {
            taskstat = "Not Started";
        } else {
            taskstat = rs.getString("taskstat");
        }
        String startdate = year3 + "-" + month3 + "-" + day3 + " " + hour3 + ":" + minute3;
        Tasks task = new Tasks();
        task.setTranid(tranid);
        task.setTaskfrom(taskfrom);
        task.setDescription(description);
        task.setRevdate(revdate);
        task.setEnddate(enddate);
        task.setTaskstat(taskstat);
        task.setStartdate(startdate);
        task.setTaskto1(rs.getString("taskto1"));
        String color1 = "";
        if (date.after(rs.getTimestamp("revdate"))) {
            color1 = "red";
        }
        if (color1 == "" && days3.after(rs.getTimestamp("revdate"))) {
            color1 = "orange";
        }
        if (color1 == "") {
            color1 = "green";
        }
        task.setlinkup1(color1);
        String color2 = "black";
        if ((Username.equals(rs.getString("taskto1")) && (!"Y".equals(rs.getString("newt1"))))
                || (Username.equals(rs.getString("taskto2")) && (!"Y".equals(rs.getString("newt2"))))
                || (Username.equals(rs.getString("taskto3")) && (!"Y".equals(rs.getString("newt3"))))
                || (Username.equals(rs.getString("taskto4")) && (!"Y".equals(rs.getString("newt4"))))
                || (Username.equals(rs.getString("taskto5")) && (!"Y".equals(rs.getString("newt5"))))
                || (Username.equals(rs.getString("taskto6")) && (!"Y".equals(rs.getString("newt6"))))
                || (Username.equals(rs.getString("taskto7")) && (!"Y".equals(rs.getString("newt7"))))
                || (Username.equals(rs.getString("taskto8")) && (!"Y".equals(rs.getString("newt8"))))
                || (Username.equals(rs.getString("taskto9")) && (!"Y".equals(rs.getString("newt9"))))
                || (Username.equals(rs.getString("taskto10")) && (!"Y".equals(rs.getString("newt10"))))
                || (Username.equals(rs.getString("taskto11")) && (!"Y".equals(rs.getString("newt11"))))
                || (Username.equals(rs.getString("taskto12")) && (!"Y".equals(rs.getString("newt12"))))
                || (Username.equals(rs.getString("taskto13")) && (!"Y".equals(rs.getString("newt13"))))
                || (Username.equals(rs.getString("taskto14")) && (!"Y".equals(rs.getString("newt14"))))
                || (Username.equals(rs.getString("taskto15")) && (!"Y".equals(rs.getString("newt15"))))) {
            color2 = "green";
        }
        task.setlinkup2(color2);

        list.add(task);

    }

    return list;
}