Example usage for java.util GregorianCalendar add

List of usage examples for java.util GregorianCalendar add

Introduction

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

Prototype

@Override
public void add(int field, int amount) 

Source Link

Document

Adds the specified (signed) amount of time to the given calendar field, based on the calendar's rules.

Usage

From source file:org.sakaiproject.calendar.impl.RecurrenceRuleBase.java

/**
* Return a List of all RecurrenceInstance objects generated by this rule within the given time range, based on the
* prototype first range, in time order.//  ww w  .java 2s .  c om
* @param prototype The prototype first TimeRange.
* @param range A time range to limit the generated ranges.
* @param timeZone The time zone to use for displaying times.
* %%% Note: this is currently not implemented, and always uses the "local" zone.
* @return a List of RecurrenceInstance generated by this rule in this range.
*/
public List generateInstances(TimeRange prototype, TimeRange range, TimeZone timeZone) {
    // these calendars are used if local time zone and the time zone where the first event was created (timeZone) are different
    GregorianCalendar firstEventCalendarDate = null;
    GregorianCalendar nextFirstEventCalendarDate = null;
    // %%% Note: base the breakdonw on the "timeZone" parameter to support multiple timeZone displays -ggolden
    TimeBreakdown startBreakdown = prototype.firstTime().breakdownLocal();

    GregorianCalendar startCalendarDate = TimeService.getCalendar(TimeService.getLocalTimeZone(), 0, 0, 0, 0, 0,
            0, 0);

    startCalendarDate.set(startBreakdown.getYear(), startBreakdown.getMonth() - 1, startBreakdown.getDay(),
            startBreakdown.getHour(), startBreakdown.getMin(), startBreakdown.getSec());

    // if local time zone and first event time zone are different
    // a new calendar is generated to calculate the re-occurring events
    // if not, the local time zone calendar is used
    boolean differentTimeZone = false;
    if (TimeService.getLocalTimeZone().getID().equals(timeZone.getID())) {
        differentTimeZone = false;
    } else {
        differentTimeZone = true;
    }

    if (differentTimeZone) {
        firstEventCalendarDate = TimeService.getCalendar(timeZone, 0, 0, 0, 0, 0, 0, 0);
        firstEventCalendarDate.setTimeInMillis(startCalendarDate.getTimeInMillis());
        nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone();
    }

    List rv = new Vector();

    GregorianCalendar nextCalendarDate = (GregorianCalendar) startCalendarDate.clone();

    int currentCount = 1;

    do {
        if (differentTimeZone) {
            // next time is calculated according to the first event time zone, not the local one
            nextCalendarDate.setTimeInMillis(nextFirstEventCalendarDate.getTimeInMillis());
        }

        Time nextTime = TimeService.newTime(nextCalendarDate);

        // is this past count?
        if ((getCount() > 0) && (currentCount > getCount()))
            break;

        // is this past until?
        if ((getUntil() != null) && isAfter(nextTime, getUntil()))
            break;

        TimeRange nextTimeRange = TimeService.newTimeRange(nextTime.getTime(), prototype.duration());

        //
        // Is this out of the range?
        //
        if (isOverlap(range, nextTimeRange)) {
            TimeRange eventTimeRange = null;

            // Single time cases require special handling.
            if (prototype.isSingleTime()) {
                eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime());
            } else {
                eventTimeRange = TimeService.newTimeRange(nextTimeRange.firstTime(), nextTimeRange.lastTime(),
                        true, false);
            }

            // use this one
            rv.add(new RecurrenceInstance(eventTimeRange, currentCount));
        }

        // if next starts after the range, stop generating
        else if (isAfter(nextTime, range.lastTime()))
            break;

        // advance interval years.

        if (differentTimeZone) {
            nextFirstEventCalendarDate = (GregorianCalendar) firstEventCalendarDate.clone();
            nextFirstEventCalendarDate.add(getRecurrenceType(), getInterval() * currentCount);
        } else {
            nextCalendarDate = (GregorianCalendar) startCalendarDate.clone();
            nextCalendarDate.add(getRecurrenceType(), getInterval() * currentCount);
        }

        currentCount++;
    } while (true);

    return rv;
}

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//www  .  j a  v a 2 s.  com
 * @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:com.zimbra.cs.mailbox.calendar.ZRecur.java

