org.apache.chemistry.opencmis.client.api.Folder Java Examples

The following examples show how to use org.apache.chemistry.opencmis.client.api.Folder. 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: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<Tree<FileableCmisObject>> getFolderTree(String folderId, int depth)
{
    CmisObject o = session.getObject(folderId);
    if(o instanceof Folder)
    {
        Folder f = (Folder)o;

        OperationContextImpl ctx = new OperationContextImpl();
        List<Tree<FileableCmisObject>> res = f.getFolderTree(depth, ctx);
        return res;
    }
    else
    {
        throw new IllegalArgumentException("Object does not exist or is not a folder");
    }
}
 
Example #2
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public FolderNode getDescendants(String folderId, int depth)
{
    Session session = getCMISSession();

    CmisObject o = session.getObject(folderId);
    if(o instanceof Folder)
    {
        Folder f = (Folder)o;

        OperationContextImpl ctx = new OperationContextImpl();
        List<Tree<FileableCmisObject>> res = f.getDescendants(depth, ctx);
        FolderNode ret = (FolderNode)CMISNode.createNode(f);
        for(Tree<FileableCmisObject> t : res)
        {
            addChildren(ret, t);
        }

        return ret;
    }
    else
    {
        throw new IllegalArgumentException("Folder does not exist or is not a folder");
    }
}
 
Example #3
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create test document with content
 * 
 * @param target
 * @param newDocName
 */
private static void createDocument(Folder target, String newDocName) {
	Map<String, String> props = new HashMap<String, String>();
	props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
	props.put(PropertyIds.NAME, newDocName);
	props.put(TypeManager.PROP_TAGS, "tag1,tag2,tag3");
	System.out.println("This is a test document: " + newDocName);
	String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation.";
	byte[] buf = null;
	try {
		buf = content.getBytes("UTF-8");
	} catch (UnsupportedEncodingException e) {
		e.printStackTrace();
	}
	ByteArrayInputStream input = new ByteArrayInputStream(buf);
	ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length,
			"text/plain; fileNameCharset=UTF-8", input);
	target.createDocument(props, contentStream, VersioningState.NONE);
}
 
Example #4
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
public List<Folder> getObjectParents(String objectId)
{
    CmisObject o = session.getObject(objectId);
    if(o instanceof FileableCmisObject)
    {
        FileableCmisObject f = (FileableCmisObject)o;

        OperationContextImpl ctx = new OperationContextImpl();
        List<Folder> res = f.getParents(ctx);
        return res;
    }
    else
    {
        throw new IllegalArgumentException("Object does not exist or is not a fileable cmis object");
    }
}
 
Example #5
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Document createUniqueDocument(Folder newFolder)
		throws UnsupportedEncodingException {
	String uniqueName = getUniqueName();
       Map<String, Object> uProperties = new HashMap<String, Object>();
       uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
       uProperties.put(PropertyIds.NAME, uniqueName);
       
       ContentStreamImpl contentStream = new ContentStreamImpl();
       contentStream.setFileName("bob");
       String shortString = "short";
       contentStream.setStream(new ByteArrayInputStream(shortString.getBytes("UTF-8")));
       contentStream.setLength(new BigInteger("5"));
       contentStream.setMimeType("text/plain");
       
       Document uniqueDocument = newFolder.createDocument(uProperties, contentStream, VersioningState.MAJOR);
       return uniqueDocument;
}
 
Example #6
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
private void deleteAllContent() {
    Session session = createSession();
    Folder rootFolder = session.getRootFolder();
    ItemIterable<CmisObject> children = rootFolder.getChildren();
    for (CmisObject cmisObject : children) {
        if ("cmis:folder".equals(cmisObject.getPropertyValue(PropertyIds.OBJECT_TYPE_ID))) {
            List<String> notDeltedIdList = ((Folder)cmisObject)
                    .deleteTree(true, UnfileObject.DELETE, true);
            if (notDeltedIdList != null && notDeltedIdList.size() > 0) {
                throw new RuntimeException("Cannot empty repo");
            }
        } else {
            cmisObject.delete(true);
        }
    }
    session.getBinding().close();
}
 
