Example usage for com.liferay.portal.kernel.repository.model Folder getParentFolderId

List of usage examples for com.liferay.portal.kernel.repository.model Folder getParentFolderId

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.repository.model Folder getParentFolderId.

Prototype

public long getParentFolderId();

Source Link

Usage

From source file:edu.jhu.cvrg.filestore.main.Liferay61FileStorer.java

License:Apache License

@Override
public FSFolder getFolder(long folderId) throws FSException {

    try {//from   www.  j  a  v a 2 s .  c  om

        Folder folder = DLAppLocalServiceUtil.getFolder(folderId);

        return new FSFolder(folder.getFolderId(), folder.getName(), folder.getParentFolderId());
    } catch (Exception e) {
        log.warn("Folder ID [" + folderId + "] does not exists.");
    }
    return null;
}

From source file:edu.jhu.cvrg.filestore.main.Liferay61FileStorer.java

License:Apache License

@Override
public List<FSFolder> getFolders(long folderId) throws FSException {
    try {//  w  ww  .  j av a 2s. c  om

        List<Folder> subFolders = DLAppLocalServiceUtil.getFolders(groupId, folderId);

        if (subFolders != null) {
            List<FSFolder> fsSubFolders = new ArrayList<FSFolder>();
            for (Folder sub : subFolders) {
                fsSubFolders.add(new FSFolder(sub.getFolderId(), sub.getName(), sub.getParentFolderId()));
            }
            return fsSubFolders;
        }

    } catch (Exception e) {
        log.warn("Folder ID [" + folderId + "] does not exists.");
    }
    return null;
}

From source file:edu.jhu.cvrg.filestore.main.Liferay61FileStorer.java

License:Apache License

@Override
public synchronized FSFolder addFolder(long parentFolderId, String folderName) throws FSException {
    Folder newFolder = null;
    Semaphore s = Semaphore.getCreateFolderSemaphore();
    folderName = Liferay61FileStorer.convertToLiferayFolderName(folderName);

    try {//from   w ww.  j a  va2s .co m
        s.take();

        FSFolder parentFolder = this.getFolder(parentFolderId);
        if (parentFolder == null) {
            throw new FSException("Folder ID [" + parentFolderId + "] does not exists.");
        }

        List<FSFolder> subFolders = this.getFolders(parentFolderId);
        if (subFolders != null) {
            for (FSFolder subFolder : subFolders) {
                if (folderName.equals(subFolder.getName())) {
                    return subFolder;
                }
            }
        }

        ServiceContext service = LiferayFacesContext.getInstance().getServiceContext();
        try {
            newFolder = DLAppLocalServiceUtil.addFolder(userId, groupId, parentFolderId, folderName, "",
                    service);
        } catch (Exception e) {
            Thread.sleep(2000);
            int tries = 5;

            for (int i = 0; i < tries && newFolder == null; i++) {
                try {
                    newFolder = DLAppLocalServiceUtil.getFolder(groupId, parentFolderId, folderName);
                } catch (Exception e2) {
                    Thread.sleep(2000);
                    log.warn("Sleep and Try Again. #" + (i));
                }
            }
        }

        if (newFolder != null) {
            StringBuilder treePath = new StringBuilder();
            extractFolderHierachic(newFolder, treePath);

            Role userRole = RoleLocalServiceUtil.getRole(companyId, FileStoreConstants.AXIS_USER_ROLE_NAME);
            ResourcePermission resourcePermission = null;

            resourcePermission = ResourcePermissionLocalServiceUtil
                    .createResourcePermission(CounterLocalServiceUtil.increment());
            resourcePermission.setCompanyId(companyId);
            resourcePermission.setName(DLFolder.class.getName());
            resourcePermission.setScope(ResourceConstants.SCOPE_INDIVIDUAL);
            resourcePermission.setPrimKey(String.valueOf(newFolder.getPrimaryKey()));
            resourcePermission.setRoleId(userRole.getRoleId());

            ResourceAction resourceActionDelete = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.DELETE);
            ResourceAction resourceActionView = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.VIEW);
            ResourceAction resourceActionAccess = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.ACCESS);
            ResourceAction resourceActionAddDoc = ResourceActionLocalServiceUtil
                    .getResourceAction(DLFolder.class.getName(), ActionKeys.ADD_DOCUMENT);
            resourcePermission
                    .setActionIds(resourceActionDelete.getBitwiseValue() + resourceActionView.getBitwiseValue()
                            + resourceActionAccess.getBitwiseValue() + resourceActionAddDoc.getBitwiseValue());
            ResourcePermissionLocalServiceUtil.addResourcePermission(resourcePermission);

            return new FSFolder(newFolder.getFolderId(), newFolder.getName(), newFolder.getParentFolderId());
        } else {
            throw new FSException("Please select a folder");
        }

    } catch (Exception e) {
        log.error(e.getMessage());
        throw new FSException("Error on record name folder's creation.", e);
    } finally {
        try {
            s.release();
        } catch (InterruptedException e) {
            log.error(e.getMessage());
        }
    }
}