Search in sources :

Example 6 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class IndexServiceImpl method getTechnicalPresenters.

/**
 * Processes the combined usernames and free text entries of the presenters (creator) field into a list of presenters
 * using the full names of the users if available and adds the usernames to a set of technical presenters.
 *
 * @param eventMetadata
 *          The metadata list that has the presenter (creator) field to pull the list of presenters from.
 * @return A {@link Tuple} with a list of friendly presenter names and a set of user names if available for the
 *         presenters.
 */
protected Tuple<List<String>, Set<String>> getTechnicalPresenters(MetadataCollection eventMetadata) {
    MetadataField<?> presentersMetadataField = eventMetadata.getOutputFields().get(DublinCore.PROPERTY_CREATOR.getLocalName());
    List<String> presenters = new ArrayList<>();
    Set<String> technicalPresenters = new HashSet<>();
    for (String presenter : MetadataUtils.getIterableStringMetadata(presentersMetadataField)) {
        User user = userDirectoryService.loadUser(presenter);
        if (user == null) {
            presenters.add(presenter);
        } else {
            String fullname = StringUtils.isNotBlank(user.getName()) ? user.getName() : user.getUsername();
            presenters.add(fullname);
            technicalPresenters.add(user.getUsername());
        }
    }
    return Tuple.tuple(presenters, technicalPresenters);
}
Also used : User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 7 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class ContributorsListProvider method getListWithTechnicalPresenters.

/**
 * Get the contributors list including usernames and organizations for the users available.
 *
 * @param query
 *          The query for the list including limit and offset.
 * @return The {@link Map} including all of the contributors.
 */
protected Map<String, String> getListWithTechnicalPresenters(ResourceListQuery query) {
    int offset = 0;
    int limit = 0;
    List<Contributor> contributorsList = new ArrayList<Contributor>();
    HashSet<String> labels = new HashSet<String>();
    Iterator<User> users = userDirectoryService.findUsers("%", offset, limit);
    while (users.hasNext()) {
        User u = users.next();
        if (StringUtils.isNotBlank(u.getName())) {
            contributorsList.add(new Contributor(u.getUsername(), u.getName()));
            labels.add(u.getName());
        } else {
            contributorsList.add(new Contributor(u.getUsername(), u.getUsername()));
            labels.add(u.getUsername());
        }
    }
    addIndexNamesToMap(labels, contributorsList, splitStringList(searchIndex.getTermsForField(EventIndexSchema.PRESENTER, Option.some(new String[] { Event.DOCUMENT_TYPE }))));
    addIndexNamesToMap(labels, contributorsList, splitStringList(searchIndex.getTermsForField(EventIndexSchema.CONTRIBUTOR, Option.some(new String[] { Event.DOCUMENT_TYPE }))));
    addIndexNamesToMap(labels, contributorsList, splitStringList(searchIndex.getTermsForField(SeriesIndexSchema.CONTRIBUTORS, Option.some(new String[] { Event.DOCUMENT_TYPE }))));
    addIndexNamesToMap(labels, contributorsList, splitStringList(searchIndex.getTermsForField(SeriesIndexSchema.ORGANIZERS, Option.some(new String[] { Event.DOCUMENT_TYPE }))));
    addIndexNamesToMap(labels, contributorsList, splitStringList(searchIndex.getTermsForField(SeriesIndexSchema.PUBLISHERS, Option.some(new String[] { Event.DOCUMENT_TYPE }))));
    Collections.sort(contributorsList, new Comparator<Contributor>() {

        @Override
        public int compare(Contributor contributor1, Contributor contributor2) {
            return contributor1.getLabel().compareTo(contributor2.getLabel());
        }
    });
    Map<String, String> contributorMap = new LinkedHashMap<>();
    for (Contributor contributor : contributorsList) {
        contributorMap.put(contributor.getKey(), contributor.getLabel());
    }
    return ListProviderUtil.filterMap(contributorMap, query);
}
Also used : User(org.opencastproject.security.api.User) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) HashSet(java.util.HashSet)

Example 8 with User

use of org.opencastproject.security.api.User 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 9 with User

use of org.opencastproject.security.api.User in project opencast by opencast.

the class ThemeMessageReceiverImpl method execute.

