org.apache.chemistry.opencmis.commons.data.ObjectList Java Examples

The following examples show how to use org.apache.chemistry.opencmis.commons.data.ObjectList. 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: LDCmisService.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
		String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems,
		ExtensionsData extension) {
	log.debug("getContentChanges " + changeLogToken.getValue() + "|" + filter + " | "
			+ new Date(Long.parseLong(changeLogToken.getValue())));

	validateSession();

	try {
		ObjectList ret = getRepository().getContentChanges(changeLogToken,
				maxItems != null ? (int) maxItems.doubleValue() : 2000);
		return ret;
	} catch (Throwable t) {
		log.error(t.getMessage(), t);
		throw t;
	}
}
 
Example #2
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
        Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
        BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    if (searchAllVersions.booleanValue())
    {
        throw new CmisInvalidArgumentException("Search all version is not supported!");
    }

    return connector.query(
            statement, includeAllowableActions, includeRelationships, renditionFilter,
            maxItems, skipCount);
}
 
Example #3
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 #4
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 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);
    checkId("Object Id", objectId);
    includeSubRelationshipTypes = getDefaultFalse(includeSubRelationshipTypes);
    relationshipDirection = getDefault(relationshipDirection);
    includeAllowableActions = getDefaultFalse(includeAllowableActions);
    maxItems = getMaxItems(maxItems);
    skipCount = getSkipCount(skipCount);

    try {
        return getWrappedService().getObjectRelationships(repositoryId, objectId, includeSubRelationshipTypes,
                relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount, extension);
    } catch (Exception e) {
        throw createCmisException(e);
    }
}
 
Example #5
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 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) {
    checkRepositoryId(repositoryId);
    includeAllowableActions = getDefaultFalse(includeAllowableActions);
    includeRelationships = getDefault(includeRelationships);
    renditionFilter = getDefaultRenditionFilter(renditionFilter);
    maxItems = getMaxItems(maxItems);
    skipCount = getSkipCount(skipCount);

    try {
        return getWrappedService().getCheckedOutDocs(repositoryId, folderId, filter, orderBy,
                includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, extension);
    } catch (Exception e) {
        throw createCmisException(e);
    }
}
 
Example #6
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
        String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    includeProperties = getDefaultFalse(includeProperties);
    includePolicyIds = getDefaultFalse(includePolicyIds);
    includeAcl = getDefaultFalse(includeAcl);
    maxItems = getMaxItems(maxItems);

    try {
        return getWrappedService().getContentChanges(repositoryId, changeLogToken, includeProperties, filter,
                includePolicyIds, includeAcl, maxItems, extension);
    } catch (Exception e) {
        throw createCmisException(e);
    }
}
 
Example #7
Source File: ConformanceCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
        Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
        BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    checkRepositoryId(repositoryId);
    checkQueryStatement(statement);
    searchAllVersions = getDefaultFalse(searchAllVersions);
    includeAllowableActions = getDefaultFalse(includeAllowableActions);
    includeRelationships = getDefault(includeRelationships);
    renditionFilter = getDefaultRenditionFilter(renditionFilter);
    maxItems = getMaxItems(maxItems);
    skipCount = getSkipCount(skipCount);

    try {
        return getWrappedService().query(repositoryId, statement, searchAllVersions, includeAllowableActions,
                includeRelationships, renditionFilter, maxItems, skipCount, extension);
    } catch (Exception e) {
        throw createCmisException(e);
    }
}
 
Example #8
Source File: IbisNavigationService.java    From iaf with Apache License 2.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) {
	// TODO Auto-generated method stub
	return navigationService.getCheckedOutDocs(repositoryId, folderId, filter, orderBy, includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, extension);
}
 
Example #9
Source File: IbisDiscoveryService.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectList getContentChanges(String repositoryId,
		Holder<String> changeLogToken, Boolean includeProperties,
		String filter, Boolean includePolicyIds, Boolean includeAcl,
		BigInteger maxItems, ExtensionsData extension) {
	// TODO Auto-generated method stub
	return discoveryService.getContentChanges(repositoryId, changeLogToken, includeProperties, filter, includePolicyIds, includeAcl, maxItems, extension);
}
 
