Search in sources :

Example 71 with AbstractList

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();
                }
            };
        }
    };
}
Also used : AbstractList(java.util.AbstractList) CoordinateIterator(org.olap4j.impl.CoordinateIterator) CellSetAxis(org.olap4j.CellSetAxis) Iterator(java.util.Iterator) CoordinateIterator(org.olap4j.impl.CoordinateIterator) Cell(org.olap4j.Cell)

Example 72 with AbstractList

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);
}
Also used : AbstractList(java.util.AbstractList) GroupMember(org.alfresco.rest.api.model.GroupMember) Query(org.alfresco.rest.framework.resource.parameters.where.Query) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) MapBasedQueryWalkerOrSupported(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalkerOrSupported)

Example 73 with AbstractList

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);
}
Also used : AbstractList(java.util.AbstractList) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) QName(org.alfresco.service.namespace.QName) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter) PagingRequest(org.alfresco.query.PagingRequest) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 74 with AbstractList

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());
    }
}
Also used : AbstractList(java.util.AbstractList) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) ArrayList(java.util.ArrayList) NodeRef(org.alfresco.service.cmr.repository.NodeRef) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) Tag(org.alfresco.rest.api.model.Tag) Pair(org.alfresco.util.Pair)

Example 75 with AbstractList

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);
}
Also used : AbstractList(java.util.AbstractList) Paging(org.alfresco.rest.framework.resource.parameters.Paging) PersonService(org.alfresco.service.cmr.security.PersonService) PagingRequest(org.alfresco.query.PagingRequest) Person(org.alfresco.rest.api.model.Person) Pair(org.alfresco.util.Pair)

Aggregations

AbstractList (java.util.AbstractList)76 ArrayList (java.util.ArrayList)30 List (java.util.List)17 HashMap (java.util.HashMap)10 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 QName (org.alfresco.service.namespace.QName)9 UserInfo (org.alfresco.rest.api.model.UserInfo)8 FileInfo (org.alfresco.service.cmr.model.FileInfo)8 WebApiDescription (org.alfresco.rest.framework.WebApiDescription)7 RexNode (org.apache.calcite.rex.RexNode)7 Collection (java.util.Collection)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 Iterator (java.util.Iterator)6 Paging (org.alfresco.rest.framework.resource.parameters.Paging)6 IOException (java.io.IOException)5 Set (java.util.Set)5 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)5 Test (org.junit.Test)5 ListIterator (java.util.ListIterator)4 RandomAccess (java.util.RandomAccess)4