@Override
protected void execute(ThemeItem themeItem) {
    String organization = getSecurityService().getOrganization().getId();
    User user = getSecurityService().getUser();
    switch(themeItem.getType()) {
        case Update:
            SerializableTheme serializableTheme = themeItem.getTheme();
            logger.debug("Update the theme with id '{}', name '{}', description '{}', organization '{}'", serializableTheme.getId(), serializableTheme.getName(), serializableTheme.getDescription(), organization);
            try {
                Theme theme = ThemeIndexUtils.getOrCreate(serializableTheme.getId(), organization, user, getSearchIndex());
                theme.setCreationDate(serializableTheme.getCreationDate());
                theme.setDefault(serializableTheme.isDefault());
                theme.setName(serializableTheme.getName());
                theme.setDescription(serializableTheme.getDescription());
                theme.setCreator(serializableTheme.getCreator());
                theme.setBumperActive(serializableTheme.isBumperActive());
                theme.setBumperFile(serializableTheme.getBumperFile());
                theme.setTrailerActive(serializableTheme.isTrailerActive());
                theme.setTrailerFile(serializableTheme.getTrailerFile());
                theme.setTitleSlideActive(serializableTheme.isTitleSlideActive());
                theme.setTitleSlideBackground(serializableTheme.getTitleSlideBackground());
                theme.setTitleSlideMetadata(serializableTheme.getTitleSlideMetadata());
                theme.setLicenseSlideActive(serializableTheme.isLicenseSlideActive());
                theme.setLicenseSlideBackground(serializableTheme.getLicenseSlideBackground());
                theme.setLicenseSlideDescription(serializableTheme.getLicenseSlideDescription());
                theme.setWatermarkActive(serializableTheme.isWatermarkActive());
                theme.setWatermarkFile(serializableTheme.getWatermarkFile());
                theme.setWatermarkPosition(serializableTheme.getWatermarkPosition());
                getSearchIndex().addOrUpdate(theme);
            } catch (SearchIndexException e) {
                logger.error("Error storing the theme {} to the search index: {}", serializableTheme.getId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            break;
        case Delete:
            logger.debug("Received Delete Theme Event {}", themeItem.getThemeId());
            // Remove the theme from the search index
            try {
                getSearchIndex().delete(Theme.DOCUMENT_TYPE, Long.toString(themeItem.getThemeId()).concat(organization));
                logger.debug("Theme {} removed from {} search index", themeItem.getThemeId(), getSearchIndex().getIndexName());
            } catch (SearchIndexException e) {
                logger.error("Error deleting the group {} from the search index: {}", themeItem.getThemeId(), ExceptionUtils.getStackTrace(e));
                return;
            }
            return;
        default:
            throw new IllegalArgumentException("Unhandled type of ThemeItem");
    }
}
Also used : User(org.opencastproject.security.api.User) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) SerializableTheme(org.opencastproject.message.broker.api.theme.SerializableTheme) Theme(org.opencastproject.index.service.impl.index.theme.Theme) SerializableTheme(org.opencastproject.message.broker.api.theme.SerializableTheme)

Example 10 with User

use of org.opencastproject.security.api.User 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)

Aggregations

User (org.opencastproject.security.api.User)156 Organization (org.opencastproject.security.api.Organization)61 JaxbUser (org.opencastproject.security.api.JaxbUser)60 JaxbRole (org.opencastproject.security.api.JaxbRole)49 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)44 SecurityService (org.opencastproject.security.api.SecurityService)43 NotFoundException (org.opencastproject.util.NotFoundException)32 Before (org.junit.Before)31 Test (org.junit.Test)27 ArrayList (java.util.ArrayList)26 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)24 JaxbOrganization (org.opencastproject.security.api.JaxbOrganization)23 AccessControlList (org.opencastproject.security.api.AccessControlList)21 Role (org.opencastproject.security.api.Role)21 UserDirectoryService (org.opencastproject.security.api.UserDirectoryService)21 HashSet (java.util.HashSet)20 OrganizationDirectoryService (org.opencastproject.security.api.OrganizationDirectoryService)18 JpaUser (org.opencastproject.security.impl.jpa.JpaUser)17 IOException (java.io.IOException)16 MediaPackage (org.opencastproject.mediapackage.MediaPackage)16