use of org.opencastproject.index.service.impl.index.event.EventHttpServletRequest in project opencast by opencast.
the class IndexServiceImpl method createEvent.
@Override
public String createEvent(JSONObject metadataJson, MediaPackage mp) throws ParseException, IOException, MediaPackageException, IngestException, NotFoundException, SchedulerException, UnauthorizedException {
if (metadataJson == null)
throw new IllegalArgumentException("No metadata set");
JSONObject source = (JSONObject) metadataJson.get("source");
if (source == null)
throw new IllegalArgumentException("No source field in metadata");
JSONObject processing = (JSONObject) metadataJson.get("processing");
if (processing == null)
throw new IllegalArgumentException("No processing field in metadata");
JSONArray allEventMetadataJson = (JSONArray) metadataJson.get("metadata");
if (allEventMetadataJson == null)
throw new IllegalArgumentException("No metadata field in metadata");
AccessControlList acl = getAccessControlList(metadataJson);
MetadataList metadataList = getMetadataListWithAllEventCatalogUIAdapters();
try {
metadataList.fromJSON(allEventMetadataJson.toJSONString());
} catch (MetadataParsingException e) {
logger.warn("Unable to parse event metadata {}", allEventMetadataJson.toJSONString());
throw new IllegalArgumentException("Unable to parse metadata set");
}
EventHttpServletRequest eventHttpServletRequest = new EventHttpServletRequest();
eventHttpServletRequest.setAcl(acl);
eventHttpServletRequest.setMetadataList(metadataList);
eventHttpServletRequest.setMediaPackage(mp);
eventHttpServletRequest.setProcessing(processing);
eventHttpServletRequest.setSource(source);
return createEvent(eventHttpServletRequest);
}
use of org.opencastproject.index.service.impl.index.event.EventHttpServletRequest in project opencast by opencast.
the class EventsEndpoint method createNewEvent.
@SuppressWarnings("unchecked")
private Response createNewEvent(HttpServletRequest request) throws ParseException, IOException, IndexServiceException, java.text.ParseException, MediaPackageException, IngestException, NotFoundException, SchedulerException, UnauthorizedException {
JSONObject source = new JSONObject();
source.put("type", "UPLOAD");
Opt<String> startDatePattern = configuredMetadataFields.containsKey("startDate") ? configuredMetadataFields.get("startDate").getPattern() : Opt.none();
Opt<String> startTimePattern = configuredMetadataFields.containsKey("startTime") ? configuredMetadataFields.get("startTime").getPattern() : Opt.none();
EventHttpServletRequest eventHttpServletRequest = EventHttpServletRequest.createFromHttpServletRequest(request, ingestService, getEventCatalogUIAdapters(), source, startDatePattern, startTimePattern);
String eventId = indexService.createEvent(eventHttpServletRequest);
return ApiResponses.Json.created(VERSION_1_0_0, URI.create(getEventUrl(eventId)), obj(f("identifier", v(eventId))));
}
use of org.opencastproject.index.service.impl.index.event.EventHttpServletRequest in project opencast by opencast.
the class EventsEndpoint method updateEvent.
private Response updateEvent(String eventId, HttpServletRequest request) {
try {
Opt<String> startDatePattern = configuredMetadataFields.containsKey("startDate") ? configuredMetadataFields.get("startDate").getPattern() : Opt.none();
Opt<String> startTimePattern = configuredMetadataFields.containsKey("startTime") ? configuredMetadataFields.get("startTime").getPattern() : Opt.none();
for (final Event event : indexService.getEvent(eventId, externalIndex)) {
EventHttpServletRequest eventHttpServletRequest = EventHttpServletRequest.updateFromHttpServletRequest(event, request, getEventCatalogUIAdapters(), startDatePattern, startTimePattern);
if (eventHttpServletRequest.getMetadataList().isSome()) {
indexService.updateEventMetadata(eventId, eventHttpServletRequest.getMetadataList().get(), externalIndex);
}
if (eventHttpServletRequest.getAcl().isSome()) {
indexService.updateEventAcl(eventId, eventHttpServletRequest.getAcl().get(), externalIndex);
}
return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
} catch (NotFoundException e) {
return ApiResponses.notFound("Cannot find an event with id '%s'.", eventId);
} catch (UnauthorizedException e) {
return Response.status(Status.UNAUTHORIZED).build();
} catch (IllegalArgumentException e) {
logger.debug("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
return RestUtil.R.badRequest(e.getMessage());
} catch (IndexServiceException e) {
logger.error("Unable to get multi part fields or file for event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (SearchIndexException e) {
logger.error("Unable to update event '{}' because: {}", eventId, ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(e, Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations