Subversion Repositories bacoAlunos

Rev

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