use of org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSites.
public CollectionWithPagingInfo<Site> getSites(final Parameters parameters) {
final BeanPropertiesFilter filter = parameters.getFilter();
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
for (SortColumn sortCol : sortCols) {
QName sortPropQName = SORT_PARAMS_TO_QNAMES.get(sortCol.column);
if (sortPropQName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
}
} else {
// default sort order
sortProps.add(new Pair<>(ContentModel.PROP_TITLE, Boolean.TRUE));
}
List<FilterProp> filterProps = getFilterPropListOfSites(parameters);
final PagingResults<SiteInfo> pagingResult = siteService.listSites(filterProps, sortProps, pagingRequest);
final List<SiteInfo> sites = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Site> page = new AbstractList<Site>() {
@Override
public Site get(int index) {
SiteInfo siteInfo = sites.get(index);
String role = null;
if (filter.isAllowed(Site.ROLE)) {
role = siteService.getMembersRole(siteInfo.getShortName(), personId);
}
return new Site(siteInfo, role);
}
@Override
public int size() {
return sites.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, page, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter in project alfresco-remote-api by Alfresco.
the class SitesImpl method getFavouriteSites.
public CollectionWithPagingInfo<FavouriteSite> getFavouriteSites(String personId, Parameters parameters) {
personId = people.validatePerson(personId);
Paging paging = parameters.getPaging();
BeanPropertiesFilter filter = parameters.getFilter();
PagingResults<SiteInfo> favouriteSites = getFavouriteSites(personId, Util.getPagingRequest(paging));
List<FavouriteSite> favourites = new ArrayList<FavouriteSite>(favouriteSites.getPage().size());
for (SiteInfo favouriteSite : favouriteSites.getPage()) {
String role = null;
if (filter.isAllowed(Site.ROLE)) {
role = getSiteRole(favouriteSite.getShortName(), personId);
}
FavouriteSite favourite = new FavouriteSite(favouriteSite, role);
favourites.add(favourite);
}
return CollectionWithPagingInfo.asPaged(paging, favourites, favouriteSites.hasMoreItems(), favouriteSites.getTotalResultCount().getFirst());
}
use of org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter in project alfresco-remote-api by Alfresco.
the class SearchApiWebscript method getParams.
/**
* Gets the Params object, parameters come from the SearchQuery json not the request
* @param webScriptRequest
* @param searchQuery
* @return Params
*/
protected Params getParams(WebScriptRequest webScriptRequest, List<String> fields, List<String> include, Paging paging) {
if (paging == null) {
paging = Paging.DEFAULT;
}
BeanPropertiesFilter filter = null;
if (fields != null && !fields.isEmpty()) {
List<String> selectList = new ArrayList<>(fields.size());
selectList.addAll(fields);
if (include != null && !include.isEmpty()) {
selectList.addAll(include);
}
filter = getFilter("", selectList);
}
Params.RecognizedParams recognizedParams = new Params.RecognizedParams(null, paging, filter, null, include, null, null, null, false);
return Params.valueOf(null, recognizedParams, null, webScriptRequest);
}
use of org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractor method getRecognizedParams.
/**
* Finds the formal set of params that any rest service could potentially have passed in as request params
*
* @param req WebScriptRequest
* @return RecognizedParams a POJO containing the params for use with the Params objects
*/
default Params.RecognizedParams getRecognizedParams(WebScriptRequest req) {
Paging paging = findPaging(req);
List<SortColumn> sorting = getSort(req.getParameter(PARAM_ORDERBY));
Map<String, BeanPropertiesFilter> relationFilter = getRelationFilter(req.getParameter(PARAM_RELATIONS));
Query whereQuery = getWhereClause(req.getParameter(PARAM_WHERE));
Map<String, String[]> requestParams = getRequestParameters(req);
boolean includeSource = Boolean.valueOf(req.getParameter(PARAM_INCLUDE_SOURCE_ENTITY));
List<String> includedFields = getIncludeClause(req.getParameter(PARAM_INCLUDE));
List<String> selectFields = getSelectClause(req.getParameter(PARAM_SELECT));
String fields = req.getParameter(PARAM_FILTER_FIELDS);
String properties = req.getParameter(PARAM_FILTER_PROPERTIES);
if ((fields != null) && (properties != null)) {
if (rpeLogger().isWarnEnabled()) {
rpeLogger().warn("Taking 'fields' param [" + fields + "] and ignoring deprecated 'properties' param [" + properties + "]");
}
}
BeanPropertiesFilter filter = getFilter((fields != null ? fields : properties), includedFields);
return new Params.RecognizedParams(requestParams, paging, filter, relationFilter, includedFields, selectFields, whereQuery, sorting, includeSource);
}
use of org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractorTest method getFilterTest.
@Test
public void getFilterTest() {
BeanPropertiesFilter theFilter = getFilter(null);
assertNotNull(theFilter);
assertTrue("Null passed in so must return the default BeanPropertiesFilter.ALLOW_ALL class", BeanPropertiesFilter.AllProperties.class.equals(theFilter.getClass()));
assertTrue(theFilter.isAllowed("bob"));
assertTrue(theFilter.isAllowed("fred"));
assertTrue(theFilter.isAllowed("50"));
assertTrue(theFilter.isAllowed("b.z"));
theFilter = getFilter("bob");
assertNotNull(theFilter);
assertTrue("Must return the BeanPropertiesFilter class", theFilter instanceof BeanPropertiesFilter);
assertTrue(theFilter.isAllowed("bob"));
assertFalse(theFilter.isAllowed("fred"));
assertFalse(theFilter.isAllowed("50"));
assertFalse(theFilter.isAllowed("b.z"));
theFilter = getFilter("50,fred,b.z");
assertNotNull(theFilter);
assertTrue("Must return the BeanPropertiesFilter class", theFilter instanceof BeanPropertiesFilter);
assertFalse(theFilter.isAllowed("bob"));
assertTrue(theFilter.isAllowed("fred"));
assertTrue(theFilter.isAllowed("50"));
assertTrue(theFilter.isAllowed("b.z"));
theFilter = getFilter("50,fred,");
assertNotNull(theFilter);
assertTrue("Must return the BeanPropertiesFilter class", theFilter instanceof BeanPropertiesFilter);
assertFalse(theFilter.isAllowed("bob"));
assertTrue(theFilter.isAllowed("fred"));
assertTrue(theFilter.isAllowed("50"));
assertFalse(theFilter.isAllowed("b.z"));
theFilter = getFilter("50, bob, fred ,");
assertNotNull(theFilter);
assertTrue("Must return the BeanPropertiesFilter class", theFilter instanceof BeanPropertiesFilter);
assertTrue(theFilter.isAllowed("bob"));
assertTrue(theFilter.isAllowed("fred"));
assertTrue(theFilter.isAllowed("50"));
assertFalse(theFilter.isAllowed("b.z"));
}
Aggregations