Search in sources :

Example 6 with EventCatalogUIAdapter

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

the class EventsEndpoint method getEventMetadata.

protected Opt<MetadataList> getEventMetadata(Event event) throws IndexServiceException, Exception {
    MetadataList metadataList = new MetadataList();
    List<EventCatalogUIAdapter> catalogUIAdapters = getEventCatalogUIAdapters();
    catalogUIAdapters.remove(this.eventCatalogUIAdapter);
    MediaPackage mediaPackage = indexService.getEventMediapackage(event);
    if (catalogUIAdapters.size() > 0) {
        for (EventCatalogUIAdapter catalogUIAdapter : catalogUIAdapters) {
            // TODO: This is very slow:
            MetadataCollection fields = catalogUIAdapter.getFields(mediaPackage);
            if (fields != null)
                metadataList.add(catalogUIAdapter, fields);
        }
    }
    // TODO: This is slow:
    MetadataCollection collection = EventUtils.getEventMetadata(event, eventCatalogUIAdapter);
    ExternalMetadataUtils.changeSubjectToSubjects(collection);
    ExternalMetadataUtils.removeCollectionList(collection);
    metadataList.add(eventCatalogUIAdapter, collection);
    if (WorkflowInstance.WorkflowState.RUNNING.toString().equals(event.getWorkflowState())) {
        metadataList.setLocked(Locked.WORKFLOW_RUNNING);
    }
    return Opt.some(metadataList);
}
Also used : MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) MediaPackage(org.opencastproject.mediapackage.MediaPackage) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection)

Example 7 with EventCatalogUIAdapter

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

the class EventsEndpoint method deserializeMetadataList.

/**
 * Change the simplified fields of key values provided to the external api into a {@link MetadataList}.
 *
 * @param json
 *          The json string that contains an array of metadata field lists for the different catalogs.
 * @return A {@link MetadataList} with the fields populated with the values provided.
 * @throws ParseException
 *           Thrown if unable to parse the json string.
 * @throws NotFoundException
 *           Thrown if unable to find the catalog or field that the json refers to.
 */
protected MetadataList deserializeMetadataList(String json) throws ParseException, NotFoundException {
    MetadataList metadataList = new MetadataList();
    JSONParser parser = new JSONParser();
    JSONArray jsonCatalogs = (JSONArray) parser.parse(json);
    for (int i = 0; i < jsonCatalogs.size(); i++) {
        JSONObject catalog = (JSONObject) jsonCatalogs.get(i);
        String flavorString = catalog.get("flavor").toString();
        if (StringUtils.trimToNull(flavorString) == null) {
            throw new IllegalArgumentException("Unable to create new event as no flavor was given for one of the metadata collections");
        }
        MediaPackageElementFlavor flavor = MediaPackageElementFlavor.parseFlavor(flavorString);
        MetadataCollection collection = null;
        EventCatalogUIAdapter adapter = null;
        for (EventCatalogUIAdapter eventCatalogUIAdapter : getEventCatalogUIAdapters()) {
            if (eventCatalogUIAdapter.getFlavor().equals(flavor)) {
                adapter = eventCatalogUIAdapter;
                collection = eventCatalogUIAdapter.getRawFields();
            }
        }
        if (collection == null) {
            throw new IllegalArgumentException(String.format("Unable to find an EventCatalogUIAdapter with Flavor '%s'", flavorString));
        }
        String fieldsJson = catalog.get("fields").toString();
        if (StringUtils.trimToNull(fieldsJson) != null) {
            Map<String, String> fields = RequestUtils.getKeyValueMap(fieldsJson);
            for (String key : fields.keySet()) {
                MetadataField<?> field = collection.getOutputFields().get(key);
                if (field == null) {
                    throw new NotFoundException(String.format("Cannot find a metadata field with id '%s' from Catalog with Flavor '%s'.", key, flavorString));
                }
                collection.removeField(field);
                collection.addField(MetadataField.copyMetadataFieldWithValue(field, fields.get(key)));
            }
        }
        metadataList.add(adapter, collection);
    }
    return metadataList;
}
Also used : JSONArray(org.json.simple.JSONArray) NotFoundException(org.opencastproject.util.NotFoundException) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) JSONObject(org.json.simple.JSONObject) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) JSONParser(org.json.simple.parser.JSONParser) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection)

Example 8 with EventCatalogUIAdapter

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

the class CommentSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    conflictNotifier = new CommentSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
}
Also used : JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) Before(org.junit.Before)

Example 9 with EventCatalogUIAdapter

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

the class EmailSchedulerConflictNotifierTest method setUp.

