Search in sources :

Example 31 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventsEndpoint method extendEventsStatusOverview.

private void extendEventsStatusOverview(List<Field> fields, Series series) throws SearchIndexException {
    EventSearchQuery query = new EventSearchQuery(getSecurityService().getOrganization().getId(), getSecurityService().getUser()).withoutActions().withSeriesId(series.getIdentifier());
    SearchResult<Event> result = externalIndex.getByQuery(query);
    // collect recording statuses
    int blacklisted = 0;
    int optOut = 0;
    int ready = 0;
    for (SearchResultItem<Event> item : result.getItems()) {
        Event event = item.getSource();
        if (event.getSchedulingStatus() == null)
            continue;
        SchedulingStatus schedulingStatus = SchedulingStatus.valueOf(event.getSchedulingStatus());
        if (SchedulingStatus.BLACKLISTED.equals(schedulingStatus)) {
            blacklisted++;
        } else if (series.isOptedOut() || SchedulingStatus.OPTED_OUT.equals(schedulingStatus)) {
            optOut++;
        } else {
            ready++;
        }
    }
    fields.add(f("events", obj(f("BLACKLISTED", v(blacklisted)), f("OPTED_OUT", v(optOut)), f("READY", v(ready)))));
}
Also used : EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Event(org.opencastproject.index.service.impl.index.event.Event) SchedulingStatus(org.opencastproject.index.service.impl.index.event.Event.SchedulingStatus)

Example 32 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventsEndpointTest method testSerializationOfAcl.

