use of java.util.AbstractList in project pentaho-kettle by pentaho.
the class CellSetFormatter method cellIter.
/**
* Returns an iterator over cells in a result.
*/
private static Iterable<Cell> cellIter(final int[] pageCoords, final CellSet cellSet) {
return new Iterable<Cell>() {
public Iterator<Cell> iterator() {
final int[] axisDimensions = new int[cellSet.getAxes().size() - pageCoords.length];
assert pageCoords.length <= axisDimensions.length;
for (int i = 0; i < axisDimensions.length; i++) {
final CellSetAxis axis = cellSet.getAxes().get(i);
axisDimensions[i] = axis.getPositions().size();
}
final CoordinateIterator coordIter = new CoordinateIterator(axisDimensions, true);
return new Iterator<Cell>() {
public boolean hasNext() {
return coordIter.hasNext();
}
public Cell next() {
final int[] ints = coordIter.next();
final AbstractList<Integer> intList = new AbstractList<Integer>() {
@Override
public Integer get(final int index) {
return index < ints.length ? ints[index] : pageCoords[index - ints.length];
}
@Override
public int size() {
return pageCoords.length + ints.length;
}
};
return cellSet.getCell(intList);
}
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
use of java.util.AbstractList in project alfresco-remote-api by Alfresco.
the class GroupsFilter method getGroupMembers.
public CollectionWithPagingInfo<GroupMember> getGroupMembers(String groupId, final Parameters parameters) {
validateGroupId(groupId, false);
// Not allowed to list all members.
if (PermissionService.ALL_AUTHORITIES.equals(groupId)) {
throw new UnsupportedResourceOperationException();
}
Paging paging = parameters.getPaging();
// Retrieve sort column. This is limited for now to sort column due to
// v0 api implementation. Should be improved in the future.
Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
AuthorityType authorityType = null;
// Parse where clause properties.
Query q = parameters.getQuery();
if (q != null) {
MapBasedQueryWalkerOrSupported propertyWalker = new MapBasedQueryWalkerOrSupported(LIST_GROUP_MEMBERS_QUERY_PROPERTIES, null);
QueryHelper.walk(q, propertyWalker);
String memberTypeStr = propertyWalker.getProperty(PARAM_MEMBER_TYPE, WhereClauseParser.EQUALS, String.class);
authorityType = getAuthorityType(memberTypeStr);
}
PagingResults<AuthorityInfo> pagingResult = getAuthoritiesInfo(authorityType, groupId, sortProp, paging);
// Create response.
final List<AuthorityInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
List<GroupMember> groupMembers = new AbstractList<GroupMember>() {
@Override
public GroupMember get(int index) {
AuthorityInfo authorityInfo = page.get(index);
return getGroupMember(authorityInfo);
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, groupMembers, pagingResult.hasMoreItems(), totalItems);
}
use of java.util.AbstractList 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 java.util.AbstractList in project alfresco-remote-api by Alfresco.
the class TagsImpl method addTags.
public List<Tag> addTags(String nodeId, final List<Tag> tags) {
NodeRef nodeRef = nodes.validateNode(nodeId);
if (!typeConstraint.matches(nodeRef)) {
throw new UnsupportedResourceOperationException("Cannot tag this node");
}
List<String> tagValues = new AbstractList<String>() {
@Override
public String get(int arg0) {
String tag = tags.get(arg0).getTag();
return tag;
}
@Override
public int size() {
return tags.size();
}
};
try {
List<Pair<String, NodeRef>> tagNodeRefs = taggingService.addTags(nodeRef, tagValues);
List<Tag> ret = new ArrayList<Tag>(tags.size());
for (Pair<String, NodeRef> pair : tagNodeRefs) {
ret.add(new Tag(pair.getSecond(), pair.getFirst()));
}
return ret;
} catch (IllegalArgumentException e) {
throw new InvalidArgumentException(e.getMessage());
}
}
use of java.util.AbstractList in project alfresco-remote-api by Alfresco.
the class PeopleImpl method getPeople.
@Override
public CollectionWithPagingInfo<Person> getPeople(final Parameters parameters) {
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
List<Pair<QName, Boolean>> sortProps = getSortProps(parameters);
// For now the results are not filtered
// please see REPO-555
final PagingResults<PersonService.PersonInfo> pagingResult = personService.getPeople(null, null, sortProps, pagingRequest);
final List<PersonService.PersonInfo> page = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Person> people = new AbstractList<Person>() {
@Override
public Person get(int index) {
PersonService.PersonInfo personInfo = page.get(index);
Person person = getPersonWithProperties(personInfo.getUserName(), parameters.getInclude());
return person;
}
@Override
public int size() {
return page.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, people, pagingResult.hasMoreItems(), totalItems);
}
Aggregations