Package org.fcrepo.server.search

Examples of org.fcrepo.server.search.FieldSearchResult


            RepositoryException {
        // this is the exact same as the other getHeaders, except for the FieldSearch call,
        // and the fact that we re-throw UnknownSessionTokenException
        // as a BadResumptionTokenException
        List l = null;
        FieldSearchResult fsr;
        try {
            fsr = m_fieldSearch.resumeFindObjects(resumptionToken);
            l = fsr.objectFieldsList();
        } catch (UnknownSessionTokenException uste) {
            throw new BadResumptionTokenException("Not a known resumptionToken.");
        } catch (ServerException se) {
            throw new RepositoryException(se.getClass().getName() + ": "
                    + se.getMessage());
        }
        if (l.size() == 0) {
            throw new NoRecordsMatchException("No records match the given criteria.");
        }
        ArrayList<Object> ret = new ArrayList<Object>();
        for (int i = 0; i < l.size(); i++) {
            ObjectFields f = (ObjectFields) l.get(i);
            String identifier =
                    "oai:" + m_repositoryDomainName + ":" + f.getPid();
            Date datestamp = f.getDCMDate();
            HashSet<String> setSpecs = new HashSet<String>();
            ret.add(new SimpleHeader(identifier, datestamp, setSpecs, true));
        }
        if (fsr.getToken() != null) {
            ret.add(new SimpleResumptionToken(fsr.getToken(), fsr
                    .getExpirationDate(), fsr.getCompleteListSize(), fsr
                    .getCursor()));
        }
        return ret;
    }