Example #7
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static Document createDocument(Folder target, String newDocName, Session session)
{
    Map<String, String> props = new HashMap<String, String>();
    props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    props.put(PropertyIds.NAME, newDocName);
    String content = "aegif Mind Share Leader Generating New Paradigms by aegif corporation.";
    byte[] buf = null;
    try
    {
        buf = content.getBytes("ISO-8859-1"); // set the encoding here for the content stream
    }
    catch (UnsupportedEncodingException e)
    {
        e.printStackTrace();
    }

    ByteArrayInputStream input = new ByteArrayInputStream(buf);

    ContentStream contentStream = session.getObjectFactory().createContentStream(newDocName, buf.length,
            "text/plain; charset=UTF-8", input); // additionally set the charset here
    // NOTE that we intentionally specified the wrong charset here (as UTF-8)
    // because Alfresco does automatic charset detection, so we will ignore this explicit request
    return target.createDocument(props, contentStream, VersioningState.MAJOR);
}
 
Example #8
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public FolderNode getChildren(String folderId, int skipCount, int maxItems)
{
    CmisObject o = session.getObject(folderId);
    if(o instanceof Folder)
    {
        Folder f = (Folder)o;
        FolderNode ret = (FolderNode)CMISNode.createNode(f);

        OperationContextImpl ctx = new OperationContextImpl();
        ItemIterable<CmisObject> res = f.getChildren(ctx);
        res.skipTo(skipCount);
        ItemIterable<CmisObject> l = res.getPage(maxItems);
        for(CmisObject c : l)
        {
            CMISNode child = null;
            if(c.getBaseType() instanceof FolderTypeDefinition)
            {
                child = (FolderNode)CMISNode.createNode(c);
                ret.addFolder((FolderNode)child);
            }
            else
            {
                child = CMISNode.createNode(c);
                ret.addNode(child);
            }
        }

        return ret;
    }
    else
    {
        throw new IllegalArgumentException("Folder does not exist or is not a folder");
    }
}
 
Example #9
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<String> removeTree(String objectId, boolean allVersions, UnfileObject unfile, boolean continueOnFailure)
{
    CmisObject o = getObject(objectId);
    if(o instanceof Folder)
    {
        Folder f = (Folder)o;
        List<String> res = f.deleteTree(allVersions, unfile, continueOnFailure);
        return res;
    }
    else
    {
        throw new IllegalArgumentException("Object does not exist or is not a folder");
    }
}
 
Example #10
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public FolderNode getRootFolder()
{
    Folder rootFolder = session.getRootFolder();

    FolderNode ret = (FolderNode)CMISNode.createNode(rootFolder);
    return ret;
}
 
Example #11
Source File: TestRemovePermissions.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param session Session
 * @param name String
 * @return Folder
 */
private Folder createFolder(Session session, String name)
{
    Folder testFolder;
    Folder folder = session.getRootFolder();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, name);

    testFolder = folder.createFolder(properties);

    return testFolder;
}
 
Example #12
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Document createDocument(String parentId, String name, Map<String, Serializable> properties, ContentStream contentStream, VersioningState versioningState)
{
    CmisObject o = getObject(parentId);

    if(o instanceof Folder)
    {
        Folder f = (Folder)o;

        if(properties == null)
        {
            properties = new HashMap<String, Serializable>();
        }
        String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID);
        String type = "cmis:document";
        if(objectTypeId == null)
        {
            objectTypeId = type;
        }
        if(objectTypeId.indexOf(type) == -1)
        {
            StringBuilder sb = new StringBuilder(objectTypeId);
            if(sb.length() > 0)
            {
                sb.append(",");
            }
            sb.append(type);
            objectTypeId = sb.toString();
        }

        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);

        Document res = f.createDocument(properties, contentStream, versioningState);
        return res;
    }
    else
    {
        throw new IllegalArgumentException("Parent does not exists or is not a folder");
    }
}
 
