Example usage for java.util GregorianCalendar clear

List of usage examples for java.util GregorianCalendar clear

Introduction

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

Prototype

public final void clear(int field) 

Source Link

Document

Sets the given calendar field value and the time value (millisecond offset from the Epoch) of this Calendar undefined.

Usage

From source file:org.callimachusproject.sql.SqlTupleResult.java

private Value value(int col) throws SQLException {
    int type = md.getColumnType(col);
    String str = rs.getString(col);
    if (str == null)
        return null;
    switch (type) {
    case java.sql.Types.NULL:
        return null;
    case java.sql.Types.DATALINK:
        return vf.createURI(str);
    case java.sql.Types.BINARY:
    case java.sql.Types.VARBINARY:
    case java.sql.Types.BIT:
    case java.sql.Types.BLOB:
    case java.sql.Types.LONGVARBINARY:
    case java.sql.Types.JAVA_OBJECT:
        return vf.createLiteral(Hex.encodeHexString(rs.getBytes(col)), XMLSchema.HEXBINARY);
    case java.sql.Types.DECIMAL:
    case java.sql.Types.NUMERIC:
        return vf.createLiteral(str, XMLSchema.DECIMAL);
    case java.sql.Types.TINYINT:
    case java.sql.Types.SMALLINT:
    case java.sql.Types.INTEGER:
    case java.sql.Types.BIGINT:
        return vf.createLiteral(str, XMLSchema.INTEGER);
    case java.sql.Types.DOUBLE:
    case java.sql.Types.FLOAT:
    case java.sql.Types.REAL:
        return vf.createLiteral(str, XMLSchema.DOUBLE);
    case java.sql.Types.BOOLEAN:
        return vf.createLiteral(rs.getBoolean(col));
    case java.sql.Types.DATE:
        GregorianCalendar date = new GregorianCalendar();
        date.setTime(rs.getDate(col));/*from w w w  .j  av a  2s.c om*/
        date.clear(Calendar.AM_PM);
        date.clear(Calendar.HOUR);
        date.clear(Calendar.HOUR_OF_DAY);
        date.clear(Calendar.MINUTE);
        date.clear(Calendar.SECOND);
        date.clear(Calendar.MILLISECOND);
        return vf.createLiteral(df.newXMLGregorianCalendar(date));
    case java.sql.Types.TIME:
        GregorianCalendar time = new GregorianCalendar();
        time.setTime(rs.getTime(col));
        time.clear(Calendar.ERA);
        time.clear(Calendar.YEAR);
        time.clear(Calendar.MONTH);
        time.clear(Calendar.WEEK_OF_YEAR);
        time.clear(Calendar.WEEK_OF_MONTH);
        time.clear(Calendar.DATE);
        time.clear(Calendar.DAY_OF_MONTH);
        time.clear(Calendar.DAY_OF_YEAR);
        time.clear(Calendar.DAY_OF_WEEK);
        time.clear(Calendar.DAY_OF_WEEK_IN_MONTH);
        return vf.createLiteral(df.newXMLGregorianCalendar(time));
    case java.sql.Types.TIMESTAMP:
        return vf.createLiteral(rs.getTimestamp(col));
    case java.sql.Types.SQLXML:
        return vf.createLiteral(str, RDF.XMLLITERAL);
    case java.sql.Types.ARRAY:
    case java.sql.Types.CHAR:
    case java.sql.Types.CLOB:
    case java.sql.Types.DISTINCT:
    case java.sql.Types.LONGNVARCHAR:
    case java.sql.Types.NCHAR:
    case java.sql.Types.NCLOB:
    case java.sql.Types.NVARCHAR:
    case java.sql.Types.OTHER:
    case java.sql.Types.REF:
    case java.sql.Types.ROWID:
    case java.sql.Types.STRUCT:
    case java.sql.Types.VARCHAR:
    default:
        return vf.createLiteral(str);
    }
}

From source file:org.eevolution.form.CRP.java

/**
 * Create Category Dataset based on Weight , date start and resource
 * @param start/*from  w  w  w . j  a v  a2 s.  c  o m*/
 * @param resource
 * @return CategoryDataset
 */