View Full Code Here


        try {
            Context context = getContext();
            String[] wantedFields = getWantedFields(m_servletRequest);
            MediaType mime = RestHelper.getContentType(format);

            FieldSearchResult result = null;

            if (wantedFields.length > 0 || sessionToken != null) {
                if (sessionToken != null) {
                    result = m_access.resumeFindObjects(context, sessionToken);
                } else {
View Full Code Here

            RepositoryException {
        if (!metadataPrefix.equals("oai_dc")) {
            throw new CannotDisseminateFormatException("Repository does not provide that format in OAI-PMH responses.");
        }
        List l = null;
        FieldSearchResult fsr;
        try {
            fsr =
                    m_fieldSearch
                            .findObjects(s_headerAndDCFields,
                                         (int) getMaxRecords(),
                                         new FieldSearchQuery(Condition
                                                 .getConditions("dcmDate>'2000-01-01'"
                                                         + getDatePart(from,
                                                                       until))));
            l = fsr.objectFieldsList();
        } catch (ServerException se) {
            throw new RepositoryException(se.getClass().getName() + ": "
                    + se.getMessage());
        }
        if (l.size() == 0) {
            throw new NoRecordsMatchException("No records match the given criteria.");
        }
        ArrayList<Object> ret = new ArrayList<Object>();
        for (int i = 0; i < l.size(); i++) {
            ObjectFields f = (ObjectFields) l.get(i);
            ret.add(new SimpleRecord(getHeader(f), getDCXML(f), s_emptySet));
        }
        if (fsr.getToken() != null) {
            // add resumptionToken stuff
            ret.add(new SimpleResumptionToken(fsr.getToken(), fsr
                    .getExpirationDate(), fsr.getCompleteListSize(), fsr
                    .getCursor()));
        }
        return ret;
    }
View Full Code Here

            RepositoryException {
        // this is the exact same as the other getRecords, except for the FieldSearch call,
        // and the fact that we re-throw UnknownSessionTokenException
        // as a BadResumptionTokenException
        List l = null;
        FieldSearchResult fsr;
        try {
            fsr = m_fieldSearch.resumeFindObjects(resumptionToken);
            l = fsr.objectFieldsList();
        } catch (UnknownSessionTokenException uste) {
            throw new BadResumptionTokenException("Not a known resumptionToken.");
        } catch (ServerException se) {
            throw new RepositoryException(se.getClass().getName() + ": "
                    + se.getMessage());
        }
        if (l.size() == 0) {
            throw new NoRecordsMatchException("No records match the given criteria.");
        }
        ArrayList<Object> ret = new ArrayList<Object>();
        for (int i = 0; i < l.size(); i++) {
            ObjectFields f = (ObjectFields) l.get(i);
            ret.add(new SimpleRecord(getHeader(f), getDCXML(f), s_emptySet));
        }
        if (fsr.getToken() != null) {
            ret.add(new SimpleResumptionToken(fsr.getToken(), fsr
                    .getExpirationDate(), fsr.getCompleteListSize(), fsr
                    .getCursor()));
        }
        return ret;
    }
View Full Code Here

            RepositoryException {
        if (!metadataPrefix.equals("oai_dc")) {
            throw new CannotDisseminateFormatException("Repository does not provide that format in OAI-PMH responses.");
        }
        List l = null;
        FieldSearchResult fsr;
        try {
            fsr =
                    m_fieldSearch
                            .findObjects(s_headerFields,
                                         (int) getMaxHeaders(),
                                         new FieldSearchQuery(Condition
                                                 .getConditions("dcmDate>'2000-01-01'"
                                                         + getDatePart(from,
                                                                       until))));
            l = fsr.objectFieldsList();
        } catch (ServerException se) {
            throw new RepositoryException(se.getClass().getName() + ": "
                    + se.getMessage());
        }
        if (l.size() == 0) {
            throw new NoRecordsMatchException("No records match the given criteria.");
        }
        ArrayList<Object> ret = new ArrayList<Object>();
        for (int i = 0; i < l.size(); i++) {
            ObjectFields f = (ObjectFields) l.get(i);
            String identifier =
                    "oai:" + m_repositoryDomainName + ":" + f.getPid();
            Date datestamp = f.getDCMDate();
            HashSet<String> setSpecs = new HashSet<String>();

            ret.add(new SimpleHeader(identifier, datestamp, setSpecs, true));
        }
        if (fsr.getToken() != null) {
            ret.add(new SimpleResumptionToken(fsr.getToken(), fsr
                    .getExpirationDate(), fsr.getCompleteListSize(), fsr
                    .getCursor()));
        }
        return ret;
    }
View Full Code Here

                        .append("Maximum Results: <select name=\"maxResults\"><option value=\"20\">20</option><option value=\"40\">40</option><option value=\"60\">60</option><option value=\"80\">80</option></select> ");
                html.append("<p><input type=\"submit\" value=\"Search\"> ");
                html.append("</td></tr></table></center>");
                html.append("</form><hr size=1>");
            }
            FieldSearchResult fsr = null;
            if (fieldsArray != null && fieldsArray.length > 0
                    || sessionToken != null) {
                if (sessionToken != null) {
                    fsr = m_access.resumeFindObjects(context, sessionToken);
                } else {
                    if (terms != null && terms.length() != 0) {
                        fsr =
                                m_access
                                        .findObjects(context,
                                                     fieldsArray,
                                                     maxResults,
                                                     new FieldSearchQuery(terms));
                    } else {
                        fsr =
                                m_access
                                        .findObjects(context,
                                                     fieldsArray,
                                                     maxResults,
                                                     new FieldSearchQuery(Condition
                                                             .getConditions(query)));
                    }
                }
                List<ObjectFields> searchResults = fsr.objectFieldsList();
                if (!xml) {
                    html
                            .append("<center><table width=\"90%\" border=\"1\" cellpadding=\"5\" cellspacing=\"5\" bgcolor=\"silver\">\n");
                    html.append("<tr>");
                    for (String element : fieldsArray) {
                        html
                                .append("<td valign=\"top\"><strong>");
                        html.append(element);
                        html.append("</strong></td>");
                    }
                    html.append("</tr>");
                }
                SimpleDateFormat formatter =
                        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
                for (int i = 0; i < searchResults.size(); i++) {
                    ObjectFields f = searchResults.get(i);
                    if (xml) {
                        xmlBuf.append("  <objectFields>\n");
                        appendXML("pid", f.getPid(), xmlBuf);
                        appendXML("label", f.getLabel(), xmlBuf);
                        appendXML("state", f.getState(), xmlBuf);
                        appendXML("ownerId", f.getOwnerId(), xmlBuf);
                        appendXML("cDate", f.getCDate(), formatter, xmlBuf);
                        appendXML("mDate", f.getMDate(), formatter, xmlBuf);
                        appendXML("dcmDate", f.getDCMDate(), formatter, xmlBuf);
                        appendXML("title", f.titles(), xmlBuf);
                        appendXML("creator", f.creators(), xmlBuf);
                        appendXML("subject", f.subjects(), xmlBuf);
                        appendXML("description", f.descriptions(), xmlBuf);
                        appendXML("publisher", f.publishers(), xmlBuf);
                        appendXML("contributor", f.contributors(), xmlBuf);
                        appendXML("date", f.dates(), xmlBuf);
                        appendXML("type", f.types(), xmlBuf);
                        appendXML("format", f.formats(), xmlBuf);
                        appendXML("identifier", f.identifiers(), xmlBuf);
                        appendXML("source", f.sources(), xmlBuf);
                        appendXML("language", f.languages(), xmlBuf);
                        appendXML("relation", f.relations(), xmlBuf);
                        appendXML("coverage", f.coverages(), xmlBuf);
                        appendXML("rights", f.rights(), xmlBuf);
                        xmlBuf.append("  </objectFields>\n");
                    } else {
                        html.append("<tr>");
                        for (String l : fieldsArray) {
                            html.append("<td valign=\"top\">");
                            if (l.equalsIgnoreCase("pid")) {
                                html.append("<a href=\"objects/");
                                html.append(f.getPid().replace("%", "%25"));
                                html.append("\">");
                                html.append(f.getPid());
                                html.append("</a>");
                            } else if (l.equalsIgnoreCase("label")) {
                                if (f.getLabel() != null) {
                                    html
                                            .append(StreamUtility.enc(f
                                                    .getLabel()));
                                }
                            } else if (l.equalsIgnoreCase("state")) {
                                html.append(f.getState());
                            } else if (l.equalsIgnoreCase("ownerId")) {
                                if (f.getOwnerId() != null) {
                                    html.append(f.getOwnerId());
                                }
                            } else if (l.equalsIgnoreCase("cDate")) {
                                html.append(formatter.format(f.getCDate()));
                            } else if (l.equalsIgnoreCase("mDate")) {
                                html.append(formatter.format(f.getMDate()));
                            } else if (l.equalsIgnoreCase("dcmDate")) {
                                if (f.getDCMDate() != null) {
                                    html.append(formatter
                                            .format(f.getDCMDate()));
                                }
                            } else if (l.equalsIgnoreCase("title")) {
                                html.append(getList(f.titles()));
                            } else if (l.equalsIgnoreCase("creator")) {
                                html.append(getList(f.creators()));
                            } else if (l.equalsIgnoreCase("subject")) {
                                html.append(getList(f.subjects()));
                            } else if (l.equalsIgnoreCase("description")) {
                                html.append(getList(f.descriptions()));
                            } else if (l.equalsIgnoreCase("publisher")) {
                                html.append(getList(f.publishers()));
                            } else if (l.equalsIgnoreCase("contributor")) {
                                html.append(getList(f.contributors()));
                            } else if (l.equalsIgnoreCase("date")) {
                                html.append(getList(f.dates()));
                            } else if (l.equalsIgnoreCase("type")) {
                                html.append(getList(f.types()));
                            } else if (l.equalsIgnoreCase("format")) {
                                html.append(getList(f.formats()));
                            } else if (l.equalsIgnoreCase("identifier")) {
                                html.append(getList(f.identifiers()));
                            } else if (l.equalsIgnoreCase("source")) {
                                html.append(getList(f.sources()));
                            } else if (l.equalsIgnoreCase("language")) {
                                html.append(getList(f.languages()));
                            } else if (l.equalsIgnoreCase("relation")) {
                                html.append(getList(f.relations()));
                            } else if (l.equalsIgnoreCase("coverage")) {
                                html.append(getList(f.coverages()));
                            } else if (l.equalsIgnoreCase("rights")) {
                                html.append(getList(f.rights()));
                            }
                            html.append("</td>");
                        }
                        html.append("</tr>");
                        html.append("<tr><td colspan=\"");
                        html.append(fieldsArray.length);
                        html.append("\"></td></tr>");
                    }
                }
                if (!xml) {
                    html.append("</table>");
                    if (fsr != null && fsr.getToken() != null) {
                        if (fsr.getCursor() != -1) {
                            long viewingStart = fsr.getCursor() + 1;
                            long viewingEnd =
                                    fsr.objectFieldsList().size()
                                            + viewingStart - 1;
                            html.append("<p>Viewing results " + viewingStart
                                    + " to " + viewingEnd);
                            if (fsr.getCompleteListSize() != -1) {
                                html.append(" of " + fsr.getCompleteListSize());
                            }
                            html.append("</p>\n");
                        }
                        html.append("<form method=\"post\" action=\"search\">");
                        if (fieldHash.contains("pid")) {
                            html
                                    .append("<input type=\"hidden\" name=\"pid\" value=\"true\">");
                        }
                        if (fieldHash.contains("label")) {
                            html
                                    .append("<input type=\"hidden\" name=\"label\" value=\"true\">");
                        }
                        if (fieldHash.contains("state")) {
                            html
                                    .append("<input type=\"hidden\" name=\"state\" value=\"true\">");
                        }
                        if (fieldHash.contains("ownerId")) {
                            html
                                    .append("<input type=\"hidden\" name=\"ownerId\" value=\"true\">");
                        }
                        if (fieldHash.contains("cDate")) {
                            html
                                    .append("<input type=\"hidden\" name=\"cDate\" value=\"true\">");
                        }
                        if (fieldHash.contains("mDate")) {
                            html
                                    .append("<input type=\"hidden\" name=\"mDate\" value=\"true\">");
                        }
                        if (fieldHash.contains("dcmDate")) {
                            html
                                    .append("<input type=\"hidden\" name=\"dcmDate\" value=\"true\">");
                        }
                        if (fieldHash.contains("title")) {
                            html
                                    .append("<input type=\"hidden\" name=\"title\" value=\"true\">");
                        }
                        if (fieldHash.contains("creator")) {
                            html
                                    .append("<input type=\"hidden\" name=\"creator\" value=\"true\">");
                        }
                        if (fieldHash.contains("subject")) {
                            html
                                    .append("<input type=\"hidden\" name=\"subject\" value=\"true\">");
                        }
                        if (fieldHash.contains("description")) {
                            html
                                    .append("<input type=\"hidden\" name=\"description\" value=\"true\">");
                        }
                        if (fieldHash.contains("publisher")) {
                            html
                                    .append("<input type=\"hidden\" name=\"publisher\" value=\"true\">");
                        }
                        if (fieldHash.contains("contributor")) {
                            html
                                    .append("<input type=\"hidden\" name=\"contributor\" value=\"true\">");
                        }
                        if (fieldHash.contains("date")) {
                            html
                                    .append("<input type=\"hidden\" name=\"date\" value=\"true\">");
                        }
                        if (fieldHash.contains("type")) {
                            html
                                    .append("<input type=\"hidden\" name=\"type\" value=\"true\">");
                        }
                        if (fieldHash.contains("format")) {
                            html
                                    .append("<input type=\"hidden\" name=\"format\" value=\"true\">");
                        }
                        if (fieldHash.contains("identifier")) {
                            html
                                    .append("<input type=\"hidden\" name=\"identifier\" value=\"true\">");
                        }
                        if (fieldHash.contains("source")) {
                            html
                                    .append("<input type=\"hidden\" name=\"source\" value=\"true\">");
                        }
                        if (fieldHash.contains("language")) {
                            html
                                    .append("<input type=\"hidden\" name=\"language\" value=\"true\">");
                        }
                        if (fieldHash.contains("relation")) {
                            html
                                    .append("<input type=\"hidden\" name=\"relation\" value=\"true\">");
                        }
                        if (fieldHash.contains("coverage")) {
                            html
                                    .append("<input type=\"hidden\" name=\"coverage\" value=\"true\">");
                        }
                        if (fieldHash.contains("rights")) {
                            html
                                    .append("<input type=\"hidden\" name=\"rights\" value=\"true\">");
                        }
                        html
                                .append("\n<input type=\"hidden\" name=\"sessionToken\" value=\""
                                        + fsr.getToken() + "\">\n");
                        html
                                .append("\n<input type=\"hidden\" name=\"maxResults\" value=\""
                                        + maxResults + "\">\n");
                        html
                                .append("<input type=\"submit\" value=\"More Results &gt;\"></form>");
                    }
                    html.append("</center>\n");
                }
            }
            if (!xml) {
                response.setContentType("text/html; charset=UTF-8");
                PrintWriter out = response.getWriter();
                out
                        .print("<html><head><title>Search Repository</title></head>");
                out.print("<body><center>");
                out
                        .println("<table width=\"784\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">");
                out
                        .println("<tr><td width=\"141\" height=\"134\" valign=\"top\"><img src=\"images/newlogo2.jpg\" width=\"141\" height=\"134\"/></td>");
                out.println("<td width=\"643\" valign=\"top\">");
                out.println("<center><h2>Fedora Repository</h2>");
                out.println("<h3>Find Objects</h3>");
                out.println("</center></td></tr></table>");
                out.print(html.toString());
                out.print("</center>");
                out.print("</body>");
                out.print("</html>");
                out.flush();
                out.close();
            } else {
                response.setContentType("text/xml; charset=UTF-8");
                PrintWriter out =
                        new PrintWriter(new OutputStreamWriter(response
                                .getOutputStream(), "UTF-8"));
                out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
                out.println("<result xmlns=\"" + TYPES.uri + "\">");
                if (fsr != null && fsr.getToken() != null) {
                    out.println("  <listSession>");
                    out.println("    <token>" + fsr.getToken() + "</token>");
                    if (fsr.getCursor() != -1) {
                        out.println("    <cursor>" + fsr.getCursor()
                                + "</cursor>");
                    }
                    if (fsr.getCompleteListSize() != -1) {
                        out.println("    <completeListSize>"
                                + fsr.getCompleteListSize()
                                + "</completeListSize>");
                    }
                    if (fsr.getExpirationDate() != null) {
                        out
                                .println("    <expirationDate>"
                                        + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
                                                .format(fsr.getExpirationDate())
                                        + "</expirationDate>");
                    }
                    out.println("  </listSession>");
                }
                out.println("<resultList>");
View Full Code Here

                TypeUtility.convertFieldSearchQueryToGenFieldSearchQuery(query);
        org.fcrepo.server.types.gen.FieldSearchResult searchResult =
                apia.findObjects(org.fcrepo.server.utilities.TypeUtility.convertStringtoAOS(OBJECT_RESULT_FIELDS),
                                 MAX_FIND_RESULTS,
                                 genFieldSearchQuery);
        FieldSearchResult fsr =
                TypeUtility
                        .convertGenFieldSearchResultToFieldSearchResult(searchResult);
        for (ObjectFields fields : fsr.objectFieldsList()) {
            stash.add(fields.getPid());
        }
        token = fsr.getToken();
    }
View Full Code Here

     * and set the stash and token from the results.
     */
    private void resumeSearch() throws RemoteException {
        org.fcrepo.server.types.gen.FieldSearchResult searchResult =
                apia.resumeFindObjects(token);
        FieldSearchResult fsr =
                TypeUtility
                        .convertGenFieldSearchResultToFieldSearchResult(searchResult);
        for (ObjectFields fields : fsr.objectFieldsList()) {
            stash.add(fields.getPid());
        }
        token = fsr.getToken();
    }
View Full Code Here

TOP

Related Classes of org.fcrepo.server.search.FieldSearchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.