Subversion Repositories bacoAlunos

Rev

Rev 1629 | Rev 1836 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1629 Rev 1830
Line 1... Line 1...
1
package pt.estgp.estgweb.services.questionarios;
1
package pt.estgp.estgweb.services.questionarios;
2
 
2
 
-
 
3
import jomm.dao.impl.AbstractDao;
-
 
4
import jomm.utils.StreamsUtils;
3
import org.apache.log4j.Logger;
5
import org.apache.log4j.Logger;
-
 
6
import org.hibernate.Criteria;
-
 
7
import org.json.JSONException;
-
 
8
import org.json.JSONObject;
4
import pt.estgp.estgweb.domain.*;
9
import pt.estgp.estgweb.domain.*;
5
import pt.estgp.estgweb.domain.dao.DaoFactory;
10
import pt.estgp.estgweb.domain.dao.DaoFactory;
6
import pt.estgp.estgweb.services.jobs.JobDeamon;
11
import pt.estgp.estgweb.services.jobs.JobDeamon;
7
import pt.estgp.estgweb.services.jobs.ServiceJob;
12
import pt.estgp.estgweb.services.jobs.ServiceJob;
-
 
13
import pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable;
8
import pt.estgp.estgweb.utils.ConfigProperties;
14
import pt.estgp.estgweb.utils.ConfigProperties;
-
 
15
import pt.estgp.estgweb.utils.Globals;
9
import pt.estgp.estgweb.web.exceptions.NotAuthorizedException;
16
import pt.estgp.estgweb.web.exceptions.NotAuthorizedException;
10
import pt.estgp.estgweb.web.form.questionarios.widgets.ReportAdminAlunosWidgetForm;
17
import pt.estgp.estgweb.web.form.questionarios.widgets.ReportAdminAlunosWidgetForm;
11
import pt.utl.ist.berserk.logic.serviceManager.IService;
18
import pt.utl.ist.berserk.logic.serviceManager.IService;
12
 
19
 
-
 
20
import java.io.IOException;
-
 
21
import java.io.InputStream;
-
 
22
import java.net.URL;
13
import java.util.ArrayList;
23
import java.util.ArrayList;
14
import java.util.HashSet;
24
import java.util.HashSet;
15
import java.util.List;
25
import java.util.List;
16
import java.util.Set;
26
import java.util.Set;
17
 
27
 
-
 
28
import static org.hibernate.criterion.Restrictions.eq;
-
 
29
import static org.hibernate.criterion.Restrictions.like;
-
 
30
 
18
/**
31
/**
19
 * Created by jorgemachado on 21/03/16.
32
 * Created by jorgemachado on 21/03/16.
20
 */
33
 */
21
public class QuestionariosReportsService implements IService
34
public class QuestionariosReportsService implements IService
22
{
35
{
23
 
36
 
24
    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);
37
    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);
25
 
38
 
26
 
39
 
-
 
40
 
-
 
41
 
27
    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
42
    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
28
    {
43
    {
29
        QuestionarioReportFileGroup reportFileGroup = (QuestionarioReportFileGroup) 1.5.0/docs/api/java/lang/Class.html">Class.forName(classType).newInstance();
44
        QuestionarioReportFileGroup reportFileGroup = (QuestionarioReportFileGroup) 1.5.0/docs/api/java/lang/Class.html">Class.forName(classType).newInstance();
30
        reportFileGroup.setTitle(title);
45
        reportFileGroup.setTitle(title);
31
        1.5.0/docs/api/java/lang/String.html">String processorClassForGroup = ConfigProperties.getProperty("questionarios.processor." + classType);
46
        1.5.0/docs/api/java/lang/String.html">String processorClassForGroup = ConfigProperties.getProperty("questionarios.processor." + classType);
Line 45... Line 60...
45
        QuestionarioReportFile reportFile = DaoFactory.getQuestionarioReportFileDaoImpl()
60
        QuestionarioReportFile reportFile = DaoFactory.getQuestionarioReportFileDaoImpl()
46
                .load(reportFileId);
61
                .load(reportFileId);
47
        reportFile.setActive(active);
62
        reportFile.setActive(active);
48
    }
63
    }
49
 
64
 
50
    public QuestionarioReportFileGroupImpl runJobGenerate(long reportGroupId,1.5.0/docs/api/java/lang/String.html">String title,boolean active, UserSession session) throws NotAuthorizedException, 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException {
65
    public QuestionarioReportFileGroupImpl runJobGenerate(long reportGroupId,1.5.0/docs/api/java/lang/String.html">String title,boolean active, 1.5.0/docs/api/java/lang/String.html">String generateSigesCode, UserSession session) throws NotAuthorizedException, 1.5.0/docs/api/java/lang/ClassNotFoundException.html">ClassNotFoundException {
51
 
66
 
52
        QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId);
67
        QuestionarioReportFileGroupImpl reportGroup = (QuestionarioReportFileGroupImpl) DaoFactory.getQuestionarioReportFileGroupDaoImpl().load(reportGroupId);
53
        reportGroup.setTitle(title);
68
        reportGroup.setTitle(title);
54
        reportGroup.setActive(active);
69
        reportGroup.setActive(active);
55
 
70
 
Line 70... Line 85...
70
        paramJob.setName(ServiceJob.JOB_questionario_report_id_KEY);
85
        paramJob.setName(ServiceJob.JOB_questionario_report_id_KEY);
71
        paramJob.setDescription("ID do Report Group");
86
        paramJob.setDescription("ID do Report Group");
