org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CmisUtils.java    From iaf with Apache License 2.0 6 votes vote down vote up
public static ObjectList xml2ObjectList(Element result, IPipeLineSession context) {
	ObjectListImpl objectList = new ObjectListImpl();
	objectList.setNumItems(CmisUtils.parseBigIntegerAttr(result, "numberOfItems"));
	objectList.setHasMoreItems(CmisUtils.parseBooleanAttr(result, "hasMoreItems"));

	List<ObjectData> objects = new ArrayList<ObjectData>();

	Element objectsElem = XmlUtils.getFirstChildTag(result, "objects");
	for (Node type : XmlUtils.getChildTags(objectsElem, "objectData")) {
		ObjectData objectData = xml2ObjectData((Element) type, context);
		objects.add(objectData);
	}
	objectList.setObjects(objects);

	return objectList;
}
 
Example #2
Source File: CmisServiceImpl.java    From document-management-system with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ObjectList getCheckedOutDocs(String repositoryId, String folderId, String filter, String orderBy,
                                    Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems,
                                    BigInteger skipCount, ExtensionsData extension) {
	log.debug("getCheckedOutDocs({}, {}, {})", new Object[]{repositoryId, folderId, filter});
	ObjectListImpl result = new ObjectListImpl();

	result.setHasMoreItems(false);
	result.setNumItems(BigInteger.ZERO);
	List<ObjectData> emptyList = Collections.emptyList();
	result.setObjects(emptyList);

	return result;
}
 
Example #3
Source File: LDRepository.java    From document-management-software with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ObjectList getContentChanges(Holder<String> changeLogToken, int max) throws CmisPermissionDeniedException {
		
		log.debug("getContentChanges {}", changeLogToken.getValue());
		
		if (changeLogToken == null) 
			throw new CmisInvalidArgumentException("Missing change log token holder");
		
		long minDate;

		try {
			minDate = Long.parseLong(changeLogToken.getValue());
		} catch (NumberFormatException e) {
			throw new CmisInvalidArgumentException("Invalid change log token");
		}
		
		ObjectListImpl ol = new ObjectListImpl();
		
		List<ObjectData> odsDocs = getDocumentLastChanges(minDate, max);
		List<ObjectData> odsFolders = getFolderLastChanges(minDate, max);
		
		//put together the 2 lists
		List<ObjectData> complex = new ArrayList<ObjectData>();
		complex.addAll(odsDocs);
		complex.addAll(odsFolders);
		
//	    log.debug("Before sort");
//	    for (ObjectData objectData : complex) {
//	    	log.debug("ChangeTime {}", objectData.getChangeEventInfo().getChangeTime().getTime());
//		}		
		
		// sort the content of list complex by date
		Collections.sort(complex, new Comparator<ObjectData>() {
			public int compare(ObjectData o1, ObjectData o2) {
				return o1.getChangeEventInfo().getChangeTime().getTime()
						.compareTo(o2.getChangeEventInfo().getChangeTime().getTime());
			}
		});
		
//	    log.debug("After sort");
//	    for (ObjectData objectData : complex) {
//	    	log.debug("ChangeTime {} {} {} {}", objectData.getChangeEventInfo().getChangeType(), objectData.getId() ,objectData.getChangeEventInfo().getChangeTime().getTime(), objectData.getChangeEventInfo().getChangeTime().getTime().getTime());
//		}
	    
	    boolean hasMoreItems = complex.size() > max;
        if (hasMoreItems) {
        	complex = complex.subList(0, max);
        }

		ol.setObjects(complex);
		
		Date date = null;
		if (complex.size() > 0) {
			//ol.setNumItems(BigInteger.valueOf(complex.size()));
			ol.setNumItems(BigInteger.valueOf(-1));
			//ol.setHasMoreItems(true);
			ol.setHasMoreItems(Boolean.valueOf(hasMoreItems));
			date = ((ObjectData)complex.get(complex.size() -1)).getChangeEventInfo().getChangeTime().getTime();
// 			log.debug("date {}", date);
// 			log.debug("date.getTime {}", date.getTime());
		} else {
			ol.setHasMoreItems(Boolean.valueOf(false));
			ol.setNumItems(BigInteger.ZERO);
		}

		String latestChangeLogToken = date == null ? null : String.valueOf(date.getTime());
		log.debug("latestChangeLogToken {}", latestChangeLogToken);
		changeLogToken.setValue(latestChangeLogToken);

		return ol;
	}
 
