use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SeriesUpdatedEventHandler method updateEpisodeCatalog.
private boolean updateEpisodeCatalog(MediaPackage mp) throws DistributionException, MediaPackageException, NotFoundException, ServiceRegistryException, IllegalArgumentException, IOException {
// Update the episode catalog
for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
episodeCatalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
episodeCatalog.setChecksum(null);
// Distribute the updated episode dublincore
Job distributionJob = distributionService.distribute(CHANNEL_ID, mp, episodeCatalog.getIdentifier());
JobBarrier barrier = new JobBarrier(null, serviceRegistry, distributionJob);
Result jobResult = barrier.waitForJobs();
if (jobResult.getStatus().get(distributionJob).equals(FINISHED)) {
mp.remove(episodeCatalog);
mp.add(getFromXml(serviceRegistry.getJob(distributionJob.getId()).getPayload()));
} else {
logger.error("Unable to distribute episode catalog {}", episodeCatalog.getIdentifier());
return false;
}
}
return true;
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class WorkflowPermissionsUpdatedEventHandler method handleEvent.
public void handleEvent(final SeriesItem seriesItem) {
// A series or its ACL has been updated. Find any mediapackages with that series, and update them.
logger.debug("Handling {}", seriesItem);
String seriesId = seriesItem.getSeriesId();
// We must be an administrative user to make this query
final User prevUser = securityService.getUser();
final Organization prevOrg = securityService.getOrganization();
try {
securityService.setUser(SecurityUtil.createSystemUser(systemAccount, prevOrg));
// Note: getWorkflowInstances will only return a given number of results (default 20)
WorkflowQuery q = new WorkflowQuery().withSeriesId(seriesId);
WorkflowSet result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
Integer offset = 0;
while (result.size() > 0) {
for (WorkflowInstance instance : result.getItems()) {
if (!instance.isActive())
continue;
Organization org = instance.getOrganization();
securityService.setOrganization(org);
MediaPackage mp = instance.getMediaPackage();
// Update the series XACML file
if (SeriesItem.Type.UpdateAcl.equals(seriesItem.getType())) {
// Build a new XACML file for this mediapackage
authorizationService.setAcl(mp, AclScope.Series, seriesItem.getAcl());
}
// Update the series dublin core
if (SeriesItem.Type.UpdateCatalog.equals(seriesItem.getType())) {
DublinCoreCatalog seriesDublinCore = seriesItem.getMetadata();
mp.setSeriesTitle(seriesDublinCore.getFirst(DublinCore.PROPERTY_TITLE));
// Update the series dublin core
Catalog[] seriesCatalogs = mp.getCatalogs(MediaPackageElements.SERIES);
if (seriesCatalogs.length == 1) {
Catalog c = seriesCatalogs[0];
String filename = FilenameUtils.getName(c.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), c.getIdentifier(), filename, dublinCoreService.serialize(seriesDublinCore));
c.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
c.setChecksum(null);
}
}
// Remove the series catalog and isPartOf from episode catalog
if (SeriesItem.Type.Delete.equals(seriesItem.getType())) {
mp.setSeries(null);
mp.setSeriesTitle(null);
for (Catalog c : mp.getCatalogs(MediaPackageElements.SERIES)) {
mp.remove(c);
try {
workspace.delete(c.getURI());
} catch (NotFoundException e) {
logger.info("No series catalog to delete found {}", c.getURI());
}
}
for (Catalog episodeCatalog : mp.getCatalogs(MediaPackageElements.EPISODE)) {
DublinCoreCatalog episodeDublinCore = DublinCoreUtil.loadDublinCore(workspace, episodeCatalog);
episodeDublinCore.remove(DublinCore.PROPERTY_IS_PART_OF);
String filename = FilenameUtils.getName(episodeCatalog.getURI().toString());
URI uri = workspace.put(mp.getIdentifier().toString(), episodeCatalog.getIdentifier(), filename, dublinCoreService.serialize(episodeDublinCore));
episodeCatalog.setURI(uri);
// setting the URI to a new source so the checksum will most like be invalid
episodeCatalog.setChecksum(null);
}
}
// Update the search index with the modified mediapackage
workflowService.update(instance);
}
offset++;
q = q.withStartPage(offset);
result = workflowService.getWorkflowInstancesForAdministrativeRead(q);
}
} catch (WorkflowException e) {
logger.warn(e.getMessage());
} catch (UnauthorizedException e) {
logger.warn(e.getMessage());
} catch (IOException e) {
logger.warn(e.getMessage());
} finally {
securityService.setOrganization(prevOrg);
securityService.setUser(prevUser);
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SeriesServiceDatabaseImpl method storeSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#storeSeries(org.opencastproject.metadata.dublincore.
* DublinCoreCatalog)
*/
@Override
public DublinCoreCatalog storeSeries(DublinCoreCatalog dc) throws SeriesServiceDatabaseException, UnauthorizedException {
if (dc == null) {
throw new SeriesServiceDatabaseException("Invalid value for Dublin core catalog: null");
}
String seriesId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
String seriesXML;
try {
seriesXML = serializeDublinCore(dc);
} catch (Exception e1) {
logger.error("Could not serialize Dublin Core: {}", e1);
throw new SeriesServiceDatabaseException(e1);
}
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
DublinCoreCatalog newSeries = null;
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
// no series stored, create new entity
entity = new SeriesEntity();
entity.setOrganization(securityService.getOrganization().getId());
entity.setSeriesId(seriesId);
entity.setSeries(seriesXML);
em.persist(entity);
newSeries = dc;
} else {
// Ensure this user is allowed to update this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser + " is not authorized to update series " + seriesId);
}
}
entity.setSeries(seriesXML);
em.merge(entity);
}
tx.commit();
return newSeries;
} catch (Exception e) {
logger.error("Could not update series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SeriesServiceRemoteImpl method updateSeries.
@Override
public DublinCoreCatalog updateSeries(DublinCoreCatalog dc) throws SeriesException, UnauthorizedException {
String seriesId = dc.getFirst(DublinCore.PROPERTY_IDENTIFIER);
HttpPost post = new HttpPost("/");
try {
List<BasicNameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("series", dc.toXmlString()));
post.setEntity(new UrlEncodedFormEntity(params));
} catch (Exception e) {
throw new SeriesException("Unable to assemble a remote series request for updating series " + seriesId, e);
}
HttpResponse response = getResponse(post, SC_NO_CONTENT, SC_CREATED, SC_UNAUTHORIZED);
try {
if (response != null) {
int statusCode = response.getStatusLine().getStatusCode();
if (SC_NO_CONTENT == statusCode) {
logger.info("Successfully updated series {} in the series service", seriesId);
return null;
} else if (SC_UNAUTHORIZED == statusCode) {
throw new UnauthorizedException("Not authorized to update series " + seriesId);
} else if (SC_CREATED == statusCode) {
DublinCoreCatalog catalogImpl = DublinCores.read(response.getEntity().getContent());
logger.info("Successfully created series {} in the series service", seriesId);
return catalogImpl;
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to update series " + seriesId + " using the remote series services: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to update series " + seriesId + " using the remote series services");
}
use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.
the class SeriesServiceRemoteImpl method getSeries.
@Override
public DublinCoreCatalog getSeries(String seriesID) throws SeriesException, NotFoundException, UnauthorizedException {
HttpGet get = new HttpGet(seriesID + ".xml");
HttpResponse response = getResponse(get, SC_OK, SC_NOT_FOUND, SC_UNAUTHORIZED);
try {
if (response != null) {
if (SC_NOT_FOUND == response.getStatusLine().getStatusCode()) {
throw new NotFoundException("Series " + seriesID + " not found in remote series index!");
} else if (SC_UNAUTHORIZED == response.getStatusLine().getStatusCode()) {
throw new UnauthorizedException("Not authorized to get series " + seriesID);
} else {
DublinCoreCatalog dublinCoreCatalog = DublinCores.read(response.getEntity().getContent());
logger.debug("Successfully received series {} from the remote series index", seriesID);
return dublinCoreCatalog;
}
}
} catch (UnauthorizedException e) {
throw e;
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
throw new SeriesException("Unable to parse series from remote series index: " + e);
} finally {
closeConnection(response);
}
throw new SeriesException("Unable to get series from remote series index");
}
Aggregations