use of org.opencastproject.matterhorn.search.SearchResultItem in project opencast by opencast.
the class EventIndexUtilsTest method testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName.
@Test
@SuppressWarnings("unchecked")
public void testUpdateSeriesNameInputSeriesEventuallyAddedToIndexExpectsSetsName() throws SearchIndexException {
// Input data
String seriesId = "my_series";
String eventId = "my_event";
// Mocks
Series series = EasyMock.createMock(Series.class);
EasyMock.expect(series.getTitle()).andReturn(seriesId);
SearchResultItem<Series> seriesResult = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(seriesResult.getSource()).andReturn(series);
ArrayList<SearchResultItem<Series>> seriesCollection = new ArrayList<SearchResultItem<Series>>();
seriesCollection.add(seriesResult);
SearchResult<Series> eventuallyResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(0L);
EasyMock.expect(eventuallyResult.getHitCount()).andReturn(1L);
EasyMock.expect(eventuallyResult.getItems()).andReturn(seriesCollection.toArray(new SearchResultItem[1]));
Event event = EasyMock.createMock(Event.class);
EasyMock.expect(event.getSeriesId()).andReturn(seriesId).anyTimes();
EasyMock.expect(event.getSeriesName()).andReturn(null).anyTimes();
EasyMock.expect(event.getIdentifier()).andReturn(eventId).anyTimes();
event.setSeriesName(seriesId);
EasyMock.expectLastCall();
AbstractSearchIndex searchIndex = EasyMock.createMock(AbstractSearchIndex.class);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.expect(searchIndex.getByQuery(EasyMock.anyObject(SeriesSearchQuery.class))).andReturn(eventuallyResult);
EasyMock.replay(eventuallyResult, event, searchIndex, series, seriesResult);
// Run test
EventIndexUtils.updateSeriesName(event, defaultOrganization.getId(), user, searchIndex, 3, 50L);
}
use of org.opencastproject.matterhorn.search.SearchResultItem in project opencast by opencast.
the class TestSeriesEndpoint method createEvents.
@SuppressWarnings("unchecked")
private SearchResultItem<Event>[] createEvents(int readyCount, int blacklistedCount, int optedOutCount) {
SearchResultItem<Event>[] eventitems = new SearchResultItem[readyCount + blacklistedCount + optedOutCount];
int total = 1;
String orgId = new DefaultOrganization().getId();
for (int i = 0; i < readyCount; i++) {
Event readyEvent = new Event(Integer.toString(i + total), orgId);
readyEvent.setOptedOut(false);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(readyEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
for (int i = 0; i < blacklistedCount; i++) {
Event blacklistedEvent = new Event(Integer.toString(i + total), orgId);
blacklistedEvent.setBlacklisted(true);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(blacklistedEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
for (int i = 0; i < optedOutCount; i++) {
Event optedOutEvent = new Event(Integer.toString(i + total), orgId);
optedOutEvent.setOptedOut(true);
SearchResultItem<Event> eventItem = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(eventItem.getSource()).andReturn(optedOutEvent);
EasyMock.replay(eventItem);
eventitems[total - 1] = eventItem;
total++;
}
return eventitems;
}
use of org.opencastproject.matterhorn.search.SearchResultItem in project opencast by opencast.
the class TestSeriesEndpoint method setupIndex.
@SuppressWarnings({ "unchecked" })
private void setupIndex() throws SearchIndexException, IOException, IllegalStateException, ParseException {
long time = DateTimeSupport.fromUTC("2014-04-27T14:35:50Z");
Series series1 = createSeries("1", "title 1", "contributor 1", "organizer 1", time, 1L);
time = DateTimeSupport.fromUTC("2014-04-28T14:35:50Z");
Series series2 = createSeries("2", "title 2", "contributor 2", "organizer 2", time, null);
time = DateTimeSupport.fromUTC("2014-04-29T14:35:50Z");
Series series3 = createSeries("3", "title 3", "contributor 3", "organizer 3", time, null);
org.opencastproject.index.service.impl.index.theme.Theme theme1 = new org.opencastproject.index.service.impl.index.theme.Theme(1L, new DefaultOrganization().getId());
theme1.setName("theme-1-name");
theme1.setDescription("theme-1-description");
SearchResultItem<Series> item1 = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(item1.getSource()).andReturn(series1).anyTimes();
SearchResultItem<Series> item2 = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(item2.getSource()).andReturn(series2).anyTimes();
SearchResultItem<Series> item3 = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(item3.getSource()).andReturn(series3).anyTimes();
SearchResultItem<Series>[] ascSeriesItems = new SearchResultItem[3];
ascSeriesItems[0] = item1;
ascSeriesItems[1] = item2;
ascSeriesItems[2] = item3;
SearchResultItem<Series>[] descSeriesItems = new SearchResultItem[3];
descSeriesItems[0] = item3;
descSeriesItems[1] = item2;
descSeriesItems[2] = item1;
// final SearchResultItem<Event>[] eventItems1 = new SearchResultItem[0];
final SearchResultItem<Event>[] eventItems1 = createEvents(1, 1, 1);
// Setup the events for series 2
final SearchResultItem<Event>[] eventItems2 = new SearchResultItem[0];
// Setup the events for series 3
final SearchResultItem<Event>[] eventItems3 = createEvents(0, 1, 2);
final SearchResultItem<org.opencastproject.index.service.impl.index.theme.Theme> themeItem1 = EasyMock.createMock(SearchResultItem.class);
EasyMock.expect(themeItem1.getSource()).andReturn(theme1);
// Setup series search results
final SearchResult<Series> ascSeriesSearchResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(ascSeriesSearchResult.getItems()).andReturn(ascSeriesItems);
EasyMock.expect(ascSeriesSearchResult.getHitCount()).andReturn((long) ascSeriesItems.length);
final SearchResult<Series> descSeriesSearchResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(descSeriesSearchResult.getItems()).andReturn(descSeriesItems);
EasyMock.expect(descSeriesSearchResult.getHitCount()).andReturn((long) descSeriesItems.length);
// Create an empty search result.
final SearchResult<Series> emptySearchResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(emptySearchResult.getPageSize()).andReturn(0L).anyTimes();
// Create a single search result for series 1.
final SearchResult<Series> oneSearchResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(oneSearchResult.getPageSize()).andReturn(1L).anyTimes();
EasyMock.expect(oneSearchResult.getItems()).andReturn(new SearchResultItem[] { item1 }).anyTimes();
// Create a single search result for series 2.
final SearchResult<Series> twoSearchResult = EasyMock.createMock(SearchResult.class);
EasyMock.expect(twoSearchResult.getPageSize()).andReturn(1L).anyTimes();
EasyMock.expect(twoSearchResult.getItems()).andReturn(new SearchResultItem[] { item2 }).anyTimes();
adminuiSearchIndex = EasyMock.createMock(AdminUISearchIndex.class);
final Capture<SeriesSearchQuery> captureSeriesSearchQuery = EasyMock.newCapture();
final Capture<EventSearchQuery> captureEventSearchQuery = EasyMock.newCapture();
final Capture<ThemeSearchQuery> captureThemeSearchQuery = EasyMock.newCapture();
EasyMock.expect(adminuiSearchIndex.getByQuery(EasyMock.capture(captureSeriesSearchQuery))).andAnswer(new IAnswer<SearchResult<Series>>() {
@Override
public SearchResult<Series> answer() throws Throwable {
if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getIdentifier().length == 1) {
if ("1".equals(captureSeriesSearchQuery.getValue().getIdentifier()[0])) {
return oneSearchResult;
} else if ("2".equals(captureSeriesSearchQuery.getValue().getIdentifier()[0])) {
return twoSearchResult;
} else {
return emptySearchResult;
}
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesContributorsSortOrder() == Order.Ascending) {
return ascSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesContributorsSortOrder() == Order.Descending) {
return descSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesDateSortOrder() == Order.Ascending) {
return ascSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesDateSortOrder() == Order.Descending) {
return descSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesOrganizersSortOrder() == Order.Ascending) {
return ascSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesOrganizersSortOrder() == Order.Descending) {
return descSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesTitleSortOrder() == Order.Ascending) {
return ascSeriesSearchResult;
} else if (captureSeriesSearchQuery.hasCaptured() && captureSeriesSearchQuery.getValue().getSeriesTitleSortOrder() == Order.Descending) {
return descSeriesSearchResult;
} else {
return ascSeriesSearchResult;
}
}
});
EasyMock.expect(adminuiSearchIndex.getByQuery(EasyMock.capture(captureEventSearchQuery))).andAnswer(new IAnswer<SearchResult<Event>>() {
@Override
public SearchResult<Event> answer() throws Throwable {
SearchResult<Event> eventsSearchResult = EasyMock.createMock(SearchResult.class);
if (captureEventSearchQuery.hasCaptured() && "1".equals(captureEventSearchQuery.getValue().getSeriesId()) && !("RUNNING".equals(captureEventSearchQuery.getValue().getWorkflowState())) && !("INSTANTIATED".equals(captureEventSearchQuery.getValue().getWorkflowState()))) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems1).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems1.length).anyTimes();
} else if (captureEventSearchQuery.hasCaptured() && "1".equals(captureEventSearchQuery.getValue().getSeriesId()) && "INSTANTIATED".equals(captureEventSearchQuery.getValue().getWorkflowState())) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems2).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems2.length).anyTimes();
} else if (captureEventSearchQuery.hasCaptured() && "1".equals(captureEventSearchQuery.getValue().getSeriesId()) && "RUNNING".equals(captureEventSearchQuery.getValue().getWorkflowState())) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems2).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems2.length).anyTimes();
} else if (captureEventSearchQuery.hasCaptured() && "2".equals(captureEventSearchQuery.getValue().getSeriesId()) && !("RUNNING".equals(captureEventSearchQuery.getValue().getWorkflowState()))) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems2).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems2.length).anyTimes();
} else if (captureEventSearchQuery.hasCaptured() && "3".equals(captureEventSearchQuery.getValue().getSeriesId())) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems3).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems3.length).anyTimes();
} else if (captureEventSearchQuery.hasCaptured() && "2".equals(captureEventSearchQuery.getValue().getSeriesId()) && "RUNNING".equals(captureEventSearchQuery.getValue().getWorkflowState())) {
// Setup events search results
EasyMock.expect(eventsSearchResult.getItems()).andReturn(eventItems3).anyTimes();
EasyMock.expect(eventsSearchResult.getHitCount()).andReturn((long) eventItems3.length).anyTimes();
} else {
if (!captureEventSearchQuery.hasCaptured()) {
Assert.fail("Haven't captured an event search query yet.");
} else {
logger.info("IDs for search query" + captureEventSearchQuery.getValue().getSeriesId());
Assert.fail("Tried to get an event collection that doesn't exist.");
}
}
EasyMock.replay(eventsSearchResult);
return eventsSearchResult;
}
}).anyTimes();
EasyMock.expect(adminuiSearchIndex.getByQuery(EasyMock.capture(captureThemeSearchQuery))).andAnswer(new IAnswer<SearchResult<org.opencastproject.index.service.impl.index.theme.Theme>>() {
@Override
public SearchResult<org.opencastproject.index.service.impl.index.theme.Theme> answer() throws Throwable {
SearchResult<org.opencastproject.index.service.impl.index.theme.Theme> themeSearchResult = EasyMock.createMock(SearchResult.class);
// Setup theme search results
EasyMock.expect(themeSearchResult.getPageSize()).andReturn(1L).anyTimes();
EasyMock.expect(themeSearchResult.getItems()).andReturn(new SearchResultItem[] { themeItem1 }).anyTimes();
EasyMock.replay(themeSearchResult);
return themeSearchResult;
}
}).anyTimes();
EasyMock.replay(adminuiSearchIndex, item1, item2, item3, themeItem1, ascSeriesSearchResult, descSeriesSearchResult, emptySearchResult, oneSearchResult, twoSearchResult);
}
use of org.opencastproject.matterhorn.search.SearchResultItem 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.matterhorn.search.SearchResultItem in project opencast by opencast.
the class SeriesEndpoint method getSeriesList.
@GET
@Path("")
@Produces({ "application/json", "application/v1.0.0+json" })
@RestQuery(name = "getseries", description = "Returns a list of series.", returnDescription = "", restParameters = { @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 series is returned.", responseCode = HttpServletResponse.SC_OK) })
public Response getSeriesList(@HeaderParam("Accept") String acceptHeader, @QueryParam("filter") String filter, @QueryParam("sort") String sort, @QueryParam("order") String order, @QueryParam("offset") int offset, @QueryParam("limit") int limit) throws UnauthorizedException {
try {
SeriesSearchQuery query = new SeriesSearchQuery(securityService.getOrganization().getId(), securityService.getUser());
Option<String> optSort = Option.option(trimToNull(sort));
if (offset > 0) {
query.withOffset(offset);
}
// If limit is 0, we set the default limit
query.withLimit(limit < 1 ? DEFAULT_LIMIT : limit);
// 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 ("managedAcl".equals(name)) {
query.withAccessPolicy(value);
} else if ("contributors".equals(name)) {
query.withContributor(value);
} else if ("CreationDate".equals(name)) {
if (name.split("/").length == 2) {
try {
Tuple<Date, Date> fromAndToCreationRange = getFromAndToCreationRange(name.split("/")[0], name.split("/")[1]);
query.withCreatedFrom(fromAndToCreationRange.getA());
query.withCreatedTo(fromAndToCreationRange.getB());
} catch (IllegalArgumentException e) {
return RestUtil.R.badRequest(e.getMessage());
}
}
query.withCreator(value);
} else if ("Creator".equals(name)) {
query.withCreator(value);
} else if ("textFilter".equals(name)) {
query.withText("*" + value + "*");
} else if ("language".equals(name)) {
query.withLanguage(value);
} else if ("license".equals(name)) {
query.withLicense(value);
} else if ("organizers".equals(name)) {
query.withOrganizer(value);
} else if ("subject".equals(name)) {
query.withSubject(value);
} else if ("title".equals(name)) {
query.withTitle(value);
}
}
}
if (optSort.isSome()) {
Set<SortCriterion> sortCriteria = RestUtils.parseSortQueryParameter(optSort.get());
for (SortCriterion criterion : sortCriteria) {
switch(criterion.getFieldName()) {
case SeriesIndexSchema.TITLE:
query.sortByTitle(criterion.getOrder());
break;
case SeriesIndexSchema.CONTRIBUTORS:
query.sortByContributors(criterion.getOrder());
break;
case SeriesIndexSchema.CREATOR:
query.sortByOrganizers(criterion.getOrder());
break;
case EventIndexSchema.CREATED:
query.sortByCreatedDateTime(criterion.getOrder());
break;
default:
logger.info("Unknown filter criteria {}", criterion.getFieldName());
return Response.status(SC_BAD_REQUEST).build();
}
}
}
logger.trace("Using Query: " + query.toString());
SearchResult<Series> result = externalIndex.getByQuery(query);
return ApiResponses.Json.ok(VERSION_1_0_0, arr($(result.getItems()).map(new Fn<SearchResultItem<Series>, JValue>() {
@Override
public JValue apply(SearchResultItem<Series> a) {
final Series s = a.getSource();
JValue subjects;
if (s.getSubject() == null) {
subjects = arr();
} else {
subjects = arr(splitSubjectIntoArray(s.getSubject()));
}
Date createdDate = s.getCreatedDateTime();
return obj(f("identifier", v(s.getIdentifier())), f("title", v(s.getTitle())), f("creator", v(s.getCreator(), BLANK)), f("created", v(createdDate != null ? toUTC(createdDate.getTime()) : null, BLANK)), f("subjects", subjects), f("contributors", arr($(s.getContributors()).map(Functions.stringToJValue))), f("organizers", arr($(s.getOrganizers()).map(Functions.stringToJValue))), f("publishers", arr($(s.getPublishers()).map(Functions.stringToJValue))));
}
}).toList()));
} catch (Exception e) {
logger.warn("Could not perform search query: {}", ExceptionUtils.getStackTrace(e));
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
}
Aggregations