Example #4
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ObjectList getObjectRelationships(NodeRef nodeRef, RelationshipDirection relationshipDirection,
        String typeId, String filter, Boolean includeAllowableActions, BigInteger maxItems, BigInteger skipCount)
{
    ObjectListImpl result = new ObjectListImpl();
    result.setHasMoreItems(false);
    result.setNumItems(BigInteger.ZERO);
    result.setObjects(new ArrayList<ObjectData>());

    if (nodeRef.getStoreRef().getProtocol().equals(VersionBaseModel.STORE_PROTOCOL))
    {
        // relationships from and to versions are not preserved
        return result;
    }

    // get relationships
    List<AssociationRef> assocs = new ArrayList<AssociationRef>();
    if (relationshipDirection == RelationshipDirection.SOURCE
            || relationshipDirection == RelationshipDirection.EITHER)
    {
        assocs.addAll(nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }
    if (relationshipDirection == RelationshipDirection.TARGET
            || relationshipDirection == RelationshipDirection.EITHER)
    {
        assocs.addAll(nodeService.getSourceAssocs(nodeRef, RegexQNamePattern.MATCH_ALL));
    }

    int skip = (skipCount == null ? 0 : skipCount.intValue());
    int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
    int counter = 0;
    boolean hasMore = false;

    if (max > 0)
    {
        // filter relationships that not map the CMIS domain model
        for (AssociationRef assocRef : assocs)
        {
            TypeDefinitionWrapper assocTypeDef = getOpenCMISDictionaryService().findAssocType(assocRef.getTypeQName());
            if (assocTypeDef == null || getType(assocRef.getSourceRef()) == null
                    || getType(assocRef.getTargetRef()) == null)
            {
                continue;
            }

            if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId))
            {
                continue;
            }

            counter++;

            if (skip > 0)
            {
                skip--;
                continue;
            }

            max--;
            if (max > 0)
            {
            	try
            	{
                 result.getObjects().add(
                         createCMISObject(createNodeInfo(assocRef), filter, includeAllowableActions,
                                 IncludeRelationships.NONE, RENDITION_NONE, false, false/*, cmisVersion*/));
                }
                catch(CmisObjectNotFoundException e)
                {
                    // ignore objects that have not been found (perhaps because their type is unknown to CMIS)
                }
            }
            else
            {
                hasMore = true;
            }
        }
    }

    result.setNumItems(BigInteger.valueOf(counter));
    result.setHasMoreItems(hasMore);

    return result;
}
 
Example #5
Source File: CMISConnector.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Returns content changes.
 */
public ObjectList getContentChanges(Holder<String> changeLogToken, BigInteger maxItems)
{
    final ObjectListImpl result = new ObjectListImpl();
    result.setObjects(new ArrayList<ObjectData>());

    // Collect entryIds to use a counter and a way to find the last changeLogToken
    final List<Long> entryIds = new ArrayList<Long>();

    EntryIdCallback changeLogCollectingCallback = new EntryIdCallback(true)
    {
        @Override
        public boolean handleAuditEntry(Long entryId, String user, long time, Map<String, Serializable> values)
        {
            entryIds.add(entryId);
            result.getObjects().addAll(createChangeEvents(time, values));
            return super.handleAuditEntry(entryId, user, time, values);
        }
    };

    Long from = null;
    if ((changeLogToken != null) && (changeLogToken.getValue() != null))
    {
        try
        {
            from = Long.parseLong(changeLogToken.getValue());
        }
        catch (NumberFormatException e)
        {
            throw new CmisInvalidArgumentException("Invalid change log token: " + changeLogToken.getValue());
        }
    }

    AuditQueryParameters params = new AuditQueryParameters();
    params.setApplicationName(CMIS_CHANGELOG_AUDIT_APPLICATION);
    params.setForward(true);
    params.setFromId(from);

    // So we have a BigInteger.  We need to ensure that we cut it down to an integer smaller than Integer.MAX_VALUE
    
    int maxResults = (maxItems == null ? contentChangesDefaultMaxItems : maxItems.intValue());
    maxResults = maxResults < 1 ? contentChangesDefaultMaxItems : maxResults;           // Just a double check of the unbundled contents
    maxResults = maxResults > contentChangesDefaultMaxItems ? contentChangesDefaultMaxItems : maxResults;   // cut it down
    int queryFor = maxResults + 1;                          // Query for 1 more so that we know if there are more results

    auditService.auditQuery(changeLogCollectingCallback, params, queryFor);

    int resultSize = result.getObjects().size();

    // Use the entryIds as a counter is more reliable then the result.getObjects().
    // result.getObjects() can be more or less then the requested maxResults, because it is filtered based on the content.
    boolean hasMoreItems = entryIds.size() >= maxResults;
    result.setHasMoreItems(hasMoreItems);
    // Check if we got more than the client requested
    if (hasMoreItems && resultSize >= maxResults)
    {
        // We are assuming there are there is only one extra document now in line with how it used to behave
        // Remove extra item that was not actually requested
        result.getObjects().remove(resultSize - 1);
        entryIds.remove(resultSize - 1);
    }

    if (changeLogToken != null)
    {
        //Update the changelog after removing the last item if there are more items.
        Long newChangeLogToken = entryIds.isEmpty() ? from : entryIds.get(entryIds.size() - 1);
        changeLogToken.setValue(String.valueOf(newChangeLogToken));
    }

    return result;
}
 
Example #6
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ObjectList getObjectRelationships(
        String repositoryId, String objectId, Boolean includeSubRelationshipTypes,
        RelationshipDirection relationshipDirection, String typeId, String filter, Boolean includeAllowableActions,
        BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    // what kind of object is it?
    CMISNodeInfo info = getOrCreateNodeInfo(objectId, "Object");

    if (info.isVariant(CMISObjectVariant.ASSOC))
    {
        throw new CmisInvalidArgumentException("Object is a relationship!");
    }

    if (info.isVariant(CMISObjectVariant.VERSION))
    {
        throw new CmisInvalidArgumentException("Object is a document version!");
    }

    // check if the relationship base type is requested
    if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId))
    {
        boolean isrt = (includeSubRelationshipTypes == null ? false : includeSubRelationshipTypes.booleanValue());
        if (isrt)
        {
            // all relationships are a direct subtype of the base type in
            // Alfresco -> remove filter
            typeId = null;
        }
        else
        {
            // there are no relationships of the base type in Alfresco ->
            // return empty list
            ObjectListImpl result = new ObjectListImpl();
            result.setHasMoreItems(false);
            result.setNumItems(BigInteger.ZERO);
            result.setObjects(new ArrayList<ObjectData>());
            return result;
        }
    }

    return connector.getObjectRelationships(
            info.getNodeRef(), relationshipDirection, typeId, filter, includeAllowableActions,
            maxItems, skipCount);
}