use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method getEventMetadata.
@GET
@Path("{eventId}/metadata.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "geteventmetadata", description = "Returns all the data related to the metadata tab in the event details modal as JSON", returnDescription = "All the data related to the event metadata tab as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns all the data related to the event metadata tab as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getEventMetadata(@PathParam("eventId") String eventId) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(eventId, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", eventId);
MetadataList metadataList = new MetadataList();
List<EventCatalogUIAdapter> catalogUIAdapters = getIndexService().getEventCatalogUIAdapters();
catalogUIAdapters.remove(getIndexService().getCommonEventCatalogUIAdapter());
MediaPackage mediaPackage = getIndexService().getEventMediapackage(optEvent.get());
for (EventCatalogUIAdapter catalogUIAdapter : catalogUIAdapters) {
metadataList.add(catalogUIAdapter, catalogUIAdapter.getFields(mediaPackage));
}
metadataList.add(getIndexService().getCommonEventCatalogUIAdapter(), EventUtils.getEventMetadata(optEvent.get(), getIndexService().getCommonEventCatalogUIAdapter()));
final String wfState = optEvent.get().getWorkflowState();
if (wfState != null && WorkflowUtil.isActive(WorkflowInstance.WorkflowState.valueOf(wfState)))
metadataList.setLocked(Locked.WORKFLOW_RUNNING);
return okJson(metadataList.toJSON());
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method updateAssets.
// MH-12085 Add manually uploaded assets, multipart file upload has to be a POST
@POST
@Path("{eventId}/assets")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@RestQuery(name = "updateAssets", description = "Update or create an asset for the eventId by the given metadata as JSON and files in the body", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, restParameters = { @RestParameter(name = "metadata", isRequired = true, type = RestParameter.Type.TEXT, description = "The list of asset metadata") }, reponses = { @RestResponse(description = "The asset has been added.", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "Could not add asset, problem with the metadata or files.", responseCode = HttpServletResponse.SC_BAD_REQUEST), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) }, returnDescription = "The workflow identifier")
public Response updateAssets(@PathParam("eventId") final String eventId, @Context HttpServletRequest request) throws Exception {
try {
MediaPackage mp = getMediaPackageByEventId(eventId);
String result = getIndexService().updateEventAssets(mp, request);
return Response.status(Status.CREATED).entity(result).build();
} catch (NotFoundException e) {
return notFound("Cannot find an event with id '%s'.", eventId);
} catch (IllegalArgumentException e) {
return RestUtil.R.badRequest(e.getMessage());
} catch (Exception e) {
return RestUtil.R.serverError();
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method getNewConflicts.
@POST
@Path("new/conflicts")
@RestQuery(name = "checkNewConflicts", description = "Checks if the current scheduler parameters are in a conflict with another event", returnDescription = "Returns NO CONTENT if no event are in conflict within specified period or list of conflicting recordings in JSON", restParameters = { @RestParameter(name = "metadata", isRequired = true, description = "The metadata as JSON", type = RestParameter.Type.TEXT) }, reponses = { @RestResponse(responseCode = HttpServletResponse.SC_NO_CONTENT, description = "No conflicting events found"), @RestResponse(responseCode = HttpServletResponse.SC_CONFLICT, description = "There is a conflict"), @RestResponse(responseCode = HttpServletResponse.SC_BAD_REQUEST, description = "Missing or invalid parameters") })
public Response getNewConflicts(@FormParam("metadata") String metadata) throws NotFoundException {
if (StringUtils.isBlank(metadata)) {
logger.warn("Metadata is not specified");
return Response.status(Status.BAD_REQUEST).build();
}
JSONParser parser = new JSONParser();
JSONObject metadataJson;
try {
metadataJson = (JSONObject) parser.parse(metadata);
} catch (Exception e) {
logger.warn("Unable to parse metadata {}", metadata);
return RestUtil.R.badRequest("Unable to parse metadata");
}
String device;
String startDate;
String endDate;
try {
device = (String) metadataJson.get("device");
startDate = (String) metadataJson.get("start");
endDate = (String) metadataJson.get("end");
} catch (Exception e) {
logger.warn("Unable to parse metadata {}", metadata);
return RestUtil.R.badRequest("Unable to parse metadata");
}
if (StringUtils.isBlank(device) || StringUtils.isBlank(startDate) || StringUtils.isBlank(endDate)) {
logger.warn("Either device, start date or end date were not specified");
return Response.status(Status.BAD_REQUEST).build();
}
Date start;
try {
start = new Date(DateTimeSupport.fromUTC(startDate));
} catch (Exception e) {
logger.warn("Unable to parse start date {}", startDate);
return RestUtil.R.badRequest("Unable to parse start date");
}
Date end;
try {
end = new Date(DateTimeSupport.fromUTC(endDate));
} catch (Exception e) {
logger.warn("Unable to parse end date {}", endDate);
return RestUtil.R.badRequest("Unable to parse end date");
}
String rruleString = (String) metadataJson.get("rrule");
RRule rrule = null;
TimeZone timeZone = TimeZone.getDefault();
String durationString = null;
if (StringUtils.isNotEmpty(rruleString)) {
try {
rrule = new RRule(rruleString);
rrule.validate();
} catch (Exception e) {
logger.warn("Unable to parse rrule {}: {}", rruleString, e.getMessage());
return Response.status(Status.BAD_REQUEST).build();
}
durationString = (String) metadataJson.get("duration");
if (StringUtils.isBlank(durationString)) {
logger.warn("If checking recurrence, must include duration.");
return Response.status(Status.BAD_REQUEST).build();
}
Agent agent = getCaptureAgentStateService().getAgent(device);
String timezone = agent.getConfiguration().getProperty("capture.device.timezone");
if (StringUtils.isBlank(timezone)) {
timezone = TimeZone.getDefault().getID();
logger.warn("No 'capture.device.timezone' set on agent {}. The default server timezone {} will be used.", device, timezone);
}
timeZone = TimeZone.getTimeZone(timezone);
}
String eventId = (String) metadataJson.get("id");
try {
List<MediaPackage> events = null;
if (StringUtils.isNotEmpty(rruleString)) {
events = getSchedulerService().findConflictingEvents(device, rrule, start, end, Long.parseLong(durationString), timeZone);
} else {
events = getSchedulerService().findConflictingEvents(device, start, end);
}
if (!events.isEmpty()) {
List<JValue> eventsJSON = new ArrayList<>();
for (MediaPackage event : events) {
Opt<Event> eventOpt = getIndexService().getEvent(event.getIdentifier().compact(), getIndex());
if (eventOpt.isSome()) {
final Event e = eventOpt.get();
if (StringUtils.isNotEmpty(eventId) && eventId.equals(e.getIdentifier()))
continue;
eventsJSON.add(obj(f("start", v(e.getTechnicalStartTime())), f("end", v(e.getTechnicalEndTime())), f("title", v(e.getTitle()))));
} else {
logger.warn("Index out of sync! Conflicting event catalog {} not found on event index!", event.getIdentifier().compact());
}
}
if (!eventsJSON.isEmpty())
return conflictJson(arr(eventsJSON));
}
return Response.noContent().build();
} catch (Exception e) {
logger.error("Unable to find conflicting events for {}, {}, {}: {}", device, startDate, endDate, ExceptionUtils.getStackTrace(e));
return RestUtil.R.serverError();
}
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method getMediaList.
@GET
@Path("{eventId}/asset/media/media.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getMediaList", description = "Returns a list of media from the given event as JSON", returnDescription = "The list of media from the given event as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns a list of media from the given event as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getMediaList(@PathParam("eventId") String id) throws Exception {
Opt<Event> optEvent = getIndexService().getEvent(id, getIndex());
if (optEvent.isNone())
return notFound("Cannot find an event with id '%s'.", id);
MediaPackage mp = getIndexService().getEventMediapackage(optEvent.get());
return okJson(arr(getEventMediaPackageElements(mp.getTracks())));
}
use of org.opencastproject.mediapackage.MediaPackage in project opencast by opencast.
the class AbstractEventEndpoint method getPublication.
@GET
@Path("{eventId}/asset/publication/{id}.json")
@Produces(MediaType.APPLICATION_JSON)
@RestQuery(name = "getPublication", description = "Returns the details of a publication from the given event and publication id as JSON", returnDescription = "The details of a publication from the given event and publication id as JSON", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = RestParameter.Type.STRING), @RestParameter(name = "id", description = "The publication id", isRequired = true, type = RestParameter.Type.STRING) }, reponses = { @RestResponse(description = "Returns the publication of a catalog from the given event and publication id as JSON", responseCode = HttpServletResponse.SC_OK), @RestResponse(description = "No event or publication with this identifier was found.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response getPublication(@PathParam("eventId") String eventId, @PathParam("id") String id) throws NotFoundException, SearchIndexException, IndexServiceException {
MediaPackage mp = getMediaPackageByEventId(eventId);
Publication publication = null;
for (Publication p : mp.getPublications()) {
if (id.equals(p.getIdentifier())) {
publication = p;
break;
}
}
if (publication == null)
return notFound("Cannot find publication with id '%s'.", id);
return okJson(publicationToJSON(publication));
}
Aggregations