Search in sources :

Example 1 with TechnicalMetadata

use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.

the class SchedulerUtil method toHumanReadableString.

/**
 * Converts a scheduler event to a human readable string
 *
 * @param workspace
 *          the workspace
 * @param catalogFlavors
 *          the event catalog flavors
 * @param event
 *          the scheduler event
 * @return a human readable string
 */
public static String toHumanReadableString(Workspace workspace, List<MediaPackageElementFlavor> catalogFlavors, SchedulerEvent event) {
    TechnicalMetadata technicalMetadata = event.getTechnicalMetadata();
    StringBuilder sb = new StringBuilder("Event: ").append(CharUtils.LF);
    sb.append("- ").append(event.getEventId()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Version").append(CharUtils.LF);
    sb.append("- ").append(event.getVersion()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Start").append(CharUtils.LF);
    sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getStartDate().getTime())).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("End").append(CharUtils.LF);
    sb.append("- ").append(DateTimeSupport.toUTC(technicalMetadata.getEndDate().getTime())).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Room").append(CharUtils.LF);
    sb.append("- ").append(technicalMetadata.getAgentId()).append(CharUtils.LF);
    sb.append(CharUtils.LF);
    sb.append("Scheduling configuration").append(CharUtils.LF);
    sb.append("- optout: ").append(technicalMetadata.isOptOut()).append(CharUtils.LF);
    for (Entry<String, String> entry : technicalMetadata.getCaptureAgentConfiguration().entrySet()) {
        sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    sb.append("Presenters").append(CharUtils.LF);
    for (String presenter : technicalMetadata.getPresenters()) {
        sb.append("- ").append(presenter).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    sb.append("Workflow configuration").append(CharUtils.LF);
    for (Entry<String, String> entry : technicalMetadata.getWorkflowProperties().entrySet()) {
        sb.append("- ").append(entry.getKey()).append(": ").append(entry.getValue()).append(CharUtils.LF);
    }
    sb.append(CharUtils.LF);
    for (Catalog c : $(event.getMediaPackage().getCatalogs())) {
        if (!catalogFlavors.contains(c.getFlavor()))
            continue;
        DublinCoreCatalog dublinCore;
        try {
            dublinCore = DublinCoreUtil.loadDublinCore(workspace, c);
        } catch (Exception e) {
            logger.error("Unable to read event dublincore: {}", ExceptionUtils.getStackTrace(e));
            continue;
        }
        sb.append("Event metadata ").append("(").append(c.getFlavor().toString()).append(")").append(CharUtils.LF);
        for (Entry<EName, List<DublinCoreValue>> entry : dublinCore.getValues().entrySet()) {
            EName eName = entry.getKey();
            for (DublinCoreValue value : entry.getValue()) {
                sb.append("- ").append(eName.getNamespaceURI()).append(":").append(eName.getLocalName()).append(": ").append(value.getValue());
                boolean hasLanguageDefined = !DublinCore.LANGUAGE_UNDEFINED.equals(value.getLanguage());
                if (hasLanguageDefined || value.getEncodingScheme().isSome()) {
                    sb.append(" (");
                    if (hasLanguageDefined) {
                        sb.append("lang:").append(value.getLanguage());
                        if (value.getEncodingScheme().isSome())
                            sb.append("/");
                    }
                    for (EName schema : value.getEncodingScheme()) {
                        sb.append(schema.getLocalName());
                    }
                    sb.append(")");
                }
                sb.append(CharUtils.LF);
            }
        }
        sb.append(CharUtils.LF);
    }
    return sb.toString();
}
Also used : EName(org.opencastproject.mediapackage.EName) DublinCoreValue(org.opencastproject.metadata.dublincore.DublinCoreValue) ArrayList(java.util.ArrayList) AccessControlList(org.opencastproject.security.api.AccessControlList) List(java.util.List) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Catalog(org.opencastproject.mediapackage.Catalog) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 2 with TechnicalMetadata

use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.

the class CommentSchedulerConflictNotifierTest method testCommentSchedulerConflict.

@Test
public void testCommentSchedulerConflict() throws Exception {
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    Map<String, String> caProperties = new HashMap<String, String>();
    caProperties.put("test", "true");
    caProperties.put("clear", "all");
    Map<String, String> wfProperties = new HashMap<String, String>();
    wfProperties.put("test", "false");
    wfProperties.put("skip", "true");
    final String mpId = "1234";
    final TechnicalMetadata technicalMetadata = new TechnicalMetadataImpl(mpId, "demo", new Date(), new Date(new Date().getTime() + 10 * 60 * 1000), false, userIds, wfProperties, caProperties, null);
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.setIdentifier(new IdImpl(mpId));
    mp.add(DublinCores.mkOpencastEpisode().getCatalog());
    DublinCoreCatalog extendedEvent = DublinCores.mkStandard();
    extendedEvent.setFlavor(new MediaPackageElementFlavor("extended", "episode"));
    mp.add(extendedEvent);
    final SchedulerEvent schedulerEvent = EasyMock.createNiceMock(SchedulerEvent.class);
    EasyMock.expect(schedulerEvent.getTechnicalMetadata()).andReturn(technicalMetadata).anyTimes();
    EasyMock.expect(schedulerEvent.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(schedulerEvent.getEventId()).andReturn(mpId).anyTimes();
    EasyMock.expect(schedulerEvent.getVersion()).andReturn("2").anyTimes();
    EasyMock.replay(schedulerEvent);
    ConflictingEvent conflictingEvent = EasyMock.createNiceMock(ConflictingEvent.class);
    EasyMock.expect(conflictingEvent.getOldEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getNewEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getConflictStrategy()).andReturn(Strategy.NEW).anyTimes();
    EasyMock.replay(conflictingEvent);
    List<ConflictingEvent> conflicts = new ArrayList<>();
    conflicts.add(conflictingEvent);
    EventCommentService eventCommentService = EasyMock.createNiceMock(EventCommentService.class);
    EasyMock.expect(eventCommentService.updateComment(EasyMock.anyObject(EventComment.class))).andReturn(null).once();
    EasyMock.replay(eventCommentService);
    conflictNotifier.setEventCommentService(eventCommentService);
    conflictNotifier.notifyConflicts(conflicts);
    EasyMock.verify(eventCommentService);
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) EventCommentService(org.opencastproject.event.comment.EventCommentService) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with TechnicalMetadata

use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.

the class AbstractEventEndpoint method updateEventScheduling.

@PUT
@Path("{eventId}/scheduling")
@RestQuery(name = "updateEventScheduling", description = "Updates the scheduling information of an event", returnDescription = "The method doesn't return any content", pathParameters = { @RestParameter(name = "eventId", isRequired = true, description = "The event identifier", type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "scheduling", isRequired = true, description = "The updated scheduling (JSON object)", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = SC_BAD_REQUEST, description = "The required params were missing in the request."), @RestResponse(responseCode = SC_NOT_FOUND, description = "If the event has not been found."), @RestResponse(responseCode = SC_NO_CONTENT, description = "The method doesn't return any content") })
public Response updateEventScheduling(@PathParam("eventId") String eventId, @FormParam("scheduling") String scheduling) throws NotFoundException, UnauthorizedException, SearchIndexException {
    if (StringUtils.isBlank(scheduling))
        return RestUtil.R.badRequest("Missing parameters");
    try {
        final Event event = getEventOrThrowNotFoundException(eventId);
        TechnicalMetadata technicalMetadata = getSchedulerService().getTechnicalMetadata(eventId);
        final org.codehaus.jettison.json.JSONObject schedulingJson = new org.codehaus.jettison.json.JSONObject(scheduling);
        Opt<String> agentId = Opt.none();
        if (schedulingJson.has(SCHEDULING_AGENT_ID_KEY)) {
            agentId = Opt.some(schedulingJson.getString(SCHEDULING_AGENT_ID_KEY));
            logger.trace("Updating agent id of event '{}' from '{}' to '{}'", eventId, technicalMetadata.getAgentId(), agentId);
        }
        Opt<Date> start = Opt.none();
        if (schedulingJson.has(SCHEDULING_START_KEY)) {
            start = Opt.some(new Date(DateTimeSupport.fromUTC(schedulingJson.getString(SCHEDULING_START_KEY))));
            logger.trace("Updating start time of event '{}' id from '{}' to '{}'", eventId, DateTimeSupport.toUTC(technicalMetadata.getStartDate().getTime()), DateTimeSupport.toUTC(start.get().getTime()));
        }
        Opt<Date> end = Opt.none();
        if (schedulingJson.has(SCHEDULING_END_KEY)) {
            end = Opt.some(new Date(DateTimeSupport.fromUTC(schedulingJson.getString(SCHEDULING_END_KEY))));
            logger.trace("Updating end time of event '{}' id from '{}' to '{}'", eventId, DateTimeSupport.toUTC(technicalMetadata.getEndDate().getTime()), DateTimeSupport.toUTC(end.get().getTime()));
        }
        Opt<Map<String, String>> agentConfiguration = Opt.none();
        if (schedulingJson.has(SCHEDULING_AGENT_CONFIGURATION_KEY)) {
            agentConfiguration = Opt.some(JSONUtils.toMap(schedulingJson.getJSONObject(SCHEDULING_AGENT_CONFIGURATION_KEY)));
            logger.trace("Updating agent configuration of event '{}' id from '{}' to '{}'", eventId, technicalMetadata.getCaptureAgentConfiguration(), agentConfiguration);
        }
        Opt<Opt<Boolean>> optOut = Opt.none();
        if (schedulingJson.has(SCHEDULING_OPT_OUT_KEY)) {
            optOut = Opt.some(Opt.some(schedulingJson.getBoolean(SCHEDULING_OPT_OUT_KEY)));
            logger.trace("Updating optout status of event '{}' id from '{}' to '{}'", eventId, event.getOptedOut(), optOut);
        }
        if (start.isNone() && end.isNone() && agentId.isNone() && agentConfiguration.isNone() && optOut.isNone())
            return Response.noContent().build();
        if ((start.isSome() || end.isSome()) && end.getOr(technicalMetadata.getEndDate()).before(start.getOr(technicalMetadata.getStartDate())))
            return RestUtil.R.badRequest("The end date is before the start date");
        getSchedulerService().updateEvent(eventId, start, end, agentId, Opt.<Set<String>>none(), Opt.<MediaPackage>none(), Opt.<Map<String, String>>none(), agentConfiguration, optOut, SchedulerService.ORIGIN);
        return Response.noContent().build();
    } catch (JSONException e) {
        return RestUtil.R.badRequest("The scheduling object is not valid");
    } catch (ParseException e) {
        return RestUtil.R.badRequest("The UTC dates in the scheduling object is not valid");
    } catch (SchedulerException e) {
        logger.error("Unable to update scheduling technical metadata of event {}: {}", eventId, ExceptionUtils.getStackTrace(e));
        throw new WebApplicationException(e, SC_INTERNAL_SERVER_ERROR);
    }
}
Also used : SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) JSONException(org.codehaus.jettison.json.JSONException) Date(java.util.Date) Opt(com.entwinemedia.fn.data.Opt) JSONObject(org.json.simple.JSONObject) Event(org.opencastproject.index.service.impl.index.event.Event) ParseException(java.text.ParseException) Map(java.util.Map) HashMap(java.util.HashMap) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Path(javax.ws.rs.Path) RestQuery(org.opencastproject.util.doc.rest.RestQuery) PUT(javax.ws.rs.PUT)

Example 4 with TechnicalMetadata

use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.

the class EmailSchedulerConflictNotifierTest method testEmailSchedulerConflict.

@Test
public void testEmailSchedulerConflict() throws Exception {
    Set<String> userIds = new HashSet<>();
    userIds.add("user1");
    userIds.add("user2");
    Map<String, String> caProperties = new HashMap<String, String>();
    caProperties.put("test", "true");
    caProperties.put("clear", "all");
    Map<String, String> wfProperties = new HashMap<String, String>();
    wfProperties.put("test", "false");
    wfProperties.put("skip", "true");
    final String mpId = "1234";
    final TechnicalMetadata technicalMetadata = new TechnicalMetadataImpl(mpId, "demo", new Date(), new Date(new Date().getTime() + 10 * 60 * 1000), false, userIds, wfProperties, caProperties, null);
    final MediaPackage mp = MediaPackageBuilderFactory.newInstance().newMediaPackageBuilder().createNew();
    mp.setIdentifier(new IdImpl(mpId));
    mp.add(DublinCores.mkOpencastEpisode().getCatalog());
    DublinCoreCatalog extendedEvent = DublinCores.mkStandard();
    extendedEvent.setFlavor(new MediaPackageElementFlavor("extended", "episode"));
    mp.add(extendedEvent);
    final SchedulerEvent schedulerEvent = EasyMock.createNiceMock(SchedulerEvent.class);
    EasyMock.expect(schedulerEvent.getTechnicalMetadata()).andReturn(technicalMetadata).anyTimes();
    EasyMock.expect(schedulerEvent.getMediaPackage()).andReturn(mp).anyTimes();
    EasyMock.expect(schedulerEvent.getEventId()).andReturn(mpId).anyTimes();
    EasyMock.expect(schedulerEvent.getVersion()).andReturn("2").anyTimes();
    EasyMock.replay(schedulerEvent);
    ConflictingEvent conflictingEvent = EasyMock.createNiceMock(ConflictingEvent.class);
    EasyMock.expect(conflictingEvent.getOldEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getNewEvent()).andReturn(schedulerEvent).anyTimes();
    EasyMock.expect(conflictingEvent.getConflictStrategy()).andReturn(Strategy.NEW).anyTimes();
    EasyMock.replay(conflictingEvent);
    List<ConflictingEvent> conflicts = new ArrayList<>();
    conflicts.add(conflictingEvent);
    final Integer[] counter = new Integer[1];
    counter[0] = 0;
    SmtpService smtpService = new SmtpService() {

        @Override
        public void send(MimeMessage message) throws MessagingException {
            counter[0]++;
        }
    };
    conflictNotifier.setSmtpService(smtpService);
    conflictNotifier.notifyConflicts(conflicts);
    Assert.assertEquals(1, counter[0].intValue());
}
Also used : ConflictingEvent(org.opencastproject.scheduler.api.ConflictingEvent) HashMap(java.util.HashMap) TechnicalMetadataImpl(org.opencastproject.scheduler.api.TechnicalMetadataImpl) ArrayList(java.util.ArrayList) MediaPackageElementFlavor(org.opencastproject.mediapackage.MediaPackageElementFlavor) Date(java.util.Date) IdImpl(org.opencastproject.mediapackage.identifier.IdImpl) SchedulerEvent(org.opencastproject.scheduler.api.SchedulerEvent) SmtpService(org.opencastproject.kernel.mail.SmtpService) MimeMessage(javax.mail.internet.MimeMessage) MediaPackage(org.opencastproject.mediapackage.MediaPackage) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with TechnicalMetadata

use of org.opencastproject.scheduler.api.TechnicalMetadata in project opencast by opencast.

the class SchedulerRestService method getTechnicalMetadataJSON.

/**
 * Gets a XML with the media package for the specified event.
 *
 * @param eventId
 *          The unique ID of the event.
 * @return media package XML for the event
 */
@GET
@Produces(MediaType.TEXT_XML)
@Path("{id:.+}/technical.json")
@RestQuery(name = "gettechnicalmetadatajson", description = "Retrieves the technical metadata for specified event", returnDescription = "technical metadata as JSON", pathParameters = { @RestParameter(name = "id", isRequired = true, description = "ID of event for which the technical metadata will be retrieved", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "technical metadata of event is in the body of response"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "Event with specified ID does not exist"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to remove the event. Maybe you need to authenticate.") })
public Response getTechnicalMetadataJSON(@PathParam("id") String eventId) throws UnauthorizedException {
    try {
        TechnicalMetadata metadata = service.getTechnicalMetadata(eventId);
        Val state = v("");
        Val lastHeard = v("");
        if (metadata.getRecording().isSome()) {
            state = v(metadata.getRecording().get().getState());
            lastHeard = v(DateTimeSupport.toUTC(metadata.getRecording().get().getLastCheckinTime()));
        }
        Arr presenters = arr(mlist(metadata.getPresenters()).map(Jsons.stringVal));
        List<Prop> wfProperties = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getWorkflowProperties().entrySet()) {
            wfProperties.add(p(entry.getKey(), entry.getValue()));
        }
        List<Prop> agentConfig = new ArrayList<>();
        for (Entry<String, String> entry : metadata.getCaptureAgentConfiguration().entrySet()) {
            agentConfig.add(p(entry.getKey(), entry.getValue()));
        }
        return RestUtil.R.ok(obj(p("id", metadata.getEventId()), p("location", metadata.getAgentId()), p("start", DateTimeSupport.toUTC(metadata.getStartDate().getTime())), p("end", DateTimeSupport.toUTC(metadata.getEndDate().getTime())), p("optOut", metadata.isOptOut()), p("presenters", presenters), p("wfProperties", obj(wfProperties.toArray(new Prop[wfProperties.size()]))), p("agentConfig", obj(agentConfig.toArray(new Prop[agentConfig.size()]))), p("state", state), p("lastHeardFrom", lastHeard)));
    } catch (NotFoundException e) {
        logger.info("Event with id '{}' does not exist.", eventId);
        return Response.status(Status.NOT_FOUND).build();
    } catch (SchedulerException e) {
        logger.error("Unable to retrieve event with id '{}': {}", eventId, getMessage(e));
        throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : Val(org.opencastproject.util.Jsons.Val) Arr(org.opencastproject.util.Jsons.Arr) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) WebApplicationException(javax.ws.rs.WebApplicationException) Prop(org.opencastproject.util.Jsons.Prop) ArrayList(java.util.ArrayList) NotFoundException(org.opencastproject.util.NotFoundException) TechnicalMetadata(org.opencastproject.scheduler.api.TechnicalMetadata) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

TechnicalMetadata (org.opencastproject.scheduler.api.TechnicalMetadata)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 MediaPackage (org.opencastproject.mediapackage.MediaPackage)3 Path (javax.ws.rs.Path)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 MediaPackageElementFlavor (org.opencastproject.mediapackage.MediaPackageElementFlavor)2 IdImpl (org.opencastproject.mediapackage.identifier.IdImpl)2 ConflictingEvent (org.opencastproject.scheduler.api.ConflictingEvent)2 SchedulerEvent (org.opencastproject.scheduler.api.SchedulerEvent)2 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)2 TechnicalMetadataImpl (org.opencastproject.scheduler.api.TechnicalMetadataImpl)2 NotFoundException (org.opencastproject.util.NotFoundException)2 RestQuery (org.opencastproject.util.doc.rest.RestQuery)2 Opt (com.entwinemedia.fn.data.Opt)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1