Subversion Repositories bacoAlunos

Rev

Rev 1306 | Go to most recent revision | Details | 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;
4
import pt.estgp.estgweb.utils.DatesUtils;
5
import pt.estgp.estgweb.utils.RoleManager;
6
import pt.estgp.estgweb.utils.StringsUtils;
7
import pt.estgp.estgweb.utils.AreasBelongUtils;
8
import pt.estgp.estgweb.domain.dao.DaoFactory;
9
import pt.estgp.estgweb.domain.*;
10
import jomm.dao.impl.AbstractDao;
11
import static org.hibernate.criterion.Restrictions.*;
12
 
13
import java.util.List;
14
 
15
import org.hibernate.Query;
16
import org.hibernate.Criteria;
17
import org.apache.log4j.Logger;
18
 
19
/**
20
 * @author Jorge
21
 * @date 16/Jan/2009
22
 * @time 15:17:12
23
 */
24
public class SetUserArea
25
{
26
    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);
27
 
28
    public void run()
29
    {
30
        List<Student> students = DaoFactory.getStudentDaoImpl().findAll();
31
        for (Student student : students)
32
        {
33
            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());
34
            List<String> areas = q.list();
35
            if (areas != null && areas.size() > 0)
36
            {
37
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
38
                {
39
                    student.removeRole("teacher." + area);
40
                    student.addRole("student." + area);
41
                }
42
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
43
                student.setAreasBelong(areasStr);
44
                logger.info("Setting student: " + student.getId() + " areas:" + areasStr);
45
            }
46
            else
47
                logger.warn("Student ID=" + student.getId() + ": SIGES(" + student.getSigesCode() + ")" + student.getName() + " has no subscribed units");
48
        }
49
        List<Teacher> teachers = DaoFactory.getTeacherDaoImpl().findAll();
50
        for (Teacher teacher : teachers)
51
        {
52
            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());
53
            List<String> areas = q.list();
54
            if (areas != null && areas.size() > 0)
55
            {
56
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
57
                {
58
                    teacher.addRole("teacher." + area);
59
                }
60
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
61
                teacher.setAreasBelong(areasStr);
62
                logger.info("Setting Teacher: " + teacher.getId() + " areas:" + areasStr);
63
            }
64
            else
65
                logger.warn("Student ID=" + teacher.getId() + ": SIGES(" + teacher.getSigesCode() + ")" + teacher.getName() + " has no teached units");
66
        }
67
 
68
    }
69
 
70
    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException
71
    {
72
        AbstractDao.getCurrentSession().beginTransaction();
73
        new SetUserArea().run();
74
        AbstractDao.getCurrentSession().getTransaction().commit();
75
    }
76
}