package net.sourceforge.fenixedu.presentationTier.Action.library; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import net.sourceforge.fenixedu.applicationTier.Filtro.exception.FenixFilterException; import net.sourceforge.fenixedu.applicationTier.Servico.exceptions.FenixServiceException; import net.sourceforge.fenixedu.applicationTier.Servico.person.SearchPerson; import net.sourceforge.fenixedu.applicationTier.Servico.person.SearchPerson.SearchParameters; import net.sourceforge.fenixedu.applicationTier.Servico.person.SearchPerson.SearchPersonPredicate; import net.sourceforge.fenixedu.dataTransferObject.library.LibraryUserListBean; import net.sourceforge.fenixedu.dataTransferObject.library.LibraryUserSearchBean; import net.sourceforge.fenixedu.domain.Person; import net.sourceforge.fenixedu.domain.exceptions.DomainException; import net.sourceforge.fenixedu.domain.integration.koha.KohaRecord; import net.sourceforge.fenixedu.domain.library.LibraryCard; import net.sourceforge.fenixedu.presentationTier.Action.base.FenixDispatchAction; import net.sourceforge.fenixedu.presentationTier.Action.exceptions.FenixActionException; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import pt.ist.fenixWebFramework.renderers.utils.RenderUtils; import pt.ist.fenixframework.pstm.AbstractDomainObject; import pt.utl.ist.fenix.tools.util.CollectionPager; /** * This action is responsible for the manage library card number feature and * showing the information of the Koha record. * * @author António Casqueiro (ajsco@iscte.pt) */ public class KohaIntegrationManagementDA extends FenixDispatchAction { public ActionForward prepare(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException { request.setAttribute("searchCriteria", new LibraryUserSearchBean()); return mapping.findForward("search-criteria"); } public ActionForward backToSearchCriteria(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException, FenixServiceException { final LibraryUserSearchBean searchBean = (LibraryUserSearchBean) getRenderedObject("searchCriteria"); // Call invalidateViewState to clear the previous state, otherwise the // schema of the page appears empty. RenderUtils.invalidateViewState("searchCriteria"); request.setAttribute("searchCriteria", searchBean); return mapping.findForward("search-criteria"); } public ActionForward backToSearchResult(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException, FenixServiceException { return search(mapping, form, request, response); } public ActionForward search(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException, FenixServiceException { final LibraryUserSearchBean searchBean = (LibraryUserSearchBean) getRenderedObject("searchCriteria"); request.setAttribute("searchCriteria", searchBean); String documentIdType = searchBean.getIdDocumentType() != null ? searchBean.getIdDocumentType().toString() : null; try { SearchParameters searchParameters = new SearchPerson.SearchParameters(searchBean.getName(), null, searchBean.getUsername(), searchBean.getIdDocumentNumber(), documentIdType, null, null, null, null, Boolean.TRUE, null, Boolean.FALSE, null, null, null, null, searchBean.getLibraryCardNumber()); SearchPersonPredicate predicate = new SearchPerson.SearchPersonPredicate(searchParameters); Object[] args = { searchParameters, predicate }; @SuppressWarnings("unchecked") final CollectionPager result = (CollectionPager) executeService("SearchPerson", args); final LibraryUserListBean list = new LibraryUserListBean(result.getCollection()); if (list.getPersons().size() == 0) { addActionMessage("message", request, "error.nonExisting.users"); } else { request.setAttribute("searchResult", list); return mapping.findForward("search-result"); } } catch (DomainException e) { addActionMessage(request, e.getKey(), e.getArgs()); } return mapping.findForward("search-criteria"); } public ActionForward showDetail(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException, FenixServiceException { String id = request.getParameter("externalId"); final LibraryUserSearchBean searchBean = (LibraryUserSearchBean) getRenderedObject("searchCriteria"); request.setAttribute("searchCriteria", searchBean); // Read person final Person person = AbstractDomainObject.fromExternalId(id); // Find Koha record KohaRecord kohaRecord = KohaRecord.findRecord(person.getUsername()); request.setAttribute("result", kohaRecord); return mapping.findForward("show-detail"); } public ActionForward editLibraryCardNumber(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws FenixActionException, FenixFilterException, FenixServiceException { String id = request.getParameter("externalId"); final LibraryUserSearchBean searchBean = (LibraryUserSearchBean) getRenderedObject("searchCriteria"); request.setAttribute("searchCriteria", searchBean); // Read person final Person person = AbstractDomainObject.fromExternalId(id); // Get/create library card LibraryCard libraryCard = LibraryCard.getLibraryCardCreateEmptyIfNeeded(person); request.setAttribute("result", libraryCard); return mapping.findForward("edit-card"); } }