Search in sources :

Example 1 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerManager method replaceMetadataAndMediaResource.

@Override
public DepositReceipt replaceMetadataAndMediaResource(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    IRI iri = new IRI(editIRI);
    String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri);
    String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri);
    final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
    LOGGER.info(MessageFormat.format("REQUEST: Replace metadata and resource of {0} from {1} !", objectIdString, collection));
    collectionProvider.getAuthHandler().authentication(authCredentials);
    MCRObjectID objectId = MCRObjectID.getInstance(objectIdString);
    if (!MCRMetadataManager.exists(objectId)) {
        throwObjectDoesNotExist(objectIdString);
    }
    MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId);
    return collectionProvider.getContainerHandler().replaceMetadataAndResources((MCRObject) retrievedMCRBase, deposit);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 2 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerManager method addResources.

@Override
public DepositReceipt addResources(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    IRI iri = new IRI(editIRI);
    String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri);
    String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri);
    final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
    LOGGER.info(MessageFormat.format("REQUEST: add resources {0} from {1} !", objectIdString, collection));
    collectionProvider.getAuthHandler().authentication(authCredentials);
    MCRObjectID objectId = MCRObjectID.getInstance(objectIdString);
    if (!MCRMetadataManager.exists(objectId)) {
        throwObjectDoesNotExist(objectIdString);
    }
    MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId);
    return collectionProvider.getContainerHandler().addResources((MCRObject) retrievedMCRBase, deposit);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 3 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordContainerManager method replaceMetadata.

@Override
public DepositReceipt replaceMetadata(String editIRI, Deposit deposit, AuthCredentials authCredentials, SwordConfiguration swordConfiguration) throws SwordError, SwordServerException, SwordAuthException {
    IRI iri = new IRI(editIRI);
    String collection = MCRSwordUtil.ParseLinkUtil.EditIRI.getCollectionFromEditIRI(iri);
    String objectIdString = MCRSwordUtil.ParseLinkUtil.EditIRI.getObjectFromEditIRI(iri);
    final MCRSwordCollectionProvider collectionProvider = MCRSword.getCollection(collection);
    LOGGER.info(MessageFormat.format("REQUEST: Replace metadata of {0} from {1} !", objectIdString, collection));
    collectionProvider.getAuthHandler().authentication(authCredentials);
    MCRObjectID objectId = MCRObjectID.getInstance(objectIdString);
    if (!MCRMetadataManager.exists(objectId)) {
        throwObjectDoesNotExist(objectIdString);
    }
    MCRBase retrievedMCRBase = MCRMetadataManager.retrieve(objectId);
    checkIsObject(retrievedMCRBase);
    return collectionProvider.getContainerHandler().replaceMetadata((MCRObject) retrievedMCRBase, deposit);
}
Also used : IRI(org.apache.abdera.i18n.iri.IRI) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 4 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSwordServiceDocumentManager method buildSwordCollectionList.

private List<SwordCollection> buildSwordCollectionList(String workspaceName, AuthCredentials auth) {
    String baseURL = MCRFrontendUtil.getBaseURL();
    List<SwordCollection> swordCollections = new ArrayList<>();
    MCRSword.getCollectionsOfWorkspace(workspaceName).stream().map(collection -> new AbstractMap.SimpleEntry<>(collection, MCRSword.getCollection(collection))).filter(collectionEntry -> collectionEntry.getValue().isVisible()).forEach(collection -> {
        SwordCollection swordCollection = new SwordCollection();
        final String collectionTitle = collection.getKey();
        swordCollection.setTitle(collectionTitle);
        // add the supported packaging to the collection Provider
        final MCRSwordCollectionProvider collectionProvider = collection.getValue();
        collectionProvider.getSupportedPagacking().forEach(swordCollection::addAcceptPackaging);
        swordCollection.setHref(baseURL + MCRSwordConstants.SWORD2_COL_IRI + collectionTitle + "/");
        swordCollections.add(swordCollection);
    });
    return swordCollections;
}
Also used : AbstractMap(java.util.AbstractMap) SwordError(org.swordapp.server.SwordError) SwordConfiguration(org.swordapp.server.SwordConfiguration) MCRSwordConstants(org.mycore.sword.MCRSwordConstants) SwordCollection(org.swordapp.server.SwordCollection) SwordAuthException(org.swordapp.server.SwordAuthException) MCRFrontendUtil(org.mycore.frontend.MCRFrontendUtil) ServiceDocumentManager(org.swordapp.server.ServiceDocumentManager) ArrayList(java.util.ArrayList) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) AbstractMap(java.util.AbstractMap) List(java.util.List) MCRSword(org.mycore.sword.MCRSword) ServiceDocument(org.swordapp.server.ServiceDocument) SwordServerException(org.swordapp.server.SwordServerException) AuthCredentials(org.swordapp.server.AuthCredentials) SwordWorkspace(org.swordapp.server.SwordWorkspace) ArrayList(java.util.ArrayList) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) SwordCollection(org.swordapp.server.SwordCollection)