Example #10
Source File: IbisDiscoveryService.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement,
		Boolean searchAllVersions, Boolean includeAllowableActions,
		IncludeRelationships includeRelationships, String renditionFilter,
		BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {

	if(!eventDispatcher.contains(CmisEvent.QUERY)) {
		return discoveryService.query(repositoryId, statement, searchAllVersions, includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, extension);
	}
	else {
		XmlBuilder cmisXml = new XmlBuilder("cmis");
		cmisXml.addSubElement(buildXml("repositoryId", repositoryId));
		cmisXml.addSubElement(buildXml("statement", statement));
		cmisXml.addSubElement(buildXml("searchAllVersions", searchAllVersions));
		cmisXml.addSubElement(buildXml("includeAllowableActions", includeAllowableActions));
		cmisXml.addSubElement(buildXml("includeRelationships", includeRelationships.name()));
		cmisXml.addSubElement(buildXml("renditionFilter", renditionFilter));
		cmisXml.addSubElement(buildXml("maxItems", maxItems));
		cmisXml.addSubElement(buildXml("skipCount", skipCount));

		IPipeLineSession context = new PipeLineSessionBase();
		context.put(CmisUtils.CMIS_CALLCONTEXT_KEY, callContext);
		Element cmisResult = eventDispatcher.trigger(CmisEvent.QUERY, cmisXml.toXML(), context);
		Element typesXml = XmlUtils.getFirstChildTag(cmisResult, "objectList");

		return CmisUtils.xml2ObjectList(typesXml, context);
	}
}
 
Example #11
Source File: FilterCmisService.java    From iaf with Apache License 2.0 5 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) {
	return getRelationshipService().getObjectRelationships(repositoryId, objectId, includeSubRelationshipTypes,
			relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount, extension);
}
 
Example #12
Source File: FilterCmisService.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
		Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
		BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
	return getDiscoveryService().query(repositoryId, statement, searchAllVersions, includeAllowableActions,
			includeRelationships, renditionFilter, maxItems, skipCount, extension);
}
 
Example #13
Source File: FilterCmisService.java    From iaf with Apache License 2.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) {
	return getNavigationService().getCheckedOutDocs(repositoryId, folderId, filter, orderBy,
			includeAllowableActions, includeRelationships, renditionFilter, maxItems, skipCount, extension);
}
 
Example #14
Source File: CmisUtils.java    From iaf with Apache License 2.0 5 votes vote down vote up
public static XmlBuilder objectList2xml(ObjectList result) {
	XmlBuilder objectListXml = new XmlBuilder("objectList");
	if(result.getNumItems() != null)
		objectListXml.addAttribute("numberOfItems", result.getNumItems().toString());
	if(result.hasMoreItems() != null)
		objectListXml.addAttribute("hasMoreItems", result.hasMoreItems());

	XmlBuilder objectDataXml = new XmlBuilder("objects");
	for (ObjectData objectData : result.getObjects()) {
		objectDataXml.addSubElement(CmisUtils.objectData2Xml(objectData));
	}
	objectListXml.addSubElement(objectDataXml);

	return objectListXml;
}
 
Example #15
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * ACE-33
 * 
 * Cmis Item support
 */
@Test
public void testItems()
{

    withCmisService(new CmisServiceCallback<String>() {
        @Override
        public String execute(CmisService cmisService) {
            List<RepositoryInfo> repositories = cmisService.getRepositoryInfos(null);
            assertTrue(repositories.size() > 0);
            RepositoryInfo repo = repositories.get(0);
            String repositoryId = repo.getId();
            
        	TypeDefinition def = cmisService.getTypeDefinition(repositoryId, "cmis:item", null);
        	assertNotNull("the cmis:item type is not defined", def); 
            
        	@SuppressWarnings("unused")
            TypeDefinition p = cmisService.getTypeDefinition(repositoryId, "I:cm:person", null);
        	assertNotNull("the I:cm:person type is not defined", def); 
        	
        	ObjectList result = cmisService.query(repositoryId, "select * from cm:person", Boolean.FALSE, Boolean.TRUE, IncludeRelationships.NONE, "", BigInteger.TEN, BigInteger.ZERO, null);
        	assertTrue("", result.getNumItems().intValue() > 0);
        	return "";
    
        };
    }, CmisVersion.CMIS_1_1);
	
}
 