Example #13
Source File: PublicApiClient.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Folder createFolder(String folderId, String name, Map<String, Serializable> properties)
{
    CmisObject o = getObject(folderId);

    if(o instanceof Folder)
    {
        Folder f = (Folder)o;

        if(properties == null)
        {
            properties = new HashMap<String, Serializable>();
        }
        String objectTypeId = (String)properties.get(PropertyIds.OBJECT_TYPE_ID);
        String type = "cmis:folder";
        if(objectTypeId == null)
        {
            objectTypeId = type;
        }
        if(objectTypeId.indexOf(type) == -1)
        {
            StringBuilder sb = new StringBuilder(objectTypeId);
            if(sb.length() > 0)
            {
                sb.append(",");
            }
            sb.append(type);
            objectTypeId = sb.toString();
        }

        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);

        Folder res = f.createFolder(properties);
        return res;
    }
    else
    {
        throw new IllegalArgumentException("Parent does not exist or is not a folder");
    }
}
 
Example #14
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main1(String[] args) throws IOException {

		Folder root = connect();
		root.getName();

		// cleanup(root, TEST_FOLDER_NAME);
		// Folder newFolder = createFolder(root, TEST_FOLDER_NAME);
		// createDocument(newFolder, TEST_DOCUMENT_NAME_1);
		// createDocument(newFolder, TEST_DOCUMENT_NAME_2);
		// System.out.println("+++ List Folder +++");
		// listFolder(0, newFolder);
		// DeleteDocument(newFolder, "/" + TEST_DOCUMENT_NAME_2);
		// System.out.println("+++ List Folder +++");
		// listFolder(0, newFolder);

		CmisObject object = session.getObjectByPath(TEST_FOLDER_PATH);
		System.out.println(object.getId() + " " + object.getName());
		//
		// object = session.getObjectByPath(TEST_FOLDER_NAME + "/" +
		// TEST_DOCUMENT_NAME_1);
		// System.out.println(object.getId() + " " +
		// object.getProperty(TypeManager.PROP_TITLE).getValues().get(0));

		// checkoutCheckin();

		ItemIterable<QueryResult> result = session
				.query("SELECT cmis:objectId,cmis:name,ldoc:tags FROM cmis:document WHERE ldoc:tags = '12345'", true);
		for (QueryResult r : result) {
			System.out.println("result: " + r.getPropertyById("ldoc:tags"));
		}
	}
 
Example #15
Source File: TestCreateAction.java    From iaf with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
	@Override
	public CmisSender createSender() throws ConfigurationException {
		CmisSender sender = spy(new CmisSender());

		sender.setUrl("http://dummy.url");
		sender.setRepository("dummyRepository");
		sender.setUsername("test");
		sender.setPassword("test");
		sender.setKeepSession(false);

		Session cmisSession = mock(Session.class);
		ObjectFactory objectFactory = mock(ObjectFactoryImpl.class);
		doReturn(objectFactory).when(cmisSession).getObjectFactory();

//			GENERIC cmis object
		ObjectId objectId = mock(ObjectIdImpl.class);
		doReturn(objectId).when(cmisSession).createObjectId(anyString());
		CmisObject cmisObject = spy(new CmisTestObject());
		doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class));
		doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class), any(OperationContext.class));
		
//			CREATE
		Folder folder = mock(FolderImpl.class);
		doReturn(cmisObject).when(folder).createDocument(anyMap(), any(ContentStreamImpl.class), any(VersioningState.class));
		doReturn(folder).when(cmisSession).getRootFolder();
		doReturn(objectId).when(cmisSession).createDocument(anyMap(), any(ObjectId.class), any(ContentStreamImpl.class), any(VersioningState.class));
		doReturn("dummy_id").when(objectId).getId();
		
		try {
			doReturn(cmisSession).when(sender).createCmisSession(any(ParameterValueList.class));
		} catch (SenderException e) {
			//Since we stub the entire session it won't throw exceptions
		}

		return sender;
	}
 
