use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventsEndpoint method addEventAce.
@POST
@Path("{eventId}/acl/{action}")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "addeventace", description = "Grants permission to execute action on the specified event to any user with role role. Note that this is a convenience method to avoid having to build and post a complete access control list.", returnDescription = "", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = STRING), @RestParameter(name = "action", description = "The action that is allowed to be executed", isRequired = true, type = STRING) }, restParameters = { @RestParameter(name = "role", isRequired = true, description = "The role that is granted permission", type = STRING) }, reponses = { @RestResponse(description = "The permission has been created in the access control list of the specified event.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "The specified event does not exist.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response addEventAce(@HeaderParam("Accept") String acceptHeader, @PathParam("eventId") String id, @PathParam("action") String action, @FormParam("role") String role) throws Exception {
List<AccessControlEntry> entries = new ArrayList<>();
for (final Event event : indexService.getEvent(id, externalIndex)) {
AccessControlList accessControlList = getAclFromEvent(event);
AccessControlEntry newAce = new AccessControlEntry(role, action, true);
boolean alreadyInAcl = false;
for (AccessControlEntry ace : accessControlList.getEntries()) {
if (ace.equals(newAce)) {
// We have found an identical access control entry so just return.
entries = accessControlList.getEntries();
alreadyInAcl = true;
break;
} else if (ace.getAction().equals(newAce.getAction()) && ace.getRole().equals(newAce.getRole()) && !ace.isAllow()) {
entries.add(newAce);
alreadyInAcl = true;
} else {
entries.add(ace);
}
}
if (!alreadyInAcl) {
entries.add(newAce);
}
AccessControlList withNewAce = new AccessControlList(entries);
try {
withNewAce = indexService.updateEventAcl(id, withNewAce, externalIndex);
} catch (IllegalArgumentException e) {
logger.error("Unable to update event '{}' acl entry with action '{}' and role '{}' because: {}", id, action, role, ExceptionUtils.getStackTrace(e));
return Response.status(Status.FORBIDDEN).build();
}
return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventsEndpoint method getEvents.
@GET
@Path("/")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getevents", description = "Returns a list of events. By setting the optional sign parameter to true, the method will pre-sign distribution urls if signing is turned on in Opencast. Remember to consider the maximum validity of signed URLs when caching this response.", returnDescription = "", restParameters = { @RestParameter(name = "sign", isRequired = false, description = "Whether public distribution urls should be signed.", type = Type.BOOLEAN), @RestParameter(name = "withacl", isRequired = false, description = "Whether the acl metadata should be included in the response.", type = Type.BOOLEAN), @RestParameter(name = "withmetadata", isRequired = false, description = "Whether the metadata catalogs should be included in the response.", type = Type.BOOLEAN), @RestParameter(name = "withpublications", isRequired = false, description = "Whether the publication ids and urls should be included in the response.", type = Type.BOOLEAN), @RestParameter(name = "filter", isRequired = false, description = "A comma seperated list of filters to limit the results with. A filter is the filter's name followed by a colon \":\" and then the value to filter with so it is the form <Filter Name>:<Value to Filter With>.", type = STRING), @RestParameter(name = "sort", description = "Sort the results based upon a list of comma seperated sorting criteria. In the comma seperated list each type of sorting is specified as a pair such as: <Sort Name>:ASC or <Sort Name>:DESC. Adding the suffix ASC or DESC sets the order as ascending or descending order and is mandatory.", isRequired = false, type = STRING), @RestParameter(name = "limit", description = "The maximum number of results to return for a single request.", isRequired = false, type = RestParameter.Type.INTEGER), @RestParameter(name = "offset", description = "Number of results to skip based on the limit. 0 is the first set of results up to the limit, 1 is the second set of results after the first limit, 2 is third set of results after skipping the first two sets of results etc.", isRequired = false, type = RestParameter.Type.INTEGER) }, reponses = { @RestResponse(description = "A (potentially empty) list of events is returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getEvents(@HeaderParam("Accept") String acceptHeader, @QueryParam("id") String id, @QueryParam("commentReason") String reasonFilter, @QueryParam("commentResolution") String resolutionFilter, @QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("offset") Integer offset, @QueryParam("limit") Integer limit, @QueryParam("sign") boolean sign, @QueryParam("withacl") Boolean withAcl, @QueryParam("withmetadata") Boolean withMetadata, @QueryParam("withpublications") Boolean withPublications) {
Option<Integer> optLimit = Option.option(limit);
Option<Integer> optOffset = Option.option(offset);
Option<String> optSort = Option.option(trimToNull(sort));
EventSearchQuery query = new EventSearchQuery(getSecurityService().getOrganization().getId(), getSecurityService().getUser());
// If the limit is set to 0, this is not taken into account
if (optLimit.isSome() && limit == 0) {
optLimit = Option.none();
}
// Parse the filters
if (StringUtils.isNotBlank(filter)) {
for (String f : filter.split(",")) {
String[] filterTuple = f.split(":");
if (filterTuple.length < 2) {
logger.info("No value for filter {} in filters list: {}", filterTuple[0], filter);
continue;
}
String name = filterTuple[0];
String value = filterTuple[1];
if ("presenters".equals(name))
query.withPresenter(value);
if ("contributors".equals(name))
query.withContributor(value);
if ("location".equals(name))
query.withLocation(value);
if ("textFilter".equals(name))
query.withText("*" + value + "*");
if ("series".equals(name))
query.withSeriesId(value);
if ("subject".equals(name))
query.withSubject(value);
}
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case EventIndexSchema.TITLE:
query.sortByTitle(criterion.getOrder());
break;
case EventIndexSchema.PRESENTER:
query.sortByPresenter(criterion.getOrder());
break;
case EventIndexSchema.TECHNICAL_START:
case "technical_date":
query.sortByTechnicalStartDate(criterion.getOrder());
break;
case EventIndexSchema.TECHNICAL_END:
query.sortByTechnicalEndDate(criterion.getOrder());
break;
case EventIndexSchema.START_DATE:
case "date":
query.sortByStartDate(criterion.getOrder());
break;
case EventIndexSchema.END_DATE:
query.sortByEndDate(criterion.getOrder());
break;
case EventIndexSchema.REVIEW_STATUS:
query.sortByReviewStatus(criterion.getOrder());
break;
case EventIndexSchema.WORKFLOW_STATE:
query.sortByWorkflowState(criterion.getOrder());
break;
case EventIndexSchema.SCHEDULING_STATUS:
query.sortBySchedulingStatus(criterion.getOrder());
break;
case EventIndexSchema.SERIES_NAME:
query.sortBySeriesName(criterion.getOrder());
break;
case EventIndexSchema.LOCATION:
query.sortByLocation(criterion.getOrder());
break;
default:
return RestUtil.R.badRequest(String.format("Unknown search criterion in request: %s", criterion.getFieldName()));
}
}
}
// TODO: Add the comment resolution filter to the query
CommentResolution resolution = null;
if (StringUtils.isNotBlank(resolutionFilter)) {
try {
resolution = CommentResolution.valueOf(resolutionFilter);
} catch (Exception e) {
logger.debug("Unable to parse comment resolution filter {}", resolutionFilter);
return Response.status(Status.BAD_REQUEST).build();
}
}
if (optLimit.isSome())
query.withLimit(optLimit.get());
if (optOffset.isSome())
query.withOffset(offset);
// TODO: Add other filters to the query
SearchResult<Event> results = null;
try {
results = externalIndex.getByQuery(query);
} catch (SearchIndexException e) {
logger.error("The External Search Index was not able to get the events list: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
SearchResultItem<Event>[] items = results.getItems();
List<IndexObject> events = new ArrayList<>();
for (SearchResultItem<Event> item : items) {
Event source = item.getSource();
source.updatePreview(previewSubtype);
events.add(source);
}
try {
return getJsonEvents(acceptHeader, events, withAcl, withMetadata, withPublications, sign);
} catch (Exception e) {
logger.error("Unable to get events because: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
}
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventsEndpoint method deleteEventAce.
@DELETE
@Path("{eventId}/acl/{action}/{role}")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "deleteeventace", description = "Revokes permission to execute action on the specified event from any user with role role.", returnDescription = "", pathParameters = { @RestParameter(name = "eventId", description = "The event id", isRequired = true, type = STRING), @RestParameter(name = "action", description = "The action that is no longer allowed to be executed", isRequired = true, type = STRING), @RestParameter(name = "role", description = "The role that is no longer granted permission", isRequired = true, type = STRING) }, reponses = { @RestResponse(description = "The permission has been revoked from the access control list of the specified event.", responseCode = HttpServletResponse.SC_NO_CONTENT), @RestResponse(description = "The specified event does not exist.", responseCode = HttpServletResponse.SC_NOT_FOUND) })
public Response deleteEventAce(@HeaderParam("Accept") String acceptHeader, @PathParam("eventId") String id, @PathParam("action") String action, @PathParam("role") String role) throws Exception {
List<AccessControlEntry> entries = new ArrayList<>();
for (final Event event : indexService.getEvent(id, externalIndex)) {
AccessControlList accessControlList = getAclFromEvent(event);
boolean foundDelete = false;
for (AccessControlEntry ace : accessControlList.getEntries()) {
if (ace.getAction().equals(action) && ace.getRole().equals(role)) {
foundDelete = true;
} else {
entries.add(ace);
}
}
if (!foundDelete) {
return ApiResponses.notFound("Unable to find an access control entry with action '%s' and role '%s'", action, role);
}
AccessControlList withoutDeleted = new AccessControlList(entries);
try {
withoutDeleted = indexService.updateEventAcl(id, withoutDeleted, externalIndex);
} catch (IllegalArgumentException e) {
logger.error("Unable to delete event's '{}' acl entry with action '{}' and role '{}' because: {}", id, action, role, ExceptionUtils.getStackTrace(e));
return Response.status(Status.FORBIDDEN).build();
}
return ApiResponses.Json.noContent(ApiVersion.VERSION_1_0_0);
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class EventsEndpoint method getEventMetadataByType.
private Response getEventMetadataByType(String id, String type) throws IndexServiceException, Exception {
for (final Event event : indexService.getEvent(id, externalIndex)) {
Opt<MediaPackageElementFlavor> flavor = getFlavor(type);
if (flavor.isNone()) {
return R.badRequest(String.format("Unable to parse type '%s' as a flavor so unable to find the matching catalog.", type));
}
// Try the main catalog first as we load it from the index.
if (flavor.get().equals(eventCatalogUIAdapter.getFlavor())) {
MetadataCollection collection = EventUtils.getEventMetadata(event, eventCatalogUIAdapter);
ExternalMetadataUtils.changeSubjectToSubjects(collection);
ExternalMetadataUtils.removeCollectionList(collection);
convertStartDateTimeToApiV1(collection);
ExternalMetadataUtils.changeTypeOrderedTextToText(collection);
return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, collection.toJSON());
}
// Try the other catalogs
List<EventCatalogUIAdapter> catalogUIAdapters = getEventCatalogUIAdapters();
catalogUIAdapters.remove(eventCatalogUIAdapter);
MediaPackage mediaPackage = indexService.getEventMediapackage(event);
if (catalogUIAdapters.size() > 0) {
for (EventCatalogUIAdapter catalogUIAdapter : catalogUIAdapters) {
if (flavor.get().equals(catalogUIAdapter.getFlavor())) {
MetadataCollection fields = catalogUIAdapter.getFields(mediaPackage);
ExternalMetadataUtils.removeCollectionList(fields);
convertStartDateTimeToApiV1(fields);
ExternalMetadataUtils.changeTypeOrderedTextToText(fields);
return ApiResponses.Json.ok(ApiVersion.VERSION_1_0_0, fields.toJSON());
}
}
}
return ApiResponses.notFound("Cannot find a catalog with type '%s' for event with id '%s'.", type, id);
}
return ApiResponses.notFound("Cannot find an event with id '%s'.", id);
}
use of org.opencastproject.index.service.impl.index.event.Event in project opencast by opencast.
the class AdminUIEventSearchQueryTest method populateIndex.
/**
* Adds sample pages to the search index and returns the number of documents added.
*
* @return the number of pages added
*/
protected int populateIndex() throws Exception {
int count = 0;
// Add content to the index
for (int i = 0; i < 10; i++) {
Event event = new Event(Integer.toString(i), rightOrg.getId());
idx.addOrUpdate(event);
count++;
}
return count;
}
Aggregations