Search in sources :

Example 1 with EventHttpServletRequest

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);
}
Also used : AccessControlList(org.opencastproject.security.api.AccessControlList) MetadataList(org.opencastproject.index.service.catalog.adapter.MetadataList) EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) MetadataParsingException(org.opencastproject.metadata.dublincore.MetadataParsingException) JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray)

Example 2 with 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))));
}
Also used : EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) JSONObject(org.json.simple.JSONObject)

Example 3 with EventHttpServletRequest

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);
    }
}
Also used : EventHttpServletRequest(org.opencastproject.index.service.impl.index.event.EventHttpServletRequest) WebApplicationException(javax.ws.rs.WebApplicationException) SearchIndexException(org.opencastproject.matterhorn.search.SearchIndexException) UnauthorizedException(org.opencastproject.security.api.UnauthorizedException) Event(org.opencastproject.index.service.impl.index.event.Event) NotFoundException(org.opencastproject.util.NotFoundException) IndexServiceException(org.opencastproject.index.service.exception.IndexServiceException)

Aggregations

EventHttpServletRequest (org.opencastproject.index.service.impl.index.event.EventHttpServletRequest)3 JSONObject (org.json.simple.JSONObject)2 WebApplicationException (javax.ws.rs.WebApplicationException)1 JSONArray (org.json.simple.JSONArray)1 MetadataList (org.opencastproject.index.service.catalog.adapter.MetadataList)1 IndexServiceException (org.opencastproject.index.service.exception.IndexServiceException)1 Event (org.opencastproject.index.service.impl.index.event.Event)1 SearchIndexException (org.opencastproject.matterhorn.search.SearchIndexException)1 MetadataParsingException (org.opencastproject.metadata.dublincore.MetadataParsingException)1 AccessControlList (org.opencastproject.security.api.AccessControlList)1 UnauthorizedException (org.opencastproject.security.api.UnauthorizedException)1 NotFoundException (org.opencastproject.util.NotFoundException)1