Subversion Repositories bacoAlunos

Rev

Rev 1579 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.domain;

import jomm.utils.StringsUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import pt.estgp.estgweb.domain.utils.InputDrivenInput;
import pt.estgp.estgweb.utils.ConfigProperties;
import pt.estgp.estgweb.utils.DatesUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jorgemachado on 05/11/16.
 */

public class QuestionarioReportFileGroupAnoImpl extends QuestionarioReportFileGroupAno
{
    public static final 1.5.0/docs/api/java/lang/String.html">String INPUT_DRIVEN_ANO_NAME = "Ano";
    public static final 1.5.0/docs/api/java/lang/String.html">String INPUT_DRIVEN_PERIODOS_NAME = "Periodos";
    public static final 1.5.0/docs/api/java/lang/String.html">String INPUT_DRIVEN_DEGREES_NAME = "Tipos";

    public void setPeriodosList(List<String> periodos)
    {
        setPeriodos(StringsUtils.getSerialElements(periodos, ";"));
    }
    public void setDegreesList(List<String> degrees)
    {
        setDegrees(StringsUtils.getSerialElements(degrees, ";"));
    }

    public 1.5.0/docs/api/java/lang/String.html">String[] getPeriodosArray()
    {
        return StringsUtils.getElementsFromSerial(getPeriodos(), ";").toArray(new 1.5.0/docs/api/java/lang/String.html">String[0]);
    }
    public 1.5.0/docs/api/java/lang/String.html">String[] getDegreesArray()
    {
        return StringsUtils.getElementsFromSerial(getDegrees(), ";").toArray(new 1.5.0/docs/api/java/lang/String.html">String[0]);
    }

    public boolean isSemestre1()
    {
        return hasPeriodo("S1");
    }
    public boolean isSemestre2()
    {
        return hasPeriodo("S2");
    }
    public boolean isTrimestre1()
    {
        return hasPeriodo("T1");
    }
    public boolean isTrimestre2()
    {
        return hasPeriodo("T2");
    }
    public boolean isTrimestre3()
    {
        return hasPeriodo("T3");
    }
    public boolean isTrimestre4()
    {
        return hasPeriodo("T4");
    }
    public boolean isAnuais()
    {
        return hasPeriodo("A");
    }

    public boolean isLicenciaturas()
    {
        return hasDegree("L");
    }
    public boolean isMestrados()
    {
        return hasDegree("M");
    }
    public boolean isTesps()
    {
        return hasDegree("T");
    }
    public boolean isCets()
    {
        return hasDegree("E");
    }

    private boolean hasPeriodo(1.5.0/docs/api/java/lang/String.html">String periodo)
    {
        if(getPeriodos() == null || getPeriodos().length() == 0)
            return false;
        else
            return getPeriodos().contains(periodo);
    }

    private boolean hasDegree(1.5.0/docs/api/java/lang/String.html">String degree)
    {
        if(getDegrees() == null || getDegrees().length() == 0)
            return false;
        else
            return getDegrees().contains(degree);
    }

    public 1.5.0/docs/api/java/lang/String.html">String getPeriodosDesc()
    {
        1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder str = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder();
        if(getPeriodos() != null)
        {
            1.5.0/docs/api/java/lang/String.html">String union = "";
            for(1.5.0/docs/api/java/lang/String.html">String periodo: getPeriodosArray())
            {
                str.append(union).append(ConfigProperties.getProperty("intranet.semestre." + periodo));
                union = " ,";
            }
        }
        return str.toString();
    }
    public 1.5.0/docs/api/java/lang/String.html">String getDegreesDesc()
    {
        1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder str = new 1.5.0/docs/api/java/lang/StringBuilder.html">StringBuilder();
        if(getDegrees() != null)
        {
            1.5.0/docs/api/java/lang/String.html">String union = "";
            for(1.5.0/docs/api/java/lang/String.html">String degree: getDegreesArray())
            {
                str.append(union).append(ConfigProperties.getProperty("course." + degree));
                union = " ,";
            }
        }
        return str.toString();
    }

    @1.5.0/docs/api/java/lang/Override.html">Override
    public List<InputDrivenInput> getInputs()
    {
        List<InputDrivenInput> inputs = new ArrayList<InputDrivenInput>();
        inputs.add(new InputDrivenInput(INPUT_DRIVEN_ANO_NAME,getImportYear()));
        inputs.add(new InputDrivenInput(INPUT_DRIVEN_PERIODOS_NAME,getPeriodosDesc()));
        inputs.add(new InputDrivenInput(INPUT_DRIVEN_DEGREES_NAME,getDegreesDesc()));
        return inputs;
    }

    public JSONArray getInputsJsonArray() throws JSONException
    {
        JSONArray inputs = new JSONArray();

        if(getImportYear()!= null && getImportYear().trim().length()>0)
        {
            JSONObject yearJson = new JSONObject();
            yearJson.put("name" ,INPUT_DRIVEN_ANO_NAME);
            yearJson.put("value",getImportYear());
            inputs.put(yearJson);
        }

        if(getPeriodos()!= null && getPeriodos().trim().length()>0)
        {
            JSONObject periodosJson = new JSONObject();
            periodosJson.put("name" ,INPUT_DRIVEN_PERIODOS_NAME);
            periodosJson.put("value",getPeriodosDesc());
            inputs.put(periodosJson);
        }

        if(getDegrees()!= null && getDegrees().trim().length()>0)
        {
            JSONObject degreesJson = new JSONObject();
            degreesJson.put("name" ,INPUT_DRIVEN_DEGREES_NAME);
            degreesJson.put("value",getDegreesDesc());
            inputs.put(degreesJson);
        }

        return inputs;
    }

    public 1.5.0/docs/api/java/lang/String.html">String getInputsJson() throws JSONException
    {
        return getInputsJsonArray().toString();
    }

    public 1.5.0/docs/api/java/lang/String.html">String getImportYearFormatted(){
        return DatesUtils.getImportYearFormatted(getImportYear());
    }
}