Search in sources :

Example 16 with DCMIPeriod

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

the class EventIndexUtils method updateEvent.

/**
 * Update the given {@link Event} with the given {@link DublinCore}.
 *
 * @param event
 *          the event to update
 * @param dc
 *          the catalog with the metadata for the update
 * @return the updated event
 */
public static Event updateEvent(Event event, DublinCore dc) {
    event.setTitle(dc.getFirst(DublinCore.PROPERTY_TITLE));
    event.setDescription(dc.getFirst(DublinCore.PROPERTY_DESCRIPTION));
    event.setSubject(dc.getFirst(DublinCore.PROPERTY_SUBJECT));
    event.setLocation(dc.getFirst(DublinCore.PROPERTY_SPATIAL));
    event.setLanguage(dc.getFirst(DublinCore.PROPERTY_LANGUAGE));
    event.setSource(dc.getFirst(DublinCore.PROPERTY_SOURCE));
    event.setSeriesId(dc.getFirst(DublinCore.PROPERTY_IS_PART_OF));
    event.setLicense(dc.getFirst(DublinCore.PROPERTY_LICENSE));
    event.setRights(dc.getFirst(DublinCore.PROPERTY_RIGHTS_HOLDER));
    Date created;
    String encodedDate = dc.getFirst(DublinCore.PROPERTY_CREATED);
    if (StringUtils.isBlank(encodedDate)) {
        created = new Date();
    } else {
        created = EncodingSchemeUtils.decodeDate(encodedDate);
    }
    event.setCreated(DateTimeSupport.toUTC(created.getTime()));
    String strPeriod = dc.getFirst(DublinCore.PROPERTY_TEMPORAL);
    try {
        if (StringUtils.isNotBlank(strPeriod)) {
            DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(strPeriod);
            event.setRecordingStartDate(DateTimeSupport.toUTC(period.getStart().getTime()));
            event.setRecordingEndDate(DateTimeSupport.toUTC(period.getEnd().getTime()));
            event.setDuration(period.getEnd().getTime() - period.getStart().getTime());
        } else {
            event.setRecordingStartDate(DateTimeSupport.toUTC(created.getTime()));
        }
    } catch (Exception e) {
        logger.warn("Invalid start and end date/time for event {}: {}", event.getIdentifier(), strPeriod);
        event.setRecordingStartDate(DateTimeSupport.toUTC(created.getTime()));
    }
    updateTechnicalDate(event);
    // TODO: Add support for language
    event.setContributors(splitStringList(dc.get(DublinCore.PROPERTY_CONTRIBUTOR, DublinCore.LANGUAGE_ANY)));
    event.setPresenters(splitStringList(dc.get(DublinCore.PROPERTY_CREATOR, DublinCore.LANGUAGE_ANY)));
    return event;
}
Also used : DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) Date(java.util.Date) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) NotFoundException(org.opencastproject.util.NotFoundException) IOException(java.io.IOException)

Example 17 with DCMIPeriod

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

the class SchedulerRestService method stopCapture.

