Subversion Repositories bacoAlunos

Rev

Rev 225 | Rev 254 | 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;
253 jmachado 28
    private List<CourseUnit> teachedUnitsCurrentYearView = null;
215 jmachado 29
    private List<Course> teachedCoursesView = null;
253 jmachado 30
    private List<Course> teachedCoursesCurrentYearView = null;
202 jmachado 31
 
215 jmachado 32
    public TeacherImpl()
33
    {
34
        setScholarDegree(Globals.PROFILE_SCHOLAR_DEGREE_SUPERIOR);
35
    }
36
 
114 jmachado 37
    public 1.5.0/docs/api/java/lang/String.html">String getManagedRole() {
38
        return TEACHER_ROLE;
39
    }
146 jmachado 40
 
215 jmachado 41
    public List<Course> getTeachedCoursesView()
42
    {
43
        getTeachedUnitsView();
44
        return teachedCoursesView;
45
    }
46
 
214 jmachado 47
    public List<CourseUnit> getTeachedUnitsView()
202 jmachado 48
    {
49
        if(teachedUnitsView == null)
50
        {
215 jmachado 51
            teachedCoursesView = new ArrayList<Course>();
202 jmachado 52
            try
53
            {
54
                IServiceManager sm = ServiceManager.getInstance();
55
                1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
56
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
214 jmachado 57
                teachedUnitsView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnits", args, names);
202 jmachado 58
                if(teachedUnitsView == null)
214 jmachado 59
                    teachedUnitsView = new ArrayList<CourseUnit>();
215 jmachado 60
                for(CourseUnit c: teachedUnitsView)
61
                {
62
                    if(!teachedCoursesView.contains(c.getCourse()))
63
                    {
64
                        teachedCoursesView.add(c.getCourse());
65
                    }
66
                }
202 jmachado 67
            }
68
            catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
69
            {
70
                logger.error(e,e);
71
            }
72
        }
73
        return teachedUnitsView;
74
    }
75
 
253 jmachado 76
    public List<CourseUnit> getTeachedUnitsCurrentYearView()
77
    {
78
        if(teachedUnitsCurrentYearView == null)
79
        {
80
            teachedCoursesCurrentYearView = new ArrayList<Course>();
81
            try
82
            {
83
                IServiceManager sm = ServiceManager.getInstance();
84
                1.5.0/docs/api/java/lang/String.html">String[] names = new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
85
                5+0%2Fdocs%2Fapi+Object">Object[] args = new 5+0%2Fdocs%2Fapi+Object">Object[]{getId()};
86
                teachedUnitsCurrentYearView = (List<CourseUnit>) sm.execute(null, "LoadTeachedUnitsCurrentYear", args, names);
87
                if(teachedUnitsCurrentYearView == null)
88
                    teachedUnitsCurrentYearView = new ArrayList<CourseUnit>();
89
                for(CourseUnit c: teachedUnitsCurrentYearView)
90
                {
91
                    if(!teachedCoursesCurrentYearView.contains(c.getCourse()))
92
                    {
93
                        teachedCoursesCurrentYearView.add(c.getCourse());
94
                    }
95
                }
96
            }
97
            catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e)
98
            {
99
                logger.error(e,e);
100
            }
101
        }
102
        return teachedUnitsCurrentYearView;
103
    }
104
 
204 jmachado 105
    public boolean hasCourseUnit(long id)
106
    {
107
        return hasCourseUnit(id,false);
108
    }
109
 
146 jmachado 110
    public boolean hasCourseUnit(CourseUnit courseUnit)
111
    {
204 jmachado 112
        return hasCourseUnit(courseUnit.getId(),false);
202 jmachado 113
    }
114
 
204 jmachado 115
    public boolean hasCourseUnit(long id, boolean transaction)
202 jmachado 116
    {
214 jmachado 117
        List<CourseUnit> cUnits;
202 jmachado 118
        if(transaction)
214 jmachado 119
            cUnits = new ArrayList<CourseUnit>(getTeachedUnits());
202 jmachado 120
        else
121
            cUnits = getTeachedUnitsView();
122
        if(cUnits == null)
146 jmachado 123
            return false;
202 jmachado 124
        for(CourseUnit c: cUnits)
146 jmachado 125
        {
204 jmachado 126
            if(c.getId() == id)
146 jmachado 127
                return true;
128
        }
129
        return false;
130
    }
223 jmachado 131
 
225 jmachado 132
    public void removeUnitLocaly(CourseUnit unit)
223 jmachado 133
    {
225 jmachado 134
        setLocalRemovedTeachedUnits(StringsUtils.addElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),","));
223 jmachado 135
    }
136
 
225 jmachado 137
    public void addUnitLocaly(CourseUnit unit)
223 jmachado 138
    {
225 jmachado 139
        setLocalRemovedTeachedUnits(StringsUtils.removeElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),","));
223 jmachado 140
    }
141
 
225 jmachado 142
    public boolean isLocalRemovedUnit(CourseUnit unit)
223 jmachado 143
    {
225 jmachado 144
        return StringsUtils.hasElement(getLocalRemovedTeachedUnits(),"" + unit.getId(),",");
223 jmachado 145
    }
114 jmachado 146
}