Subversion Repositories bacoAlunos

Rev

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