public List<Date> expandRecurrenceOverRange(ParsedDateTime dtStart, long rangeStart, long rangeEnd)
        throws ServiceException {
    List<Date> toRet = new LinkedList<Date>();

    Date rangeStartDate = new Date(rangeStart);
    // subtract 1000ms (1sec) because the code in the method treats
    // end time as inclusive while the rangeEnd input argument is
    // exclusive value
    Date rangeEndDate = new Date(rangeEnd - 1000);
    Date dtStartDate = new Date(dtStart.getUtcTime());

    Date earliestDate;//from  w w w.  j  av a2s.  c om
    if (dtStartDate.after(rangeStartDate))
        earliestDate = dtStartDate;
    else
        earliestDate = rangeStartDate;

    if (mUntil != null) {
        Date until = mUntil.getDateForRecurUntil(dtStart.getTimeZone());
        if (until.before(rangeEndDate))
            rangeEndDate = until;
    }

    // Set limit of expansion count.
    int maxInstancesFromConfig = sExpansionLimits.maxInstances;
    int maxInstancesExpanded;
    if (maxInstancesFromConfig <= 0)
        maxInstancesExpanded = mCount;
    else if (mCount <= 0)
        maxInstancesExpanded = maxInstancesFromConfig;
    else
        maxInstancesExpanded = Math.min(mCount, maxInstancesFromConfig);
    int numInstancesExpanded = 1; // initially 1 rather than 0 because DTSTART is always included

    // Set hard limit of expansion time range.  (bug 21989)
    ParsedDateTime earliestDateTime = ParsedDateTime.fromUTCTime(earliestDate.getTime());
    Date hardEndDate = getEstimatedEndTime(earliestDateTime);
    if (hardEndDate.before(rangeEndDate))
        rangeEndDate = hardEndDate;

    if (rangeEndDate.before(earliestDate)) {
        ZimbraLog.calendar.debug(
                "Expanding recurrence over range where range end %s is before earliest date %s",
                DateUtil.formatDate(rangeEndDate), DateUtil.formatDate(earliestDate));
        return toRet;
    }

    GregorianCalendar cur = dtStart.getCalendarCopy();
    int baseMonthDay = cur.get(Calendar.DAY_OF_MONTH);
    boolean baseIsLeapDay = ((baseMonthDay == 29) && (cur.get(Calendar.MONTH) == Calendar.FEBRUARY));

    // until we hit rangeEnd, or we've SAVED count entries:
    //
    //     gather each set {
    //
    //
    //
    //        curDate forward one INTERVAL
    //
    //     }
    //     check Set against BYSETPOS & ranges & count
    //

    int interval = mInterval;
    if (interval <= 0)
        interval = 1;

    // DTSTART is always part of the expansion, as long as it falls within
    // the range.
    if (!dtStartDate.before(earliestDate) && !dtStartDate.after(rangeEndDate))
        toRet.add(dtStartDate);

    int numConsecutiveIterationsWithoutMatchingInstance = 0;
    boolean pastHardEndTime = false;
    long numIterations = 0; // track how many times we looped
    while (!pastHardEndTime && (maxInstancesExpanded <= 0 || numInstancesExpanded < maxInstancesExpanded)) {
        numIterations++;
        boolean curIsAtOrAfterEarliestDate = !cur.getTime().before(earliestDate);
        boolean curIsAfterEndDate = cur.getTime().after(rangeEndDate);
        List<Calendar> addList = new LinkedList<Calendar>();

        switch (mFreq) {
        case HOURLY:
            /*
             * BYSECOND - for each listed second
             * BYMINUTE - for each listed minute in hour
             * BYHOUR - match iff in hour list
             * BYDAY - for each day listed
             * BYMONTHDAY - only those monthdays
             * BYYEARDAY - only those yeardays
             * BYMONTH - only those months
             */
            if (!checkMonthList(cur))
                continue;

            if (!checkYearDayList(cur))
                continue;

            if (!checkMonthDayList(cur))
                continue;

            if (!checkDayList(cur))
                continue;

            if (!checkHourList(cur))
                continue;

            addList.add((Calendar) (cur.clone()));

            cur.add(Calendar.HOUR_OF_DAY, interval);

            addList = expandHourList(addList);
            addList = expandMinuteList(addList);
            addList = expandSecondList(addList);

            break;
        case DAILY:
            /*
             * BYSECOND - for each listed second in day
             * BYMINUTE - for each listed minute in day
             * BYHOUR - for each listed hour in day
             * BYDAY - no ordinal allowed, match iff in day list
             * BYMONTHDAY - only that day
             * BYYEARDAY - only that day
             * BYWEEKNO -- YEARLY ONLY
             * BYMONTH - only that month
             *
             * while (count check & until check & rangeEnd check) {
             *    if (byMonth && !month matches)
             *      curDay = set MONTH to matching month
             *
             *    if (byYearDay && !yearday matches)
             *      curDay = set DAY to next matching yearday
             *
             *    if (byMonthday && !monthday matches)
             *      curDay = skip to next matching monthday
             *
             *    if (byDay && !day in list)
             *      curDay = skip to next mathcing byDay
             *
             *    if (!byHour or FOR EACH HOUR IN HOURLIST)
             *      if (!byMinute or FOR EACH MINUTE IN MINLIST)
             *        if (!bySecond or FOR EACH SECOND IN LIST)
             *          ----add to list---
             *
             *     check against BYSETPOS
             *
             *     curDay+=1 day
             * }
             *
             */

            if (!checkMonthList(cur))
                continue;

            if (!checkYearDayList(cur))
                continue;

            if (!checkMonthDayList(cur))
                continue;

            if (!checkDayList(cur))
                continue;

            addList.add((Calendar) (cur.clone()));

            cur.add(Calendar.DAY_OF_YEAR, interval);

            addList = expandHourList(addList);
            addList = expandMinuteList(addList);
            addList = expandSecondList(addList);
            break;
        case WEEKLY:
            /*
             * BYSECOND - for every listed second
             * BYMINUTE - for every listed minute
             * BYHOUR - for every listed hour
             * BYDAY - for every listed day
             * BYMONTHDAY - MAYBE once a month
             * BYYEARDAY - MAYBE once a year
             * BYMONTH - iff month matches
             *
             *  for each (INTERVAL)WEEK{
             *    if (byMonth && !month matches)
             *      curDay = set MONTH to DtStart in next matching month
             *
             *    if (byYearDay && !yearday matches)
             *      curDay = set date to next matching yearday
             *
             *    if (byMonthDay && !monthday matches)
             *      curDay = skip to next matching monthday
             *
             *    if (!byDay or FOREACH day in list)
             *      if (!byHour or FOREACH hour in list)
             *        if (!byMinute or FOREACH minute in list)
             *          if (!bySecond or FOREACH second in list)
             *            ----add to list----
             *
             *    check against BYSETPOS
             *
             *    curDay += 1 week
             * } while (count check & until check & rangeEnd check)
             *
             */
            if (!checkMonthList(cur))
                continue;

            if (!checkYearDayList(cur))
                continue;

            if (!checkMonthDayList(cur))
                continue;

            addList.add((Calendar) (cur.clone()));

            cur.add(Calendar.WEEK_OF_YEAR, interval);

            addList = expandDayListForWeekly(addList);
            addList = expandHourList(addList);
            addList = expandMinuteList(addList);
            addList = expandSecondList(addList);
            break;
        case MONTHLY:
            if (!checkMonthList(cur))
                continue;

            if (!checkYearDayList(cur))
                continue;

            addList.add((Calendar) (cur.clone()));

            cur.set(Calendar.DAY_OF_MONTH, 1);
            cur.add(Calendar.MONTH, interval);
            int daysInMonth = cur.getActualMaximum(Calendar.DAY_OF_MONTH);
            cur.set(Calendar.DAY_OF_MONTH, Math.min(baseMonthDay, daysInMonth));

            addList = expandMonthDayList(addList);
            addList = expandDayListForMonthlyYearly(addList);
            addList = expandHourList(addList);
            addList = expandMinuteList(addList);
            addList = expandSecondList(addList);

            break;
        case YEARLY:
            /*
             * BYSECOND
             * BYMINUTE
             * BYHOUR
             * BYDAY
             * BYMONTHDAY
             * BYYEARDAY
             * BYWEEKNO - specified week
             * BYMONTH - once
             */
            if (baseIsLeapDay) {
                // previously adding a year to a leap day will have rounded down to the 28th.
                // If this happened, we need to be sure that if we are back in a leap
                // year, it is back at 29th
                cur.set(Calendar.DAY_OF_MONTH, cur.getActualMaximum(Calendar.DAY_OF_MONTH));
            }
            if (ignoreYearForRecurrenceExpansion(cur, baseIsLeapDay)) {
                cur.add(Calendar.YEAR, interval);
                break;
            }
            addList.add((Calendar) (cur.clone()));

            cur.add(Calendar.YEAR, interval);

            addList = expandMonthList(addList);
            addList = expandYearDayList(addList);

            addList = expandMonthDayList(addList);
            addList = expandDayListForMonthlyYearly(addList);
            addList = expandHourList(addList);
            addList = expandMinuteList(addList);
            addList = expandSecondList(addList);

            break;
        default:
            // MINUTELY and SECONDLY are intentionally not supported for performance reasons.
            return toRet;
        }

        addList = handleSetPos(addList);

        boolean noInstanceFound = true;
        boolean foundInstancePastEndDate = false;
        // add all the ones that match!
        for (Calendar addCal : addList) {
            Date toAdd = addCal.getTime();

            // We already counted DTSTART before the main loop, so don't
            // count it twice.
            if (toAdd.compareTo(dtStartDate) == 0) {
                noInstanceFound = false;
                continue;
            }

            // we still have expanded this instance, even if it isn't in our
            // current date window
            if (toAdd.after(dtStartDate))
                numInstancesExpanded++;

            if (!toAdd.after(rangeEndDate)) {
                if (!toAdd.before(earliestDate)) {
                    toRet.add(toAdd);
                    noInstanceFound = false;
                }
            } else {
                foundInstancePastEndDate = true;
                break;
            }

            if (maxInstancesExpanded > 0 && numInstancesExpanded >= maxInstancesExpanded)
                break;
        }

        // Detect invalid rule.  If the rule was invalid the current iteration, which is for the current
        // frequency interval, would have found no matching instance.  The next iteration will also find
        // no matching instance, and there is no need to keep iterating until we go past the hard end
        // time or COUNT/UNTIL limit.
        //
        // However, we have to make an exception for leap year.  An yearly rule looking for February 29th
        // will find no instance in up to 3 consecutive years before finding Feb 29th in the fourth year.
        //
        // So the invalid rule detection must look for at least 4 consecutive failed iterations.
        if (curIsAtOrAfterEarliestDate) {
            if (noInstanceFound)
                numConsecutiveIterationsWithoutMatchingInstance++;
            else
                numConsecutiveIterationsWithoutMatchingInstance = 0;
            if (numConsecutiveIterationsWithoutMatchingInstance >= 4) {
                ZimbraLog.calendar.warn("Invalid recurrence rule: " + toString());
                return toRet;
            }
        }

        pastHardEndTime = foundInstancePastEndDate || (noInstanceFound && curIsAfterEndDate);
    }

    return toRet;
}

