Search in sources :

Example 6 with SecurityContext

use of org.opencastproject.security.util.SecurityContext in project opencast by opencast.

the class IndexServiceImpl method updateCommentCatalog.

@Override
public void updateCommentCatalog(final Event event, final List<EventComment> comments) throws Exception {
    final SecurityContext securityContext = new SecurityContext(securityService, securityService.getOrganization(), securityService.getUser());
    executorService.execute(new Runnable() {

        @Override
        public void run() {
            securityContext.runInContext(new Effect0() {

                @Override
                protected void run() {
                    try {
                        MediaPackage mediaPackage = getEventMediapackage(event);
                        updateMediaPackageCommentCatalog(mediaPackage, comments);
                        switch(getEventSource(event)) {
                            case WORKFLOW:
                                logger.info("Update workflow mediapacakge {} with updated comments catalog.", event.getIdentifier());
                                Opt<WorkflowInstance> workflowInstance = getCurrentWorkflowInstance(event.getIdentifier());
                                if (workflowInstance.isNone()) {
                                    logger.error("No workflow instance for event {} found!", event.getIdentifier());
                                    throw new IndexServiceException("No workflow instance found for event " + event.getIdentifier());
                                }
                                WorkflowInstance instance = workflowInstance.get();
                                instance.setMediaPackage(mediaPackage);
                                updateWorkflowInstance(instance);
                                break;
                            case ARCHIVE:
                                logger.info("Update archive mediapacakge {} with updated comments catalog.", event.getIdentifier());
                                assetManager.takeSnapshot(DEFAULT_OWNER, mediaPackage);
                                break;
                            case SCHEDULE:
                                logger.info("Update scheduled mediapacakge {} with updated comments catalog.", event.getIdentifier());
                                schedulerService.updateEvent(event.getIdentifier(), Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mediaPackage), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
                                break;
                            default:
                                logger.error("Unkown event source {}!", event.getSource().toString());
                        }
                    } catch (Exception e) {
                        logger.error("Unable to update event {} comment catalog: {}", event.getIdentifier(), getStackTrace(e));
                    }
                }
            });
        }
    });
}
Also used : Effect0(org.opencastproject.util.data.Effect0) SecurityContext(org.opencastproject.security.util.SecurityContext) MediaPackage(org.opencastproject.mediapackage.MediaPackage) WorkflowInstance(org.opencastproject.workflow.api.WorkflowInstance) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) IngestException(org.opencastproject.ingest.api.IngestException) WebApplicationException(javax.ws.rs.WebApplicationException) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) EventCommentException(org.opencastproject.event.comment.EventCommentException) IOException(java.io.IOException) JSONException(org.codehaus.jettison.json.JSONException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) ParseException(java.text.ParseException) SeriesException(org.opencastproject.series.api.SeriesException) WorkflowException(org.opencastproject.workflow.api.WorkflowException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) WorkflowDatabaseException(org.opencastproject.workflow.api.WorkflowDatabaseException) AssetManagerException(org.opencastproject.assetmanager.api.AssetManagerException)

Aggregations

SecurityContext (org.opencastproject.security.util.SecurityContext)6 Effect0 (org.opencastproject.util.data.Effect0)5 CancellationException (java.util.concurrent.CancellationException)4 ExecutionException (java.util.concurrent.ExecutionException)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 RestQuery (org.opencastproject.util.doc.rest.RestQuery)4 IOException (java.io.IOException)2 File (java.io.File)1 ParseException (java.text.ParseException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONException (org.codehaus.jettison.json.JSONException)1 AssetManagerException (org.opencastproject.assetmanager.api.AssetManagerException)1 EventCommentException (org.opencastproject.event.comment.EventCommentException)1 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)1 IngestException (org.opencastproject.ingest.api.IngestException)1 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)1 MediaPackage (org.opencastproject.mediapackage.MediaPackage)1 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)1 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)1