Example 5 with MCRSwordCollectionProvider

use of org.mycore.sword.application.MCRSwordCollectionProvider in project mycore by MyCoRe-Org.

the class MCRSword method initConfig.

private static void initConfig() {
    if (collections == null) {
        collections = new Hashtable<>();
        workspaceCollectionTable = new Hashtable<>();
        final MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
        Map<String, String> propertiesMap = mcrConfiguration.getPropertiesMap();
        final int lenghtOfPropertyPrefix = MCRSwordConstants.MCR_SWORD_COLLECTION_PREFIX.length();
        LOGGER.info("--- INITIALIZE SWORD SERVER ---");
        propertiesMap.keySet().stream().filter(// remove all which are not collections
        prop -> prop.startsWith(MCRSwordConstants.MCR_SWORD_COLLECTION_PREFIX)).filter(// remove all which have no suffix
        prop -> !prop.trim().equals(MCRSwordConstants.MCR_SWORD_COLLECTION_PREFIX)).map(// remove MCR_SWORD_COLLECTION_PREFIX
        prop -> prop.substring(lenghtOfPropertyPrefix)).map(// split to workspace name and collection name
        prop -> prop.split(Pattern.quote("."), 2)).filter(// remove all whith no workspace or collection name
        prop -> prop.length == 2).forEach(workspaceCollectionEntry -> {
            final String collection = workspaceCollectionEntry[1];
            final String workspace = workspaceCollectionEntry[0];
            LOGGER.info("Found collection: {} in workspace {}", collection, workspace);
            String name = MCRSwordConstants.MCR_SWORD_COLLECTION_PREFIX + workspace + "." + collection;
            LOGGER.info("Try to init : {}", name);
            MCRSwordCollectionProvider collectionProvider = mcrConfiguration.getInstanceOf(name);
            collections.put(collection, collectionProvider);
            final MCRSwordLifecycleConfiguration lifecycleConfiguration = new MCRSwordLifecycleConfiguration(collection);
            collectionProvider.init(lifecycleConfiguration);
            // This Map is needed to speed up the build of the {@link org.mycore.mir.sword2.manager.MCRServiceDocumentManager}
            List<String> collectionsOfWorkspace;
            if (workspaceCollectionTable.containsKey(workspace)) {
                collectionsOfWorkspace = workspaceCollectionTable.get(workspace);
            } else {
                collectionsOfWorkspace = new ArrayList<>();
                workspaceCollectionTable.put(workspace, collectionsOfWorkspace);
            }
            collectionsOfWorkspace.add(collection);
        });
        addCollectionShutdownHook();
    }
}
Also used : List(java.util.List) MCRSwordLifecycleConfiguration(org.mycore.sword.application.MCRSwordLifecycleConfiguration) Logger(org.apache.logging.log4j.Logger) Map(java.util.Map) MCRConfiguration(org.mycore.common.config.MCRConfiguration) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) LogManager(org.apache.logging.log4j.LogManager) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRSwordCollectionProvider(org.mycore.sword.application.MCRSwordCollectionProvider) MCRSwordLifecycleConfiguration(org.mycore.sword.application.MCRSwordLifecycleConfiguration)

Aggregations

MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)15 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)7 IRI (org.apache.abdera.i18n.iri.IRI)6 MCRBase (org.mycore.datamodel.metadata.MCRBase)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 MCRObject (org.mycore.datamodel.metadata.MCRObject)2 SwordError (org.swordapp.server.SwordError)2 AbstractMap (java.util.AbstractMap)1 Collections (java.util.Collections)1 Hashtable (java.util.Hashtable)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Abdera (org.apache.abdera.Abdera)1 Feed (org.apache.abdera.model.Feed)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRFrontendUtil (org.mycore.frontend.MCRFrontendUtil)1