Example usage for com.liferay.portal.sharepoint Tree addChild

List of usage examples for com.liferay.portal.sharepoint Tree addChild

Introduction

In this page you can find the example usage for com.liferay.portal.sharepoint Tree addChild.

Prototype

public void addChild(ResponseElement node) 

Source Link

Usage

From source file:com.liferay.portlet.documentlibrary.sharepoint.DLSharepointStorageImpl.java

License:Open Source License

@Override
public Tree getDocumentsTree(SharepointRequest sharepointRequest) throws Exception {

    Tree documentsTree = new Tree();

    String parentFolderPath = sharepointRequest.getRootPath();

    long groupId = SharepointUtil.getGroupId(parentFolderPath);
    long parentFolderId = getLastFolderId(groupId, parentFolderPath,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    if (parentFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        List<FileEntry> fileEntries = DLAppServiceUtil.getFileEntries(groupId, parentFolderId);

        for (FileEntry fileEntry : fileEntries) {
            documentsTree.addChild(getFileEntryTree(fileEntry, parentFolderPath));
        }/*from w w  w.  j ava2  s  . co  m*/
    }

    return documentsTree;
}

From source file:com.liferay.portlet.documentlibrary.sharepoint.DLSharepointStorageImpl.java

License:Open Source License

@Override
public Tree getFoldersTree(SharepointRequest sharepointRequest) throws Exception {

    Tree foldersTree = new Tree();

    String parentFolderPath = sharepointRequest.getRootPath();

    long groupId = SharepointUtil.getGroupId(parentFolderPath);
    long parentFolderId = getLastFolderId(groupId, parentFolderPath,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    List<Folder> folders = DLAppServiceUtil.getFolders(groupId, parentFolderId, false);

    for (Folder folder : folders) {
        foldersTree.addChild(getFolderTree(folder, parentFolderPath));
    }//from   ww  w.java2  s.  co  m

    foldersTree.addChild(getFolderTree(parentFolderPath));

    return foldersTree;
}

From source file:com.liferay.portlet.documentlibrary.sharepoint.DLSharepointStorageImpl.java

License:Open Source License

@Override
public Tree[] moveDocument(SharepointRequest sharepointRequest) throws Exception {

    String parentFolderPath = sharepointRequest.getRootPath();

    long groupId = SharepointUtil.getGroupId(parentFolderPath);

    Folder folder = null;//w w w .ja  va2s  .  c o  m
    FileEntry fileEntry = null;

    try {
        long parentFolderId = getLastFolderId(groupId, parentFolderPath,
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

        folder = DLAppServiceUtil.getFolder(parentFolderId);
    } catch (Exception e1) {
        if (e1 instanceof NoSuchFolderException) {
            try {
                fileEntry = getFileEntry(sharepointRequest);
            } catch (Exception e2) {
            }
        }
    }

    Tree movedDocsTree = new Tree();
    Tree movedDirsTree = new Tree();

    String newPath = sharepointRequest.getParameterValue("newUrl");
    String newParentFolderPath = getParentFolderPath(newPath);

    long newGroupId = SharepointUtil.getGroupId(newParentFolderPath);

    long newParentFolderId = getLastFolderId(newGroupId, newParentFolderPath,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

    String newName = getResourceName(newPath);

    ServiceContext serviceContext = new ServiceContext();

    if (fileEntry != null) {
        File file = null;

        try {
            long fileEntryId = fileEntry.getFileEntryId();

            long folderId = fileEntry.getFolderId();
            String mimeType = fileEntry.getMimeType();
            String description = fileEntry.getDescription();
            String changeLog = StringPool.BLANK;

            InputStream is = fileEntry.getContentStream();

            file = FileUtil.createTempFile(is);

            String[] assetTagNames = AssetTagLocalServiceUtil.getTagNames(FileEntry.class.getName(),
                    fileEntry.getFileEntryId());

            serviceContext.setAssetTagNames(assetTagNames);

            fileEntry = DLAppServiceUtil.updateFileEntry(fileEntryId, newName, mimeType, newName, description,
                    changeLog, false, file, serviceContext);

            if (folderId != newParentFolderId) {
                fileEntry = DLAppServiceUtil.moveFileEntry(fileEntryId, newParentFolderId, serviceContext);
            }

            Tree documentTree = getFileEntryTree(fileEntry, newParentFolderPath);

            movedDocsTree.addChild(documentTree);
        } finally {
            FileUtil.delete(file);
        }
    } else if (folder != null) {
        long folderId = folder.getFolderId();

        folder = DLAppServiceUtil.moveFolder(folderId, newParentFolderId, serviceContext);

        Tree folderTree = getFolderTree(folder, newParentFolderPath);

        movedDirsTree.addChild(folderTree);
    }

    return new Tree[] { movedDocsTree, movedDirsTree };
}

From source file:com.liferay.portlet.documentlibrary.sharepoint.DLSharepointStorageImpl.java

License:Open Source License

@Override
public Tree[] removeDocument(SharepointRequest sharepointRequest) {
    String parentFolderPath = sharepointRequest.getRootPath();

    long groupId = SharepointUtil.getGroupId(parentFolderPath);

    Folder folder = null;/*from   w  w w . jav  a  2  s.c o m*/
    FileEntry fileEntry = null;

    try {
        long parentFolderId = getLastFolderId(groupId, parentFolderPath,
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

        folder = DLAppServiceUtil.getFolder(parentFolderId);
    } catch (Exception e1) {
        if (e1 instanceof NoSuchFolderException) {
            try {
                fileEntry = getFileEntry(sharepointRequest);
            } catch (Exception e2) {
            }
        }
    }

    Tree documentTree = new Tree();

    Tree removedDocsTree = new Tree();
    Tree failedDocsTree = new Tree();

    Tree folderTree = new Tree();

    Tree removedDirsTree = new Tree();
    Tree failedDirsTree = new Tree();

    if (fileEntry != null) {
        try {
            documentTree = getFileEntryTree(fileEntry, parentFolderPath);

            DLAppServiceUtil.deleteFileEntry(fileEntry.getFileEntryId());

            removedDocsTree.addChild(documentTree);
        } catch (Exception e1) {
            try {
                failedDocsTree.addChild(documentTree);
            } catch (Exception e2) {
            }
        }
    } else if (folder != null) {
        try {
            folderTree = getFolderTree(folder, parentFolderPath);

            DLAppServiceUtil.deleteFolder(folder.getFolderId());

            removedDirsTree.addChild(folderTree);
        } catch (Exception e1) {
            try {
                failedDirsTree.addChild(folderTree);
            } catch (Exception e2) {
            }
        }
    }

    return new Tree[] { removedDocsTree, removedDirsTree, failedDocsTree, failedDirsTree };
}