Example #16
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testEncodingForCreateContentStream()
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    FileFolderService ffs = serviceRegistry.getFileFolderService();
    // Authenticate as system
    AuthenticationComponent authenticationComponent = (AuthenticationComponent) ctx
            .getBean(BEAN_NAME_AUTHENTICATION_COMPONENT);
    authenticationComponent.setSystemUserAsCurrentUser();
    try
    {
        /* Create the document using openCmis services */
        Repository repository = getRepository("admin", "admin");
        Session session = repository.createSession();
        Folder rootFolder = session.getRootFolder();
        Document document = createDocument(rootFolder, "test_file_" + GUID.generate() + ".txt", session);

        ContentStream content = document.getContentStream();
        assertNotNull(content);

        content = document.getContentStream(BigInteger.valueOf(2), BigInteger.valueOf(4));
        assertNotNull(content);

        NodeRef doc1NodeRef = cmisIdToNodeRef(document.getId());
        FileInfo fileInfo = ffs.getFileInfo(doc1NodeRef);
        Map<QName, Serializable> properties = fileInfo.getProperties();
        ContentDataWithId contentData = (ContentDataWithId) properties
                .get(QName.createQName("{http://www.alfresco.org/model/content/1.0}content"));
        String encoding = contentData.getEncoding();

        assertEquals("ISO-8859-1", encoding);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
}
 
Example #17
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Clean up test folder before executing test
 * 
 * @param target
 * @param delFolderName
 */
private static void cleanup(Folder target, String delFolderName) {
	try {
		CmisObject object = session.getObjectByPath(target.getPath() + delFolderName);
		Folder delFolder = (Folder) object;
		delFolder.deleteTree(true, UnfileObject.DELETE, true);
	} catch (CmisObjectNotFoundException e) {
		System.err.println("No need to clean up.");
	}
}
 
Example #18
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 
 * @param target
 */
private static void listFolder(int depth, Folder target) {
	String indent = StringUtils.repeat("\t", depth);
	for (Iterator<CmisObject> it = target.getChildren().iterator(); it.hasNext();) {
		CmisObject o = it.next();
		if (BaseTypeId.CMIS_DOCUMENT.equals(o.getBaseTypeId())) {
			System.out.println(indent + "[Docment] " + o.getName());
		} else if (BaseTypeId.CMIS_FOLDER.equals(o.getBaseTypeId())) {
			System.out.println(indent + "[Folder] " + o.getName());
			listFolder(++depth, (Folder) o);
		}
	}

}
 
Example #19
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Delete test document
 * 
 * @param target
 * @param delDocName
 */
private static void deleteDocument(Folder target, String delDocName) {
	try {
		CmisObject object = session.getObjectByPath(target.getPath() + delDocName);
		Document delDoc = (Document) object;
		delDoc.delete(true);
	} catch (CmisObjectNotFoundException e) {
		System.err.println("Document is not found: " + delDocName);
	}
}
 
Example #20
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create test folder directly under target folder
 * 
 * @param target
 * @param createFolderName
 * @return newly created folder
 */
private static Folder createFolder(Folder target, String newFolderName) {
	Map<String, String> props = new HashMap<String, String>();
	props.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
	props.put(PropertyIds.NAME, newFolderName);
	Folder newFolder = target.createFolder(props);
	return newFolder;
}
 
Example #21
Source File: SampleClient.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Connect to logicaldoc repository
 * 
 * @return root folder object
 */
private static Folder connect(String username, String password) {
	SessionFactory sessionFactory = SessionFactoryImpl.newInstance();
	Map<String, String> parameter = new HashMap<String, String>();
	parameter.put(SessionParameter.USER, username);
	parameter.put(SessionParameter.PASSWORD, password);
	parameter.put(SessionParameter.ATOMPUB_URL, CONNECTION_URL);
	parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());
	parameter.put(SessionParameter.REPOSITORY_ID, Long.toString(5L));

	session = sessionFactory.createSession(parameter);
	return session.getRootFolder();
}
 
Example #22
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void DISABLED_testBasicFileOps()
{
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    // create folder
    Map<String,String> folderProps = new HashMap<String, String>();
    {
        folderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
        folderProps.put(PropertyIds.NAME, getName() + "-" + GUID.generate());
    }
    Folder folder = rootFolder.createFolder(folderProps, null, null, null, session.getDefaultContext());
    
    Map<String, String> fileProps = new HashMap<String, String>();
    {
        fileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
        fileProps.put(PropertyIds.NAME, "mydoc-" + GUID.generate() + ".txt");
    }
    ContentStreamImpl fileContent = new ContentStreamImpl();
    {
        ContentWriter writer = new FileContentWriter(TempFileProvider.createTempFile(getName(), ".txt"));
        writer.putContent("Ipsum and so on");
        ContentReader reader = writer.getReader();
        fileContent.setMimeType(MimetypeMap.MIMETYPE_TEXT_PLAIN);
        fileContent.setStream(reader.getContentInputStream());
    }
    folder.createDocument(fileProps, fileContent, VersioningState.MAJOR);
}
 