@Before
public void setUp() throws Exception {
    Dictionary<String, String> properties = new Hashtable<>();
    properties.put("to", "test@test.com");
    properties.put("subject", "Test email scheduler conflict");
    properties.put("template", "Dear Administrator,\n\nthe following recording schedules are conflicting with existing ones:\n\n${recordings}\nBye!");
    SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
    EasyMock.expect(securityService.getUser()).andReturn(new JaxbUser("admin", "provider", new DefaultOrganization(), new JaxbRole("admin", new DefaultOrganization(), "test"))).anyTimes();
    EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
    EasyMock.replay(securityService);
    Workspace workspace = EasyMock.createNiceMock(Workspace.class);
    EasyMock.expect(workspace.get(EasyMock.anyObject(URI.class))).andReturn(IoSupport.classPathResourceAsFile("/dublincore.xml").get()).anyTimes();
    EasyMock.replay(workspace);
    EventCatalogUIAdapter episodeAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(episodeAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("dublincore", "episode")).anyTimes();
    EasyMock.expect(episodeAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(episodeAdapter);
    EventCatalogUIAdapter extendedAdapter = EasyMock.createMock(EventCatalogUIAdapter.class);
    EasyMock.expect(extendedAdapter.getFlavor()).andReturn(new MediaPackageElementFlavor("extended", "episode")).anyTimes();
    EasyMock.expect(extendedAdapter.getOrganization()).andReturn(new DefaultOrganization().getId()).anyTimes();
    EasyMock.replay(extendedAdapter);
    BundleContext bundleContext = EasyMock.createNiceMock(BundleContext.class);
    EasyMock.expect(bundleContext.getProperty(OpencastConstants.SERVER_URL_PROPERTY)).andReturn("http://localhost:8080").anyTimes();
    EasyMock.replay(bundleContext);
    ComponentContext componentContext = EasyMock.createNiceMock(ComponentContext.class);
    EasyMock.expect(componentContext.getBundleContext()).andReturn(bundleContext).anyTimes();
    EasyMock.expect(componentContext.getProperties()).andReturn(new Hashtable<String, Object>()).anyTimes();
    EasyMock.replay(componentContext);
    conflictNotifier = new EmailSchedulerConflictNotifier();
    conflictNotifier.setSecurityService(securityService);
    conflictNotifier.setWorkspace(workspace);
    conflictNotifier.addCatalogUIAdapter(episodeAdapter);
    conflictNotifier.addCatalogUIAdapter(extendedAdapter);
    conflictNotifier.activate(componentContext);
    conflictNotifier.updated(properties);
}
Also used : ComponentContext(org.osgi.service.component.ComponentContext) Hashtable(java.util.Hashtable) JaxbUser(org.opencastproject.security.api.JaxbUser) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) JaxbRole(org.opencastproject.security.api.JaxbRole) SecurityService(org.opencastproject.security.api.SecurityService) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) DefaultOrganization(org.opencastproject.security.api.DefaultOrganization) Workspace(org.opencastproject.workspace.api.Workspace) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 10 with EventCatalogUIAdapter

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

the class EventsEndpoint method getEventMetadataByType.

private Response getEventMetadataByType(String id, String type) throws IndexServiceException, Exception {
    for (final Event event : indexService.getEvent(id, externalIndex)) {
        Opt<MediaPackageElementFlavor> flavor = getFlavor(type);
        if (flavor.isNone()) {
            return R.badRequest(String.format("Unable to parse type '%s' as a flavor so unable to find the matching catalog.", type));
        }
        // Try the main catalog first as we load it from the index.
        if (flavor.get().equals(eventCatalogUIAdapter.getFlavor())) {
            MetadataCollection collection = EventUtils.getEventMetadata(event, eventCatalogUIAdapter);
            ExternalMetadataUtils.changeSubjectToSubjects(collection);
            ExternalMetadataUtils.removeCollectionList(collection);
            convertStartDateTimeToApiV1(collection);
            ExternalMetadataUtils.changeTypeOrderedTextToText(collection);
            return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, collection.toJSON());
        }
        // Try the other catalogs
        List<EventCatalogUIAdapter> catalogUIAdapters = getEventCatalogUIAdapters();
        catalogUIAdapters.remove(eventCatalogUIAdapter);
        MediaPackage mediaPackage = indexService.getEventMediapackage(event);
        if (catalogUIAdapters.size() > 0) {
            for (EventCatalogUIAdapter catalogUIAdapter : catalogUIAdapters) {
                if (flavor.get().equals(catalogUIAdapter.getFlavor())) {
                    MetadataCollection fields = catalogUIAdapter.getFields(mediaPackage);
                    ExternalMetadataUtils.removeCollectionList(fields);
                    convertStartDateTimeToApiV1(fields);
                    ExternalMetadataUtils.changeTypeOrderedTextToText(fields);
                    return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, fields.toJSON());
                }
            }
        }
        return ApiResponses.notFound("Cannot find a catalog with type '%s' for event with id '%s'.", type, id);
    }
    return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
Also used : CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) EventCatalogUIAdapter(org.opencastproject.metadata.dublincore.EventCatalogUIAdapter) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor)

Aggregations

EventCatalogUIAdapter (org.opencastproject.metadata.dublincore.EventCatalogUIAdapter)12 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)8 MetadataCollection (org.opencastproject.metadata.dublincore.MetadataCollection)7 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)6 CommonEventCatalogUIAdapter (org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter)6 MediaPackage (org.opencastproject.mediapackage.MediaPackage)4 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 JSONArray (org.json.simple.JSONArray)3 JSONParser (org.json.simple.parser.JSONParser)3 Event (org.opencastproject.index.service.impl.index.event.Event)3 DefaultOrganization (org.opencastproject.security.api.DefaultOrganization)3 JaxbRole (org.opencastproject.security.api.JaxbRole)3 JaxbUser (org.opencastproject.security.api.JaxbUser)3 SecurityService (org.opencastproject.security.api.SecurityService)3 NotFoundException (org.opencastproject.util.NotFoundException)3 RestQuery (org.opencastproject.util.doc.rest.RestQuery)3 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2