package pt.estgp.estgweb.domain;
import jomm.utils.StringsUtils;
import org.apache.log4j.Logger;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.utils.Globals;
import pt.estgp.estgweb.utils.RoleManager;
import pt.utl.ist.berserk.logic.serviceManager.IServiceManager;
import pt.utl.ist.berserk.logic.serviceManager.ServiceManager;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Jorge Machado
* @date 28/Fev/2008
* @time 12:51:32
* @see pt.estgp.estgweb
*/
public class TeacherImpl
extends Teacher
{
public static final 1.5.0/docs/api/java/lang/String.html">String TEACHER_ROLE = Globals.
TEACHER_ROLE;
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);
private List
<CourseUnit
> teachedUnitsView =
null;
private List
<CourseUnit
> teachedUnitsCurrentYearView =
null;
private List
<Course
> teachedCoursesView =
null;
private List
<Course
> teachedCoursesCurrentYearView =
null;
public TeacherImpl
()
{
setScholarDegree
(Globals.
PROFILE_SCHOLAR_DEGREE_SUPERIOR);
}
public 1.5.0/docs/api/java/lang/String.html">String getManagedRole
()
{
List
<String
> roles =
new ArrayList
<String
>();
if(getDirectorCourses
() !=
null && getDirectorCourses
().
size() > 0
)
roles.
add(Globals.
COURSE_DIRECTOR_ROLE);
if(getCoordinatorCourses
() !=
null && getCoordinatorCourses
().
size() > 0
)
roles.
add(Globals.
COURSE_COORDINATOR_ROLE);
roles.
add(TEACHER_ROLE
);
return RoleManager.
getSerialRoles(roles
);
}
public List
<Course
> getTeachedCoursesView
()
{
getTeachedUnitsView
();
return teachedCoursesView
;
}
public List
<Course
> getTeachedCoursesCurrenYearView
()
{
getTeachedUnitsCurrentYearView
();
return teachedCoursesCurrentYearView
;
}
public List
<CourseUnit
> getTeachedUnitsViewS1
()
{
return getUnitsSemestre
("S1",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewS2
()
{
return getUnitsSemestre
("S2",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewA
()
{
return getUnitsSemestre
("A",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewT1
()
{
return getUnitsSemestre
("T1",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewT2
()
{
return getUnitsSemestre
("T2",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewT3
()
{
return getUnitsSemestre
("T3",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsViewT4
()
{
return getUnitsSemestre
("T4",getTeachedUnitsView
());
}
public List
<CourseUnit
> getTeachedUnitsView
()
{
if(teachedUnitsView ==
null)
{
teachedCoursesView =
new ArrayList
<Course
>();
try
{
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{getId
()};
teachedUnitsView =
(List
<CourseUnit
>) sm.
execute(null,
"LoadTeachedUnits", args, names
);
if(teachedUnitsView ==
null)
teachedUnitsView =
new ArrayList
<CourseUnit
>();
for(CourseUnit c: teachedUnitsView
)
{
if(!teachedCoursesView.
contains(c.
getCourse()))
{
teachedCoursesView.
add(c.
getCourse());
}
}
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e,e
);
}
}
return teachedUnitsView
;
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewS1
()
{
return getUnitsSemestre
("S1",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewS2
()
{
return getUnitsSemestre
("S2",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewA
()
{
return getUnitsSemestre
("A",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewT1
()
{
return getUnitsSemestre
("T1",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewT2
()
{
return getUnitsSemestre
("T2",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewT3
()
{
return getUnitsSemestre
("T3",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearViewT4
()
{
return getUnitsSemestre
("T4",getTeachedUnitsCurrentYearView
());
}
public List
<CourseUnit
> getTeachedUnitsViewS1
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("S1",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewS2
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("S2",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewA
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("A",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewT1
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("T1",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewT2
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("T2",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewT3
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("T3",getTeachedUnitsView
(year
));
}
public List
<CourseUnit
> getTeachedUnitsViewT4
(1.5.0/docs/api/java/lang/String.html">String year
)
{
return getUnitsSemestre
("T4",getTeachedUnitsView
(year
));
}
Map
<String,List
<CourseUnit
>> teachedUnitsYear =
new HashMap
<String,List
<CourseUnit
>>();
Map
<String,List
<Course
>> teachedCourseYear =
new HashMap
<String,List
<Course
>>();
public List
<CourseUnit
> getTeachedUnitsView
(1.5.0/docs/api/java/lang/String.html">String year
)
{
List
<CourseUnit
> cuYear = teachedUnitsYear.
get(year
);
if(cuYear ==
null)
{
List
<Course
> lc =
new ArrayList
<Course
>();
teachedCourseYear.
put(year,lc
);
try
{
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable",
"year"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{getId
(),year
};
cuYear =
(List
<CourseUnit
>) sm.
execute(null,
"LoadTeachedUnitsYear", args, names
);
if(cuYear ==
null)
cuYear =
new ArrayList
<CourseUnit
>();
for(CourseUnit c: cuYear
)
{
if(!lc.
contains(c.
getCourse()))
{
lc.
add(c.
getCourse());
}
}
teachedUnitsYear.
put(year,cuYear
);
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e,e
);
}
}
return cuYear
;
}
public List
<CourseUnit
> getTeachedUnitsCurrentYearView
()
{
if(teachedUnitsCurrentYearView ==
null)
{
teachedCoursesCurrentYearView =
new ArrayList
<Course
>();
try
{
IServiceManager sm = ServiceManager.
getInstance();
1.5.0/docs/api/java/lang/String.html">String[] names =
new 1.5.0/docs/api/java/lang/String.html">String[]{"serializable"};
5+0%2Fdocs%2Fapi+Object">Object[] args =
new 5+0%2Fdocs%2Fapi+Object">Object[]{getId
()};
teachedUnitsCurrentYearView =
(List
<CourseUnit
>) sm.
execute(null,
"LoadTeachedUnitsCurrentYear", args, names
);
if(teachedUnitsCurrentYearView ==
null)
teachedUnitsCurrentYearView =
new ArrayList
<CourseUnit
>();
for(CourseUnit c: teachedUnitsCurrentYearView
)
{
if(!teachedCoursesCurrentYearView.
contains(c.
getCourse()))
{
teachedCoursesCurrentYearView.
add(c.
getCourse());
}
}
}
catch (1.5.0/docs/api/java/lang/Throwable.html">Throwable e
)
{
logger.
error(e,e
);
}
}
return teachedUnitsCurrentYearView
;
}
public boolean hasCourseUnit
(long id
)
{
return hasCourseUnit
(id,
false);
}
public boolean hasCourseUnit
(CourseUnit courseUnit
)
{
return hasCourseUnit
(courseUnit.
getId(),
false);
}
public boolean hasCourseUnit
(long id,
boolean transaction
)
{
List
<CourseUnit
> cUnits
;
if(transaction
)
cUnits =
new ArrayList
<CourseUnit
>(getTeachedUnits
());
else
cUnits = getTeachedUnitsView
();
if(cUnits ==
null)
return false;
for(CourseUnit c: cUnits
)
{
if(c.
getId() == id
)
return true;
}
return false;
}
public void removeUnitLocaly
(CourseUnit unit
)
{
setLocalRemovedTeachedUnits
(StringsUtils.
addElement(getLocalRemovedTeachedUnits
(),
"" + unit.
getId(),
","));
//todo novo
setLocalTeachedUnits
(StringsUtils.
removeElement(getLocalTeachedUnits
(),
"" + unit.
getId(),
","));
}
public void addUnitLocaly
(CourseUnit unit
)
{
setLocalRemovedTeachedUnits
(StringsUtils.
removeElement(getLocalRemovedTeachedUnits
(),
"" + unit.
getId(),
","));
//todo novo
setLocalTeachedUnits
(StringsUtils.
removeElement(getLocalTeachedUnits
(),
"" + unit.
getId(),
","));
setLocalTeachedUnits
(StringsUtils.
addElement(getLocalTeachedUnits
(),
"" + unit.
getId(),
","));
}
public boolean isLocalRemovedUnit
(CourseUnit unit
)
{
return StringsUtils.
hasElement(getLocalRemovedTeachedUnits
(),
"" + unit.
getId(),
",");
}
public boolean isLocalUnit
(CourseUnit unit
)
{
return StringsUtils.
hasElement(getLocalTeachedUnits
(),
""+unit.
getId(),
",");
}
/**
*
* @return all roles type course comission from user roles and validationRoles from coordinated courses
* where user is main coordinator
* APENAS CURSOS ATIVOS STATUS = TRUE
*/
public List
<String
> obtainCourseComissionsAndCoordinationsRoles
()
{
List
<String
> comissionsRoles =
new ArrayList
<String
>();
for(1.5.0/docs/api/java/lang/String.html">String role: getRolesList
())
{
if(role.
startsWith(Globals.
COURSE_COMMISSION_PROGRAMS_ROLES_PREFIX))
comissionsRoles.
add(role
);
}
for(Course coordinated : getCoordinatorCourses
())
{
if(coordinated.
isStatus() && coordinated.
getValidationRole() !=
null && coordinated.
getValidationRole().
trim().
length() > 0
)
{
if(!comissionsRoles.
contains(coordinated.
getValidationRole()))
comissionsRoles.
add(coordinated.
getValidationRole());
}
}
//System.out.println("Roles for: " + getName());
/*for(String role: comissionsRoles)
{
System.out.println(role);
}*/
return comissionsRoles
;
}
/**
*
* @return all courses comission from user roles and validationRoles from coordinated courses
* where user is main coordinator
* @require opened transaction
* todo usar isto para obter coordenações
*/
public List
<Course
> obtainCourseComissionsAndCoordinations
()
{
return DaoFactory.
getCourseDaoImpl().
findActiveCoursesCoordinationsOrCommissions(this);
}
public boolean hasCoordinationsOrBelongToCourseCommissions
()
{
return obtainCourseComissionsAndCoordinationsRoles
().
size() > 0;
}
private List
<String
> excludedGenericJsonMethodsWithOpenTransactions =
null;
@
1.5.0/docs/api/java/lang/Override.html">Override
public synchronized List
<String
> getJsonExcludedProperties
() {
if(excludedGenericJsonMethodsWithOpenTransactions ==
null)
{
excludedGenericJsonMethodsWithOpenTransactions =
new ArrayList
<String
>();
searchMyMethodsStartingWith
("teachedUnits",excludedGenericJsonMethodsWithOpenTransactions
);
}
return excludedGenericJsonMethodsWithOpenTransactions
;
}
}