package pt.estgp.estgweb.services.courseunits;
import org.apache.log4j.Logger;
import pt.estgp.estgweb.domain.CourseUnit;
import pt.estgp.estgweb.domain.UserSession;
import pt.estgp.estgweb.domain.dao.DaoFactory;
import pt.estgp.estgweb.domain.views.CourseUnitView;
import pt.estgp.estgweb.services.expceptions.ServiceException;
import pt.utl.ist.berserk.logic.serviceManager.IService;
import java.util.ArrayList;
import java.util.List;
/**
* @author Jorge Machado
* @date 18/Nov/2009
* @time 2:50:07
* @email machadofisher@gmail.com
*/
public class LoadCourseUnitsBySigesCodesService
implements IService
{
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(LoadCourseUnitsBySigesCodesService.
class);
public List
<CourseUnitView
> run
(1.5.0/docs/api/java/lang/String.html">String code,
1.5.0/docs/api/java/lang/String.html">String courseCode, UserSession userSession
) throws ServiceException
{
List
<CourseUnit
> courseUnits = DaoFactory.
getCourseUnitDaoImpl().
loadBySigesCodes(code, courseCode
);
if(courseUnits ==
null || courseUnits.
size() == 0
)
return new ArrayList
<CourseUnitView
>();
List
<CourseUnitView
> courseUnitViews =
new ArrayList
<CourseUnitView
>();
for(CourseUnit cU : courseUnits
)
{
CourseUnitView cV =
new CourseUnitView
(cU
);
courseUnitViews.
add(cV
);
}
return courseUnitViews
;
}
public CourseUnitView loadUnitInEvaluation
(1.5.0/docs/api/java/lang/String.html">String code,
1.5.0/docs/api/java/lang/String.html">String courseCode, UserSession userSession
) throws ServiceException
{
CourseUnit c = DaoFactory.
getCourseUnitDaoImpl().
loadUnitInEvaluationBySigesCodes(code, courseCode
);
if(c ==
null)
return null;
return new CourseUnitView
(c
);
}
public CourseUnitView loadLastYear
(1.5.0/docs/api/java/lang/String.html">String code,
1.5.0/docs/api/java/lang/String.html">String courseCode,
1.5.0/docs/api/java/lang/String.html">String semestre, UserSession userSession
) throws ServiceException
{
if(semestre.
equals("S3"))
semestre =
"S1";
else if(semestre.
equals("S4"))
semestre =
"S2";
else if(semestre.
equals("S5"))
semestre =
"S1";
else if(semestre.
equals("S6"))
semestre =
"S2";
else if(semestre.
startsWith("A"))
semestre =
"A";
CourseUnit courseUnit = DaoFactory.
getCourseUnitDaoImpl().
loadBySigesCodeUniqueLastYear(code, courseCode,semestre
);
if(courseUnit ==
null)
return null;
return new CourseUnitView
(courseUnit
);
}
}