package net.sourceforge.fenixedu.webServices.portal; import static pt.ist.fenixframework.plugins.luceneIndexing.queryBuilder.Builder.matches; import java.util.ArrayList; import java.util.Collections; import java.util.List; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.Person.PersonIndexableFields; import net.sourceforge.fenixedu.domain.organizationalStructure.CompetenceCourseGroupUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.Party; import net.sourceforge.fenixedu.domain.organizationalStructure.Party.PartyIndexFields; import net.sourceforge.fenixedu.domain.organizationalStructure.ScientificAreaUnit; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit; import net.sourceforge.fenixedu.domain.organizationalStructure.Unit.UnitIndexableFields; import net.sourceforge.fenixedu.webServices.portal.dto.PortalPartyDTO; import net.sourceforge.fenixedu.webServices.portal.dto.PortalPersonDTO; import net.sourceforge.fenixedu.webServices.portal.dto.PortalUnitDTO; import org.apache.commons.lang.StringUtils; import pt.ist.fenixframework.plugins.luceneIndexing.DomainIndexer; import pt.ist.fenixframework.plugins.luceneIndexing.queryBuilder.dsl.SearchState; import pt.utl.ist.fenix.tools.util.StringNormalizer; // This WS interface is deprecated. Please use the JAX-WS interface instead. @Deprecated public class PartySearchService extends PortalWebService implements IPartySearchService { private static final DomainIndexer seeker = DomainIndexer.getInstance(); private static final Class[] classesToSkipInSearch = new Class[] { ScientificAreaUnit.class, CompetenceCourseGroupUnit.class }; @Override public List search(String searchQuery) { checkAccessControl(); if (StringUtils.isEmpty(searchQuery)) { return Collections.emptyList(); } String[] splittedQuery = StringNormalizer.normalize(searchQuery).split(" "); SearchState query = matches(splittedQuery[0]); for (int i = 1; i < splittedQuery.length; i++) { query = query.and().matches(splittedQuery[i]); } for (Class clazz : classesToSkipInSearch) { query = query.and().not(PartyIndexFields.SUB_CLASS, clazz.getName()); } query = query.and().expression( matches(UnitIndexableFields.IS_EXTERNAL, Boolean.FALSE.toString()).or().expression( matches(PersonIndexableFields.IS_ONLY_STUDENT, Boolean.FALSE.toString()).and().matches( PersonIndexableFields.IS_EXTERNAL, Boolean.FALSE.toString()))); List searchResult = seeker.search(Party.class, query, seeker.DEFAULT_MAX_SIZE); List partyDTOs = new ArrayList(); PortalPartyDTO dto = null; for (Party party : searchResult) { if (party.isUnit()) { dto = new PortalUnitDTO((Unit) party, true); } else { final Person person = (Person) party; if (!person.hasActiveContract()) { continue; } dto = new PortalPersonDTO(person); } partyDTOs.add(dto); } return partyDTOs; } }