Android Open Source - openpomo Activity Factory






From Project

Back to project page openpomo.

License

The source code is released under:

GNU General Public License

If you think the Android project openpomo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * This file is part of Pomodroid.// w w w  .  java2 s . c  o m
 *
 *   Pomodroid is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   Pomodroid is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with Pomodroid.  If not, see <http://www.gnu.org/licenses/>.
 */
package it.unibz.pomodroid.factories;

import java.util.Date;
import java.util.HashMap;
import java.util.Vector;

import it.unibz.pomodroid.exceptions.PomodroidException;
import it.unibz.pomodroid.models.*;


/**
 * A class that saves all information about tickets it into the
 * database. Each ticket taken from a Service is checked. If some information
 * is empty, the class provides some auto-generated values.
 *
 * @author Daniel Graziotin <d AT danielgraziotin DOT it>
 * @author Thomas Schievenin <thomas.schievenin@stud-inf.unibz.it>
 */
public class ActivityFactory {
    /**
     * String that represent a default value for empty fields in Activities
     */
    final private static String autogen = "Autogenerated value";

    /**
     * @param id         trac identifier
     * @param deadLine   date within the work has be done
     * @param attributes list containing all information about one ticket
     * @param dbHelper   reference to the database
     */
    public int produce(Vector<HashMap<String, Object>> tickets,
                       DBHelper dbHelper) throws PomodroidException {
        int ticketsNumber = 0;
        for (HashMap<String, Object> ticket : tickets) {
            fillEmptyFields(ticket);
            Activity activity = new Activity(0, 0, new Date(), (Date) ticket
                    .get("deadLine"), ticket.get("summary").toString(), ticket
                    .get("description").toString(), ticket.get("origin")
                    .toString(), (Integer) ticket.get("originId"), ticket.get(
                    "priority").toString(), ticket.get("reporter").toString(),
                    ticket.get("type").toString());

            if (!Activity.isPresent(activity.getOrigin(), activity
                    .getOriginId(), dbHelper)) {
                activity.save(dbHelper);
                ticketsNumber++;
            }

        }

        return ticketsNumber;
    }

    /**
     * @param id         trac identifier
     * @param deadLine   date within the work has be done
     * @param attributes list containing all information about one ticket
     * @param dbHelper   reference to the database
     */
    public int produceTest(Vector<HashMap<String, Object>> tickets,
                           DBHelper dbHelper) throws PomodroidException {
        int ticketsNumber = 0;
        for (HashMap<String, Object> ticket : tickets) {

            fillEmptyFields(ticket);

            Activity activity = new Activity(0, 0, new Date(), (Date) ticket
                    .get("deadLine"), ticket.get("summary").toString(), ticket
                    .get("description").toString(), ticket.get("origin")
                    .toString(), (Integer) ticket.get("originId"), ticket.get(
                    "priority").toString(), ticket.get("reporter").toString(),
                    ticket.get("type").toString());

            if (!Activity.isPresent(activity.getOrigin(), activity
                    .getOriginId(), dbHelper)) {
                ticketsNumber++;
            }

        }

        return ticketsNumber;
    }

    /**
     * Checks if there are empty fields and fills them with a default value
     *
     * @param ticket
     * @return ticket
     * @throws PomodroidException
     */
    private HashMap<String, Object> fillEmptyFields(
            HashMap<String, Object> ticket) throws PomodroidException {
        for (String key : ticket.keySet()) {
            if (isEmpty(ticket.get(key).toString()))
                ticket.put(key, autogen);
        }
        return ticket;
    }

    /**
     * Checks whether a string is null or empty
     *
     * @param string
     * @return
     * @throws PomodroidException
     */
    private boolean isEmpty(String string) throws PomodroidException {
        return (string.equals("") || string.equals(null));
    }

}




Java Source Code List

it.unibz.pomodroid.About.java
it.unibz.pomodroid.ActivityInventorySheet.java
it.unibz.pomodroid.CleanDatabase.java
it.unibz.pomodroid.EditActivity.java
it.unibz.pomodroid.EditService.java
it.unibz.pomodroid.ListServices.java
it.unibz.pomodroid.PomodoroService.java
it.unibz.pomodroid.Pomodoro.java
it.unibz.pomodroid.Pomodroid.java
it.unibz.pomodroid.Preferences.java
it.unibz.pomodroid.Services.java
it.unibz.pomodroid.SharedActivity.java
it.unibz.pomodroid.SharedListActivity.java
it.unibz.pomodroid.Statistics.java
it.unibz.pomodroid.TabPomodroid.java
it.unibz.pomodroid.TabPreferences.java
it.unibz.pomodroid.TodoTodaySheet.java
it.unibz.pomodroid.TrashSheet.java
it.unibz.pomodroid.exceptions.PomodroidException.java
it.unibz.pomodroid.factories.ActivityFactory.java
it.unibz.pomodroid.models.Activity.java
it.unibz.pomodroid.models.DBHelper.java
it.unibz.pomodroid.models.Event.java
it.unibz.pomodroid.models.Service.java
it.unibz.pomodroid.models.User.java
it.unibz.pomodroid.services.TracTicketFetcher.java
it.unibz.pomodroid.services.XmlRpcClient.java
org.xmlrpc.Test.java
org.xmlrpc.android.Base64Coder.java
org.xmlrpc.android.XMLRPCClient.java
org.xmlrpc.android.XMLRPCException.java
org.xmlrpc.android.XMLRPCFault.java
org.xmlrpc.android.XMLRPCSerializer.java