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

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

Introduction

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

Prototype

public long getFolderId();

Source Link

Usage

From source file:com.liferay.sync.messaging.SyncDLObjectMessageListener.java

License:Open Source License

protected void addSyncDLObject(long modifiedTime, String event, String type, long typePK) throws Exception {

    if (event.equals(SyncConstants.EVENT_DELETE)) {
        SyncDLObjectLocalServiceUtil.addSyncDLObject(0, modifiedTime, 0, 0, StringPool.BLANK, StringPool.BLANK,
                StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, 0,
                StringPool.BLANK, event, null, 0, StringPool.BLANK, type, typePK, StringPool.BLANK);

        return;//from  www  . j a  va 2 s  . c  om
    }

    SyncDLObject syncDLObject = null;

    if (type.equals(SyncConstants.TYPE_FILE)) {
        FileEntry fileEntry = null;

        try {
            fileEntry = DLAppLocalServiceUtil.getFileEntry(typePK);
        } catch (NoSuchFileEntryException nsfee) {
            return;
        }

        syncDLObject = SyncUtil.toSyncDLObject(fileEntry, event);
    } else {
        Folder folder = null;

        try {
            folder = DLAppLocalServiceUtil.getFolder(typePK);
        } catch (NoSuchFolderException nsfe) {
            return;
        }

        if (!SyncUtil.isSupportedFolder(folder)) {
            return;
        }

        syncDLObject = SyncUtil.toSyncDLObject(folder, event);
    }

    SyncDLObjectLocalServiceUtil.addSyncDLObject(syncDLObject.getCompanyId(), modifiedTime,
            syncDLObject.getRepositoryId(), syncDLObject.getParentFolderId(), syncDLObject.getName(),
            syncDLObject.getExtension(), syncDLObject.getMimeType(), syncDLObject.getDescription(),
            syncDLObject.getChangeLog(), syncDLObject.getExtraSettings(), syncDLObject.getVersion(),
            syncDLObject.getSize(), syncDLObject.getChecksum(), syncDLObject.getEvent(),
            syncDLObject.getLockExpirationDate(), syncDLObject.getLockUserId(), syncDLObject.getLockUserName(),
            syncDLObject.getType(), syncDLObject.getTypePK(), syncDLObject.getTypeUuid());

    if (event.equals(SyncConstants.EVENT_RESTORE) && type.equals(SyncConstants.TYPE_FOLDER)) {

        List<Object> foldersAndFileEntriesAndFileShortcuts = DLAppServiceUtil
                .getFoldersAndFileEntriesAndFileShortcuts(syncDLObject.getRepositoryId(),
                        syncDLObject.getTypePK(), WorkflowConstants.STATUS_ANY, false, QueryUtil.ALL_POS,
                        QueryUtil.ALL_POS);

        for (Object folderAndFileEntryAndFileShortcut : foldersAndFileEntriesAndFileShortcuts) {

            if (folderAndFileEntryAndFileShortcut instanceof FileEntry) {
                FileEntry fileEntry = (FileEntry) folderAndFileEntryAndFileShortcut;

                addSyncDLObject(modifiedTime, SyncConstants.EVENT_RESTORE, SyncConstants.TYPE_FILE,
                        fileEntry.getFileEntryId());
            } else if (folderAndFileEntryAndFileShortcut instanceof Folder) {
                Folder folder = (Folder) folderAndFileEntryAndFileShortcut;

                if (!SyncUtil.isSupportedFolder(folder)) {
                    continue;
                }

                addSyncDLObject(modifiedTime, SyncConstants.EVENT_RESTORE, SyncConstants.TYPE_FOLDER,
                        folder.getFolderId());
            }
        }
    }
}

From source file:com.liferay.sync.messaging.SyncMessageListener.java

License:Open Source License

