1,6 → 1,7 |
package pt.estgp.estgweb.services.courses; |
|
|
import jomm.dao.impl.AbstractDao; |
import jomm.utils.StreamsUtils; |
import org.apache.log4j.Logger; |
import org.json.JSONArray; |
32,6 → 33,7 |
import java.io.IOException; |
import java.io.InputStream; |
import java.net.URL; |
import java.net.URLConnection; |
import java.util.*; |
|
/** |
52,52 → 54,8 |
/****************************************************************************/ |
|
|
/** |
* Gera uma tabela de estatisticas dos DTP recorrendo ao servico WS de |
* load de tabelas DTP, caso o serviço nao devolva unidades são criadas novas |
* com os valores a falso. |
* |
* @param courseCode |
* @param year |
* @return UnitsDtpTable |
* @throws IOException |
* @throws JSONException |
*/ |
public UnitsDtpTable updateDtpStatsTable4Course(ReportCourseDocument reportCourseDocument, String courseCode, String year) throws IOException, JSONException |
{ |
|
ReportsUcSummarySection reportsUcSummarySection = (ReportsUcSummarySection) reportCourseDocument.findDocumentSection(ReportsUcSummarySection.class); |
UnitsDtpTable unitsDtpTable = (UnitsDtpTable) reportsUcSummarySection.findDocComponent(UnitsDtpTable.class); |
UnitDtpSemester semester1 = new UnitDtpSemester(); |
UnitDtpSemester semester2 = new UnitDtpSemester(); |
unitsDtpTable.setSemester1(semester1); |
unitsDtpTable.setSemester2(semester2); |
|
List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
|
String json = loadCourseUnitDtpStats(courseCode,year); |
JSONObject response = new JSONObject(json); |
JSONArray stats = (JSONArray) response.get("dtpstats"); |
CourseUnitDtpStat[] statsLoaded = CourseUnitDtpStat.fromJson(stats); |
|
for(CourseUnit cu :units) |
{ |
CourseUnitDtpStat statFound = CourseReportUtils.findCourseUnitDtpStat(statsLoaded, (CourseUnitImpl) cu); |
if(statFound == null) |
{ |
statFound = CourseReportUtils.createCourseUnitDtpStat(cu); |
} |
|
if(((CourseUnitImpl) cu).getSemestreAbsolutoS1S2().equals("S1")) |
semester1.getCourseUnitDtpStats().add(statFound); |
else |
semester2.getCourseUnitDtpStats().add(statFound); |
} |
|
return unitsDtpTable; |
|
} |
|
/** |
* |
* @param courseCode |
106,9 → 64,9 |
* @throws IOException |
* @throws JSONException |
*/ |
public ReportCourseDocument createNewCourseReportDocument(String courseCode,String year) throws IOException, JSONException |
public CourseReportDocument createNewCourseReportDocument(String courseCode,String year) throws IOException, JSONException |
{ |
ReportCourseDocument reportCourseDocument = new ReportCourseDocument(); |
CourseReportDocument reportCourseDocument = new CourseReportDocument(); |
reportCourseDocument.init(); |
|
|
133,9 → 91,9 |
return reportCourseDocument; |
} |
|
public SurveysResultsSection updateSurveysDataTables(String courseCode, String year, ReportCourseDocument reportCourseDocument) throws IOException, JSONException { |
public SurveysResultsSection updateSurveysDataTables(String courseCode, String year, CourseReportDocument reportCourseDocument) throws IOException, JSONException { |
SurveysSection surveysSection = (SurveysSection) reportCourseDocument.findDocumentSection(SurveysSection.class); |
SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSubSection(SurveysResultsSection.class); |
SurveysResultsSection surveysResultsSection = (SurveysResultsSection) surveysSection.findSection(SurveysResultsSection.class); |
QuestionariosDataTableComponent dataTableComponentS1 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(0); |
QuestionariosDataTableComponent dataTableComponentS2 = (QuestionariosDataTableComponent) surveysResultsSection.getComponents().get(1); |
|
154,7 → 112,7 |
* @param reportCourseDocument |
* @return UnitsLearningResultsTable |
*/ |
public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(ReportCourseDocument reportCourseDocument) |
public UnitsLearningResultsTable updateCleanLearningResultsFromCourseUnitsSections(CourseReportDocument reportCourseDocument) |
{ |
CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
|
163,7 → 121,7 |
|
Map<Integer,UnitsLearningResultYear> anosPlano = new HashMap<Integer, UnitsLearningResultYear>(); |
Map<String,UnitsLearningResultSemester> anoSemestre = new HashMap<String, UnitsLearningResultSemester>(); |
for(DocumentSection subSection : unitReportsSection.getSubSections()) |
for(DocumentSection subSection : unitReportsSection.getSections()) |
{ |
CourseUnitSection unitSection = (CourseUnitSection) subSection; |
int anoPlano = unitSection.getAnoPlano(); |
345,6 → 303,62 |
|
|
/** |
* Gera uma tabela de estatisticas dos DTP recorrendo ao servico WS de |
* load de tabelas DTP, caso o serviço nao devolva unidades são criadas novas |
* com os valores a falso. |
* |
* @param courseCode |
* @param year |
* @return UnitsDtpTable |
* @throws IOException |
* @throws JSONException |
*/ |
public UnitsDtpTable updateDtpStatsTable4Course(CourseReportDocument reportCourseDocument, String courseCode, String year) throws IOException, JSONException |
{ |
|
ReportsUcSummarySection reportsUcSummarySection = (ReportsUcSummarySection) reportCourseDocument.findDocumentSection(ReportsUcSummarySection.class); |
UnitsDtpTable unitsDtpTable = (UnitsDtpTable) reportsUcSummarySection.findDocComponent(UnitsDtpTable.class); |
UnitDtpSemester semester1 = new UnitDtpSemester(); |
UnitDtpSemester semester2 = new UnitDtpSemester(); |
unitsDtpTable.setSemester1(semester1); |
unitsDtpTable.setSemester2(semester2); |
|
List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
|
CourseUnitDtpStat[] statsLoaded; |
try |
{ |
String json = loadCourseUnitDtpStats(courseCode,year); |
JSONObject response = new JSONObject(json); |
JSONArray stats = (JSONArray) response.get("dtpstats"); |
statsLoaded = CourseUnitDtpStat.fromJson(stats); |
} |
catch(Exception e) |
{ |
logger.error(e,e); |
statsLoaded = new CourseUnitDtpStat[0]; |
} |
|
|
for(CourseUnit cu :units) |
{ |
CourseUnitDtpStat statFound = CourseReportUtils.findCourseUnitDtpStat(statsLoaded, (CourseUnitImpl) cu); |
if(statFound == null) |
{ |
statFound = CourseReportUtils.createCourseUnitDtpStat(cu); |
} |
|
if(((CourseUnitImpl) cu).getSemestreAbsolutoS1S2().equals("S1")) |
semester1.getCourseUnitDtpStats().add(statFound); |
else |
semester2.getCourseUnitDtpStats().add(statFound); |
} |
|
return unitsDtpTable; |
|
} |
|
/** |
* Update course unit sections with reports, this method dows not change learning results table |
* values from learning results stays in unit but does not change learning results Table |
* @param courseCode |
354,18 → 368,27 |
* @throws IOException |
* @return a list of CourseUnitSection |
*/ |
public List<DocumentSection> updateCleanCourseUnitSections(String courseCode, String year, ReportCourseDocument reportCourseDocument) throws JSONException, IOException { |
public List<DocumentSection> updateCleanCourseUnitSections(String courseCode, String year, CourseReportDocument reportCourseDocument) throws JSONException, IOException { |
|
List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
|
String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year); |
JSONObject object = new JSONObject(courseUnitSectionsJson); |
JSONArray evaluations = object.getJSONArray("evaluations"); |
CourseUnitSection[] courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString()); |
CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
CourseUnitSection[] courseUnitSections = null; |
try{ |
String courseUnitSectionsJson = loadCourseEvaluationSections(courseCode,year); |
JSONObject object = new JSONObject(courseUnitSectionsJson); |
JSONArray evaluations = object.getJSONArray("evaluations"); |
courseUnitSections = CourseUnitSection.fromJsonArray(evaluations.toString()); |
} |
catch(Exception e) |
{ |
logger.error(e,e); |
courseUnitSections = new CourseUnitSection[0]; |
} |
|
CourseUnitsReportsSection unitReportsSection = (CourseUnitsReportsSection) reportCourseDocument.findDocumentSection(CourseUnitsReportsSection.class); |
|
List<DocumentSection> subSections = new ArrayList<DocumentSection>(); |
unitReportsSection.setSubSections(subSections); |
unitReportsSection.setSections(subSections); |
for(CourseUnit cu :units) |
{ |
CourseUnitSection sectionFound = CourseReportUtils.findCourseUnitSection(courseUnitSections, (CourseUnitImpl) cu); |
381,7 → 404,7 |
cu.setCourseUnitEvaluation(courseUnitEvaluation); |
sectionFound.setCourseUnitEvaluation(courseUnitEvaluation); |
} |
unitReportsSection.getSubSections().add(sectionFound); |
unitReportsSection.getSections().add(sectionFound); |
} |
return subSections; |
} |
389,20 → 412,20 |
|
|
public static void main(String[] args) throws IOException, JSONException { |
/*AbstractDao.getCurrentSession().beginTransaction(); |
AbstractDao.getCurrentSession().beginTransaction(); |
|
ReportCourseDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617"); |
CourseReportDocument reportCourseDocument = new CourseReportServices().createNewCourseReportDocument("44","201617"); |
System.out.println(reportCourseDocument.toJson()); |
AbstractDao.getCurrentSession().getTransaction().commit();*/ |
AbstractDao.getCurrentSession().getTransaction().commit(); |
|
//System.setProperty("javax.net.ssl.trustStore", "/JORGE/COPIAS/.keystore"); |
//System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); |
|
URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1"); |
/*URL url = new URL("http://pae.ipportalegre.pt/wsjson/api/app/ws-course-pedagogic-results-list?code=44&year=201617&period=S1"); |
|
|
|
System.out.println(StreamsUtils.readString(url.openStream())); |
System.out.println(StreamsUtils.readString(url.openStream()));*/ |
} |
|
/* |
465,12 → 488,21 |
} |
else |
{ |
URL url = new URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS + "?code=" + courseCode + "&year=" + year); |
InputStream is = url.openStream(); |
String serviceUrl = Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_DTP_STATS + "?code=" + courseCode + "&year=" + year; |
String json = "{ dtpstats : [] }"; |
try{ |
URL url = new URL(serviceUrl); |
|
String json = StreamsUtils.readString(is); |
is.close(); |
//TODO temos de extrair o resultado do RESPONSE |
URLConnection conn = url.openConnection(); |
InputStream is = conn.getInputStream(); |
|
json = StreamsUtils.readString(is); |
is.close(); |
}catch(Throwable e) |
{ |
logger.error("Connecting " + serviceUrl,e); |
return json; |
} |
JSONObject jsonObject = new JSONObject(json); |
return jsonObject.get("response").toString(); |
} |
493,7 → 525,7 |
public String loadCourseEvaluationSections(String courseCode,String year) throws JSONException, IOException { |
|
|
if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION.indexOf("localhost")>=0) |
if(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION_REPORT.indexOf("localhost")>=0) |
{ |
JSONArray array = new JSONArray(); |
List<CourseUnit> units = DaoFactory.getCourseUnitDaoImpl().loadByCourseSiges(courseCode, year); |
510,11 → 542,22 |
} |
else |
{ |
URL url = new URL(Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION + "?code=" + courseCode + "&year=" + year); |
InputStream is = url.openStream(); |
String json = "{ evaluations : [] }"; |
String serviceUrl = Globals.SYSTEM_WSJSON_SERVICE_COURSE_UNITS_EVALUATION_REPORT + "?code=" + courseCode + "&year=" + year; |
try{ |
URL url = new URL(serviceUrl); |
|
String json = StreamsUtils.readString(is); |
is.close(); |
URLConnection conn = url.openConnection(); |
InputStream is = conn.getInputStream(); |
|
json = StreamsUtils.readString(is); |
is.close(); |
}catch(Throwable e) |
{ |
logger.error("Connecting " + serviceUrl,e); |
return json; |
} |
|
JSONObject jsonObject = new JSONObject(json); |
return jsonObject.get("response").toString(); |
} |