Search in sources :

Example 1 with MCRSwordLifecycleConfiguration

use of org.mycore.sword.application.MCRSwordLifecycleConfiguration 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

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MCRConfiguration (org.mycore.common.config.MCRConfiguration)1 MCRSwordCollectionProvider (org.mycore.sword.application.MCRSwordCollectionProvider)1 MCRSwordLifecycleConfiguration (org.mycore.sword.application.MCRSwordLifecycleConfiguration)1