protected void addSyncDLObject(long modifiedTime, String event, String type, long typePK) throws Exception {

    if (event.equals(DLSyncConstants.EVENT_DELETE)) {
        SyncDLObjectLocalServiceUtil.addSyncDLObject(0, modifiedTime, 0, 0, StringPool.BLANK, StringPool.BLANK,
                StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK, 0,
                StringPool.BLANK, event, null, 0, StringPool.BLANK, type, typePK, StringPool.BLANK);
    } else if (type.equals(DLSyncConstants.TYPE_FILE)) {
        FileEntry fileEntry = null;//from   w  ww  .j av a 2  s .co  m

        try {
            fileEntry = DLAppLocalServiceUtil.getFileEntry(typePK);
        } catch (NoSuchFileEntryException nsfee) {
            return;
        }

        Date lockExpirationDate = null;
        long lockUserId = 0;
        String lockUserName = StringPool.BLANK;

        Lock lock = fileEntry.getLock();

        if (lock != null) {
            lockExpirationDate = lock.getExpirationDate();
            lockUserId = lock.getUserId();
            lockUserName = lock.getUserName();
        }

        DLFileVersion dlFileVersion = DLFileVersionLocalServiceUtil
                .getLatestFileVersion(fileEntry.getFileEntryId(), false);

        SyncDLObjectLocalServiceUtil.addSyncDLObject(dlFileVersion.getCompanyId(), modifiedTime,
                dlFileVersion.getRepositoryId(), fileEntry.getFolderId(), dlFileVersion.getTitle(),
                dlFileVersion.getExtension(), dlFileVersion.getMimeType(), dlFileVersion.getDescription(),
                dlFileVersion.getChangeLog(), dlFileVersion.getExtraSettings(), dlFileVersion.getVersion(),
                dlFileVersion.getSize(), SyncUtil.getChecksum(dlFileVersion), event, lockExpirationDate,
                lockUserId, lockUserName, type, fileEntry.getFileEntryId(), fileEntry.getUuid());
    } else {
        Folder folder = null;

        try {
            folder = DLAppLocalServiceUtil.getFolder(typePK);
        } catch (NoSuchFolderException nsfe) {
            return;
        }

        SyncDLObjectLocalServiceUtil.addSyncDLObject(folder.getCompanyId(), modifiedTime,
                folder.getRepositoryId(), folder.getParentFolderId(), folder.getName(), StringPool.BLANK,
                StringPool.BLANK, folder.getDescription(), StringPool.BLANK, StringPool.BLANK, "-1", 0,
                StringPool.BLANK, event, null, 0, StringPool.BLANK, type, folder.getFolderId(),
                folder.getUuid());
    }
}

From source file:com.liferay.sync.service.impl.SyncDLObjectServiceImpl.java

License:Open Source License

@Override
public SyncDLObject addFolder(long repositoryId, long parentFolderId, String name, String description,
        ServiceContext serviceContext) throws PortalException {

    try {/*from ww  w . j  a va  2  s. c o m*/
        Folder folder = dlAppService.addFolder(repositoryId, parentFolderId, name, description, serviceContext);

        return toSyncDLObject(folder, SyncConstants.EVENT_ADD);
    } catch (PortalException pe) {
        if (pe instanceof DuplicateFolderNameException) {
            if (GetterUtil.getBoolean(serviceContext.getAttribute("overwrite"))) {

                Folder folder = dlAppService.getFolder(repositoryId, parentFolderId, name);

                folder = dlAppService.updateFolder(folder.getFolderId(), name, description, serviceContext);

                return toSyncDLObject(folder, SyncConstants.EVENT_UPDATE);
            }
        }

        throw new PortalException(SyncUtil.buildExceptionMessage(pe), pe);
    }
}

From source file:com.liferay.sync.service.impl.SyncDLObjectServiceImpl.java

License:Open Source License

protected SyncDLObject toSyncDLObject(Folder folder, String event) throws PortalException {

    SyncDLObject syncDLObject = SyncUtil.toSyncDLObject(folder, event);

    return checkModifiedTime(syncDLObject, folder.getFolderId());
}

From source file:com.liferay.testopensocialoauthconsumer.messaging.TestOpenSocialOAuthConsumerHotDeployMessageListener.java

License:Open Source License

protected void deleteGadget() throws Exception {
    long companyId = PortalUtil.getDefaultCompanyId();

    Company company = CompanyLocalServiceUtil.getCompany(companyId);
    Group group = GroupLocalServiceUtil.getCompanyGroup(companyId);
    User user = UserLocalServiceUtil.getDefaultUser(companyId);

    Folder gadgetEditorRootFolder = getGadgetEditorRootFolder(user.getUserId(), group.getGroupId());

    FileEntry fileEntry = null;/*ww w .  j a  v a2s  . c  o  m*/

    try {
        fileEntry = DLAppLocalServiceUtil.getFileEntry(group.getGroupId(), gadgetEditorRootFolder.getFolderId(),
                _GADGET_FILE_NAME);
    } catch (NoSuchFileEntryException nsfee) {
        return;
    }

    Gadget gadget = GadgetLocalServiceUtil.fetchGadget(company.getCompanyId(), getFileEntryURL(fileEntry));

    if (gadget != null) {
        GadgetLocalServiceUtil.deleteGadget(gadget);
    }

    DLAppLocalServiceUtil.deleteFileEntry(fileEntry.getFileEntryId());
}

From source file:com.liferay.testopensocialoauthconsumer.messaging.TestOpenSocialOAuthConsumerHotDeployMessageListener.java

License:Open Source License