Example #23
Source File: OpenCmisLocalTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testDownloadEvent() throws InterruptedException
{
    Repository repository = getRepository("admin", "admin");
    Session session = repository.createSession();
    Folder rootFolder = session.getRootFolder();
    String docname = "mydoc-" + GUID.generate() + ".txt";
    Map<String, String> props = new HashMap<String, String>();
    {
        props.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
        props.put(PropertyIds.NAME, docname);
    }
    
    // content
    byte[] byteContent = "Hello from Download testing class".getBytes();
    InputStream stream = new ByteArrayInputStream(byteContent);
    ContentStream contentStream = new ContentStreamImpl(docname, BigInteger.valueOf(byteContent.length), "text/plain", stream);

    Document doc1 = rootFolder.createDocument(props, contentStream, VersioningState.MAJOR);
    NodeRef doc1NodeRef = cmisIdToNodeRef(doc1.getId());
    
    ContentStream content = doc1.getContentStream();
    assertNotNull(content);
    
    //range request
    content = doc1.getContentStream(BigInteger.valueOf(2),BigInteger.valueOf(4));
    assertNotNull(content);
}
 
Example #24
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private void createTextDocument(Folder newFolder, String content, String fileName)
        throws UnsupportedEncodingException {
    byte[] buf = content.getBytes("UTF-8");
    ByteArrayInputStream input = new ByteArrayInputStream(buf);
    ContentStream contentStream = createSession().getObjectFactory()
            .createContentStream(fileName, buf.length, "text/plain; charset=UTF-8", input);

    Map<String, Object> properties = new HashMap<>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, CamelCMISConstants.CMIS_DOCUMENT);
    properties.put(PropertyIds.NAME, fileName);
    newFolder.createDocument(properties, contentStream, VersioningState.NONE);
}
 
Example #25
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private void populateRepositoryRootFolderWithTwoFoldersAndTwoDocuments()
        throws UnsupportedEncodingException {
    Folder folder1 = createFolderWithName("Folder1");
    Folder folder2 = createChildFolderWithName(folder1, "Folder2");
    createTextDocument(folder2, "Document2.1", "2.1.txt");
    createTextDocument(folder2, "Document2.2", "2.2.txt");
}
 
Example #26
Source File: CMISDataCreatorTest.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testCreate()
{
    Session session = getSession("admin", "admin");
    
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);

    // create the folder
    Folder newFolder = root.createFolder(properties);
    
    for(int i = 0; i < 50; i++)
    {
        AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("user"+i);
        List<String> permissions = new ArrayList<String>(1);
        permissions.add(BasicPermissions.READ);
        List<Ace> addAces = new ArrayList<Ace>(1);
        addAces.add(new AccessControlEntryImpl(principal, permissions));
        newFolder.addAcl(addAces, AclPropagation.PROPAGATE);
        
        Map<String, Object> updateProperties = new HashMap<String, Object>();
        updateProperties.put("cm:title", "Update title "+i);
        newFolder.updateProperties(properties);
        
        if(i % 10 == 0)
        {
            System.out.println("@ "+i);
        }
    }
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
    assertTrue(result.getTotalNumItems() > 0);
    
    result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false);
    assertTrue(result.getTotalNumItems() > 0);
    
}
 