From source file:com.lp.server.auftrag.ejbfac.AuftragFacBean.java

/**
 * Methode zum Erzeugen eines eines Lieferscheins aus einem bestehenden
 * Auftrag. <br>/*w ww .jav  a 2s . co  m*/
 * Nicht mengenbehaftete Positionen werden ebebfalls kopiert,
 * mengenbehaftete Positionen muessen vom Benutzer gezielt uebernommen
 * werden.
 * 
 * @param iIdAuftragI
 *            PK des bestehenden Auftrags
 * @param lieferscheinDtoI
 *            der Benutzer kann bestimmte Eigenschaften des Auftrags
 *            uebersteuern
 * @param theClientDto
 *            der aktuelle Benutzer
 * @return Integer PK des neuen Lieferscheins
 * @throws EJBExceptionLP
 *             Ausnahme
 */
public Integer erzeugeLieferscheinAusAuftrag(Integer iIdAuftragI, LieferscheinDto lieferscheinDtoI,
        Double dRabattAusRechnungsadresse, TheClientDto theClientDto) throws EJBExceptionLP {
    checkAuftragIId(iIdAuftragI);
    AuftragDto auftragBasisDto = getAuftragFac().auftragFindByPrimaryKey(iIdAuftragI);

    Integer iIdLieferschein = null;

    try {
        LieferscheinDto lieferscheinDto = (LieferscheinDto) auftragBasisDto.cloneAsLieferscheinDto();

        if (dRabattAusRechnungsadresse != null) {
            lieferscheinDto.setFAllgemeinerRabattsatz(dRabattAusRechnungsadresse);
        }

        lieferscheinDto.setFWechselkursmandantwaehrungzubelegwaehrung(
                new Double(getLocaleFac().getWechselkurs2(theClientDto.getSMandantenwaehrung(),
                        lieferscheinDto.getWaehrungCNr(), theClientDto).doubleValue()));

        KundeDto kundeDto = getKundeFac().kundeFindByPrimaryKey(lieferscheinDto.getKundeIIdLieferadresse(),
                theClientDto);
        lieferscheinDto.setLagerIId(auftragBasisDto.getLagerIIdAbbuchungslager());
        lieferscheinDto.setZiellagerIId(kundeDto.getPartnerDto().getLagerIIdZiellager());

        /**
         * Auskommentiert von CK am 22.10.2008, wegen Projekt 08/13491
         * lieferscheinDto
         * .setPersonalIIdVertreter(theClientDto.getIDPersonal());
         */

        // der Benutzer kann bestimmte vorbelegte Eigenschaften uebersteuern
        if (lieferscheinDtoI != null) {
            lieferscheinDto.setTBelegdatum(lieferscheinDtoI.getTBelegdatum());
            lieferscheinDto.setAnsprechpartnerIId(lieferscheinDtoI.getAnsprechpartnerIId());
            lieferscheinDto.setPersonalIIdVertreter(lieferscheinDtoI.getPersonalIIdVertreter());
            lieferscheinDto.setKundeIIdRechnungsadresse(lieferscheinDtoI.getKundeIIdRechnungsadresse());
            lieferscheinDto.setWaehrungCNr(lieferscheinDtoI.getWaehrungCNr());
            lieferscheinDto.setFWechselkursmandantwaehrungzubelegwaehrung(
                    lieferscheinDtoI.getFWechselkursmandantwaehrungzubelegwaehrung());
            lieferscheinDto.setLagerIId(lieferscheinDtoI.getLagerIId());
        }

        // rueckgabedatum berechenen fuer leihtage Lieferschein
        if (auftragBasisDto.getILeihtage().intValue() != 0) {
            GregorianCalendar calendar = new GregorianCalendar();
            calendar.add(Calendar.DATE, auftragBasisDto.getILeihtage().intValue());
            Timestamp rueckgabeterminLieferschein = new Timestamp(calendar.getTimeInMillis());
            lieferscheinDto.setTRueckgabetermin(rueckgabeterminLieferschein);
        }
        lieferscheinDto.setAuftragIId(iIdAuftragI);
        iIdLieferschein = getLieferscheinFac().createLieferschein(lieferscheinDto, theClientDto);

        // alle nicht mengenbehafteten Positionen mituebernehmen
        AuftragpositionDto[] aAuftragpositionDto = getAuftragpositionFac()
                .auftragpositionFindByAuftrag(iIdAuftragI);

        if (aAuftragpositionDto != null && aAuftragpositionDto.length > 0) {
            for (int i = 0; i < aAuftragpositionDto.length; i++) {
                // Kalkulatorische Artikel sofort Erledigen, damit diese im
                // LS nicht aufscheinen
                if (aAuftragpositionDto[i].getArtikelIId() != null) {
                    ArtikelDto aDto = getArtikelFac()
                            .artikelFindByPrimaryKeySmall(aAuftragpositionDto[i].getArtikelIId(), theClientDto);
                    if (Helper.short2boolean(aDto.getBKalkulatorisch())) {

                        aAuftragpositionDto[i].setAuftragpositionstatusCNr(LocaleFac.STATUS_ERLEDIGT);
                        getAuftragpositionFac().updateAuftragpositionOhneWeitereAktion(aAuftragpositionDto[i],
                                theClientDto);

                    }
                }
            }
        }
    } catch (RemoteException ex) {
        throwEJBExceptionLPRespectOld(ex);
    }
    return iIdLieferschein;
}

