use of org.opencastproject.security.impl.jpa.JpaOrganization in project opencast by opencast.
the class OrganizationDatabaseImpl method getOrganizationByHost.
@Override
public Organization getOrganizationByHost(String host, int port) throws OrganizationDatabaseException, NotFoundException {
EntityManager em = null;
try {
em = emf.createEntityManager();
Query q = em.createNamedQuery("Organization.findByHost");
q.setParameter("serverName", host);
q.setParameter("port", port);
return (JpaOrganization) q.getSingleResult();
} catch (NoResultException e) {
throw new NotFoundException();
} catch (Exception e) {
throw new OrganizationDatabaseException(e);
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.security.impl.jpa.JpaOrganization in project opencast by opencast.
the class OrganizationDatabaseImpl method containsOrganization.
/**
* @see org.opencastproject.kernel.security.persistence.OrganizationDatabase#containsOrganization(String)
*/
@Override
public boolean containsOrganization(String orgId) throws OrganizationDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
JpaOrganization organization = getOrganizationEntity(orgId, em);
return organization != null ? true : false;
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.security.impl.jpa.JpaOrganization in project opencast by opencast.
the class OrganizationDatabaseImpl method getOrganization.
/**
* @see org.opencastproject.kernel.security.persistence.OrganizationDatabase#getOrganization(java.lang.String)
*/
@Override
public Organization getOrganization(String id) throws NotFoundException, OrganizationDatabaseException {
EntityManager em = null;
try {
em = emf.createEntityManager();
JpaOrganization entity = getOrganizationEntity(id, em);
if (entity == null)
throw new NotFoundException();
return entity;
} finally {
if (em != null)
em.close();
}
}
use of org.opencastproject.security.impl.jpa.JpaOrganization 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);
}
}
use of org.opencastproject.security.impl.jpa.JpaOrganization in project opencast by opencast.
the class OrganizationDatabaseImpl method getOrganizationEntity.
/**
* Return the persisted organization entity by its id
*
* @param id
* the organization id
* @param em
* an open entity manager
* @return the organization or <code>null</code> if not found
* @throws OrganizationDatabaseException
* if there is a problem communicating with the underlying data store
*/
private JpaOrganization getOrganizationEntity(String id, EntityManager em) throws OrganizationDatabaseException {
Query q = em.createNamedQuery("Organization.findById");
q.setParameter("id", id);
try {
return (JpaOrganization) q.getSingleResult();
} catch (NoResultException e) {
return null;
} catch (Exception e) {
throw new OrganizationDatabaseException(e);
}
}
Aggregations