Example #27
Source File: CmisServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
@Override
@HasPermission(type = DefaultPermission.class, action = "list_cmis")
public List<CmisContentItem> list(@ProtectedResourceId(SITE_ID_RESOURCE_ID) String siteId,
                                  String cmisRepo, String path)
        throws CmisRepositoryNotFoundException, CmisUnavailableException, CmisTimeoutException {
    List<CmisContentItem> items = new ArrayList<CmisContentItem>();
    DataSourceRepository repositoryConfig = getConfiguration(siteId, cmisRepo);
    if (repositoryConfig != null) {
        Session session = createCMISSession(repositoryConfig);
        if (session != null) {
            String contentPath = Paths.get(repositoryConfig.getBasePath(), path).toString();
            CmisObject cmisObject = session.getObjectByPath(contentPath);
            if (cmisObject != null) {
                if (CMIS_FOLDER.equals(cmisObject.getBaseTypeId())) {
                    Folder folder = (Folder)cmisObject;
                    Iterable<CmisObject> iterable = folder.getChildren();
                    Iterator<CmisObject> iterator = iterable.iterator();
                    while (iterator.hasNext()) {
                        CmisContentItem item = new CmisContentItem();
                        CmisObject cmisItem = iterator.next();
                        item.setItemName(cmisItem.getName());
                        if (CMIS_DOCUMENT.equals(cmisItem.getBaseTypeId())) {
                            org.apache.chemistry.opencmis.client.api.Document cmisDoc =
                                    (org.apache.chemistry.opencmis.client.api.Document)cmisItem;
                            item.setItemPath(cmisDoc.getPaths().get(0));
                            item.setMimeType(cmisDoc.getContentStreamMimeType());
                            String contentId = cmisDoc.getId();
                            StringTokenizer st = new StringTokenizer(contentId, ";");
                            if (st.hasMoreTokens()) {
                                item.setItemId(st.nextToken());
                            }
                            item.setSize(cmisDoc.getContentStreamLength());
                            items.add(item);
                        } else if (CMIS_FOLDER.equals(cmisItem.getBaseTypeId())) {
                            Folder cmisFolder = (Folder)cmisItem;
                            item.setItemId(cmisFolder.getId());
                            item.setItemPath(cmisFolder.getPath());
                            item.setMimeType(MIME_TYPE_FOLDER);
                            item.setSize(-1);
                            items.add(item);
                        }
                    }
                }
            }
        }
    }
    return items;
}
 
Example #28
Source File: CmisIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private Folder createFolderWithName(String folderName) {
    Folder rootFolder = createSession().getRootFolder();
    return createChildFolderWithName(rootFolder, folderName);
}
 
Example #29
Source File: TestBindingTypes.java    From iaf with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
	@Override
	public CmisSender createSender() throws ConfigurationException {
		CmisSender sender = spy(new CmisSender());

		sender.setUrl("http://dummy.url");
		sender.setRepository("dummyRepository");
		sender.setFileContentSessionKey("fileContent");
		sender.setFileNameSessionKey("my-file");
		sender.setUsername("test");
		sender.setPassword("test");
		sender.setKeepSession(false);

		byte[] base64 = Base64.encodeBase64("dummy data".getBytes());
		session.put("fileContent", new String(base64));
		HttpServletResponse response = mock(HttpServletResponse.class);
		session.put(IPipeLineSession.HTTP_RESPONSE_KEY, response);

		Session cmisSession = mock(Session.class);
		ObjectFactory objectFactory = mock(ObjectFactoryImpl.class);
		doReturn(objectFactory).when(cmisSession).getObjectFactory();

//		GENERIC cmis object
		ObjectId objectId = mock(ObjectIdImpl.class);
		doReturn(objectId).when(cmisSession).createObjectId(anyString());
		CmisObject cmisObject = spy(new CmisTestObject());
		doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class));
		doReturn(cmisObject).when(cmisSession).getObject(any(ObjectId.class), any(OperationContext.class));

//		GET
		OperationContext operationContext = mock(OperationContextImpl.class);
		doReturn(operationContext).when(cmisSession).createOperationContext();

//		CREATE
		Folder folder = mock(FolderImpl.class);
		doReturn(cmisObject).when(folder).createDocument(anyMap(), any(ContentStreamImpl.class), any(VersioningState.class));
		doReturn(folder).when(cmisSession).getRootFolder();

//		FIND
		ItemIterable<QueryResult> query = new EmptyItemIterable<QueryResult>();
		doReturn(query).when(cmisSession).query(anyString(), anyBoolean(), any(OperationContext.class));

		try {
			doReturn(cmisSession).when(sender).createCmisSession(any(ParameterValueList.class));
		} catch (SenderException e) {
			//Since we stub the entire session it won't throw exceptions
		}

		return sender;
	}
 
Example #30
Source File: CmisTestObject.java    From iaf with Apache License 2.0 4 votes vote down vote up
@Override
public List<Folder> getParents() {
	// TODO Auto-generated method stub
	return null;
}