Search in sources :

Example 16 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class ConfigurableSeriesDCCatalogUIAdapter method loadDublinCoreCatalog.

protected Opt<DublinCoreCatalog> loadDublinCoreCatalog(String seriesId) {
    try {
        Opt<byte[]> seriesElementData = getSeriesService().getSeriesElementData(requireNonNull(seriesId), flavor.getType());
        if (seriesElementData.isSome()) {
            final DublinCoreCatalog dc = DublinCoreByteFormat.read(seriesElementData.get());
            // Make sure that the catalog has its flavor set.
            // It may happen, when updating a system, that already saved catalogs
            // do not have a flavor.
            dc.setFlavor(flavor);
            dc.addBindings(config.getXmlNamespaceContext());
            return Opt.some(dc);
        } else {
            final DublinCoreCatalog dc = DublinCores.mkStandard();
            dc.addBindings(config.getXmlNamespaceContext());
            dc.setRootTag(new EName(config.getCatalogXmlRootNamespace(), config.getCatalogXmlRootElementName()));
            dc.setFlavor(flavor);
            return Opt.some(dc);
        }
    } catch (SeriesException e) {
        logger.error("Error while loading DublinCore catalog of series '{}': {}", seriesId, ExceptionUtils.getStackTrace(e));
        return Opt.none();
    }
}
Also used : EName(org.opencastproject.mediapackage.EName) SeriesException(org.opencastproject.series.api.SeriesException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 17 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SeriesListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
    Map<String, String> series = new HashMap<String, String>();
    SeriesQuery q = new SeriesQuery().setCount(Integer.MAX_VALUE);
    if (query != null) {
        if (query.hasFilter(FILTER_TEXT)) {
            StringListFilter filter = (StringListFilter) query.getFilter(FILTER_TEXT);
            if (filter.getValue().isSome())
                q.setText(filter.getValue().get());
        }
        if (query.getLimit().isSome())
            q.setCount(query.getLimit().get());
        if (query.getOffset().isSome())
            q.setStartPage(query.getOffset().get());
    }
    List<DublinCoreCatalog> result = null;
    try {
        if (!CONTRIBUTORS.equals(listName) && !ORGANIZERS.equals(listName) && !TITLE_EXTENDED.equals(listName)) {
            return seriesService.getIdTitleMapOfAllSeries();
        }
        result = seriesService.getSeries(q).getCatalogList();
    } catch (SeriesException e) {
        throw new ListProviderException("Error appends on the series service: " + e);
    } catch (UnauthorizedException e) {
        throw new ListProviderException("Unauthorized access to series service: " + e);
    }
    for (DublinCoreCatalog dc : result) {
        if (CONTRIBUTORS.equals(listName)) {
            String contributor = dc.getFirst(DublinCore.PROPERTY_CONTRIBUTOR);
            if (StringUtils.isNotBlank(contributor))
                series.put(contributor, contributor);
        } else if (ORGANIZERS.equals(listName)) {
            String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
            if (StringUtils.isNotBlank(organizer))
                series.put(organizer, organizer);
        } else if (TITLE_EXTENDED.equals(listName)) {
            String created = dc.getFirst(DublinCoreCatalog.PROPERTY_CREATED);
            String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
            StringBuilder sb = new StringBuilder(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
            if (StringUtils.isNotBlank(created) && StringUtils.isNotBlank(organizer)) {
                List<String> extendedTitleData = new ArrayList<>();
                if (StringUtils.isNotBlank(created)) {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(EncodingSchemeUtils.decodeDate(created));
                    extendedTitleData.add(Integer.toString(calendar.get(Calendar.YEAR)));
                }
                if (StringUtils.isNotBlank(organizer))
                    extendedTitleData.add(organizer);
                sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
            }
            series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), sb.toString());
        } else {
            series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
        }
    }
    return series;
}
Also used : SeriesQuery(org.opencastproject.series.api.SeriesQuery) HashMap(java.util.HashMap) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) ListProviderException(org.opencastproject.index.service.exception.ListProviderException) SeriesException(org.opencastproject.series.api.SeriesException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) StringListFilter(org.opencastproject.index.service.resources.list.query.StringListFilter)