Example #16
Source File: AbstractCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 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) {
    return service.getObjectRelationships(repositoryId, objectId, includeSubRelationshipTypes,
            relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount, extension);
}
 
Example #17
Source File: AbstractCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
        Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
        BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
    return service.query(repositoryId, statement, searchAllVersions, includeAllowableActions, includeRelationships,
            renditionFilter, maxItems, skipCount, extension);
}
 
Example #18
Source File: AbstractCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.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) {
    return service.getCheckedOutDocs(repositoryId, folderId, filter, orderBy, includeAllowableActions,
            includeRelationships, renditionFilter, maxItems, skipCount, extension);
}
 
Example #19
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ObjectList getContentChanges(
        String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
        String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension)
{
    checkRepositoryId(repositoryId);

    return connector.getContentChanges(changeLogToken, maxItems);
}
 
Example #20
Source File: LDCmisService.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public ObjectList query(String repositoryId, String statement, Boolean searchAllVersions,
		Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter,
		BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
	validateSession();
	return getRepository().query(statement, maxItems != null ? maxItems.intValue() : null);
}
 
Example #21
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * MNT-20139
 * CmisConnector returns wrong values for changeLogToken and hasMoreItems
 */
@Test
public void testGetContentChanges()
{
    setupAudit();

    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    try
    {
        // create folders with files
        createContent("testfolder" + GUID.generate(), "testdoc.txt" + GUID.generate(), false);
        createContent("testfolder" + GUID.generate(), "testdoc.txt" + GUID.generate(), false);
        createContent("testfolder" + GUID.generate(), "testdoc.txt" + GUID.generate(), false);

        Holder<String> changeLogToken = new Holder<String>();

        /*
         * GetContentChanges with maxitems = 2 and null changeLogToken
         * Check that changeLogToken should be the latest from the retrieved entries
         */
        ObjectList ol = this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("2"));
        assertEquals(2, ol.getObjects().size());
        assertEquals("ChangeLogToken should be latest from retrieved entries.", "2", changeLogToken.getValue());
        assertTrue(ol.hasMoreItems());

        /*
         * GetContentChanges with maxitems = 2 and changeLogToken = 0
         * Check that changeLogToken should be the latest from the retrieved entries
         */
        changeLogToken.setValue(Integer.toString(0));
        ol = this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("2"));
        assertEquals(2, ol.getObjects().size());
        assertEquals("ChangeLogToken should be latest from retrieved entries.", "2", changeLogToken.getValue());
        assertTrue(ol.hasMoreItems());

        /*
         * GetContentChanges with changeLogToken = maxChangeLogToken - 2
         * Check that changeLogToken is not null when the latest entries (fromToken) are retrieved
         */
        Long latestToken = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Long>()
        {
            public Long execute() throws Exception
            {
                return Long.parseLong(cmisConnector.getRepositoryInfo(CmisVersion.CMIS_1_1).getLatestChangeLogToken());
            }
        }, true, false);

        Long fromToken = latestToken - 2;
        changeLogToken.setValue(fromToken.toString());

        ol = this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("20"));
        assertEquals(3, ol.getObjects().size());
        assertNotNull(changeLogToken.getValue());
        assertEquals("ChangeLogToken should be the latest from all entries.", latestToken.toString(), changeLogToken.getValue());
        assertFalse(ol.hasMoreItems());
    }
    finally
    {
        auditSubsystem.destroy();
        AuthenticationUtil.popAuthentication();
    };
}
 
Example #22
Source File: AbstractCmisServiceWrapper.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
        String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension) {
    return service.getContentChanges(repositoryId, changeLogToken, includeProperties, filter, includePolicyIds,
            includeAcl, maxItems, extension);
}
 
Example #23
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * MNT-11727: move and rename operations should be shown as an UPDATE in the CMIS change log
 */
