Subversion Repositories bacoAlunos

Rev

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

Rev Author Line No. Line
114 jmachado 1
package pt.estgp.estgweb.domain;
2
 
3
import pt.estgp.estgweb.Globals;
223 jmachado 4
import pt.estgp.estgweb.utils.RoleManager;
202 jmachado 5
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
6
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
114 jmachado 7
 
214 jmachado 8
import java.util.List;
9
import java.util.ArrayList;
202 jmachado 10
 
11
import org.apache.log4j.Logger;
223 jmachado 12
import jomm.utils.StringsUtils;
202 jmachado 13
 
114 jmachado 14
/**
15
 * @author Jorge Machado
16
 * @date 28/Fev/2008
17
 * @time 12:51:32
18
 * @see pt.estgp.estgweb
19
 */
20
public class TeacherImpl extends Teacher
21
{
22
 
23
    public static final 1.5.0/docs/api/java/lang/String.html">String TEACHER_ROLE = Globals.TEACHER_ROLE;
24
 
202 jmachado 25
    public 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(TeacherImpl.class);
114 jmachado 26
 
214 jmachado 27
    private List<CourseUnit> teachedUnitsView = null;
215 jmachado 28
    private List<Course> teachedCoursesView = null;
202 jmachado 29
 
215 jmachado 30
    public TeacherImpl()
31
    {
32
        setScholarDegree(Globals.PROFILE_SCHOLAR_DEGREE_SUPERIOR);
33
    }
34
 
114 jmachado 35
    public 1.5.0/docs/api/java/lang/String.html">String getManagedRole() {
36
        return TEACHER_ROLE;
37
    }
146 jmachado 38
 
215 jmachado 39
    public List<Course> getTeachedCoursesView()
40
    {
41
        getTeachedUnitsView();
42
        return teachedCoursesView;
43
    }
44
 
214 jmachado 45
    public List<CourseUnit> getTeachedUnitsView()
202 jmachado 46
    {
47
        if(teachedUnitsView == null)
48
        {
215 jmachado 49
            teachedCoursesView = new ArrayList<Course>();
202 jmachado 50
            try
51
            {
52
                IServiceManager sm = ServiceManager.getInstance();
53
                1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
54
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
214 jmachado 55
                teachedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnits", args, names);
202 jmachado 56
                if(teachedUnitsView == null)
214 jmachado 57
                    teachedUnitsView = new ArrayList<CourseUnit>();
215 jmachado 58
                for(CourseUnit c: teachedUnitsView)
59
                {
60
                    if(!teachedCoursesView.contains(c.getCourse()))
61
                    {
62
                        teachedCoursesView.add(c.getCourse());
63
                    }
64
                }
202 jmachado 65
            }
66
            catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
67
            {
68
                logger.error(e,e);
69
            }
70
        }
71
        return teachedUnitsView;
72
    }
73
 
204 jmachado 74
    public boolean hasCourseUnit(long id)
75
    {
76
        return hasCourseUnit(id,false);
77
    }
78
 
146 jmachado 79
    public boolean hasCourseUnit(CourseUnit courseUnit)
80
    {
204 jmachado 81
        return hasCourseUnit(courseUnit.getId(),false);
202 jmachado 82
    }
83
 
204 jmachado 84
    public boolean hasCourseUnit(long id, boolean transaction)
202 jmachado 85
    {
214 jmachado 86
        List<CourseUnit> cUnits;
202 jmachado 87
        if(transaction)
214 jmachado 88
            cUnits = new ArrayList<CourseUnit>(getTeachedUnits());
202 jmachado 89
        else
90
            cUnits = getTeachedUnitsView();
91
        if(cUnits == null)
146 jmachado 92
            return false;
202 jmachado 93
        for(CourseUnit c: cUnits)
146 jmachado 94
        {
204 jmachado 95
            if(c.getId() == id)
146 jmachado 96
                return true;
97
        }
98
        return false;
99
    }
223 jmachado 100
 
101
    public void removeUnitLocaly(long id)
102
    {
103
        setLocalRemovedTeachedUnits(StringsUtils.addElement(getLocalRemovedTeachedUnits(),"" + id,","));
104
    }
105
 
106
    public void addUnitLocaly(long id)
107
    {
108
        setLocalRemovedTeachedUnits(StringsUtils.removeElement(getLocalRemovedTeachedUnits(),"" + id,","));
109
    }
110
 
111
    public boolean isLocalRemovedUnit(long id)
112
    {
113
        return StringsUtils.hasElement(getLocalRemovedTeachedUnits(),"" + id,",");
114
    }
114 jmachado 115
}