Rev 1547 | Rev 1692 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | fvelez | 1 | package pt.estgp.estgweb.domain; |
2 | |||
1546 | jmachado | 3 | import org.apache.log4j.Logger; |
4 | import pt.estgp.estgweb.services.courses.CoursesService; |
||
5 | import pt.estgp.estgweb.services.courses.xsd.Curso; |
||
6 | import pt.estgp.estgweb.services.courses.xsd.UnidadeImpl; |
||
7 | import pt.estgp.estgweb.services.courses.xsd.UnidadeType; |
||
1496 | jmachado | 8 | import pt.estgp.estgweb.utils.ConfigProperties; |
9 | |||
1 | fvelez | 10 | import java.io.Serializable; |
1546 | jmachado | 11 | import java.util.HashMap; |
1496 | jmachado | 12 | import java.util.List; |
1546 | jmachado | 13 | import java.util.Map; |
1 | fvelez | 14 | |
15 | /** |
||
16 | * @author Jorge Machado |
||
17 | * @date 2/Mar/2008 |
||
18 | * @time 10:27:25 |
||
19 | * @see pt.estgp.estgweb.domain |
||
20 | */ |
||
21 | public class CourseImpl extends Course |
||
22 | { |
||
23 | |||
1546 | jmachado | 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(CourseImpl.class); |
25 | |||
1 | fvelez | 26 | public 1.5.0/docs/api/java/io/Serializable.html">Serializable getSerializable() |
27 | { |
||
28 | return getId(); |
||
29 | } |
||
1312 | jmachado | 30 | |
31 | public boolean isFromCourseCommission(UserSession userSession) |
||
32 | { |
||
1585 | jmachado | 33 | return isFromCourseCommission(userSession.getUser()); |
1312 | jmachado | 34 | } |
1496 | jmachado | 35 | |
1585 | jmachado | 36 | public boolean isFromCourseCommission(User user) |
37 | { |
||
38 | return user != null && |
||
39 | ( |
||
40 | user.hasRole(getValidationRole()) |
||
41 | || |
||
42 | (getDirector() != null && user.getId() == getDirector().getId()) |
||
43 | || |
||
44 | (getCoordinator() != null && user.getId() == getCoordinator().getId())); |
||
45 | } |
||
46 | |||
1496 | jmachado | 47 | public 1.5.0/docs/api/java/lang/String.html">String getDegreeForJsonApi() |
48 | { |
||
49 | return ConfigProperties.getProperty("course." + getDegree()); |
||
50 | } |
||
51 | |||
52 | public void setDegreeForJsonApi() |
||
53 | { |
||
54 | //is needed for Genson generation |
||
55 | } |
||
56 | |||
1543 | jmachado | 57 | public 1.5.0/docs/api/java/lang/String.html">String getDegreeForJsonApiEn() |
58 | { |
||
59 | return ConfigProperties.getProperty("course." + getDegree() + ".en"); |
||
60 | } |
||
1496 | jmachado | 61 | |
1543 | jmachado | 62 | public void setDegreeForJsonApiEn() |
63 | { |
||
64 | //is needed for Genson generation |
||
65 | } |
||
1496 | jmachado | 66 | |
1543 | jmachado | 67 | public 1.5.0/docs/api/java/lang/String.html">String getDegreeForJsonApiEs() |
68 | { |
||
69 | return ConfigProperties.getProperty("course." + getDegree()+ ".es"); |
||
70 | } |
||
71 | |||
72 | public void setDegreeForJsonApiEs() |
||
73 | { |
||
74 | //is needed for Genson generation |
||
75 | } |
||
76 | |||
77 | public 1.5.0/docs/api/java/lang/String.html">String getDegreeForJsonApiFr() |
||
78 | { |
||
79 | return ConfigProperties.getProperty("course." + getDegree()+ ".fr"); |
||
80 | } |
||
81 | |||
82 | public void setDegreeForJsonApiFr() |
||
83 | { |
||
84 | //is needed for Genson generation |
||
85 | } |
||
86 | |||
87 | |||
88 | |||
89 | |||
90 | |||
1496 | jmachado | 91 | public 1.5.0/docs/api/java/lang/String.html">String getStatusForJsonApi() |
92 | { |
||
1521 | jmachado | 93 | if(isShowStudiesPlan()) |
1496 | jmachado | 94 | { |
95 | return "active"; |
||
96 | } |
||
97 | else |
||
98 | return "inactive"; |
||
99 | } |
||
100 | |||
101 | public void setStatusForJsonApi() |
||
102 | { |
||
103 | //is needed for Genson generation |
||
104 | } |
||
105 | |||
106 | public 1.5.0/docs/api/java/lang/String.html">String getSchoolForJsonApi() |
||
107 | { |
||
108 | return ConfigProperties.getProperty("institution.code.prefix." + getInstitutionalCode()); |
||
109 | } |
||
110 | |||
111 | public void setSchoolForJsonApi() |
||
112 | { |
||
113 | //is needed for Genson generation |
||
114 | } |
||
115 | |||
116 | //Auxiliary method fot manual load |
||
117 | List<Teacher> courseComission; |
||
118 | |||
119 | public void setCourseComission(List<Teacher> courseComission) { |
||
120 | this.courseComission = courseComission; |
||
121 | } |
||
122 | |||
123 | public List<Teacher> getCourseComission() { |
||
124 | return courseComission; |
||
125 | } |
||
1546 | jmachado | 126 | |
127 | |||
128 | /** |
||
129 | * Services |
||
130 | */ |
||
131 | |||
132 | /* |
||
133 | Os identificadores sao formados por codigo-siges + $ + semestreId (S1,S2,A,T1,T2,T3,T4) |
||
134 | Isto foi feito assim porque no caso de uma unidade existir nos dois semestres S1 e S2 |
||
135 | nao existem duvidas da qual se trata |
||
136 | |||
137 | Ou seja imagine-se um plano em que uma unidade 123 esta' em S2 (corresponde a S2 no siges ano 1) e |
||
138 | tambem em S3 (corresponde a S1 no siges ano 2) |
||
139 | No caso dos questionarios cada questionario esta associado ou a S1 ou S2 ou a A, no momento da invocacao |
||
140 | deste servico, dependendo do semestre requisitado assim vai |
||
141 | ser a unidade devolvida, ou seja se o invocador pedir 123 S1 o ano fornecido sera 2 caso seja 123 S2 o ano |
||
142 | devolvido sera 1 |
||
143 | |||
144 | */ |
||
145 | private Map<String,Integer> sigesAnoPlano = null; |
||
146 | private Map<String,String> sigesPeriodoPlano = null; |
||
147 | private Map<String,Integer> sigesSemestrePlanoConvertido = null; |
||
1547 | jmachado | 148 | //private Map<String,Integer> sigesSemestrePlanoAbsoluto = null; |
1546 | jmachado | 149 | |
150 | |||
151 | /** |
||
152 | * Require Opened Transaction |
||
153 | */ |
||
154 | |||
155 | public CourseStudiesPlan getStudiesPlanLastVersion() |
||
156 | { |
||
157 | if(getStudiesPlans() != null && getStudiesPlans().size() > 0) |
||
158 | { |
||
159 | return getStudiesPlans().iterator().next(); |
||
160 | } |
||
161 | return null; |
||
162 | } |
||
163 | |||
164 | |||
165 | /** |
||
166 | * Este serviço inicializa mapas de correspondencia entre unidades dado o seu codigo siges |
||
167 | * e o periodo siges onde estão inseridas e as suas posicoes no plano de estudo |
||
168 | * |
||
169 | * Exemplo dado 12344 e S1 |
||
170 | * Podemos ter que a unidade está em periodo plano S3, anoPlano 2 semestre convertido 3 e semestre absoluto 1 |
||
171 | * |
||
172 | * Exemplo para 12345 e T7 |
||
173 | * Podemos ter que a unidade está em periodo plano T7, anoPlano 2 semestre convertido 4 e semestre absoluto 2 |
||
174 | */ |
||
175 | public void initUnitsAnosFromStudiesPlan() |
||
176 | { |
||
177 | |||
178 | sigesAnoPlano = new HashMap<String, Integer>(); |
||
179 | sigesPeriodoPlano = new HashMap<String, String>(); |
||
180 | sigesSemestrePlanoConvertido = new HashMap<String, Integer>(); |
||
1547 | jmachado | 181 | //sigesSemestrePlanoAbsoluto = new HashMap<String, Integer>(); |
1546 | jmachado | 182 | |
183 | CoursesService coursesService = new CoursesService(); |
||
184 | |||
185 | CourseStudiesPlanImpl lastVersion = (CourseStudiesPlanImpl) getStudiesPlanLastVersion(); |
||
186 | if(lastVersion != null) |
||
187 | { |
||
188 | |||
189 | Curso curso = coursesService.loadCursoPlanoFromXml(lastVersion.getXml()); |
||
190 | if(curso == null) |
||
191 | { |
||
192 | logger.error("Cant init course units anos from studies plan because JaxB parse from Xml return null (see more in CoursesService().loadCursoPlanoFromXml())"); |
||
193 | return; |
||
194 | } |
||
195 | for(Curso.Semestre semestre: curso.getSemestre()) |
||
196 | { |
||
197 | |||
198 | 1.5.0/docs/api/java/lang/String.html">String periodoSiges = UnidadeImpl.getPeriodoSiges(semestre.getId()); |
||
199 | if(periodoSiges == null) |
||
200 | { |
||
201 | logger.info("Semestre provavelmente opcional ignorado " + semestre.getId()); |
||
202 | } |
||
203 | else |
||
204 | { |
||
205 | 1.5.0/docs/api/java/lang/Integer.html">Integer anoPlano = UnidadeImpl.getAnoFromPlano(semestre.getId()); |
||
206 | 1.5.0/docs/api/java/lang/Integer.html">Integer semestrePlanoConvertido = UnidadeImpl.getSemestreConvertido(semestre.getId()); |
||
1547 | jmachado | 207 | //Integer semestrePlanoAbsoluto = UnidadeImpl.getSemestreAbsoluto(semestre.getId()); |
1546 | jmachado | 208 | |
209 | for(Curso.Semestre.Perfil perfil: semestre.getPerfil()) |
||
210 | { |
||
211 | for(UnidadeType unidade: perfil.getUnidade()) |
||
212 | { |
||
213 | sigesAnoPlano.put(unidade.getSiges() + "$" + periodoSiges,anoPlano); |
||
214 | sigesPeriodoPlano.put(unidade.getSiges() + "$" + periodoSiges,semestre.getId()); |
||
215 | sigesSemestrePlanoConvertido.put(unidade.getSiges() + "$" + periodoSiges,semestrePlanoConvertido); |
||
1547 | jmachado | 216 | //sigesSemestrePlanoAbsoluto.put(unidade.getSiges() + "$" + periodoSiges,semestrePlanoAbsoluto); |
1546 | jmachado | 217 | } |
218 | } |
||
219 | for(UnidadeType unidade: semestre.getUnidade()) |
||
220 | { |
||
221 | sigesAnoPlano.put(unidade.getSiges() + "$" + periodoSiges,anoPlano); |
||
222 | sigesPeriodoPlano.put(unidade.getSiges() + "$" + periodoSiges,semestre.getId()); |
||
223 | sigesSemestrePlanoConvertido.put(unidade.getSiges() + "$" + periodoSiges,semestrePlanoConvertido); |
||
1547 | jmachado | 224 | //sigesSemestrePlanoAbsoluto.put(unidade.getSiges() + "$" + periodoSiges,semestrePlanoAbsoluto); |
1546 | jmachado | 225 | } |
226 | } |
||
227 | |||
228 | } |
||
229 | |||
230 | } |
||
231 | |||
232 | } |
||
233 | |||
234 | /** |
||
235 | * require open transaction |
||
236 | * @param periodoSiges |
||
237 | * @param sigesCode |
||
238 | * @return 1, 2, 3, 4 |
||
239 | */ |
||
240 | public 1.5.0/docs/api/java/lang/Integer.html">Integer getUnidadeAnoPlano(1.5.0/docs/api/java/lang/String.html">String periodoSiges,1.5.0/docs/api/java/lang/String.html">String sigesCode) |
||
241 | { |
||
242 | if(sigesAnoPlano == null) |
||
243 | initUnitsAnosFromStudiesPlan(); |
||
244 | return sigesAnoPlano.get(sigesCode + "$" + periodoSiges); |
||
245 | } |
||
246 | |||
247 | |||
248 | /** |
||
249 | * require open transaction |
||
250 | * @param periodoSiges |
||
251 | * @param sigesCode |
||
252 | * @return S1, .., S8, T1 .. T8, A1 .. A4 |
||
253 | */ |
||
254 | public 1.5.0/docs/api/java/lang/String.html">String getUnidadePeriodoPlano(1.5.0/docs/api/java/lang/String.html">String periodoSiges,1.5.0/docs/api/java/lang/String.html">String sigesCode) |
||
255 | { |
||
256 | if(sigesPeriodoPlano == null) |
||
257 | initUnitsAnosFromStudiesPlan(); |
||
258 | return sigesPeriodoPlano.get(sigesCode + "$" + periodoSiges); |
||
259 | } |
||
260 | |||
261 | |||
262 | /** |
||
263 | * require open transaction |
||
264 | * @param periodoSiges |
||
265 | * @param sigesCode |
||
266 | * @return S1 = 1, S2 = 2,S3 = 3,S4 = 4 ...T1 e T2 = 1, T2 e T3 = 2, T4 e T5 = 3 ... |
||
267 | * |
||
268 | */ |
||
269 | public 1.5.0/docs/api/java/lang/Integer.html">Integer getUnidadeSemestrePlanoConvertido(1.5.0/docs/api/java/lang/String.html">String periodoSiges,1.5.0/docs/api/java/lang/String.html">String sigesCode) |
||
270 | { |
||
271 | if(sigesSemestrePlanoConvertido == null) |
||
272 | initUnitsAnosFromStudiesPlan(); |
||
273 | return sigesSemestrePlanoConvertido.get(sigesCode + "$" + periodoSiges); |
||
274 | } |
||
275 | |||
276 | |||
277 | /** |
||
278 | * require open transaction |
||
279 | * @param periodoSiges |
||
280 | * @param sigesCode |
||
281 | * @return S1 = 1, S2 = 2, S3 = 1, S4 = 2 ... T1 e T2 = 1, T2 e T3 = 2, T4 e T5 = 1, T6 e T7 = 2 |
||
282 | */ |
||
1547 | jmachado | 283 | /*public Integer getUnidadeSemestrePlanoAbsoluto(String periodoSiges,String sigesCode) |
1546 | jmachado | 284 | { |
285 | if(sigesSemestrePlanoAbsoluto == null) |
||
286 | initUnitsAnosFromStudiesPlan(); |
||
287 | return sigesSemestrePlanoAbsoluto.get(sigesCode + "$" + periodoSiges); |
||
1547 | jmachado | 288 | }*/ |
1546 | jmachado | 289 | |
290 | |||
291 | |||
1 | fvelez | 292 | } |