@Ignore
@Test
public void testSerializationOfAcl() throws IOException {
    String emptyAclJson = IOUtils.toString(getClass().getResource("/acl-empty.json"));
    // Test empty acl
    AccessControlList acl = new AccessControlList();
    Event event = new Event();
    event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
    Response result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
    assertTrue(result.getMetadata().get("Content-Type") != null);
    assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
    assertThat(emptyAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
    // Test acl with one entry
    String oneAclJson = IOUtils.toString(getClass().getResource("/acl-one.json"));
    AccessControlEntry ace = new AccessControlEntry("ROLE_ADMIN", "write", true);
    acl = new AccessControlList(ace);
    event = new Event();
    event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
    result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
    assertTrue(result.getMetadata().get("Content-Type") != null);
    assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
    assertThat(oneAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
    // Test acl with many entries
    String manyAclJson = IOUtils.toString(getClass().getResource("/acl-many.json"));
    AccessControlEntry ace1 = new AccessControlEntry("ROLE_ADMIN", "write", true);
    AccessControlEntry ace2 = new AccessControlEntry("ROLE_USER", "read", true);
    acl = new AccessControlList(ace1, ace2);
    event = new Event();
    event.setAccessPolicy(AccessControlParser.toJsonSilent(acl));
    result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, arr(AclUtils.serializeAclToJson(acl)));
    assertTrue(result.getMetadata().get("Content-Type") != null);
    assertEquals("application/" + ApiVersion.CURRENT_VERSION + "+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
    assertThat(manyAclJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) Response(javax.ws.rs.core.Response) Event(org.opencastproject.index.service.impl.index.event.Event) AccessControlEntry(org.opencastproject.security.api.AccessControlEntry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 33 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventsEndpointTest method testGetEventsJsonResponse.

@Ignore
@Test
public void testGetEventsJsonResponse() throws Exception {
    String eventJson = IOUtils.toString(getClass().getResource("/events.json"));
    String acceptHeader = "application/" + ApiVersion.CURRENT_VERSION.toExternalForm() + "+" + ApiFormat.JSON;
    List<IndexObject> events = new ArrayList<IndexObject>();
    List<String> contributors = new ArrayList<String>();
    contributors.add("Physics Department");
    List<Publication> publications = getExamplePublications();
    Event event1 = new Event("e6aeb8df-a852-46cd-8128-b89de696f20e", defaultOrg.getId());
    event1.setArchiveVersion(2L);
    event1.setCreated("2015-03-12T10:38:54Z");
    event1.setCreator("Opencast Administrator");
    event1.setContributors(contributors);
    event1.setDescription("Cooling without moving parts and using only heat as an input");
    event1.setDuration(7200000L);
    event1.setHasPreview(true);
    event1.setLocation("physics-e-01");
    List<String> presenters = new ArrayList<String>();
    presenters.add("Prof. A. Einstein");
    event1.setPresenters(presenters);
    event1.setPublications(publications);
    event1.setWorkflowState(WorkflowState.SUCCEEDED);
    event1.setRecordingStartDate("2015-03-20T04:00:00Z");
    event1.setSubject("Space Final Frontier");
    event1.setTitle("Einstein refrigerator");
    events.add(event1);
    Event event2 = new Event("f5aeb8df-a852-46cd-8128-b89de696f20e", defaultOrg.getId());
    event2.setArchiveVersion(5L);
    event2.setCreated("2015-03-12T10:38:54Z");
    event2.setCreator("Opencast Administrator");
    event2.setContributors(contributors);
    event2.setDescription("The history of the universe from the big bang to black holes");
    event2.setDuration(7200000L);
    event2.setHasPreview(true);
    event2.setLocation("physics-e-02");
    presenters = new ArrayList<String>();
    presenters.add("Prof. Stephen Hawking");
    event2.setPresenters(presenters);
    event2.setPublications(publications);
    event2.setWorkflowState(WorkflowState.SUCCEEDED);
    event2.setRecordingStartDate("2015-03-20T04:00:00Z");
    event2.setSubject("Space Final Frontier, Mathematics");
    event2.setTitle("The Theory of Everything");
    events.add(event2);
    EventsEndpoint endpoint = new EventsEndpoint();
    Response result = endpoint.getJsonEvents(acceptHeader, events, false, false, false, false);
    assertTrue(result.getMetadata().get("Content-Type") != null);
    assertEquals("application/v1.0.0+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
    assertThat(eventJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) IndexObject(org.opencastproject.index.service.impl.index.IndexObject) Publication(org.opencastproject.mediapackage.Publication) Event(org.opencastproject.index.service.impl.index.event.Event) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 34 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class EventsEndpointTest method testGetEventJsonResponse.

@Ignore
@Test
public void testGetEventJsonResponse() throws Exception {
    String eventJson = IOUtils.toString(getClass().getResource("/event-single.json"));
    List<String> contributors = new ArrayList<String>();
    contributors.add("Physics Department");
    List<Publication> publications = getExamplePublications();
    Event event = new Event("e6aeb8df-a852-46cd-8128-b89de696f20e", defaultOrg.getId());
    event.setArchiveVersion(2L);
    event.setCreated("2015-03-12T10:38:54Z");
    event.setCreator("Opencast Administrator");
    event.setContributors(contributors);
    event.setDescription("Cooling without moving parts and using only heat as an input");
    event.setDuration(7200000L);
    event.setHasPreview(true);
    event.setLocation("physics-e-01");
    List<String> presenters = new ArrayList<String>();
    presenters.add("Prof. A. Einstein");
    event.setPresenters(presenters);
    event.setPublications(publications);
    event.setWorkflowState(WorkflowState.SUCCEEDED);
    event.setRecordingStartDate("2015-03-20T04:00:00Z");
    event.setSubject("Space Final Frontier, Chemistry");
    event.setTitle("Einstein refrigerator");
    EventsEndpoint endpoint = new EventsEndpoint();
    Response result = ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, endpoint.eventToJSON(event, false, false, false, false));
    assertTrue(result.getMetadata().get("Content-Type") != null);
    assertEquals("application/v1.0.0+json", result.getMetadata().get("Content-Type").get(0).toString().toLowerCase());
    assertThat(eventJson, SameJSONAs.sameJSONAs(result.getEntity().toString()).allowingAnyArrayOrdering());
}
Also used : Response(javax.ws.rs.core.Response) ArrayList(java.util.ArrayList) Publication(org.opencastproject.mediapackage.Publication) Event(org.opencastproject.index.service.impl.index.event.Event) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 35 with Event

use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.

the class IndexServiceImplTest method testUpdateMediaPackageMetadata.

@Test
public void testUpdateMediaPackageMetadata() throws Exception {
    // mock/initialize dependencies
    String username = "user1";
    String org = "mh_default_org";
    String testResourceLocation = "/events/update-event.json";
    String metadataJson = IOUtils.toString(getClass().getResourceAsStream(testResourceLocation));
    MetadataCollection metadataCollection = new DublinCoreMetadataCollection();
    metadataCollection.addField(MetadataField.createTextMetadataField("title", Opt.some("title"), "EVENTS.EVENTS.DETAILS.METADATA.TITLE", false, true, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextLongMetadataField("creator", Opt.some("creator"), "EVENTS.EVENTS.DETAILS.METADATA.PRESENTERS", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    metadataCollection.addField(MetadataField.createTextMetadataField("isPartOf", Opt.some("isPartOf"), "EVENTS.EVENTS.DETAILS.METADATA.SERIES", false, false, Opt.none(), Opt.none(), Opt.none(), Opt.none(), Opt.none()));
    MetadataList metadataList = new MetadataList(metadataCollection, metadataJson);
    String eventId = "event-1";
    Event event = new Event(eventId, org);
    event.setTitle("Test Event 1");
    SearchQuery query = EasyMock.createMock(SearchQuery.class);
    EasyMock.expect(query.getLimit()).andReturn(100);
    EasyMock.expect(query.getOffset()).andReturn(0);
    EasyMock.replay(query);
    SearchResultItemImpl<Event> searchResultItem = new SearchResultItemImpl<>(1.0, event);
    SearchResultImpl<Event> searchResult = new SearchResultImpl<>(query, 0, 0);
    searchResult.addResultItem(searchResultItem);
    SecurityService securityService = setupSecurityService(username, org);
    AbstractSearchIndex index = EasyMock.createMock(AbstractSearchIndex.class);
    MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().loadFromXml(getClass().getResourceAsStream("/events/update-event-mp.xml"));
    EasyMock.expect(index.getByQuery(EasyMock.anyObject(EventSearchQuery.class))).andReturn(searchResult);
    EasyMock.replay(index);
    Workspace workspace = EasyMock.createMock(Workspace.class);
    EasyMock.expect(workspace.put(EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyString(), EasyMock.anyObject())).andReturn(getClass().getResource("/dublincore.xml").toURI()).anyTimes();
    EasyMock.expect(workspace.read(EasyMock.anyObject())).andAnswer(() -> getClass().getResourceAsStream("/dublincore.xml")).anyTimes();
    EasyMock.replay(workspace);
    CommonEventCatalogUIAdapter commonEventCatalogUIAdapter = setupCommonCatalogUIAdapter(workspace).getA();
    // Using scheduler as the source of the media package here.
    SchedulerService schedulerService = EasyMock.createMock(SchedulerService.class);
    EasyMock.expect(schedulerService.getMediaPackage(EasyMock.anyString())).andReturn(mp);
    Capture<Opt<MediaPackage>> mpCapture = new Capture<>();
    schedulerService.updateEvent(EasyMock.anyString(), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.capture(mpCapture), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyObject(Opt.class), EasyMock.anyString());
    EasyMock.expectLastCall();
    EasyMock.replay(schedulerService);
    SeriesService seriesService = EasyMock.createMock(SeriesService.class);
    DublinCoreCatalog seriesDC = DublinCores.read(getClass().getResourceAsStream("/events/update-event-series.xml"));
    EasyMock.expect(seriesService.getSeries(EasyMock.anyString())).andReturn(seriesDC);
    EasyMock.expect(seriesService.getSeriesAccessControl(EasyMock.anyString())).andReturn(null);
    EasyMock.expect(seriesService.getSeriesElements(EasyMock.anyString())).andReturn(Opt.none());
    EasyMock.replay(seriesService);
    // create service
    IndexServiceImpl indexService = new IndexServiceImpl();
    indexService.setSecurityService(securityService);
    indexService.setSchedulerService(schedulerService);
    indexService.setCommonEventCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.addCatalogUIAdapter(commonEventCatalogUIAdapter);
    indexService.setSeriesService(seriesService);
    indexService.setWorkspace(workspace);
    MetadataList updateEventMetadata = indexService.updateEventMetadata(org, metadataList, index);
    Assert.assertTrue(mpCapture.hasCaptured());
    Assert.assertEquals("series-1", mp.getSeries());
    Assert.assertEquals(1, mp.getCatalogs(MediaPackageElements.SERIES).length);
}
Also used : DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) SearchQuery(org.opencastproject.matterhorn.search.SearchQuery) SearchResultItemImpl(org.opencastproject.matterhorn.search.impl.SearchResultItemImpl) SchedulerService(org.opencastproject.scheduler.api.SchedulerService) EventSearchQuery(org.opencastproject.index.service.impl.index.event.EventSearchQuery) Capture(org.easymock.Capture) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) AbstractSearchIndex(org.opencastproject.index.service.impl.index.AbstractSearchIndex) Opt(com.entwinemedia.fn.data.Opt) SearchResultImpl(org.opencastproject.matterhorn.search.impl.SearchResultImpl) SeriesService(org.opencastproject.series.api.SeriesService) SecurityService(org.opencastproject.security.api.SecurityService) MediaPackage(org.opencastproject.mediapackage.MediaPackage) Event(org.opencastproject.index.service.impl.index.event.Event) CommonEventCatalogUIAdapter(org.opencastproject.index.service.catalog.adapter.events.CommonEventCatalogUIAdapter) DublinCoreMetadataCollection(org.opencastproject.index.service.catalog.adapter.DublinCoreMetadataCollection) MetadataCollection(org.opencastproject.metadata.dublincore.MetadataCollection) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Workspace(org.opencastproject.workspace.api.Workspace) Test(org.junit.Test)

Aggregations

Event (org.opencastproject.index.service.impl.index.event.Event)67 Path (javax.ws.rs.Path)35 RestQuery (org.opencastproject.util.doc.rest.RestQuery)34 NotFoundException (org.opencastproject.util.NotFoundException)26 WebApplicationException (javax.ws.rs.WebApplicationException)24 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)22 Produces (javax.ws.rs.Produces)21 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)19 MediaPackage (org.opencastproject.mediapackage.MediaPackage)19 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)19 ParseException (java.text.ParseException)17 JSONException (org.codehaus.jettison.json.JSONException)17 UrlSigningException (org.opencastproject.security.urlsigning.exception.UrlSigningException)17 GET (javax.ws.rs.GET)16 AclServiceException (org.opencastproject.authorization.xacml.manager.api.AclServiceException)16 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)16 EventCommentException (org.opencastproject.event.comment.EventCommentException)15 WorkflowDatabaseException (org.opencastproject.workflow.api.WorkflowDatabaseException)15 JobEndpointException (org.opencastproject.adminui.exception.JobEndpointException)14 WorkflowStateException (org.opencastproject.workflow.api.WorkflowStateException)14