Search in sources :

Example 1 with MCRSet

use of org.mycore.oai.set.MCRSet in project mycore by MyCoRe-Org.

the class MCROAISetManager method createSetList.

protected OAIDataList<MCRSet> createSetList() {
    OAIDataList<MCRSet> setList = new OAIDataList<>();
    synchronized (this.setConfigurationMap) {
        for (MCROAISetConfiguration<?, ?, ?> conf : this.setConfigurationMap.values()) {
            MCROAISetHandler<?, ?, ?> handler = conf.getHandler();
            Map<String, MCRSet> setMap = handler.getSetMap();
            synchronized (setMap) {
                setMap.clear();
                Element resolved = MCRURIResolver.instance().resolve(conf.getURI());
                if (resolved == null) {
                    throw new MCRException("Could not resolve set URI " + conf.getURI() + " for set " + conf.getId() + ".");
                }
                for (Element setElement : resolved.getChildren("set", OAIConstants.NS_OAI)) {
                    MCRSet set = createSet(conf.getId(), setElement);
                    setMap.put(set.getSpec(), set);
                    if (!contains(set.getSpec(), setList)) {
                        if (!handler.filter(set)) {
                            setList.add(set);
                        }
                    }
                }
            }
        }
    }
    return setList;
}
Also used : MCRException(org.mycore.common.MCRException) Element(org.jdom2.Element) OAIDataList(org.mycore.oai.pmh.OAIDataList) MCRSet(org.mycore.oai.set.MCRSet)

Example 2 with MCRSet

use of org.mycore.oai.set.MCRSet in project mycore by MyCoRe-Org.

the class MCROAISetManager method createSet.

private MCRSet createSet(String setId, Element setElement) {
    String setSpec = setElement.getChildText("setSpec", NS_OAI);
    String setName = setElement.getChildText("setName", NS_OAI);
    MCRSet set = new MCRSet(setId, getSetSpec(setSpec), setName);
    set.getDescription().addAll(setElement.getChildren("setDescription", NS_OAI).stream().flatMap(// first childElement of setDescription
    e -> e.getChildren().stream().limit(1)).peek(Element::detach).map(d -> (Description) new Description() {

        @Override
        public Element toXML() {
            return d;
        }

        @Override
        public void fromXML(Element descriptionElement) {
            throw new UnsupportedOperationException();
        }
    }).collect(Collectors.toList()));
    return set;
}
Also used : Description(org.mycore.oai.pmh.Description) Element(org.jdom2.Element) MCRSet(org.mycore.oai.set.MCRSet)

Example 3 with MCRSet

use of org.mycore.oai.set.MCRSet in project mycore by MyCoRe-Org.

the class MCROAIAdapter method getSet.

/*
     * (non-Javadoc)
     * @see org.mycore.oai.pmh.dataprovider.OAIAdapter#getSet(java.lang.String)
     */
@Override
public MCRSet getSet(String setSpec) throws NoSetHierarchyException, NoRecordsMatchException {
    MCROAISetManager setManager = getSetManager();
    OAIDataList<MCRSet> setList = setManager.get();
    if (setList.isEmpty()) {
        throw new NoSetHierarchyException();
    }
    MCRSet set = MCROAISetManager.get(setSpec, setList);
    if (set == null) {
        throw new NoRecordsMatchException();
    }
    return set;
}
Also used : NoSetHierarchyException(org.mycore.oai.pmh.NoSetHierarchyException) NoRecordsMatchException(org.mycore.oai.pmh.NoRecordsMatchException) MCRSet(org.mycore.oai.set.MCRSet)

Aggregations

MCRSet (org.mycore.oai.set.MCRSet)3 Element (org.jdom2.Element)2 MCRException (org.mycore.common.MCRException)1 Description (org.mycore.oai.pmh.Description)1 NoRecordsMatchException (org.mycore.oai.pmh.NoRecordsMatchException)1 NoSetHierarchyException (org.mycore.oai.pmh.NoSetHierarchyException)1 OAIDataList (org.mycore.oai.pmh.OAIDataList)1