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;
}
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);
}
}
}
Aggregations