Example usage for com.liferay.portal.sharepoint SharepointRequest getParameterValue

List of usage examples for com.liferay.portal.sharepoint SharepointRequest getParameterValue

Introduction

In this page you can find the example usage for com.liferay.portal.sharepoint SharepointRequest getParameterValue.

Prototype

public String getParameterValue(String name) 

Source Link

Usage

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 ww.j  a  v  a2s.  com
    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 };
}