Subversion Repositories bacoAlunos

Rev

Rev 1579 | Rev 1586 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.services.questionarios;

import jomm.dao.impl.AbstractDao;
import org.apache.log4j.Logger;
import pt.estgp.estgweb.domain.*;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.services.jobs.JobDeamon;
import pt.estgp.estgweb.services.jobs.ServiceJob;
import pt.estgp.estgweb.utils.ConfigProperties;
import pt.estgp.estgweb.web.exceptions.NotAuthorizedException;
import pt.estgp.estgweb.web.form.questionarios.widgets.ReportAdminAlunosWidgetForm;
import pt.utl.ist.berserk.logic.serviceManager.IService;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * Created by jorgemachado on 21/03/16.
 */

public class QuestionariosReportsService implements IService
{

    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(QuestionariosReportsService.class);


    public void saveReportGroup(1.5.0/docs/api/java/lang/String.html">String title,1.5.0/docs/api/java/lang/String.html">String classType, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException
    {
        QuestionarioReportFileGroup reportFileGroup = (QuestionarioReportFileGroup) 1.5.0/docs/api/java/lang/Class.html">Class.forName(classType).newInstance();
        reportFileGroup.setTitle(title);
        1.5.0/docs/api/java/lang/String.html">String processorClassForGroup = ConfigProperties.getProperty("questionarios.processor." + classType);
        reportFileGroup.setReportProcessorClass(processorClassForGroup);
        AbstractDao.getCurrentSession().save(reportFileGroup);
    }

    public void updateReportGroup(long reportGroupId, 1.5.0/docs/api/java/lang/String.html">String title, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException
    {
        QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId);
        reportGroup.setTitle(title);
    }

    public QuestionarioReportFileGroupImpl runJobGenerate(long reportGroupId,1.5.0/docs/api/java/lang/String.html">String title, UserSession session) throws NotAuthorizedException, 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException {

        QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId);
        reportGroup.setTitle(title);
        Set<JobServiceTaskParameter> paramsJob = new HashSet<JobServiceTaskParameter>();

        JobServiceTaskParameterImpl paramJob = DomainObjectFactory.createJobServiceTaskParameterImpl();
        paramJob.setName(ServiceJob.JOB_questionario_report_id_KEY);
        paramJob.setDescription("ID do Report Group");
        paramJob.setObject("" + reportGroupId);
        paramsJob.add(paramJob);

        1.5.0/docs/api/java/lang/Class.html">Class reportGeneratorServiceClass = 1.5.0/docs/api/java/lang/Class.html">Class.forName(reportGroup.getReportProcessorClass());

        JobServiceTask job = JobDeamon.createServiceJob(reportGeneratorServiceClass, session.getUser(), paramsJob,
                "Service: Geração de Reports para o group " + reportGroupId + " - " + reportGroup.getTitle());
        reportGroup.setReportGenerationTaskId(job.getId());

        return reportGroup;
    }


    /*************WIDGET ALUNOS REPORTS***************/

    public void saveReportGroupAlunosParameters(ReportAdminAlunosWidgetForm form, UserSession userSession) throws 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException, 1.5.0/docs/api/java/lang/IllegalAccessException.html">IllegalAccessException, 1.5.0/docs/api/java/lang/InstantiationException.html">InstantiationException
    {
        QuestionarioReportFileGroupAnoImpl reportGroup = (QuestionarioReportFileGroupAnoImpl) DaoFactory.getQuestionarioReportFileGroupAnoDaoImpl().load(form.getQuestionarioReportGroupId());
        List<String> periodos = new ArrayList<String>();
        List<String> degrees = new ArrayList<String>();
        reportGroup.setImportYear(form.getAno());

        if(form.isAnuais())
            periodos.add("A");
        if(form.isSemestre1())
            periodos.add("S1");
        if(form.isSemestre2())
            periodos.add("S2");
        if(form.isTrimestre1())
            periodos.add("T1");
        if(form.isTrimestre2())
            periodos.add("T2");
        if(form.isTrimestre3())
            periodos.add("T3");
        if(form.isTrimestre4())
            periodos.add("T4");

        if(form.isLicenciaturas())
            degrees.add("L");
        if(form.isMestrados())
            degrees.add("M");
        if(form.isTesps())
            degrees.add("T");
        if(form.isCets())
            degrees.add("E");


        reportGroup.setPeriodosList(periodos);
        reportGroup.setDegreesList(degrees);


    }




}