use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.
the class SeriesListProvider method getList.
@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) throws ListProviderException {
Map<String, String> series = new HashMap<String, String>();
SeriesQuery q = new SeriesQuery().setCount(Integer.MAX_VALUE);
if (query != null) {
if (query.hasFilter(FILTER_TEXT)) {
StringListFilter filter = (StringListFilter) query.getFilter(FILTER_TEXT);
if (filter.getValue().isSome())
q.setText(filter.getValue().get());
}
if (query.getLimit().isSome())
q.setCount(query.getLimit().get());
if (query.getOffset().isSome())
q.setStartPage(query.getOffset().get());
}
List<DublinCoreCatalog> result = null;
try {
if (!CONTRIBUTORS.equals(listName) && !ORGANIZERS.equals(listName) && !TITLE_EXTENDED.equals(listName)) {
return seriesService.getIdTitleMapOfAllSeries();
}
result = seriesService.getSeries(q).getCatalogList();
} catch (SeriesException e) {
throw new ListProviderException("Error appends on the series service: " + e);
} catch (UnauthorizedException e) {
throw new ListProviderException("Unauthorized access to series service: " + e);
}
for (DublinCoreCatalog dc : result) {
if (CONTRIBUTORS.equals(listName)) {
String contributor = dc.getFirst(DublinCore.PROPERTY_CONTRIBUTOR);
if (StringUtils.isNotBlank(contributor))
series.put(contributor, contributor);
} else if (ORGANIZERS.equals(listName)) {
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
if (StringUtils.isNotBlank(organizer))
series.put(organizer, organizer);
} else if (TITLE_EXTENDED.equals(listName)) {
String created = dc.getFirst(DublinCoreCatalog.PROPERTY_CREATED);
String organizer = dc.getFirst(DublinCore.PROPERTY_CREATOR);
StringBuilder sb = new StringBuilder(dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
if (StringUtils.isNotBlank(created) && StringUtils.isNotBlank(organizer)) {
List<String> extendedTitleData = new ArrayList<>();
if (StringUtils.isNotBlank(created)) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(EncodingSchemeUtils.decodeDate(created));
extendedTitleData.add(Integer.toString(calendar.get(Calendar.YEAR)));
}
if (StringUtils.isNotBlank(organizer))
extendedTitleData.add(organizer);
sb.append(" (").append(StringUtils.join(extendedTitleData, ", ")).append(")");
}
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), sb.toString());
} else {
series.put(dc.getFirst(DublinCore.PROPERTY_IDENTIFIER), dc.getFirst(DublinCoreCatalog.PROPERTY_TITLE));
}
}
return series;
}
use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.
the class SeriesServiceRemoteImpl method getSeriesAsJson.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("series.json")
@RestQuery(name = "listSeriesAsJson", description = "Returns the series matching the query parameters", returnDescription = "Returns the series search results as JSON", restParameters = { @RestParameter(name = "q", isRequired = false, description = "Free text search", type = STRING), @RestParameter(name = "edit", isRequired = false, description = "Whether this query should return only series that are editable", type = BOOLEAN), @RestParameter(name = "fuzzyMatch", isRequired = false, description = "Whether a partial match on series id is allowed, default is false", type = BOOLEAN), @RestParameter(name = "seriesId", isRequired = false, description = "The series identifier", type = STRING), @RestParameter(name = "seriesTitle", isRequired = false, description = "The series title", type = STRING), @RestParameter(name = "creator", isRequired = false, description = "The series creator", type = STRING), @RestParameter(name = "contributor", isRequired = false, description = "The series contributor", type = STRING), @RestParameter(name = "publisher", isRequired = false, description = "The series publisher", type = STRING), @RestParameter(name = "rightsholder", isRequired = false, description = "The series rights holder", type = STRING), @RestParameter(name = "createdfrom", isRequired = false, description = "Filter results by created from (yyyy-MM-dd'T'HH:mm:ss'Z')", type = STRING), @RestParameter(name = "createdto", isRequired = false, description = "Filter results by created to (yyyy-MM-dd'T'HH:mm:ss'Z')", type = STRING), @RestParameter(name = "language", isRequired = false, description = "The series language", type = STRING), @RestParameter(name = "license", isRequired = false, description = "The series license", type = STRING), @RestParameter(name = "subject", isRequired = false, description = "The series subject", type = STRING), @RestParameter(name = "abstract", isRequired = false, description = "The series abstract", type = STRING), @RestParameter(name = "description", isRequired = false, description = "The series description", type = STRING), @RestParameter(name = "sort", isRequired = false, description = "The sort order. May include any of the following: TITLE, SUBJECT, CREATOR, PUBLISHER, CONTRIBUTOR, ABSTRACT, DESCRIPTION, CREATED, AVAILABLE_FROM, AVAILABLE_TO, LANGUAGE, RIGHTS_HOLDER, SPATIAL, TEMPORAL, IS_PART_OF, REPLACES, TYPE, ACCESS, LICENCE. Add '_DESC' to reverse the sort order (e.g. TITLE_DESC).", type = STRING), @RestParameter(name = "startPage", isRequired = false, description = "The page offset", type = STRING), @RestParameter(name = "count", isRequired = false, description = "Results per page (max 100)", type = STRING) }, reponses = { @RestResponse(responseCode = SC_OK, description = "The access control list."), @RestResponse(responseCode = SC_UNAUTHORIZED, description = "If the current user is not authorized to perform this action") })
public // CHECKSTYLE:OFF
Response getSeriesAsJson(@QueryParam("q") String text, @QueryParam("seriesId") String seriesId, @QueryParam("edit") Boolean edit, @QueryParam("fuzzyMatch") Boolean fuzzyMatch, @QueryParam("seriesTitle") String seriesTitle, @QueryParam("creator") String creator, @QueryParam("contributor") String contributor, @QueryParam("publisher") String publisher, @QueryParam("rightsholder") String rightsHolder, @QueryParam("createdfrom") String createdFrom, @QueryParam("createdto") String createdTo, @QueryParam("language") String language, @QueryParam("license") String license, @QueryParam("subject") String subject, @QueryParam("abstract") String seriesAbstract, @QueryParam("description") String description, @QueryParam("sort") String sort, @QueryParam("startPage") String startPage, @QueryParam("count") String count) throws UnauthorizedException {
// CHECKSTYLE:ON
try {
SeriesQuery seriesQuery = getSeries(text, seriesId, edit, seriesTitle, creator, contributor, publisher, rightsHolder, createdFrom, createdTo, language, license, subject, seriesAbstract, description, sort, startPage, count, fuzzyMatch);
DublinCoreCatalogList result = getSeries(seriesQuery);
return Response.ok(result.getResultsAsJson()).build();
} catch (UnauthorizedException e) {
throw e;
} catch (Exception e) {
logger.warn("Could not perform search query: {}", e.getMessage());
}
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR);
}
use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.
the class SeriesServiceImplTest method testSeriesFuzzyIdSearchQuery.
@Test
public void testSeriesFuzzyIdSearchQuery() throws Exception {
testCatalog.set(DublinCore.PROPERTY_IDENTIFIER, "20160119999");
seriesService.updateSeries(testCatalog);
SeriesQuery q = new SeriesQuery().setSeriesId("201601");
q.setFuzzyMatch(true);
List<DublinCoreCatalog> result = seriesService.getSeries(q).getCatalogList();
Assert.assertEquals(1, result.size());
}
use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.
the class SeriesServiceSolrTest method testAccessControlManagmentRewrite.
@Test
public void testAccessControlManagmentRewrite() throws Exception {
// sample access control list
SecurityService securityService = EasyMock.createNiceMock(SecurityService.class);
User user = new JaxbUser("anonymous", "test", new DefaultOrganization(), new JaxbRole("ROLE_ANONYMOUS", new DefaultOrganization()));
EasyMock.expect(securityService.getOrganization()).andReturn(new DefaultOrganization()).anyTimes();
EasyMock.expect(securityService.getUser()).andReturn(user).anyTimes();
EasyMock.replay(securityService);
// deactivate the default index created in setUp()
index.deactivate();
// create a new index with the security service anonymous user
index = new SeriesServiceSolrIndex();
index.solrRoot = PathSupport.concat("target", Long.toString(System.currentTimeMillis()));
dcService = new DublinCoreCatalogService();
index.setDublinCoreService(dcService);
index.setSecurityService(securityService);
index.activate(null);
AccessControlList accessControlList = new AccessControlList();
List<AccessControlEntry> acl = accessControlList.getEntries();
acl.add(new AccessControlEntry("ROLE_ANONYMOUS", Permissions.Action.READ.toString(), true));
index.updateIndex(testCatalog);
String seriesID = testCatalog.getFirst(DublinCore.PROPERTY_IDENTIFIER);
index.updateSecurityPolicy(seriesID, accessControlList);
SeriesQuery q = new SeriesQuery();
DublinCoreCatalogList result = index.search(q);
Assert.assertTrue("Only one anomymous series", result.size() == 1);
index.updateSecurityPolicy(seriesID, new AccessControlList());
q = new SeriesQuery();
result = index.search(q);
Assert.assertTrue("No anomymous series", result.size() == 0);
}
use of org.opencastproject.series.api.SeriesQuery in project opencast by opencast.
the class SeriesServiceSolrTest method testSpecialOrgId.
@Test
public void testSpecialOrgId() throws Exception {
String seriesId = "09157c61-d886-4b4a-a7b1-48da8618e780";
DublinCoreCatalog firstCatalog = dcService.newInstance();
firstCatalog.add(DublinCore.PROPERTY_IDENTIFIER, seriesId);
firstCatalog.add(DublinCore.PROPERTY_TITLE, "Cats and Dogs");
firstCatalog.add(DublinCore.PROPERTY_CREATED, "2007-05-03");
index.updateIndex(firstCatalog);
SeriesQuery q = new SeriesQuery().setSeriesId(seriesId);
DublinCoreCatalogList result = index.search(q);
Assert.assertTrue("One series satisfy id", result.size() == 1);
Assert.assertEquals(1, index.count());
index.delete(seriesId);
result = index.search(q);
Assert.assertTrue("No series satisfy id", result.size() == 0);
Assert.assertEquals(0, index.count());
}
Aggregations