protected void setupGadget() throws Exception {
    Class<?> clazz = getClass();

    ClassLoader classLoader = clazz.getClassLoader();

    long companyId = PortalUtil.getDefaultCompanyId();

    User user = UserLocalServiceUtil.getDefaultUser(companyId);
    Group group = GroupLocalServiceUtil.getCompanyGroup(companyId);

    Folder gadgetEditorRootFolder = getGadgetEditorRootFolder(user.getUserId(), group.getGroupId());

    FileEntry fileEntry = null;//from   w ww. j av a2s.c o  m

    try {
        fileEntry = DLAppLocalServiceUtil.getFileEntry(group.getGroupId(), gadgetEditorRootFolder.getFolderId(),
                _GADGET_FILE_NAME);
    } catch (NoSuchFileEntryException nsfee) {
        InputStream inputStream = classLoader
                .getResourceAsStream("/resources/gadgets/".concat(_GADGET_FILE_NAME));

        String xml = new String(FileUtil.getBytes(inputStream));

        xml = StringUtil.replace(xml,
                new String[] { "[$ACCESS_URL$]", "[$AUTHORIZATION_URL$]", "[$FOLDER_ID$]", "[$PORTAL_URL$]",
                        "[$REPOSITORY_ID$]", "[$REQUEST_URL$]" },
                new String[] { "/c/portal/oauth/access_token", "/c/portal/oauth/authorize",
                        String.valueOf(gadgetEditorRootFolder.getFolderId()), "http://localhost:8080",
                        String.valueOf(group.getGroupId()), "/c/portal/oauth/request_token" });

        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);
        serviceContext.setScopeGroupId(group.getGroupId());

        serviceContext.setAttribute("sourceFileName", _GADGET_FILE_NAME);

        fileEntry = DLAppLocalServiceUtil.addFileEntry(user.getUserId(),
                gadgetEditorRootFolder.getRepositoryId(), gadgetEditorRootFolder.getFolderId(),
                _GADGET_FILE_NAME, ContentTypes.APPLICATION_X_WWW_FORM_URLENCODED_UTF8, _GADGET_FILE_NAME,
                StringPool.BLANK, StringPool.BLANK, xml.getBytes(StringPool.UTF8), serviceContext);
    }

    Gadget gadget = GadgetLocalServiceUtil.fetchGadget(companyId, getFileEntryURL(fileEntry));

    if (gadget == null) {
        ServiceContext serviceContext = new ServiceContext();

        serviceContext.setAddGroupPermissions(true);
        serviceContext.setAddGuestPermissions(true);
        serviceContext.setScopeGroupId(group.getGroupId());

        GadgetLocalServiceUtil.addGadget(companyId, getFileEntryURL(fileEntry), _PORTLET_CATEGORY_NAMES,
                serviceContext);
    }
}

From source file:com.liferay.wiki.model.impl.WikiNodeImpl.java

License:Open Source License

@Override
public Folder addAttachmentsFolder() throws PortalException {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }//  w w  w . j  ava 2 s.c  om

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.addPortletRepository(getGroupId(),
            WikiConstants.SERVICE_NAME, serviceContext);

    Folder folder = PortletFileRepositoryUtil.addPortletFolder(getUserId(), repository.getRepositoryId(),
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getNodeId()), serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
}

From source file:com.liferay.wiki.model.impl.WikiNodeImpl.java

License:Open Source License

@Override
public long getAttachmentsFolderId() {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return _attachmentsFolderId;
    }//from   w  w w  .java 2 s  .  c om

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(),
            WikiConstants.SERVICE_NAME);

    if (repository == null) {
        return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

    try {
        Folder folder = PortletFileRepositoryUtil.getPortletFolder(repository.getRepositoryId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, String.valueOf(getNodeId()));

        _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
    }

    return _attachmentsFolderId;
}

From source file:com.liferay.wiki.model.impl.WikiPageImpl.java

License:Open Source License

@Override
public Folder addAttachmentsFolder() throws PortalException {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return PortletFileRepositoryUtil.getPortletFolder(_attachmentsFolderId);
    }/*from   w  ww.ja  v a 2  s . co  m*/

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.addPortletRepository(getGroupId(),
            WikiConstants.SERVICE_NAME, serviceContext);

    WikiNode node = getNode();

    Folder nodeFolder = node.addAttachmentsFolder();

    Folder folder = PortletFileRepositoryUtil.addPortletFolder(getUserId(), repository.getRepositoryId(),
            nodeFolder.getFolderId(), String.valueOf(getResourcePrimKey()), serviceContext);

    _attachmentsFolderId = folder.getFolderId();

    return folder;
}

From source file:com.liferay.wiki.model.impl.WikiPageImpl.java

License:Open Source License

@Override
public long getAttachmentsFolderId() {
    if (_attachmentsFolderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {

        return _attachmentsFolderId;
    }//from w w  w. ja va  2 s .  c  o m

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);

    Repository repository = PortletFileRepositoryUtil.fetchPortletRepository(getGroupId(),
            WikiConstants.SERVICE_NAME);

    long nodeAttachmentsFolderId = getNodeAttachmentsFolderId();

    if ((repository == null) || (nodeAttachmentsFolderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID)) {

        return DLFolderConstants.DEFAULT_PARENT_FOLDER_ID;
    }

    try {
        Folder folder = PortletFileRepositoryUtil.getPortletFolder(repository.getRepositoryId(),
                nodeAttachmentsFolderId, String.valueOf(getResourcePrimKey()));

        _attachmentsFolderId = folder.getFolderId();
    } catch (Exception e) {
    }

    return _attachmentsFolderId;
}