Search in sources :

Example 16 with MCRConfiguration

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

the class MCRQLSearchServlet method init.

@Override
public void init() throws ServletException {
    super.init();
    MCRConfiguration config = MCRConfiguration.instance();
    String prefix = "MCR.SearchServlet.";
    defaultSearchField = config.getString(prefix + "DefaultSearchField", "allMeta");
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration)

Example 17 with MCRConfiguration

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

the class MCRPIRegistrationService method getMetadataManager.

public MCRPersistentIdentifierMetadataManager<T> getMetadataManager() {
    Map<String, String> properties = getProperties();
    MCRConfiguration configuration = MCRConfiguration.instance();
    String metadataManager;
    if (properties.containsKey(METADATA_MANAGER_PROPERTY_KEY)) {
        metadataManager = properties.get(METADATA_MANAGER_PROPERTY_KEY);
    } else if (properties.containsKey(METADATA_MANAGER_DEPRECATED_PROPERTY_KEY)) {
        LOGGER.warn(MessageFormat.format("You should use {0}{1}.{2} instead of {3}{4}.{5}", REGISTRATION_CONFIG_PREFIX, getRegistrationServiceID(), METADATA_MANAGER_PROPERTY_KEY, REGISTRATION_CONFIG_PREFIX, getRegistrationServiceID(), METADATA_MANAGER_DEPRECATED_PROPERTY_KEY));
        metadataManager = properties.get(METADATA_MANAGER_DEPRECATED_PROPERTY_KEY);
    } else {
        throw new MCRConfigurationException(getRegistrationServiceID() + " has no MetadataManager(or legacy Inscriber)!");
    }
    String className;
    String metadataManagerPropertyKey;
    metadataManagerPropertyKey = METADATA_MANAGER_CONFIG_PREFIX + metadataManager;
    className = configuration.getString(metadataManagerPropertyKey, null);
    if (className == null) {
        metadataManagerPropertyKey = METADATA_MANAGER_DEPRECATED_CONFIG_PREFIX + metadataManager;
        className = configuration.getString(metadataManagerPropertyKey, null);
        if (className == null) {
            throw new MCRConfigurationException("Missing property: " + METADATA_MANAGER_CONFIG_PREFIX + metadataManager + " or " + metadataManagerPropertyKey);
        }
        LOGGER.warn("You should use {} instead of {}", METADATA_MANAGER_CONFIG_PREFIX + metadataManager, METADATA_MANAGER_DEPRECATED_PROPERTY_KEY + metadataManager);
    }
    className = repairDeprecatedClassNames(className, metadataManagerPropertyKey);
    try {
        @SuppressWarnings("unchecked") Class<MCRPersistentIdentifierMetadataManager<T>> classObject = (Class<MCRPersistentIdentifierMetadataManager<T>>) Class.forName(className);
        Constructor<MCRPersistentIdentifierMetadataManager<T>> constructor = classObject.getConstructor(String.class);
        return constructor.newInstance(metadataManager);
    } catch (ClassNotFoundException e) {
        throw new MCRConfigurationException("Configurated class (" + metadataManagerPropertyKey + ") not found: " + className, e);
    } catch (NoSuchMethodException e) {
        throw new MCRConfigurationException("Configurated class (" + metadataManagerPropertyKey + ") needs a string constructor: " + className);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new MCRException(e);
    }
}
Also used : MCRException(org.mycore.common.MCRException) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MCRConfiguration(org.mycore.common.config.MCRConfiguration)

Example 18 with MCRConfiguration

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

the class MCROAIQuerySetResolver method getQuery.

private SolrQuery getQuery() {
    SolrQuery solrQuery = new SolrQuery();
    MCRConfiguration config = MCRConfiguration.instance();
    // query
    String idQuery = getResult().stream().map(getIdentifier()).map(MCRSolrUtils::escapeSearchValue).collect(Collectors.joining(" OR ", "id:(", ")"));
    solrQuery.setQuery(idQuery);
    solrQuery.setFilterQueries(query);
    solrQuery.setFields("id");
    solrQuery.setRows(getResult().size());
    // request handler
    solrQuery.setRequestHandler(config.getString(getConfigPrefix() + "Search.RequestHandler", "/select"));
    return solrQuery;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 19 with MCRConfiguration

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

the class MCROAIQueryToSetHandler method getSetFilterQuery.

private String getSetFilterQuery(String setId) {
    MCRConfiguration config = MCRConfiguration.instance();
    String queryProperty = getConfigPrefix() + "Sets." + setId + ".Query";
    String configQuery;
    try {
        configQuery = config.getString(queryProperty);
    } catch (MCRConfigurationException e) {
        String deprecatedProperty = getConfigPrefix() + "MapSetToQuery." + setId;
        configQuery = config.getString(deprecatedProperty, null);
        if (configQuery == null) {
            throw e;
        }
        LogManager.getLogger().warn("Property '{}' is deprecated and support will be removed. Please rename to '{}' soon!", deprecatedProperty, queryProperty);
    }
    return configQuery;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration) MCRConfigurationException(org.mycore.common.config.MCRConfigurationException)

Example 20 with MCRConfiguration

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

the class MCROAIDataProvider method getOAIAdapter.

private OAIAdapter getOAIAdapter() {
    String oaiAdapterKey = getServletName();
    MCROAIAdapter oaiAdapter = mcrOAIAdapterMap.get(oaiAdapterKey);
    if (oaiAdapter == null) {
        synchronized (this) {
            // double check because of synchronize block
            oaiAdapter = mcrOAIAdapterMap.get(oaiAdapterKey);
            if (oaiAdapter == null) {
                MCRConfiguration config = MCRConfiguration.instance();
                String adapter = MCROAIAdapter.PREFIX + oaiAdapterKey + ".Adapter";
                oaiAdapter = config.getInstanceOf(adapter, MCROAIAdapter.class.getName());
                oaiAdapter.init(this.myBaseURL, oaiAdapterKey);
                mcrOAIAdapterMap.put(oaiAdapterKey, oaiAdapter);
            }
        }
    }
    return oaiAdapter;
}
Also used : MCRConfiguration(org.mycore.common.config.MCRConfiguration)

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