use of org.opencastproject.kernel.security.persistence.OrganizationDatabaseException in project opencast by opencast.
the class OrganizationDirectoryServiceImpl method updated.
@Override
@SuppressWarnings("rawtypes")
public void updated(String pid, Dictionary properties) throws ConfigurationException {
if (persistence == null) {
logger.debug("No persistence available: Ignoring organization update for pid='{}'", pid);
unhandledOrganizations.put(pid, properties);
return;
}
logger.debug("Updating organization pid='{}'", pid);
// Gather the properties
final String id = (String) properties.get(ORG_ID_KEY);
final String name = (String) properties.get(ORG_NAME_KEY);
final String server = (String) properties.get(ORG_SERVER_KEY);
// Make sure the configuration meets the minimum requirements
if (StringUtils.isBlank(id))
throw new ConfigurationException(ORG_ID_KEY, ORG_ID_KEY + " must be set");
if (StringUtils.isBlank(server))
throw new ConfigurationException(ORG_SERVER_KEY, ORG_SERVER_KEY + " must be set");
String[] serverUrls = StringUtils.split(server, ",");
final String portAsString = StringUtils.trimToNull((String) properties.get(ORG_PORT_KEY));
final int port = portAsString != null ? Integer.parseInt(portAsString) : 80;
final String adminRole = (String) properties.get(ORG_ADMIN_ROLE_KEY);
final String anonRole = (String) properties.get(ORG_ANONYMOUS_ROLE_KEY);
// Build the properties map
final Map<String, String> orgProperties = new HashMap<String, String>();
for (Enumeration<?> e = properties.keys(); e.hasMoreElements(); ) {
final String key = (String) e.nextElement();
if (!key.startsWith(ORG_PROPERTY_PREFIX)) {
continue;
}
orgProperties.put(key.substring(ORG_PROPERTY_PREFIX.length()), (String) properties.get(key));
}
// Load the existing organization or create a new one
try {
JpaOrganization org;
try {
org = (JpaOrganization) persistence.getOrganization(id);
org.setName(name);
for (String serverUrl : serverUrls) {
if (StringUtils.isNotBlank(serverUrl)) {
org.addServer(serverUrl, port);
}
}
org.setAdminRole(adminRole);
org.setAnonymousRole(anonRole);
org.setProperties(orgProperties);
logger.info("Updating organization '{}'", id);
persistence.storeOrganization(org);
fireOrganizationUpdated(org);
} catch (NotFoundException e) {
HashMap<String, Integer> servers = new HashMap<String, Integer>();
for (String serverUrl : serverUrls) {
if (StringUtils.isNotBlank(serverUrl)) {
servers.put(serverUrl, port);
}
}
org = new JpaOrganization(id, name, servers, adminRole, anonRole, orgProperties);
logger.info("Creating organization '{}'", id);
persistence.storeOrganization(org);
fireOrganizationRegistered(org);
}
cache.invalidate();
} catch (OrganizationDatabaseException e) {
logger.error("Unable to register organization '{}': {}", id, e);
}
}
Aggregations