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);
}
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);
}
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);
}
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;
}
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();
}
}
Aggregations