protected CategoryDataset createWeightDataset(Timestamp start, MResource rosource) {

    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    String namepossiblecapacity = "Possible Capacity";

    MResourceType t = MResourceType.get(Env.getCtx(), rosource.getS_ResourceType_ID());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    double currentweight = DB.getSQLValue(null,
            "SELECT SUM( (mo.qtyordered-mo.qtydelivered)*(SELECT mp.weight FROM M_Product mp WHERE  mo.m_product_id=mp.m_product_id )) FROM PP_Order mo WHERE AD_Client_ID=?",
            rosource.getAD_Client_ID());
    double dailyCapacity = rosource.getDailyCapacity().doubleValue();
    double utilization = rosource.getPercentUtilization().doubleValue();
    double summary = 0;

    int day = 0;
    while (day < 32) {

        day++;
        switch (gc1.get(Calendar.DAY_OF_WEEK)) {

        case Calendar.SUNDAY:

            if (t.isOnSunday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.MONDAY:

            if (t.isOnMonday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.TUESDAY:

            if (t.isOnTuesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.WEDNESDAY:

            if (t.isOnWednesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.THURSDAY:

            if (t.isOnThursday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.FRIDAY:

            if (t.isOnFriday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.SATURDAY:

            if (t.isOnSaturday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;
        }

        dataset.addValue(currentweight, nameload, new Integer(day));
        dataset.addValue(summary, namesummary, new Integer(day));

        gc1.add(Calendar.DATE, 1);
    }
    return dataset;
}

From source file:org.eevolution.form.CRP.java

/**
 * Create Category Dataset based on date start and resource
 * @param start//from   ww  w  .j av a2 s  . com
 * @param resource
 * @return CategoryDataset
 */
protected CategoryDataset createDataset(Timestamp start, MResource resource) {
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    MResourceType t = MResourceType.get(Env.getCtx(), resource.getS_ResourceType_ID());
    int days = 1;
    long hours = t.getTimeSlotHours();

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    //      Long Hours = new Long(hours);                            
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ",
            resource.getS_Resource_ID());
    MUOM uom = MUOM.get(Env.getCtx(), C_UOM_ID);
    if (!uom.isHour()) {
        return dataset;
    }
    long summary = 0;

    while (days < 32) {
        String day = new String(new Integer(date.getDate()).toString());
        long HoursLoad = getLoad(resource, date).longValue();
        Long Hours = new Long(hours);

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            days++;
            if (t.isOnSunday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.MONDAY:
            days++;
            if (t.isOnMonday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.TUESDAY:
            days++;
            if (t.isOnTuesday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.WEDNESDAY:
            days++;
            if (t.isOnWednesday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.THURSDAY:
            days++;
            if (t.isOnThursday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.FRIDAY:
            days++;
            if (t.isOnFriday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.SATURDAY:
            days++;
            if (t.isOnSaturday()) {
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(HoursLoad, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (HoursLoad);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        }

    }
    return dataset;
}

From source file:org.eevolution.form.VSCRP.java

public CategoryDataset createWeightDataset(Timestamp start, MResource r) {

    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);//w ww.ja v a2  s .  c  om
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    String namepossiblecapacity = "Possible Capacity";

    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    double currentweight = DB.getSQLValue(null,
            "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id )  )From mpc_order mo Where ad_client_id=?",
            r.getAD_Client_ID());
    // fjviejo e-evolution machineqty capacidad por el numero de maquinas
    // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID());
    double dailyCapacity = DB.getSQLValue(null,
            "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID());
    System.out.println("***** Capacidad diaria " + dailyCapacity);
    // e-evolution end
    double utilization = DB.getSQLValue(null,
            "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID());

    double summary = 0;

    int day = 0;
    while (day < 32) {

        day++;

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {

        case Calendar.SUNDAY:

            if (t.isOnSunday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.MONDAY:

            if (t.isOnMonday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.TUESDAY:

            if (t.isOnTuesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.WEDNESDAY:

            if (t.isOnWednesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.THURSDAY:

            if (t.isOnThursday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.FRIDAY:

            if (t.isOnFriday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.SATURDAY:

            if (t.isOnSaturday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;
        }

        dataset.addValue(currentweight, nameload, new Integer(day));
        dataset.addValue(summary, namesummary, new Integer(day));

        gc1.add(Calendar.DATE, 1);
    }

    return dataset;
}

From source file:org.eevolution.form.VCRP.java

public CategoryDataset createWeightDataset(Timestamp start, MResource r) {

    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);/*from  w  w  w.  j  a v  a2 s  .  c o m*/
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    String nameload = Msg.translate(Env.getCtx(), "Load");
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    String namepossiblecapacity = "Possible Capacity";

    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    double currentweight = DB.getSQLValue(null,
            "Select SUM( (mo.qtyordered-mo.qtydelivered)*(Select mp.weight From m_product mp Where mo.m_product_id=mp.m_product_id )  )From mpc_order mo Where ad_client_id=?",
            r.getAD_Client_ID());
    // fjviejo e-evolution machineqty capacidad por el numero de maquinas
    // double dailyCapacity = DB.getSQLValue(null,"Select dailycapacity From s_resource Where s_resource_id=?",r.getS_Resource_ID());
    double dailyCapacity = DB.getSQLValue(null,
            "Select dailycapacity*MachineQty From s_resource Where s_resource_id=?", r.getS_Resource_ID());
    System.out.println("***** Capacidad diaria " + dailyCapacity);
    // e-evolution end
    double utilization = DB.getSQLValue(null,
            "Select percentutillization From s_resource Where s_resource_id=?", r.getS_Resource_ID());

    double summary = 0;

    int day = 0;

    /*
     *     Vit4B Modificado para que tome 28 dias y
     *
     *
     */

    while (day < 29) {

        day++;

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {

        case Calendar.SUNDAY:

            if (t.isOnSunday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.MONDAY:

            if (t.isOnMonday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.TUESDAY:

            if (t.isOnTuesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.WEDNESDAY:

            if (t.isOnWednesday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.THURSDAY:

            if (t.isOnThursday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.FRIDAY:

            if (t.isOnFriday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;

        case Calendar.SATURDAY:

            if (t.isOnSaturday()) {

                currentweight -= (dailyCapacity * utilization) / 100;
                summary += ((dailyCapacity * utilization) / 100);

                dataset.addValue(dailyCapacity, namepossiblecapacity, new Integer(day));
                dataset.addValue((dailyCapacity * utilization) / 100, namecapacity, new Integer(day));
            } else {

                dataset.addValue(0, namepossiblecapacity, new Integer(day));
                dataset.addValue(0, namecapacity, new Integer(day));
            }

            break;
        }

        dataset.addValue(currentweight, nameload, new Integer(day));
        dataset.addValue(summary, namesummary, new Integer(day));

        gc1.add(Calendar.DATE, 1);
    }

    return dataset;
}

From source file:org.eevolution.form.VSCRP.java

public CategoryDataset createDataset(Timestamp start, MResource r) {
    //System.out.println("Create new data set");
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);//w ww .  j  a va2s  .co m
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    System.out.println("\n Namecapacity :" + namecapacity);
    String nameload = Msg.translate(Env.getCtx(), "Load");
    System.out.println("\n Nameload :" + nameload);
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    System.out.println("\n Namesummary :" + namesummary);
    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
    System.out.println("\n Resourcetype " + t);
    int days = 1;
    long hours = 0;

    if (t.isTimeSlot()) {

        hours = MMPCMRP.getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotEnd());

    } else {
        //fjviejo e-evolution MachineQty
        if (r.getDailyCapacity().multiply(r.getMachineQty()).compareTo(Env.ZERO) != 0)
            hours = r.getDailyCapacity().multiply(r.getMachineQty()).longValue();
        else
            //fjviejo e-evolution end
            hours = 24;
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //      Long Hours = new Long(hours);                            
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ",
            r.getS_Resource_ID());
    MUOM uom = new MUOM(Env.getCtx(), C_UOM_ID, null);
    System.out.println("\n uom1 " + uom + "\n");
    //System.out.println("um.isHour()"+ uom.isHour() );
    if (!uom.isHour()) {
        System.out.println("\n uom2 " + uom + "\n");
        return dataset;
    }
    System.out.println("\n Dataset " + dataset + "\n");
    int summary = 0;
    int secondsAcum = 0;
    long hoursAcum = 0;

    while (days < 29) {
        //System.out.println("Day Number" + days);
        String day = new String(new Integer(date.getDate()).toString());
        System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID());
        System.out.println("Date:" + date);
        int seconds = getLoad(r.getS_Resource_ID(), date, date);
        Long Hours = new Long(hours);
        System.out.println("Summary " + summary);
        System.out.println("Capacity " + hours);
        System.out.println("Load " + seconds);

        /*
        **  Realizo la verificacin sobre que da me encuentro
        **  para graficar cada 7 dias el estado de la semana.
        **
        **  secondsAcum y hoursAcum llevan los acumulados para la semana
        **  los reinicio en cada nueva semana.
        **
        **  VIT4B - 07/12/2006
        */

        if (days == 1 || days == 8 || days == 15 || days == 22) {
            secondsAcum = 0;
            hoursAcum = 0;
        }

        secondsAcum += seconds;
        hoursAcum += hours;

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            if (t.isOnSunday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600); //+ (Hours.intValue() - ((seconds / 3600)));
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.MONDAY:
            if (t.isOnMonday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.TUESDAY:
            if (t.isOnTuesday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.WEDNESDAY:
            if (t.isOnWednesday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.THURSDAY:
            if (t.isOnThursday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.FRIDAY:
            if (t.isOnFriday()) {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {

                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        case Calendar.SATURDAY:
            if (t.isOnSaturday()) {
                /*
                                                **  Realizo la verificacin sobre que da me encuentro
                                                **  para graficar cada 7 dias el estado de la semana.
                                                **
                                                **  VIT4B - 07/12/2006
                                                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }

                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            } else {
                /*
                **  Realizo la verificacin sobre que da me encuentro
                **  para graficar cada 7 dias el estado de la semana.
                **
                **  VIT4B - 07/12/2006
                */

                if (days == 7 || days == 14 || days == 21 || days == 28) {
                    dataset.addValue(hoursAcum, namecapacity, day);
                    dataset.addValue(secondsAcum / 3600, nameload, day);
                    dataset.addValue(summary, namesummary, day);

                }
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = new Timestamp(gc1.getTimeInMillis());
                break;
            }
        }

        days++;

    }
    return dataset;
}

From source file:org.eevolution.form.VCRP.java

public CategoryDataset createDataset(Timestamp start, MResource r) {
    //System.out.println("Create new data set");
    GregorianCalendar gc1 = new GregorianCalendar();
    gc1.setTimeInMillis(start.getTime());
    gc1.clear(Calendar.MILLISECOND);
    gc1.clear(Calendar.SECOND);/*  ww w.  ja v a2 s.c o m*/
    gc1.clear(Calendar.MINUTE);
    gc1.clear(Calendar.HOUR_OF_DAY);

    Timestamp date = start;
    String namecapacity = Msg.translate(Env.getCtx(), "Capacity");
    System.out.println("\n Namecapacity :" + namecapacity);
    String nameload = Msg.translate(Env.getCtx(), "Load");
    System.out.println("\n Nameload :" + nameload);
    String namesummary = Msg.translate(Env.getCtx(), "Summary");
    System.out.println("\n Namesummary :" + namesummary);
    MResourceType t = new MResourceType(Env.getCtx(), r.getS_ResourceType_ID(), null);
    System.out.println("\n Resourcetype " + t);
    int days = 1;
    long hours = 0;

    if (t.isTimeSlot()) {

        hours = MMPCMRP.getHoursAvailable(t.getTimeSlotStart(), t.getTimeSlotEnd());

    } else {
        //fjviejo e-evolution MachineQty
        if (r.getDailyCapacity().multiply(r.getMachineQty()).compareTo(Env.ZERO) != 0)
            hours = r.getDailyCapacity().multiply(r.getMachineQty()).longValue();
        else
            //fjviejo e-evolution end
            hours = 24;
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    //      Long Hours = new Long(hours);
    int C_UOM_ID = DB.getSQLValue(null, "SELECT C_UOM_ID FROM M_Product WHERE S_Resource_ID = ? ",
            r.getS_Resource_ID());
    MUOM uom = new MUOM(Env.getCtx(), C_UOM_ID, null);
    System.out.println("\n uom1 " + uom + "\n");
    //System.out.println("um.isHour()"+ uom.isHour() );
    if (!uom.isHour()) {
        System.out.println("\n uom2 " + uom + "\n");
        return dataset;
    }
    System.out.println("\n Dataset " + dataset + "\n");
    int summary = 0;
    //int cont = 1;
    DateFormat formatter = DateFormat.getDateInstance();

    /*
     *     Vit4B Modificado para que tome 28 dias y
     *
     *
     */

    while (days < 29) {
        /*
         *      VIT4B MODIFICACION PARA ACUMULADO DE DIAS
         *
         *
         *
                
                
        //System.out.println("Day Number" + days);
        String strday = formatter.format(date);
        //String day = new String(new Integer (date.getDate()).toString());
        String day = new String(formatter.format(date));
        //day = day.substring(0,5);
                
        int index = day.indexOf("/");
                
        String str = day.substring(0,index);
        System.out.println("str: " + str + " index de / " + index);
                
        String str2 = day.substring(index+1,day.length());
        System.out.println("str2 resto: " + str2);
                
        index = str2.indexOf("/");
        System.out.println(index);
                
        String str3 = str2.substring(0,index);
        System.out.println("str3: " + str3 + " index de / " + index);
                
        String str4 = str2.substring(index+1,str2.length());
        System.out.println(str4);
                
        System.out.println("dia: " + str);
        System.out.println("mes: " + str3);
        System.out.println("ao: " + str4);
                
        //day = str + str3;
                
        day = new String(str + str3);
                
                
        //day = day.substring(0,day.lastIndexOf("/"));
        //day =day.substring(0,3);
                
        //cont++;
                
        System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID());
        System.out.println("Date: "  +  date + " day: "  +  day);
        int seconds = getLoad(r.getS_Resource_ID(),date ,date);
        Long Hours = new Long(hours);
        System.out.println("Summary "+ summary);
        System.out.println("Capacity "+ hours);
        System.out.println("Load "+ seconds);
                
        /*
         *
         *      VIT4B MODIFICACION PARA ACUMULADO DE DIAS
         *
         *
         */

        /*
         *      ORIGINAL COMPIERE
         */

        String day = new String(new Integer(date.getDate()).toString());
        System.out.println("r.getS_Resource_ID()" + r.getS_Resource_ID());
        System.out.println("Date:" + date);

        /*
         *      VIT4B - Modificacin para calcular como se calcula el reporte CCRP
         *      en funcion de la carga parcial
         *
         *
         */

        int seconds = getLoad(r.getS_Resource_ID(), date, date);

        //BigDecimal value = calculateLoad(date, r, null);
        //int seconds = value.intValue();

        Long Hours = new Long(hours);
        System.out.println("Summary " + summary);
        System.out.println("Load " + seconds);

        /*
         *      FIN ORIGINAL COMPIERE
         *
         */

        switch (gc1.get(Calendar.DAY_OF_WEEK)) {
        case Calendar.SUNDAY:
            days++;
            if (t.isOnSunday()) { //System.out.println("si Sunday");
                                  //Msg.translate(Env.getCtx(), "OnSunday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600); //+ (Hours.intValue() - ((seconds / 3600)));
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else { //System.out.println("no Sunday");
                     //String day = Msg.translate(Env.getCtx(), "OnSunday") ;
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.MONDAY:
            days++;
            if (t.isOnMonday()) { //System.out.println("si Monday");
                                  //String day = Msg.translate(Env.getCtx(), "OnMonday") ;
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {
                //System.out.println("no Monday");
                //String day = Msg.translate(Env.getCtx(), "OnMonday")  ;
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.TUESDAY:
            days++;
            if (t.isOnTuesday()) { //System.out.println("si TuesDay");
                                   //String day = Msg.translate(Env.getCtx(), "OnTuesday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {
                //System.out.println("no TuesDay");
                //String day = Msg.translate(Env.getCtx(), "OnTuesday");
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.WEDNESDAY:
            days++;
            if (t.isOnWednesday()) {
                //String day = Msg.translate(Env.getCtx(), "OnWednesday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {

                //String day = Msg.translate(Env.getCtx(), "OnWednesday");
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.THURSDAY:
            days++;
            if (t.isOnThursday()) {
                //String day = Msg.translate(Env.getCtx(), "OnThursday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {

                //String day = Msg.translate(Env.getCtx(), "OnThursday");
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.FRIDAY:
            days++;
            if (t.isOnFriday()) {
                //String day = Msg.translate(Env.getCtx(), "OnFriday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {

                //String day = Msg.translate(Env.getCtx(), "OnFriday");
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        case Calendar.SATURDAY:
            days++;
            if (t.isOnSaturday()) {
                //String day = Msg.translate(Env.getCtx(), "OnSaturday");
                dataset.addValue(hours, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary + Hours.intValue() - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            } else {
                //String day = Msg.translate(Env.getCtx(), "OnSaturday");
                dataset.addValue(0, namecapacity, day);
                dataset.addValue(seconds / 3600, nameload, day);
                dataset.addValue(summary, namesummary, day);
                summary = summary - (seconds / 3600);
                gc1.add(Calendar.DATE, 1);
                date = org.compiere.util.TimeUtil.addDays(date, 1);
                break;
            }
        }

    }
    return dataset;
}

From source file:org.betaconceptframework.astroboa.console.jsf.browse.ContentObjectSearchByContentType.java

public String findContentObjectsByContentTypeAndPresent_UIAction() {

    // reset search criteria to begin a new search
    contentObjectCriteria = null;/*from w  ww.  j a v  a2  s .com*/
    contentObjectCriteria = CmsCriteriaFactory.newContentObjectCriteria();

    uiComponentBinding.resetContentObjectTableScrollerComponent();
    contentObjectList.resetViewAndStateBeforeNewContentSearchResultsPresentation();

    // We add the selected content type into search criteria
    HtmlTree contentObjectFolderTree = uiComponentBinding.getContentObjectFolderTreeRichFaces();
    TreeNode selectedTreeNodeObject = contentObjectFolderTree.getTreeNode();
    LazyLoadingContentObjectFolderTreeNodeRichFaces selectedNode;

    // There is possibly a bug in Rich Faces Tree Implementation. The first time a tree node is selected in the tree the selected tree node
    // that is returned has type <LazyLoadingContentObjectFolderTreeNodeRichFaces> as it should be. However any subsequent selected tree node
    // is returned as a <TreeNodeImpl> object which should not happen. 
    // So we should check the returned type to decide how we will access the selected tree node.
    if (LazyLoadingContentObjectFolderTreeNodeRichFaces.class.isInstance(selectedTreeNodeObject)) {
        selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) contentObjectFolderTree.getTreeNode();
    } else if (TreeNodeImpl.class.isInstance(selectedTreeNodeObject)) {
        selectedNode = (LazyLoadingContentObjectFolderTreeNodeRichFaces) selectedTreeNodeObject.getData();
    } else
        throw new RuntimeException("Cannot determine the class of the selected tree node");

    contentObjectCriteria.addContentObjectTypeEqualsCriterion(selectedNode.getContentType());
    contentObjectCriteria.doNotCacheResults();

    // We should find and add the selected date into search criteria if a date folder has been selected
    String message = "";

    if (!selectedNode.getType().equals("contentTypeFolder")) {
        String fullContentObjectFolderPath = selectedNode.getContentObjectFolder().getFullPath(); //the full path contains date information. Its format is the following: YYYY/M/D eg. 2006/5/2
        String[] dateComponents = StringUtils.split(fullContentObjectFolderPath, "/"); // we split the path to the year, month and day components

        if (dateComponents == null || dateComponents.length == 0 || dateComponents.length > 3) {
            logger.error("Error while loading content objects. Invalid path for content object folder {}",
                    fullContentObjectFolderPath);
            JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null,
                    FacesMessage.SEVERITY_ERROR);
            return null;
        }

        GregorianCalendar fromDate = new GregorianCalendar(TimeZone.getDefault());
        GregorianCalendar toDate = new GregorianCalendar(TimeZone.getDefault());

        //Find out whether user has clicked a year, a month or a day
        if (dateComponents.length == 1) {
            //User has selected year.
            //Find all content objects created the selected year
            //from 01/01/selectedYear
            //to   31/12/selectedYear
            fromDate.set(Integer.valueOf(dateComponents[0]), 0, 1, 0, 0, 0);
            toDate.set(Integer.valueOf(dateComponents[0]), 11, 31, 23, 59, 59);

            message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy");
        } else if (dateComponents.length == 2) {
            //User has selected month.
            //Find all content objects created the selected year
            //from 01/selectedMonth/selectedYear
            //to   31/selectedMonth/selectedYear

            //Fix Month information
            //In  CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc
            //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion
            String month = dateComponents[1];
            int javaMonth = Integer.valueOf(month) - 1;

            fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, 1, 0, 0, 0);
            toDate.set(Integer.valueOf(dateComponents[0]), javaMonth,
                    fromDate.getActualMaximum(Calendar.DAY_OF_MONTH), 23, 59, 59);

            message = DateUtils.format(fromDate, "dd/MM/yyyy") + " - " + DateUtils.format(toDate, "dd/MM/yyyy");
        } else {
            //User has selected a day
            //from selectedDay at midnight
            //to selectedDay at 23:59:59.999
            //Fix Month information
            //In  CmsBackEnd. month enumeration starts from 1 for January, 2 for February .etc
            //Where as in Java Calendar month enumeration is zero based. Thus we need a conversion
            String month = dateComponents[1];
            int javaMonth = Integer.valueOf(month) - 1;

            // we create a date range for the selected date (24 hours)
            fromDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 0,
                    0, 0);
            toDate.set(Integer.valueOf(dateComponents[0]), javaMonth, Integer.valueOf(dateComponents[2]), 23,
                    59, 59);

            message = DateUtils.format(fromDate, "dd/MM/yyyy");
        }

        //Above method is setting 0 to hour, minute and second but we also need to clear milliseconds
        fromDate.clear(Calendar.MILLISECOND);
        //System.out.println(DateUtils.format(fromDate, "dd/MM/yyyy HH:mm"));

        toDate.set(Calendar.MILLISECOND, 999);
        //System.out.println(DateUtils.format(toDate, "dd/MM/yyyy HH:mm"));

        contentObjectCriteria.addCriterion(CriterionFactory.between("profile.created", fromDate, toDate));

    }

    contentObjectCriteria.setOffsetAndLimit(0, pageController.getRowsPerDataTablePage());

    // set required ordering
    if (searchResultsFilterAndOrdering.getSelectedResultsOrder() != null) {
        contentObjectCriteria.addOrderProperty("profile.created",
                Order.valueOf(searchResultsFilterAndOrdering.getSelectedResultsOrder()));
    } else {
        contentObjectCriteria.addOrderProperty("profile.created", Order.descending);
    }

    //   now we are ready to run the query
    try {
        long startTime = System.currentTimeMillis();
        int resultSetSize = contentObjectStatefulSearchService.searchForContentWithPagedResults(
                contentObjectCriteria, true, JSFUtilities.getLocaleAsString(),
                pageController.getRowsPerDataTablePage());
        long endTime = System.currentTimeMillis();
        getLogger().debug("Find Objects by ContentObject Type and Date: " + (endTime - startTime) + "ms");

        if (resultSetSize > 0) {

            String localisedNameOfBrowsedContentType = selectedNode.getLocalizedLabelOfContentType();
            if ("".equals(message)) {
                contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n(
                        "object.list.message.contentObjectListHeaderMessageForSearchByContentTypeWithoutDate",
                        new String[] { localisedNameOfBrowsedContentType, String.valueOf(resultSetSize) }));
            } else {
                contentObjectList.setContentObjectListHeaderMessage(JSFUtilities.getParameterisedStringI18n(
                        "object.list.message.contentObjectListHeaderMessageForSearchByContentType",
                        new String[] { localisedNameOfBrowsedContentType, message,
                                String.valueOf(resultSetSize) }));
            }
            contentObjectList.setLabelForFileGeneratedWhenExportingListToXml(localisedNameOfBrowsedContentType);
        } else
            JSFUtilities.addMessage(null, "object.list.message.noContentObjectsInThisContentObjectFolderInfo",
                    null, FacesMessage.SEVERITY_INFO);
    } catch (Exception e) {
        logger.error("Error while loading content objects ", e);
        JSFUtilities.addMessage(null, "object.list.message.contentObjectRetrievalError", null,
                FacesMessage.SEVERITY_ERROR);
    }

    return null;

}