Subversion Repositories bacoAlunos

Rev

Rev 1814 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
376 jmachado 1
package pt.estgp.estgweb.services.courses;
2
 
3
import pt.estgp.estgweb.services.expceptions.ServiceException;
1814 jmachado 4
import pt.estgp.estgweb.domain.utils.AreasBelongUtils;
376 jmachado 5
import pt.estgp.estgweb.domain.dao.DaoFactory;
6
import pt.estgp.estgweb.domain.*;
7
import jomm.dao.impl.AbstractDao;
8
 
9
import java.util.List;
10
 
11
import org.hibernate.Query;
12
import org.apache.log4j.Logger;
13
 
14
/**
15
 * @author Jorge
16
 * @date 16/Jan/2009
17
 * @time 15:17:12
18
 */
19
public class SetUserArea
20
{
21
    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(SetUserArea.class);
22
 
23
    public void run()
24
    {
25
        List<Student> students = DaoFactory.getStudentDaoImpl().findAll();
26
        for (Student student : students)
27
        {
28
            1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("select distinct c.area from c in class " + Course.class.getName() + " inner  join c.courseUnits as cu inner join cu.students as s where s.id = " + student.getId());
29
            List<String> areas = q.list();
30
            if (areas != null && areas.size() > 0)
31
            {
32
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
33
                {
34
                    student.removeRole("teacher." + area);
35
                    student.addRole("student." + area);
36
                }
37
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
38
                student.setAreasBelong(areasStr);
39
                logger.info("Setting student: " + student.getId() + " areas:" + areasStr);
40
            }
41
            else
42
                logger.warn("Student ID=" + student.getId() + ": SIGES(" + student.getSigesCode() + ")" + student.getName() + " has no subscribed units");
43
        }
44
        List<Teacher> teachers = DaoFactory.getTeacherDaoImpl().findAll();
45
        for (Teacher teacher : teachers)
46
        {
47
            1.5.0/docs/api/javax/management/Query.html">Query q = AbstractDao.getCurrentSession().createQuery("select distinct c.area from c in class " + Course.class.getName() + " inner join c.courseUnits as cu inner join cu.teachers as s where s.id = " + teacher.getId());
48
            List<String> areas = q.list();
49
            if (areas != null && areas.size() > 0)
50
            {
51
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
52
                {
53
                    teacher.addRole("teacher." + area);
54
                }
55
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
56
                teacher.setAreasBelong(areasStr);
57
                logger.info("Setting Teacher: " + teacher.getId() + " areas:" + areasStr);
58
            }
59
            else
60
                logger.warn("Student ID=" + teacher.getId() + ": SIGES(" + teacher.getSigesCode() + ")" + teacher.getName() + " has no teached units");
61
        }
62
 
63
    }
64
 
65
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException
66
    {
67
        AbstractDao.getCurrentSession().beginTransaction();
68
        new SetUserArea().run();
69
        AbstractDao.getCurrentSession().getTransaction().commit();
70
    }
71
}