use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRCStoreVFS method init.
@Override
public void init(String storeId) {
super.init(storeId);
uri = MCRConfiguration.instance().getString(storeConfigPrefix + "URI");
String check = MCRConfiguration.instance().getString(storeConfigPrefix + "StrictHostKeyChecking", "no");
try {
fsManager = VFS.getManager();
opts = new FileSystemOptions();
SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, check);
FileObject baseDir = getBase();
// Create a folder, if it does not exist or throw an
// exception, if baseDir is not a folder
baseDir.createFolder();
if (!baseDir.isWriteable()) {
String msg = "Content store base directory is not writeable: " + uri;
throw new MCRConfigurationException(msg);
}
} catch (FileSystemException ex) {
throw new MCRException(ex.getCode(), ex);
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRContentStoreFactory method buildExtender.
/**
* If the MCRContentStore of the MCRFile given provides an
* MCRAudioVideoExtender implementation, this method creates and initializes
* the MCRAudioVideoExtender instance for the MCRFile. The instance that is
* returned is configured by the property
* <tt>MCR.IFS.AVExtender.<StoreID>.Class</tt> in mycore.properties.
*
* @param file
* the non-null MCRFile that should get an MCRAudioVideoExtender
* @return the MCRAudioVideoExtender for the MCRFile given, or null
* @throws MCRConfigurationException
* if the MCRAudioVideoExtender implementation class could not
* be loaded
*/
static MCRAudioVideoExtender buildExtender(MCRFile file) {
if (file == null || !providesAudioVideoExtender(file.getStoreID())) {
return null;
}
Class<? extends MCRAudioVideoExtender> cl = getExtenderClass(file.getStoreID());
try {
MCRAudioVideoExtender ext = cl.getDeclaredConstructor().newInstance();
ext.init(file);
return ext;
} catch (Exception exc) {
if (exc instanceof MCRException) {
throw (MCRException) exc;
}
String msg = "Could not build MCRAudioVideoExtender instance";
throw new MCRConfigurationException(msg, exc);
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRPIRegistrationService method getGenerator.
private MCRPersistentIdentifierGenerator<T> getGenerator() {
Supplier<? extends RuntimeException> generatorPropertiesNotSetError = () -> new MCRConfigurationException("Configuration property " + REGISTRATION_CONFIG_PREFIX + registrationServiceID + ".Generator is not set");
String generatorName = Optional.ofNullable(getProperties().get("Generator")).orElseThrow(generatorPropertiesNotSetError);
String inscriberPropertyKey = GENERATOR_CONFIG_PREFIX + generatorName;
String className = MCRConfiguration.instance().getString(inscriberPropertyKey);
try {
@SuppressWarnings("unchecked") Class<MCRPersistentIdentifierGenerator<T>> classObject = (Class<MCRPersistentIdentifierGenerator<T>>) Class.forName(className);
Constructor<MCRPersistentIdentifierGenerator<T>> constructor = classObject.getConstructor(String.class);
return constructor.newInstance(generatorName);
} catch (ClassNotFoundException e) {
throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") not found: " + className, e);
} catch (NoSuchMethodException e) {
throw new MCRConfigurationException("Configurated class (" + inscriberPropertyKey + ") needs a string constructor: " + className);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new MCRException(e);
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRPIRegistrationServiceManager method getRegistrationService.
public <T extends MCRPersistentIdentifier> MCRPIRegistrationService<T> getRegistrationService(String registrationServiceID) {
String propertyName = REGISTRATION_SERVICE_CONFIG_PREFIX + registrationServiceID;
Class<? extends MCRPIRegistrationService<T>> piClass = MCRConfiguration.instance().getClass(propertyName);
try {
Constructor<? extends MCRPIRegistrationService<T>> constructor = piClass.getConstructor(String.class);
return constructor.newInstance(registrationServiceID);
} catch (NoSuchMethodException e) {
throw new MCRConfigurationException("The property : " + propertyName + " points to existing class, but without string constructor(serviceid)!", e);
} catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
throw new MCRException("Cant initialize class the class defined in: " + propertyName, e);
}
}
use of org.mycore.common.config.MCRConfigurationException in project mycore by MyCoRe-Org.
the class MCRTokenRequest method post.
/**
* Posts the request and returns the response.
*
* @throws MCRConfigurationException if request fails, e.g. because of misconfigured client ID and secret
*/
public MCRTokenResponse post() throws MCRConfigurationException, IOException {
Entity<Form> formEntity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
WebTarget target = baseTarget.path("token");
Builder b = target.request().accept(MediaType.APPLICATION_JSON);
Response r = b.post(formEntity);
MCRTokenResponse response = new MCRTokenResponse(r);
if (!response.wasSuccessful()) {
throw new MCRConfigurationException(response.getStatusMessage());
}
return response;
}
Aggregations