package net.sourceforge.fenixedu.webServices.macaddress; import java.util.ArrayList; import java.util.List; import javax.servlet.ServletRequest; import net.sourceforge.fenixedu.domain.MacAddress; import net.sourceforge.fenixedu.util.HostAccessControl; import org.codehaus.xfire.transport.http.XFireServletController; import pt.iscte.ci.metadata.ISCTE; @ISCTE(author = "Paulo Zenida") public class MacAddressRegistryService implements IMacAddressRegistryService { public List getStudentMacAddresses() { final ServletRequest servletRequest = XFireServletController.getRequest(); if (HostAccessControl.isAllowed(getClass(), servletRequest)) { final List macAddresses = MacAddress.getAllActiveMacAddresses(); return getMacAddressBeans(macAddresses, true); } else { throw new RuntimeException(HostAccessControl.getRemoteAddress(servletRequest) + " is not allowed to access this service"); } } public List getNonStudentMacAddresses() { final ServletRequest servletRequest = XFireServletController.getRequest(); if (HostAccessControl.isAllowed(getClass(), servletRequest)) { final List macAddresses = MacAddress.getAllActiveMacAddresses(); return getMacAddressBeans(macAddresses, false); } else { throw new RuntimeException(HostAccessControl.getRemoteAddress(servletRequest) + " is not allowed to access this service"); } } private List getMacAddressBeans(final List macAddresses, final boolean isOnlyStudent) { final List result = new ArrayList(macAddresses.size()); for (final MacAddress macAddress : macAddresses) { if (isOnlyStudent == (macAddress.getPerson().hasStudent() && (!macAddress.getPerson().hasCollaborator() && !macAddress.getPerson().hasResearcher() && !macAddress.getPerson().hasAdvisor() && !macAddress.getPerson().hasGuest() && !macAddress.getPerson().hasSecurityStaff() && !macAddress.getPerson().hasInspector() && !macAddress.getPerson().hasEmployee() && !macAddress.getPerson() .hasTeacher()))) { result.add(new MacAddressBean(macAddress)); } } return result; } }