Subversion Repositories bacoAlunos

Rev

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