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