Subversion Repositories bacoAlunos

Rev

Rev 376 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package pt.estgp.estgweb.services.courses;

import pt.estgp.estgweb.services.expceptions.ServiceException;
import pt.estgp.estgweb.utils.DatesUtils;
import pt.estgp.estgweb.utils.RoleManager;
import pt.estgp.estgweb.utils.StringsUtils;
import pt.estgp.estgweb.utils.AreasBelongUtils;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.domain.*;
import jomm.dao.impl.AbstractDao;
import static org.hibernate.criterion.Restrictions.*;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Criteria;
import org.apache.log4j.Logger;

/**
 * @author Jorge
 * @date 16/Jan/2009
 * @time 15:17:12
 */

public class SetUserArea
{
    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);

    public void run()
    {
        List<Student> students = DaoFactory.getStudentDaoImpl().findAll();
        for (Student student : students)
        {
            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());
            List<String> areas = q.list();
            if (areas != null && areas.size() > 0)
            {
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
                {
                    student.removeRole("teacher." + area);
                    student.addRole("student." + area);
                }
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
                student.setAreasBelong(areasStr);
                logger.info("Setting student: " + student.getId() + " areas:" + areasStr);
            }
            else
                logger.warn("Student ID=" + student.getId() + ": SIGES(" + student.getSigesCode() + ")" + student.getName() + " has no subscribed units");
        }
        List<Teacher> teachers = DaoFactory.getTeacherDaoImpl().findAll();
        for (Teacher teacher : teachers)
        {
            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());
            List<String> areas = q.list();
            if (areas != null && areas.size() > 0)
            {
                for(1.5.0/docs/api/java/lang/String.html">String area: areas)
                {
                    teacher.addRole("teacher." + area);
                }
                1.5.0/docs/api/java/lang/String.html">String areasStr = AreasBelongUtils.getSerialAreas(areas);
                teacher.setAreasBelong(areasStr);
                logger.info("Setting Teacher: " + teacher.getId() + " areas:" + areasStr);
            }
            else
                logger.warn("Student ID=" + teacher.getId() + ": SIGES(" + teacher.getSigesCode() + ")" + teacher.getName() + " has no teached units");
        }

    }

    public static void main(1.5.0/docs/api/java/lang/String.html">String[] args) throws ServiceException
    {
        AbstractDao.getCurrentSession().beginTransaction();
        new SetUserArea().run();
        AbstractDao.getCurrentSession().getTransaction().commit();
    }
}