/* * Created on Dec 1, 2003 by jpvl * */ package net.sourceforge.fenixedu.applicationTier.Servico.department; import java.util.List; import net.sourceforge.fenixedu.applicationTier.FenixService; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.dataTransferObject.InfoDepartment; import net.sourceforge.fenixedu.domain.Department; import net.sourceforge.fenixedu.domain.Person; import pt.ist.fenixWebFramework.services.Service; import com.linkare.commons.metainfo.Linkare; /** * @author jpvl */ public class ReadDepartmentByUser extends FenixService { @Linkare(author = "Paulo Zenida", comments = "Added the logic to check in the person's selected working place for a department") @Service public static InfoDepartment run(String username) throws FenixServiceException { InfoDepartment infoDepartment = null; final Person person = Person.readPersonByUsername(username); final List departmentList = person.getManageableDepartmentCredits(); if (!departmentList.isEmpty()) { Department selectedDepartment = (Department) departmentList.get(0); for (Department department : departmentList) { if (person.getCurrentWorkingPlace() != null && person.getCurrentWorkingPlace().isDepartmentUnit() && person.getCurrentWorkingPlace().getDepartment() == department) { selectedDepartment = department; break; } } infoDepartment = InfoDepartment.newInfoFromDomain(selectedDepartment); } return infoDepartment; } }