use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class AbstractSearchIndex method deleteAssets.
/**
* Delete an event from the asset manager.
*
* @param organization
* The organization the event is a part of.
* @param user
* The user that is requesting to delete the event.
* @param uid
* The identifier of the event.
* @throws SearchIndexException
* Thrown if there is an issue with deleting the event.
* @throws NotFoundException
* Thrown if the event cannot be found.
*/
public void deleteAssets(String organization, User user, String uid) throws SearchIndexException, NotFoundException {
Event event = EventIndexUtils.getEvent(uid, organization, user, this);
if (event == null)
throw new NotFoundException("No event with id " + uid + " found.");
event.setArchiveVersion(null);
if (toDelete(event)) {
delete(Event.DOCUMENT_TYPE, uid.concat(organization));
} else {
addOrUpdate(event);
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SchedulerMessageReceiverImpl method execute.
@Override
protected void execute(SchedulerItem schedulerItem) {
DublinCoreCatalog dc = schedulerItem.getEvent();
Event event = null;
String organization = getSecurityService().getOrganization().getId();
User user = getSecurityService().getUser();
switch(schedulerItem.getType()) {
case UpdateCatalog:
logger.debug("Received Update Catalog");
// Load or create the corresponding recording event
try {
event = getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
if (isBlank(event.getCreator()))
event.setCreator(getSecurityService().getUser().getName());
if (event.getBlacklisted() == null)
event.setBlacklisted(false);
if (event.getOptedOut() == null)
event.setOptedOut(false);
if (dc != null)
EventIndexUtils.updateEvent(event, dc);
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Update series name if not already done
try {
EventIndexUtils.updateSeriesName(event, organization, user, getSearchIndex());
} catch (SearchIndexException e) {
logger.error("Error updating the series name of the event to index: {}", getStackTrace(e));
}
// Persist the scheduling event
updateEvent(event);
break;
case UpdateAcl:
logger.debug("Received Update ACL");
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setAccessPolicy(AccessControlParser.toJsonSilent(schedulerItem.getAcl()));
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateAgentId:
logger.debug("Received update event '{}' with agent id to '{}'", schedulerItem.getId(), schedulerItem.getAgentId());
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setAgentId(schedulerItem.getAgentId());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateProperties:
logger.debug("Received update event '{}' CA Properties '{}'", schedulerItem.getId(), schedulerItem.getProperties());
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setAgentConfiguration(schedulerItem.getProperties());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateOptOut:
logger.debug("Received Update opt out status");
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setOptedOut(schedulerItem.getOptOut());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateBlacklist:
logger.debug("Received Update blacklist status");
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setBlacklisted(schedulerItem.getBlacklisted());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateReviewStatus:
logger.debug("Received Update review status");
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setReviewStatus(schedulerItem.getReviewStatus());
if (schedulerItem.getReviewDate() != null)
event.setReviewDate(DateTimeSupport.toUTC(schedulerItem.getReviewDate().getTime()));
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateRecordingStatus:
logger.debug("Received Update Recording {}", schedulerItem.getMediaPackageId());
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setRecordingStatus(schedulerItem.getRecordingState());
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case DeleteRecordingStatus:
logger.debug("Received Delete recording status {}", schedulerItem.getMediaPackageId());
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setRecordingStatus(null);
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateEnd:
String endTime = schedulerItem.getEnd() == null ? null : DateTimeSupport.toUTC(schedulerItem.getEnd().getTime());
logger.debug("Received update event '{}' end time '{}'", schedulerItem.getId(), endTime);
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setTechnicalEndTime(endTime);
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdateStart:
String startTime = schedulerItem.getStart() == null ? null : DateTimeSupport.toUTC(schedulerItem.getStart().getTime());
logger.debug("Received update event '{}' start time '{}'", schedulerItem.getId(), startTime);
// Load the corresponding recording event
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setTechnicalStartTime(startTime);
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case UpdatePresenters:
logger.debug("Received update event '{}' with presenters '{}'", schedulerItem.getId(), schedulerItem.getPresenters());
try {
event = EventIndexUtils.getOrCreateEvent(schedulerItem.getMediaPackageId(), organization, user, getSearchIndex());
event.setTechnicalPresenters(new ArrayList<>(schedulerItem.getPresenters()));
} catch (SearchIndexException e) {
logger.error("Error retrieving the recording event from the search index: {}", getStackTrace(e));
return;
}
// Persist the scheduling event
updateEvent(event);
return;
case Delete:
logger.debug("Received Delete Event {}", schedulerItem.getMediaPackageId());
// Remove the scheduling from the search index
try {
getSearchIndex().deleteScheduling(organization, user, schedulerItem.getMediaPackageId());
logger.debug("Scheduled recording {} removed from the {} search index", schedulerItem.getMediaPackageId(), getSearchIndex().getIndexName());
} catch (NotFoundException e) {
logger.warn("Scheduled recording {} not found for deletion", schedulerItem.getMediaPackageId());
} catch (SearchIndexException e) {
logger.error("Error deleting the recording event from the search index: {}", getStackTrace(e));
return;
}
return;
default:
throw new IllegalArgumentException("Unhandled type of SchedulerItem");
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class AssetManagerMessageReceiverImpl method handleMessage.
/**
* Handle a delete message.
*/
private void handleMessage(DeleteEpisode msg) {
final String eventId = msg.getMediaPackageId();
final String organization = getSecurityService().getOrganization().getId();
final User user = getSecurityService().getUser();
logger.debug("Received AssetManager delete episode message {}", eventId);
// Remove the archived entry from the search index
try {
getSearchIndex().deleteAssets(organization, user, eventId);
logger.debug("Archived media package {} removed from admin ui search index", eventId);
} catch (NotFoundException e) {
logger.warn("Archived media package {} not found for deletion", eventId);
} catch (SearchIndexException e) {
logger.error("Error deleting the archived entry {} from the search index: {}", eventId, ExceptionUtils.getStackTrace(e));
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method deleteSeries.
/*
* (non-Javadoc)
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#deleteSeries(java.lang.String)
*/
@Override
public void deleteSeries(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("Series with ID " + seriesId + " does not exist");
}
// Ensure this user is allowed to delete 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);
}
}
em.remove(entity);
tx.commit();
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not delete series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
use of org.opencastproject.util.NotFoundException in project opencast by opencast.
the class SeriesServiceDatabaseImpl method getSeries.
/**
* {@inheritDoc}
*
* @see org.opencastproject.series.impl.SeriesServiceDatabase#getSeries(java.lang.String)
*/
@Override
public DublinCoreCatalog getSeries(String seriesId) throws NotFoundException, SeriesServiceDatabaseException {
EntityManager em = emf.createEntityManager();
EntityTransaction tx = em.getTransaction();
try {
tx.begin();
SeriesEntity entity = getSeriesEntity(seriesId, em);
if (entity == null) {
throw new NotFoundException("No series with id=" + seriesId + " exists");
}
// Ensure this user is allowed to read this series
String accessControlXml = entity.getAccessControl();
if (accessControlXml != null) {
AccessControlList acl = AccessControlParser.parseAcl(accessControlXml);
User currentUser = securityService.getUser();
Organization currentOrg = securityService.getOrganization();
// There are several reasons a user may need to load a series: to read content, to edit it, or add content
if (!AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.READ.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.CONTRIBUTE.toString()) && !AccessControlUtil.isAuthorized(acl, currentUser, currentOrg, Permissions.Action.WRITE.toString())) {
throw new UnauthorizedException(currentUser + " is not authorized to see series " + seriesId);
}
}
return dcService.load(IOUtils.toInputStream(entity.getDublinCoreXML(), "UTF-8"));
} catch (NotFoundException e) {
throw e;
} catch (Exception e) {
logger.error("Could not update series: {}", e.getMessage());
if (tx.isActive()) {
tx.rollback();
}
throw new SeriesServiceDatabaseException(e);
} finally {
em.close();
}
}
Aggregations