@DELETE
@Path("capture/{agent}")
@Produces(MediaType.TEXT_PLAIN)
@RestQuery(name = "stopcapture", description = "Stops an immediate capture.", returnDescription = "OK if event were successfully stopped", pathParameters = { @RestParameter(name = "agent", isRequired = true, description = "The agent identifier", type = Type.STRING) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_OK, description = "Recording stopped"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_MODIFIED, description = "The recording was already stopped"), @RestResponse(responseCode = HttpServletResponse.SC_NOT_FOUND, description = "There is no such agent"), @RestResponse(responseCode = HttpServletResponse.SC_UNAUTHORIZED, description = "You do not have permission to stop this immediate capture. Maybe you need to authenticate."), @RestResponse(responseCode = HttpServletResponse.SC_SERVICE_UNAVAILABLE, description = "The agent is not ready to communicate") })
public Response stopCapture(@PathParam("agent") String agentId) throws NotFoundException, UnauthorizedException {
    if (service == null || agentService == null || prolongingService == null)
        return Response.serverError().status(Response.Status.SERVICE_UNAVAILABLE).entity("Scheduler service is unavailable, please wait...").build();
    boolean isAdHoc = false;
    try {
        Agent agent = agentService.getAgent(agentId);
        String registrationType = (String) agent.getConfiguration().get(AGENT_REGISTRATION_TYPE);
        isAdHoc = AGENT_REGISTRATION_TYPE_ADHOC.equals(registrationType);
    } catch (NotFoundException e) {
        logger.debug("Temporarily registered agent '{}' for ad-hoc recording already removed", agentId);
    }
    try {
        String eventId;
        MediaPackage mp;
        DublinCoreCatalog eventCatalog;
        try {
            List<MediaPackage> search = service.search(Opt.some(agentId), Opt.<Date>none(), Opt.some(new Date()), Opt.some(new Date()), Opt.<Date>none());
            if (search.isEmpty()) {
                logger.info("No recording to stop found for agent '{}'!", agentId);
                return Response.notModified().build();
            } else {
                mp = search.get(0);
                eventCatalog = DublinCoreUtil.loadEpisodeDublinCore(workspace, search.get(0)).get();
                eventId = search.get(0).getIdentifier().compact();
            }
        } catch (Exception e) {
            logger.error("Unable to get the immediate recording for agent '{}': {}", agentId, e);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
        try {
            DCMIPeriod period = EncodingSchemeUtils.decodeMandatoryPeriod(eventCatalog.getFirst(DublinCore.PROPERTY_TEMPORAL));
            eventCatalog.set(PROPERTY_TEMPORAL, EncodingSchemeUtils.encodePeriod(new DCMIPeriod(period.getStart(), new Date()), Precision.Second));
            mp = addCatalog(workspace, IOUtils.toInputStream(eventCatalog.toXmlString(), "UTF-8"), "dublincore.xml", MediaPackageElements.EPISODE, mp);
            service.updateEvent(eventId, Opt.<Date>none(), Opt.<Date>none(), Opt.<String>none(), Opt.<Set<String>>none(), Opt.some(mp), Opt.<Map<String, String>>none(), Opt.<Map<String, String>>none(), Opt.<Opt<Boolean>>none(), SchedulerService.ORIGIN);
            prolongingService.stop(agentId);
            return Response.ok().build();
        } catch (UnauthorizedException e) {
            throw e;
        } catch (Exception e) {
            logger.error("Unable to update the temporal of event '{}': {}", eventId, e);
            throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (isAdHoc) {
            agentService.removeAgent(agentId);
            logger.info("Removed temporary agent registration '{}'", agentId);
        }
    }
}
Also used : Agent(org.opencastproject.capture.admin.api.Agent) WebApplicationException(javax.ws.rs.WebApplicationException) DCMIPeriod(org.opencastproject.metadata.dublincore.DCMIPeriod) NotFoundException(org.opencastproject.util.NotFoundException) Date(java.util.Date) SchedulerException(org.opencastproject.scheduler.api.SchedulerException) SchedulerConflictException(org.opencastproject.scheduler.api.SchedulerConflictException) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) SchedulerTransactionLockException(org.opencastproject.scheduler.api.SchedulerTransactionLockException) ParseException(java.text.ParseException) MediaPackageException(org.opencastproject.mediapackage.MediaPackageException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) NotFoundException(org.opencastproject.util.NotFoundException) MediaPackage(org.opencastproject.mediapackage.MediaPackage) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) DublinCoreCatalog(org.opencastproject.metadata.dublincore.DublinCoreCatalog) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) RestQuery(org.opencastproject.util.doc.rest.RestQuery)

Aggregations

DCMIPeriod (org.opencastproject.metadata.dublincore.DCMIPeriod)17 Date (java.util.Date)12 IOException (java.io.IOException)8 DublinCoreCatalog (org.opencastproject.metadata.dublincore.DublinCoreCatalog)8 MediaPackage (org.opencastproject.mediapackage.MediaPackage)6 NotFoundException (org.opencastproject.util.NotFoundException)6 ParseException (java.text.ParseException)4 DateTime (org.joda.time.DateTime)4 MediaPackageElement (org.opencastproject.mediapackage.MediaPackageElement)4 MediaPackageException (org.opencastproject.mediapackage.MediaPackageException)4 DublinCoreValue (org.opencastproject.metadata.dublincore.DublinCoreValue)4 SchedulerException (org.opencastproject.scheduler.api.SchedulerException)4 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)4 HashMap (java.util.HashMap)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 SchedulerConflictException (org.opencastproject.scheduler.api.SchedulerConflictException)3 SchedulerTransactionLockException (org.opencastproject.scheduler.api.SchedulerTransactionLockException)3 LinkedHashMap (java.util.LinkedHashMap)2 Properties (java.util.Properties)2 Path (javax.ws.rs.Path)2