From source file:edu.wisc.ssec.mcidasv.data.cyclone.AtcfStormDataSource.java

/**
 * _more_// w  ww. ja  v  a  2 s. c  o  m
 * 
 * @param stormInfo
 *            _more_
 * @param tracks
 *            _more_
 * @param trackFile
 *            _more_
 * @param waysToUse
 *            _more_
 * @param throwError
 *            _more_
 * 
 * 
 * @return _more_
 * @throws Exception
 *             _more_
 */
private boolean readTracks(StormInfo stormInfo, StormTrackCollection tracks, String trackFile,
        Hashtable<String, Boolean> waysToUse, boolean throwError) throws Exception {

    long t1 = System.currentTimeMillis();
    byte[] bytes = readFile(trackFile, true);
    long t2 = System.currentTimeMillis();
    // System.err.println("read time:" + (t2 - t1));
    boolean isZip = trackFile.endsWith(".gz");
    if ((bytes == null) && isZip) {
        String withoutGZ = trackFile.substring(0, trackFile.length() - 3);
        bytes = readFile(withoutGZ, true);
        isZip = false;
    }

    if (bytes == null) {
        if (throwError) {
            throw new BadDataException("Unable to read track file:" + trackFile);
        }
        return false;
    }

    if (isZip) {
        GZIPInputStream zin = new GZIPInputStream(new ByteArrayInputStream(bytes));
        bytes = IOUtil.readBytes(zin);
        zin.close();
    }
    GregorianCalendar convertCal = new GregorianCalendar(DateUtil.TIMEZONE_GMT);
    convertCal.clear();

    String trackData = new String(bytes);
    List lines = StringUtil.split(trackData, "\n", true, true);
    SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHH");
    fmt.setTimeZone(TimeZone.getTimeZone("UTC"));
    Hashtable trackMap = new Hashtable();
    Real altReal = new Real(RealType.Altitude, 0);
    // System.err.println("obs:" + lines.size());
    /*
     * Hashtable okWays = new Hashtable(); okWays.put(WAY_CARQ, "");
     * okWays.put(WAY_WRNG, ""); okWays.put(WAY_BEST, ""); okWays.put("ETA",
     * ""); okWays.put("NGX", ""); okWays.put("BAMS", "");
     */
    Hashtable seenDate = new Hashtable();
    initParams();
    int xcnt = 0;
    for (int i = 0; i < lines.size(); i++) {
        String line = (String) lines.get(i);
        if (i == 0) {
            // System.err.println(line);
        }
        List toks = StringUtil.split(line, ",", true);
        /*
         * System.err.println(toks.size() + " " + BASEIDX);
         * if(toks.size()<BASEIDX-1) { System.err.println("bad line:" +
         * line); continue; } else { System.err.println("good line:" +
         * line); }
         */

        // BASIN,CY,YYYYMMDDHH,TECHNUM,TECH,TAU,LatN/S,LonE/W,VMAX,MSLP,TY,RAD,WINDCODE,RAD1,RAD2,RAD3,RAD4,RADP,RRP,MRD,GUSTS,EYE,SUBREGION,MAXSEAS,INITIALS,DIR,SPEED,STORMNAME,DEPTH,SEAS,SEASCODE,SEAS1,SEAS2,SEAS3,SEAS4
        // AL, 01, 2007050612, , BEST, 0, 355N, 740W, 35, 1012, EX, 34, NEQ,
        // 0, 0, 0, 120,
        // AL, 01, 2007050812, 01, CARQ, -24, 316N, 723W, 55, 0, DB, 34,
        // AAA, 0, 0, 0, 0,

        String dateString = (String) toks.get(IDX_YYYYMMDDHH);
        String wayString = (String) toks.get(IDX_TECH);
        // if (okWays.get(wayString) == null) {
        // continue;
        // }
        boolean isBest = wayString.equals(WAY_BEST);
        boolean isWarning = wayString.equals(WAY_WRNG);
        boolean isCarq = wayString.equals(WAY_CARQ);

        int category = ((IDX_TY < toks.size()) ? getCategory((String) toks.get(IDX_TY)) : CATEGORY_XX);
        if (category != CATEGORY_XX) {
            // System.err.println("cat:" + category);
        }

        String fhour = (String) toks.get(IDX_TAU);
        int forecastHour = new Integer(fhour).intValue();
        // A hack - we've seen some atfc files that have a 5 character
        // forecast hour
        // right padded with "00", eg., 01200
        if ((fhour.length() == 5) && (forecastHour > 100)) {
            forecastHour = forecastHour / 100;
        }

        if (isWarning || isCarq) {
            forecastHour = -forecastHour;
        }

        // Check for unique dates for this way
        String dttmkey = wayString + "_" + dateString + "_" + forecastHour;
        if (seenDate.get(dttmkey) != null) {
            continue;
        }
        seenDate.put(dttmkey, dttmkey);

        Date dttm = fmt.parse(dateString);
        convertCal.setTime(dttm);
        String key;
        Way way = getWay(wayString, null);
        if (!isBest && (waysToUse != null) && (waysToUse.size() > 0) && (waysToUse.get(wayString) == null)) {
            continue;
        }

        if (isBest) {
            key = wayString;
        } else {
            key = wayString + "_" + dateString;
            convertCal.add(Calendar.HOUR_OF_DAY, forecastHour);
        }
        dttm = convertCal.getTime();
        StormTrack track = (StormTrack) trackMap.get(key);
        if (track == null) {
            way = (isBest ? Way.OBSERVATION : way);
            track = new StormTrack(stormInfo, addWay(way), new DateTime(dttm), obsParams);
            trackMap.put(key, track);
            tracks.addTrack(track);
        }
        String latString = (String) toks.get(IDX_LAT);
        String lonString = (String) toks.get(IDX_LON);
        String t = latString + " " + lonString;

        boolean south = latString.endsWith("S");
        boolean west = lonString.endsWith("W");
        double latitude = Double.parseDouble(latString.substring(0, latString.length() - 1)) / 10.0;
        double longitude = Double.parseDouble(lonString.substring(0, lonString.length() - 1)) / 10.0;
        if (south) {
            latitude = -latitude;
        }
        if (west) {
            longitude = -longitude;
        }

        EarthLocation elt = new EarthLocationLite(new Real(RealType.Latitude, latitude),
                new Real(RealType.Longitude, longitude), altReal);

        List<Real> attributes = new ArrayList<Real>();

        double windspeed = ((IDX_VMAX < toks.size()) ? getDouble((String) toks.get(IDX_VMAX)) : Double.NaN);
        double pressure = ((IDX_MSLP < toks.size()) ? getDouble((String) toks.get(IDX_MSLP)) : Double.NaN);
        attributes.add(PARAM_STORMCATEGORY.getReal((double) category));
        attributes.add(PARAM_MINPRESSURE.getReal(pressure));
        attributes.add(PARAM_MAXWINDSPEED_KTS.getReal(windspeed));

        StormTrackPoint stp = new StormTrackPoint(elt, new DateTime(dttm), forecastHour, attributes);

        track.addPoint(stp);
    }
    return true;
}

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);//  ww  w .  j a  va2s  .  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')";
    } 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);//from  w  ww .  j  a  v a  2 s.  c om
    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;
}

