Search in sources :

Example 6 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class GsonSerializationTest method init.

@Before
public void init() {
    MCRConfiguration mcrProperties = MCRConfiguration.instance();
    mcrProperties.initialize(MCRConfigurationLoaderFactory.getConfigurationLoader().load(), true);
    mcrProperties.set("MCR.Category.DAO", CategoryDAOMock.class.getName());
}
Also used : CategoryDAOMock(org.mycore.frontend.classeditor.mocks.CategoryDAOMock) MCRConfiguration(org.mycore.common.config.MCRConfiguration) Before(org.junit.Before)

Example 7 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRCategoryJsonTest method deserialize.

@Test
public void deserialize() throws Exception {
    MCRConfiguration mcrProperties = MCRConfiguration.instance();
    mcrProperties.initialize(MCRConfigurationLoaderFactory.getConfigurationLoader().load(), true);
    mcrProperties.set("MCR.Metadata.DefaultLang", "de");
    mcrProperties.set("MCR.Category.DAO", CategoryDAOMock.class.getName());
    SAXBuilder saxBuilder = new SAXBuilder();
    Document doc = saxBuilder.build(getClass().getResourceAsStream("/classi/categoryJsonErr.xml"));
    String json = doc.getRootElement().getText();
    Gson gson = MCRJSONManager.instance().createGson();
    try {
        MCRCategoryImpl fromJson = gson.fromJson(json, MCRCategoryImpl.class);
        System.out.println("FOO");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : CategoryDAOMock(org.mycore.frontend.classeditor.mocks.CategoryDAOMock) SAXBuilder(org.jdom2.input.SAXBuilder) MCRConfiguration(org.mycore.common.config.MCRConfiguration) Gson(com.google.gson.Gson) MCRCategoryImpl(org.mycore.datamodel.classifications2.impl.MCRCategoryImpl) Document(org.jdom2.Document) Test(org.junit.Test)

Example 8 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCROAISolrSetConfiguration method getFallbackHandler.

private String getFallbackHandler(String configPrefix, String setId) {
    MCRConfiguration config = MCRConfiguration.instance();
    String queryProperty = configPrefix + SETS_PREFIX + setId + ".Query";
    if (config.getString(queryProperty, config.getString(configPrefix + "MapSetToQuery." + setId, null)) != null) {
        return MCROAIQueryToSetHandler.class.getName();
    }
    String classProperty = configPrefix + SETS_PREFIX + setId + ".Classification";
    if (config.getString(classProperty, config.getString(configPrefix + "MapSetToClassification." + setId, null)) != null) {
        return MCROAIClassificationToSetHandler.class.getName();
    }
    if (config.getString(configPrefix + SETS_PREFIX + setId + ".Handler", null) == null) {
        LogManager.getLogger().error("Neither '{}' nor '{}' is defined. Please map set '{}' to classification or query.", classProperty, queryProperty, setId);
        return MCROAIClassificationToSetHandler.class.getName();
    }
    return null;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration)

Example 9 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration in project mycore by MyCoRe-Org.

the class MCRViewerMetadataConfiguration method setup.

@Override
public MCRViewerConfiguration setup(HttpServletRequest request) {
    super.setup(request);
    String derivate = getDerivate(request);
    MCRObjectID derivateID = MCRObjectID.getInstance(derivate);
    final MCRObjectID objectID = MCRMetadataManager.getObjectId(derivateID, EXPIRE_METADATA_CACHE_TIME, TimeUnit.SECONDS);
    if (objectID == null) {
        String errorMessage = MCRTranslation.translate("component.viewer.MCRIViewClientServlet.object.not.found", objectID);
        // TODO: we should not throw an webapplication exc. here -> instead throw something líke ConfigException
        throw new WebApplicationException(Response.status(Status.NOT_FOUND).entity(errorMessage).build());
    }
    // properties
    setProperty("objId", objectID.toString());
    String urlFormat = "%sreceive/%s?XSL.Transformer=%s";
    MCRConfiguration mcrConfiguration = MCRConfiguration.instance();
    String transformer = mcrConfiguration.getString("MCR.Viewer.metadata.transformer", null);
    if (transformer != null) {
        setProperty("metadataURL", String.format(Locale.ROOT, urlFormat, MCRFrontendUtil.getBaseURL(), objectID, transformer));
    }
    // script
    addLocalScript("iview-client-metadata.js", isDebugParameterSet(request));
    return this;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) WebApplicationException(javax.ws.rs.WebApplicationException) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Example 10 with MCRConfiguration

use of org.mycore.common.config.MCRConfiguration 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

MCRConfiguration (org.mycore.common.config.MCRConfiguration)26 File (java.io.File)3 ArrayList (java.util.ArrayList)3 MCRConfigurationException (org.mycore.common.config.MCRConfigurationException)3 URI (java.net.URI)2 Hashtable (java.util.Hashtable)2 Test (org.junit.Test)2 CategoryDAOMock (org.mycore.frontend.classeditor.mocks.CategoryDAOMock)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URISyntaxException (java.net.URISyntaxException)1 URLConnection (java.net.URLConnection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1