72
        paramJob.setObject("" + reportGroupId);
87
        paramJob.setObject("" + reportGroupId);
73
        paramsJob.add(paramJob);
88
        paramsJob.add(paramJob);
74
 
89
 
-
 
90
        if(generateSigesCode != null && generateSigesCode.trim().length()>0)
-
 
91
        {
-
 
92
            JobServiceTaskParameterImpl paramJobSigesCode = DomainObjectFactory.createJobServiceTaskParameterImpl();
-
 
93
            paramJobSigesCode.setName(ServiceJob.JOB_questionario_sigesCode_KEY);
-
 
94
            paramJobSigesCode.setDescription("Gerar apenas este SigesCode");
-
 
95
            paramJobSigesCode.setObject(generateSigesCode);
-
 
96
            paramsJob.add(paramJobSigesCode);
-
 
97
        }
-
 
98
 
75
        1.5.0/docs/api/java/lang/Class.html">Class reportGeneratorServiceClass = 1.5.0/docs/api/java/lang/Class.html">Class.forName(reportGroup.getReportProcessorClass());
99
        1.5.0/docs/api/java/lang/Class.html">Class reportGeneratorServiceClass = 1.5.0/docs/api/java/lang/Class.html">Class.forName(reportGroup.getReportProcessorClass());
76
 
100
 
77
        JobServiceTask job = JobDeamon.createServiceJob(reportGeneratorServiceClass, session.getUser(), paramsJob,
101
        JobServiceTask job = JobDeamon.createServiceJob(reportGeneratorServiceClass, session.getUser(), paramsJob,
78
                "Service: Geração de Reports para o group " + reportGroupId + " - " + reportGroup.getTitle());
102
                "Service: Geração de Reports para o group " + reportGroupId + " - " + reportGroup.getTitle());
79
        reportGroup.setReportGenerationTaskId(job.getId());
103
        reportGroup.setReportGenerationTaskId(job.getId());
Line 123... Line 147...
123
    }
147
    }
124
 
148
 
125
 
149
 
126
 
150
 
127
 
151
 
-
 
152
    /****************************************************************************/
-
 
153
    /* SERVICOS WS-API
-
 
154
    /****************************************************************************/
-
 
155
 
-
 
156
 
-
 
157
    /**
-
 
158
     *
-
 
159
     * @param sigesCode
-
 
160
     * @param year
-
 
161
     * @param periodIncluded
-
 
162
     * @return an encoded DataTable in JSON (pt.estgp.estgweb.services.questionarios.pedagogico.reportprocessors.utils.DataTable)
-
 
163
     * @throws IOException
-
 
164
     */
-
 
165
    public 1.5.0/docs/api/java/lang/String.html">String loadReportUnidadesSalasJson(1.5.0/docs/api/java/lang/String.html">String sigesCode, 1.5.0/docs/api/java/lang/String.html">String year, 1.5.0/docs/api/java/lang/String.html">String periodIncluded) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
-
 
166
 
-
 
167
 
-
 
168
        if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_REPORT_RESULTS.indexOf("localhost")>=0)
-
 
169
        {
-
 
170
            Criteria c = DaoFactory.getQuestionarioReportCursoFileDaoImpl().createCriteria();
-
 
171
            c.createAlias("reportGroup","rg");
-
 
172
            c.add(like("rg.periodos","%" + periodIncluded + "%"));
-
 
173
            c.add(eq("rg.importYear",year));
-
 
174
            c.add(eq("entityCode",sigesCode));
-
 
175
            List<QuestionarioReportCursoFile> files = c.list();
-
 
176
            if(files.size() == 0)
-
 
177
            {
-
 
178
                return "{}";
-
 
179
            }
-
 
180
            return files.get(0).getCourseReportQuestionsJson();
-
 
181
        }
-
 
182
        else
-
 
183
        {
-
 
184
            1.5.0/docs/api/java/net/URL.html">URL url = new 1.5.0/docs/api/java/net/URL.html">URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_REPORT_RESULTS + "?code=" + sigesCode + "&year=" + year);
-
 
185
            5+0%2Fdocs%2Fapi+InputStream">InputStream is = url.openStream();
-
 
186
 
-
 
187
            1.5.0/docs/api/java/lang/String.html">String json = StreamsUtils.readString(is);
-
 
188
            is.close();
-
 
189
            JSONObject jsonObject = new JSONObject(json);
-
 
190
            return jsonObject.getString("response").toString();
-
 
191
 
-
 
192
        }
-
 
193
 
-
 
194
    }
-
 
195
 
-
 
196
 
-
 
197
 
-
 
198
 
-
 
199
 
-
 
200
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws 1.5.0/docs/api/java/io/IOException.html">IOException, JSONException {
-
 
201
        AbstractDao.getCurrentSession().beginTransaction();
-
 
202
        1.5.0/docs/api/java/lang/String.html">String json = new QuestionariosReportsService().loadReportUnidadesSalasJson("9119", "201516", "S2");
-
 
203
 
-
 
204
        DataTable d = DataTable.fromJson(json);
-
 
205
        1.5.0/docs/api/java/lang/System.html">System.out.println(d.toJson());
-
 
206
 
-
 
207
        1.5.0/docs/api/java/lang/System.html">System.out.println(d.toJson().equals(json));
-
 
208
 
-
 
209
 
-
 
210
        AbstractDao.getCurrentSession().getTransaction().commit();
-
 
211
    }
-
 
212
 
-
 
213
 
-
 
214
 
-
 
215
 
128
}
216
}