From source file:ffsutils.TaskUtils.java

public static ArrayList<Tasks> getTrainingTask(Connection conn, UserAccount Username, String onlyUser)
        throws SQLException {
    System.out.println("getTrainingTask " + Username);
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    GregorianCalendar cal121 = new GregorianCalendar();
    cal121.setTime(date);/* w  w  w.  j a v a 2 s .c o 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 ((((taskto1 = ?) and ((taskstat1 <> 'Completed') or (taskstat1 is null))) or ((taskto2 = ?) and ((taskstat2 <> 'Completed') or (taskstat2 is null))) or ((taskto3 = ?) and ((taskstat3 <> 'Completed') or (taskstat3 is null))) or ((taskto4 = ?) and ((taskstat4 <> 'Completed') or (taskstat4 is null))) or ((taskto5 = ?) and ((taskstat5 <> 'Completed') or (taskstat5 is null))) or ((taskto6 = ?) and ((taskstat6 <> 'Completed') or (taskstat6 is null))) or ((taskto7 = ?) and ((taskstat7 <> 'Completed') or (taskstat7 is null))) or ((taskto8 = ?) and ((taskstat8 <> 'Completed') or (taskstat8 is null))) or ((taskto9 = ?) and ((taskstat9 <> 'Completed') or (taskstat9 is null))) or ((taskto10 = ?) and ((taskstat10 <> 'Completed') or (taskstat10 is null))) or ((taskto11 = ?) and ((taskstat11 <> 'Completed') or (taskstat11 is null))) or ((taskto12 = ?) and ((taskstat12 <> 'Completed') or (taskstat12 is null))) or ((taskto13 = ?) and ((taskstat13 <> 'Completed') or (taskstat13 is null))) or ((taskto14 = ?) and ((taskstat14 <> 'Completed') or (taskstat14 is null))) or ((taskto15 = ?) and ((taskstat15 <> 'Completed') or (taskstat15 is null)))) or (taskfrom = ?))and (taskstat <> 'Completed') and (train = 'Y')";
    } else {
        sql = "select * from " + Username.getcompany()
                + ".tasks where ((((taskto1 = ?) and ((taskstat1 <> 'Completed') or (taskstat1 is null))) or ((taskto2 = ?) and ((taskstat2 <> 'Completed') or (taskstat2 is null))) or ((taskto3 = ?) and ((taskstat3 <> 'Completed') or (taskstat3 is null))) or ((taskto4 = ?) and ((taskstat4 <> 'Completed') or (taskstat4 is null))) or ((taskto5 = ?) and ((taskstat5 <> 'Completed') or (taskstat5 is null))) or ((taskto6 = ?) and ((taskstat6 <> 'Completed') or (taskstat6 is null))) or ((taskto7 = ?) and ((taskstat7 <> 'Completed') or (taskstat7 is null))) or ((taskto8 = ?) and ((taskstat8 <> 'Completed') or (taskstat8 is null))) or ((taskto9 = ?) and ((taskstat9 <> 'Completed') or (taskstat9 is null))) or ((taskto10 = ?) and ((taskstat10 <> 'Completed') or (taskstat10 is null))) or ((taskto11 = ?) and ((taskstat11 <> 'Completed') or (taskstat11 is null))) or ((taskto12 = ?) and ((taskstat12 <> 'Completed') or (taskstat12 is null))) or ((taskto13 = ?) and ((taskstat13 <> 'Completed') or (taskstat13 is null))) or ((taskto14 = ?) and ((taskstat14 <> 'Completed') or (taskstat14 is null))) or ((taskto15 = ?) and ((taskstat15 <> 'Completed') or (taskstat15 is null)))) or (taskfrom = ?))and (taskstat <> 'Completed') and (train = 'Y') and (taskfrom='"
                + onlyUser + "')";
    }
    PreparedStatement pstm = conn.prepareStatement(sql);
    pstm.setString(1, Username.getUserName());
    pstm.setString(2, Username.getUserName());
    pstm.setString(3, Username.getUserName());
    pstm.setString(4, Username.getUserName());
    pstm.setString(5, Username.getUserName());
    pstm.setString(6, Username.getUserName());
    pstm.setString(7, Username.getUserName());
    pstm.setString(8, Username.getUserName());
    pstm.setString(9, Username.getUserName());
    pstm.setString(10, Username.getUserName());
    pstm.setString(11, Username.getUserName());
    pstm.setString(12, Username.getUserName());
    pstm.setString(13, Username.getUserName());
    pstm.setString(14, Username.getUserName());
    pstm.setString(15, Username.getUserName());
    pstm.setString(16, 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"));
        }
        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);
        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> getNewTask(Connection conn, UserAccount Username, String onlyUser)
        throws SQLException {
    System.out.println("getNewTask " + onlyUser);
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    GregorianCalendar cal121 = new GregorianCalendar();
    cal121.setTime(date);// w  w w. ja v a  2  s  . c  o 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 ((taskstat <> 'Completed') or (taskstat is null)) and (((taskstat1 <> 'Completed') or (taskstat1 is null)) and (taskto1 = ?) and (comadd1 is null)) or (((taskstat2 <> 'Completed') or (taskstat2 is null)) and (taskto2 = ?) and (comadd2 is null)) or (((taskstat3 <> 'Completed') or (taskstat3 is null)) and (taskto3 = ?) and (comadd3 is null)) or (((taskstat4 <> 'Completed') or (taskstat4 is null)) and (taskto4 = ?) and (comadd4 is null)) or (((taskstat5 <> 'Completed') or (taskstat5 is null)) and (taskto5 = ?) and (comadd5 is null)) or (((taskstat6 <> 'Completed') or (taskstat6 is null)) and (taskto6 = ?) and (comadd6 is null)) or (((taskstat7 <> 'Completed') or (taskstat7 is null)) and (taskto7 = ?) and (comadd7 is null)) or (((taskstat8 <> 'Completed') or (taskstat8 is null)) and (taskto8 = ?) and (comadd8 is null)) or (((taskstat9 <> 'Completed') or (taskstat9 is null)) and (taskto9 = ?) and (comadd9 is null)) or (((taskstat11 <> 'Completed') or (taskstat11 is null)) and (taskto11 = ?) and (comadd11 is null)) or (((taskstat12 <> 'Completed') or (taskstat12 is null)) and (taskto12 = ?) and (comadd12 is null)) or (((taskstat13 <> 'Completed') or (taskstat13 is null)) and (taskto13 = ?) and (comadd13 is null)) or (((taskstat14 <> 'Completed') or (taskstat14 is null)) and (taskto14 = ?) and (comadd14 is null)) or (((taskstat15 <> 'Completed') or (taskstat15 is null)) and (taskto15 = ?) and (comadd15 is null)) or (((taskstat10 <> 'Completed') or (taskstat10 is null)) and (taskto10 = ?) and (comadd10 is null)) or (((taskstat <> 'Completed') or (taskstat is null)) and (taskfrom = ?) and (comaddf is null)) ";
    } else {
        sql = "select * from " + Username.getcompany()
                + ".tasks where (((taskstat <> 'Completed') or (taskstat is null)) and (((taskstat1 <> 'Completed') or (taskstat1 is null)) and (taskto1 = ?) and (comadd1 is null)) or (((taskstat2 <> 'Completed') or (taskstat2 is null)) and (taskto2 = ?) and (comadd2 is null)) or (((taskstat3 <> 'Completed') or (taskstat3 is null)) and (taskto3 = ?) and (comadd3 is null)) or (((taskstat4 <> 'Completed') or (taskstat4 is null)) and (taskto4 = ?) and (comadd4 is null)) or (((taskstat5 <> 'Completed') or (taskstat5 is null)) and (taskto5 = ?) and (comadd5 is null)) or (((taskstat6 <> 'Completed') or (taskstat6 is null)) and (taskto6 = ?) and (comadd6 is null)) or (((taskstat7 <> 'Completed') or (taskstat7 is null)) and (taskto7 = ?) and (comadd7 is null)) or (((taskstat8 <> 'Completed') or (taskstat8 is null)) and (taskto8 = ?) and (comadd8 is null)) or (((taskstat9 <> 'Completed') or (taskstat9 is null)) and (taskto9 = ?) and (comadd9 is null)) or (((taskstat11 <> 'Completed') or (taskstat11 is null)) and (taskto11 = ?) and (comadd11 is null)) or (((taskstat12 <> 'Completed') or (taskstat12 is null)) and (taskto12 = ?) and (comadd12 is null)) or (((taskstat13 <> 'Completed') or (taskstat13 is null)) and (taskto13 = ?) and (comadd13 is null)) or (((taskstat14 <> 'Completed') or (taskstat14 is null)) and (taskto14 = ?) and (comadd14 is null)) or (((taskstat15 <> 'Completed') or (taskstat15 is null)) and (taskto15 = ?) and (comadd15 is null)) or (((taskstat10 <> 'Completed') or (taskstat10 is null)) and (taskto10 = ?) and (comadd10 is null)) or (((taskstat <> 'Completed') or (taskstat is null)) and (taskfrom = ?) and (comaddf is null))) and (taskfrom ='"
                + onlyUser + "') ";
    }
    PreparedStatement pstm = conn.prepareStatement(sql);
    pstm.setString(1, Username.getUserName());
    pstm.setString(2, Username.getUserName());
    pstm.setString(3, Username.getUserName());
    pstm.setString(4, Username.getUserName());
    pstm.setString(5, Username.getUserName());
    pstm.setString(6, Username.getUserName());
    pstm.setString(7, Username.getUserName());
    pstm.setString(8, Username.getUserName());
    pstm.setString(9, Username.getUserName());
    pstm.setString(10, Username.getUserName());
    pstm.setString(11, Username.getUserName());
    pstm.setString(12, Username.getUserName());
    pstm.setString(13, Username.getUserName());
    pstm.setString(14, Username.getUserName());
    pstm.setString(15, Username.getUserName());
    pstm.setString(16, 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);
        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> getUpdatedTasks(Connection conn, UserAccount Username, String onlyUser)
        throws SQLException {
    System.out.println("getUpdatedTasks " + Username);
    Date date = new Date();
    Calendar cal = Calendar.getInstance();
    GregorianCalendar cal121 = new GregorianCalendar();
    cal121.setTime(date);//ww w .  j ava  2s.c om
    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 == null) {
        sql = "select * from " + Username.getcompany()
                + ".tasks where (((taskstat1 <> 'Completed') or (taskstat1 is null)) and (taskto1 = ?) and (newt1 is null)) or (((taskstat2 <> 'Completed') or (taskstat2 is null)) and (taskto2 = ?) and (newt2 is null)) or (((taskstat3 <> 'Completed') or (taskstat3 is null)) and (taskto3 = ?) and (newt3 is null)) or(((taskstat4 <> 'Completed') or (taskstat4 is null)) and (taskto4 = ?) and (newt4 is null)) or (((taskstat5 <> 'Completed') or (taskstat5 is null)) and (taskto5 = ?) and (newt5 is null)) or (((taskstat6 <> 'Completed') or (taskstat6 is null)) and (taskto6 = ?) and (newt6 is null)) or (((taskstat7 <> 'Completed') or (taskstat7 is null)) and (taskto7 = ?) and (newt7 is null)) or (((taskstat8 <> 'Completed') or (taskstat8 is null)) and (taskto8 = ?) and (newt8 is null)) or (((taskstat9 <> 'Completed') or (taskstat9 is null)) and (taskto9 = ?) and (newt9 is null)) or (((taskstat11 <> 'Completed') or (taskstat11 is null)) and (taskto11 = ?) and (newt11 is null)) or (((taskstat12 <> 'Completed') or (taskstat12 is null)) and (taskto12 = ?) and (newt12 is null)) or (((taskstat13 <> 'Completed') or (taskstat12 is null)) and (taskto13 = ?) and (newt13 is null)) or (((taskstat14 <> 'Completed') or (taskstat14 is null)) and (taskto14 = ?) and (newt14 is null)) or (((taskstat15 <> 'Completed') or (taskstat15 is null)) and (taskto15 = ?) and (newt15 is null)) or (((taskstat10 <> 'Completed') or (taskstat10 is null)) and (taskto10 = ?) and (newt10 is null)) or (((taskstat <> 'Completed') or (taskstat is null)) and (taskfrom = ?) and (newtf is null))";
    } else {
        if (onlyUser.length() < 3) {
            sql = "select * from " + Username.getcompany()
                    + ".tasks where (((taskstat1 <> 'Completed') or (taskstat1 is null)) and (taskto1 = ?) and (newt1 is null)) or (((taskstat2 <> 'Completed') or (taskstat2 is null)) and (taskto2 = ?) and (newt2 is null)) or (((taskstat3 <> 'Completed') or (taskstat3 is null)) and (taskto3 = ?) and (newt3 is null)) or(((taskstat4 <> 'Completed') or (taskstat4 is null)) and (taskto4 = ?) and (newt4 is null)) or (((taskstat5 <> 'Completed') or (taskstat5 is null)) and (taskto5 = ?) and (newt5 is null)) or (((taskstat6 <> 'Completed') or (taskstat6 is null)) and (taskto6 = ?) and (newt6 is null)) or (((taskstat7 <> 'Completed') or (taskstat7 is null)) and (taskto7 = ?) and (newt7 is null)) or (((taskstat8 <> 'Completed') or (taskstat8 is null)) and (taskto8 = ?) and (newt8 is null)) or (((taskstat9 <> 'Completed') or (taskstat9 is null)) and (taskto9 = ?) and (newt9 is null)) or (((taskstat11 <> 'Completed') or (taskstat11 is null)) and (taskto11 = ?) and (newt11 is null)) or (((taskstat12 <> 'Completed') or (taskstat12 is null)) and (taskto12 = ?) and (newt12 is null)) or (((taskstat13 <> 'Completed') or (taskstat12 is null)) and (taskto13 = ?) and (newt13 is null)) or (((taskstat14 <> 'Completed') or (taskstat14 is null)) and (taskto14 = ?) and (newt14 is null)) or (((taskstat15 <> 'Completed') or (taskstat15 is null)) and (taskto15 = ?) and (newt15 is null)) or (((taskstat10 <> 'Completed') or (taskstat10 is null)) and (taskto10 = ?) and (newt10 is null)) or (((taskstat <> 'Completed') or (taskstat is null)) and (taskfrom = ?) and (newtf is null))";
        } else {
            sql = "select * from " + Username.getcompany()
                    + ".tasks where ((((taskstat1 <> 'Completed') or (taskstat1 is null)) and (taskto1 = ?) and (newt1 is null)) or (((taskstat2 <> 'Completed') or (taskstat2 is null)) and (taskto2 = ?) and (newt2 is null)) or (((taskstat3 <> 'Completed') or (taskstat3 is null)) and (taskto3 = ?) and (newt3 is null)) or(((taskstat4 <> 'Completed') or (taskstat4 is null)) and (taskto4 = ?) and (newt4 is null)) or (((taskstat5 <> 'Completed') or (taskstat5 is null)) and (taskto5 = ?) and (newt5 is null)) or (((taskstat6 <> 'Completed') or (taskstat6 is null)) and (taskto6 = ?) and (newt6 is null)) or (((taskstat7 <> 'Completed') or (taskstat7 is null)) and (taskto7 = ?) and (newt7 is null)) or (((taskstat8 <> 'Completed') or (taskstat8 is null)) and (taskto8 = ?) and (newt8 is null)) or (((taskstat9 <> 'Completed') or (taskstat9 is null)) and (taskto9 = ?) and (newt9 is null)) or (((taskstat11 <> 'Completed') or (taskstat11 is null)) and (taskto11 = ?) and (newt11 is null)) or (((taskstat12 <> 'Completed') or (taskstat12 is null)) and (taskto12 = ?) and (newt12 is null)) or (((taskstat13 <> 'Completed') or (taskstat12 is null)) and (taskto13 = ?) and (newt13 is null)) or (((taskstat14 <> 'Completed') or (taskstat14 is null)) and (taskto14 = ?) and (newt14 is null)) or (((taskstat15 <> 'Completed') or (taskstat15 is null)) and (taskto15 = ?) and (newt15 is null)) or (((taskstat10 <> 'Completed') or (taskstat10 is null)) and (taskto10 = ?) and (newt10 is null)) or (((taskstat <> 'Completed') or (taskstat is null)) and (taskfrom = ?) and (newtf is null))) and (taskfrom = '"
                    + onlyUser + "')";
        }
    }
    PreparedStatement pstm = conn.prepareStatement(sql);
    pstm.setString(1, Username.getUserName());
    pstm.setString(2, Username.getUserName());
    pstm.setString(3, Username.getUserName());
    pstm.setString(4, Username.getUserName());
    pstm.setString(5, Username.getUserName());
    pstm.setString(6, Username.getUserName());
    pstm.setString(7, Username.getUserName());
    pstm.setString(8, Username.getUserName());
    pstm.setString(9, Username.getUserName());
    pstm.setString(10, Username.getUserName());
    pstm.setString(11, Username.getUserName());
    pstm.setString(12, Username.getUserName());
    pstm.setString(13, Username.getUserName());
    pstm.setString(14, Username.getUserName());
    pstm.setString(15, Username.getUserName());
    pstm.setString(16, 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"));
        }
        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);
        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;
}