Example 18 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog 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");
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) EventIndexUtils.getOrCreateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.getOrCreateEvent) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 19 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class AssetManagerMessageReceiverImpl method handleMessage.

/**
 * Handle an update message.
 */
private void handleMessage(TakeSnapshot msg) {
    logger.debug("Received AssetManager take snapshot message");
    final MediaPackage mp = msg.getMediapackage();
    final Opt<DublinCoreCatalog> episodeDublincore = msg.getEpisodeDublincore();
    final String organization = getSecurityService().getOrganization().getId();
    final User user = getSecurityService().getUser();
    // Load or create the corresponding recording event
    final Event event;
    try {
        event = getOrCreateEvent(mp.getIdentifier().toString(), organization, user, getSearchIndex());
        final AccessControlList acl = msg.getAcl();
        List<ManagedAcl> acls = aclServiceFactory.serviceFor(getSecurityService().getOrganization()).getAcls();
        for (final ManagedAcl managedAcl : AccessInformationUtil.matchAcls(acls, acl)) {
            event.setManagedAcl(managedAcl.getName());
        }
        event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
        event.setArchiveVersion(msg.getVersion());
        if (isBlank(event.getCreator()))
            event.setCreator(getSecurityService().getUser().getName());
        updateEvent(event, mp);
        if (episodeDublincore.isSome()) {
            updateEvent(event, episodeDublincore.get());
        }
    } catch (SearchIndexException e) {
        logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
        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: {}", ExceptionUtils.getStackTrace(e));
    }
    // Persist the scheduling event
    try {
        getSearchIndex().addOrUpdate(event);
        logger.debug("Asset manager entry {} updated in the admin ui search index", event.getIdentifier());
    } catch (SearchIndexException e) {
        logger.error("Error retrieving the recording event from the search index: {}", e.getMessage());
    }
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) ManagedAcl(org.opencastproject.authorization.xacml.manager.api.ManagedAcl) Event(org.opencastproject.index.service.impl.index.event.Event) EventIndexUtils.getOrCreateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.getOrCreateEvent) EventIndexUtils.updateEvent(org.opencastproject.index.service.impl.index.event.EventIndexUtils.updateEvent) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Example 20 with DublinCoreCatalog

use of org.opencastproject.metadata.dublincore.DublinCoreCatalog in project opencast by opencast.

the class SeriesServiceSolrIndex method getDublinCore.

/*
   * (non-Javadoc)
   *
   * @see org.opencastproject.series.impl.SeriesServiceIndex#get(java.lang.String)
   */
@Override
public DublinCoreCatalog getDublinCore(String seriesId) throws SeriesServiceDatabaseException, NotFoundException {
    SolrDocument result = getSolrDocumentByID(seriesId);
    if (result == null) {
        logger.debug("No series exists with ID {}", seriesId);
        throw new NotFoundException("Series with ID " + seriesId + " does not exist");
    } else {
        String dcXML = (String) result.get(SolrFields.XML_KEY);
        DublinCoreCatalog dc;
        try {
            dc = parseDublinCore(dcXML);
        } catch (IOException e) {
            logger.error("Could not parse Dublin core:", e);
            throw new SeriesServiceDatabaseException(e);
        }
        return dc;
    }
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) SeriesServiceDatabaseException(org.opencastproject.series.impl.SeriesServiceDatabaseException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog)

Aggregations

DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)117 MediaPackage (org.opencastproject.mediapackage.MediaPackage)51 NotFoundException (org.opencastproject.util.NotFoundException)46 Test (org.junit.Test)44 Date (java.util.Date)40 IOException (java.io.IOException)30 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)29 URI (java.net.URI)23 AccessControlList (org.opencastproject.security.api.AccessControlList)22 SeriesException (org.opencastproject.series.api.SeriesException)20 ArrayList (java.util.ArrayList)18 Catalog (org.opencastproject.mediapackage.Catalog)18 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)18 EName (org.opencastproject.mediapackage.EName)17 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)17 HashMap (java.util.HashMap)16 HashSet (java.util.HashSet)15 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)15 InputStream (java.io.InputStream)14 AQueryBuilder (org.opencastproject.assetmanager.api.query.AQueryBuilder)14