@Test
public void testMoveRenameWithCMISshouldBeAuditedAsUPDATE() throws Exception
{
    // setUp audit subsystem
    setupAudit();

    AuthenticationUtil.pushAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    try
    {
        assertTrue("Audit is not enabled", auditSubsystem.isAuditEnabled());
        assertNotNull("CMIS audit is not enabled", auditSubsystem.getAuditApplicationByName("CMISChangeLog"));

        NodeRef companyHomeNodeRef = repositoryHelper.getCompanyHome();

        String folder = GUID.generate();
        FileInfo folderInfo = fileFolderService.create(companyHomeNodeRef, folder, ContentModel.TYPE_FOLDER);

        final String actualToken = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>()
        {
            public String execute() throws Exception
            {
                return cmisConnector.getRepositoryInfo(CmisVersion.CMIS_1_1).getLatestChangeLogToken();
            }
        }, true, false);

        String content = GUID.generate();
        FileInfo document = fileFolderService.create(folderInfo.getNodeRef(), content, ContentModel.TYPE_CONTENT);
        assertNotNull(document);
        nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, content);

        Holder<String> changeLogToken = new Holder<String>();
        changeLogToken.setValue(actualToken);
        ObjectList changeLog = CMISTest.this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("10"));
        List<ObjectData> events = changeLog.getObjects();
        int count = events.size();
        // it should be 3 entries: 1 for previous folder create, 1 new CREATE (for document create)
        // and 1 NEW UPDATE
        assertEquals(3, count);

        assertEquals(events.get(0).getProperties().getPropertyList().get(0).getValues().get(0), folderInfo.getNodeRef().getId());
        assertEquals(events.get(0).getChangeEventInfo().getChangeType(), ChangeType.CREATED);

        assertTrue(((String) events.get(1).getProperties().getPropertyList().get(0).getValues().get(0)).contains(document.getNodeRef().getId()));
        assertEquals(events.get(1).getChangeEventInfo().getChangeType(), ChangeType.CREATED);

        assertTrue(((String) events.get(2).getProperties().getPropertyList().get(0).getValues().get(0)).contains(document.getNodeRef().getId()));
        assertEquals(events.get(2).getChangeEventInfo().getChangeType(), ChangeType.UPDATED);

        // test rename
        final String actualToken2 = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>()
        {
            public String execute() throws Exception
            {
                return cmisConnector.getRepositoryInfo(CmisVersion.CMIS_1_1).getLatestChangeLogToken();
            }
        }, true, false);
        nodeService.setProperty(document.getNodeRef(), ContentModel.PROP_NAME, content + "-updated");

        changeLogToken = new Holder<String>();
        changeLogToken.setValue(actualToken2);
        changeLog = CMISTest.this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("10"));
        events = changeLog.getObjects();
        count = events.size();
        assertEquals(2, count);
        assertEquals("Rename operation should be shown as an UPDATE in the CMIS change log", events.get(1).getChangeEventInfo().getChangeType(), ChangeType.UPDATED);

        // test move
        String targetFolder = GUID.generate();
        FileInfo targetFolderInfo = fileFolderService.create(companyHomeNodeRef, targetFolder, ContentModel.TYPE_FOLDER);

        final String actualToken3 = transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<String>()
        {
            public String execute() throws Exception
            {
                return cmisConnector.getRepositoryInfo(CmisVersion.CMIS_1_1).getLatestChangeLogToken();
            }
        }, true, false);
        nodeService.moveNode(document.getNodeRef(), targetFolderInfo.getNodeRef(), ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS);

        changeLogToken = new Holder<String>();
        changeLogToken.setValue(actualToken3);
        changeLog = CMISTest.this.cmisConnector.getContentChanges(changeLogToken, new BigInteger("10"));
        events = changeLog.getObjects();
        count = events.size();
        assertEquals(2, count);
        assertEquals("Move operation should be shown as an UPDATE in the CMIS change log", events.get(1).getChangeEventInfo().getChangeType(), ChangeType.UPDATED);
    }
    finally
    {
        auditSubsystem.destroy();
        AuthenticationUtil.popAuthentication();
    }
}
 
Example #24
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);
}
 
Example #25
Source File: FilterCmisService.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectList getContentChanges(String repositoryId, Holder<String> changeLogToken, Boolean includeProperties,
		String filter, Boolean includePolicyIds, Boolean includeAcl, BigInteger maxItems, ExtensionsData extension) {
	return getDiscoveryService().getContentChanges(repositoryId, changeLogToken, includeProperties, filter,
			includePolicyIds, includeAcl, maxItems, extension);
}
 
Example #26
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 #27
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 #28
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;
	}