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

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

Introduction

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

Prototype

public String getName();

Source Link

Usage

From source file:com.liferay.document.library.internal.atom.FolderAtomCollectionAdapter.java

License:Open Source License

@Override
public String getEntryTitle(Folder folder) {
    return folder.getName();
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FolderStagedModelDataHandler.java

License:Open Source License

@Override
public String getDisplayName(Folder folder) {
    return folder.getName();
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.FolderStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, Folder folder) throws Exception {

    Map<Long, Long> folderIdsAndRepositoryEntryIds = (Map<Long, Long>) portletDataContext
            .getNewPrimaryKeysMap(Folder.class + ".folderIdsAndRepositoryEntryIds");

    if (!folder.isDefaultRepository()) {
        Map<Long, Long> repositoryEntryIds = (Map<Long, Long>) portletDataContext
                .getNewPrimaryKeysMap(RepositoryEntry.class);

        folderIdsAndRepositoryEntryIds.put(folder.getFolderId(), repositoryEntryIds.get(folder.getFolderId()));

        return;// ww  w . ja  va 2  s  .com
    }

    long userId = portletDataContext.getUserId(folder.getUserUuid());

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.class);

    long parentFolderId = MapUtil.getLong(folderIds, folder.getParentFolderId(), folder.getParentFolderId());

    ServiceContext serviceContext = portletDataContext.createServiceContext(folder, DLFolder.class);

    serviceContext.setUserId(userId);

    Folder importedFolder = null;

    if (portletDataContext.isDataStrategyMirror()) {
        Folder existingFolder = fetchStagedModelByUuidAndGroupId(folder.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingFolder == null) {
            String name = getFolderName(null, portletDataContext.getScopeGroupId(), parentFolderId,
                    folder.getName(), 2);

            serviceContext.setUuid(folder.getUuid());

            importedFolder = _dlAppLocalService.addFolder(userId, portletDataContext.getScopeGroupId(),
                    parentFolderId, name, folder.getDescription(), serviceContext);
        } else {
            String name = getFolderName(folder.getUuid(), portletDataContext.getScopeGroupId(), parentFolderId,
                    folder.getName(), 2);

            importedFolder = _dlAppLocalService.updateFolder(existingFolder.getFolderId(), parentFolderId, name,
                    folder.getDescription(), serviceContext);
        }
    } else {
        String name = getFolderName(null, portletDataContext.getScopeGroupId(), parentFolderId,
                folder.getName(), 2);

        importedFolder = _dlAppLocalService.addFolder(userId, portletDataContext.getScopeGroupId(),
                parentFolderId, name, folder.getDescription(), serviceContext);
    }

    Element folderElement = portletDataContext.getImportDataElement(folder);

    importFolderFileEntryTypes(portletDataContext, folderElement, folder, importedFolder, serviceContext);

    portletDataContext.importClassedModel(folder, importedFolder, DLFolder.class);

    folderIds.put(folder.getFolderId(), importedFolder.getFolderId());
    folderIdsAndRepositoryEntryIds.put(folder.getFolderId(), importedFolder.getFolderId());
}

From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FolderStagedModelDataHandlerTest.java

License:Open Source License

@Override
protected void validateImportedStagedModel(StagedModel stagedModel, StagedModel importedStagedModel)
        throws Exception {

    Assert.assertTrue(stagedModel.getCreateDate() + " " + importedStagedModel.getCreateDate(),
            DateUtil.equals(stagedModel.getCreateDate(), importedStagedModel.getCreateDate()));
    Assert.assertEquals(stagedModel.getUuid(), importedStagedModel.getUuid());

    Folder folder = (Folder) stagedModel;
    Folder importedFolder = (Folder) importedStagedModel;

    Assert.assertEquals(folder.getName(), importedFolder.getName());
    Assert.assertEquals(folder.getDescription(), importedFolder.getDescription());
}

From source file:com.liferay.document.library.internal.service.SubscriptionDLAppHelperLocalServiceWrapper.java

License:Open Source License

protected void notifySubscribers(long userId, FileVersion fileVersion, String entryURL,
        ServiceContext serviceContext) throws PortalException {

    if (!fileVersion.isApproved() || Validator.isNull(entryURL)) {
        return;/*from w ww .j ava2  s. co m*/
    }

    DLGroupServiceSettings dlGroupServiceSettings = DLGroupServiceSettings
            .getInstance(fileVersion.getGroupId());

    boolean commandUpdate = false;

    if (serviceContext.isCommandUpdate() || Constants.CHECKIN.equals(serviceContext.getCommand())) {

        commandUpdate = true;
    }

    if (serviceContext.isCommandAdd() && dlGroupServiceSettings.isEmailFileEntryAddedEnabled()) {
    } else if (commandUpdate && dlGroupServiceSettings.isEmailFileEntryUpdatedEnabled()) {
    } else {
        return;
    }

    String entryTitle = fileVersion.getTitle();

    String fromName = dlGroupServiceSettings.getEmailFromName();
    String fromAddress = dlGroupServiceSettings.getEmailFromAddress();

    LocalizedValuesMap subjectLocalizedValuesMap = null;
    LocalizedValuesMap bodyLocalizedValuesMap = null;

    if (commandUpdate) {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryUpdatedBody();
    } else {
        subjectLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedSubject();
        bodyLocalizedValuesMap = dlGroupServiceSettings.getEmailFileEntryAddedBody();
    }

    FileEntry fileEntry = fileVersion.getFileEntry();

    Folder folder = null;

    long folderId = fileEntry.getFolderId();

    if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
        folder = _dlAppLocalService.getFolder(folderId);
    }

    SubscriptionSender subscriptionSender = new GroupSubscriptionCheckSubscriptionSender(
            DLPermission.RESOURCE_NAME);

    DLFileEntry dlFileEntry = (DLFileEntry) fileEntry.getModel();

    DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService
            .getDLFileEntryType(dlFileEntry.getFileEntryTypeId());

    subscriptionSender.setClassPK(fileVersion.getFileEntryId());
    subscriptionSender.setClassName(DLFileEntryConstants.getClassName());
    subscriptionSender.setCompanyId(fileVersion.getCompanyId());

    if (folder != null) {
        subscriptionSender.setContextAttribute("[$FOLDER_NAME$]", folder.getName(), true);
    } else {
        subscriptionSender.setLocalizedContextAttribute("[$FOLDER_NAME$]",
                new EscapableLocalizableFunction(locale -> LanguageUtil.get(locale, "home")));
    }

    subscriptionSender.setContextAttributes("[$DOCUMENT_STATUS_BY_USER_NAME$]",
            fileVersion.getStatusByUserName(), "[$DOCUMENT_TITLE$]", entryTitle, "[$DOCUMENT_URL$]", entryURL);
    subscriptionSender.setContextCreatorUserPrefix("DOCUMENT");
    subscriptionSender.setCreatorUserId(fileVersion.getUserId());
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(entryTitle);
    subscriptionSender.setEntryURL(entryURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    subscriptionSender.setLocalizedContextAttribute("[$DOCUMENT_TYPE$]",
            new EscapableLocalizableFunction(locale -> dlFileEntryType.getName(locale)));
    subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));
    subscriptionSender.setMailId("file_entry", fileVersion.getFileEntryId());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (commandUpdate) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(FileEntry.class.getName(), PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setReplyToAddress(fromAddress);
    subscriptionSender.setScopeGroupId(fileVersion.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);

    subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), fileVersion.getGroupId());

    if (folder != null) {
        subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), folder.getFolderId());

        for (Long ancestorFolderId : folder.getAncestorFolderIds()) {
            subscriptionSender.addPersistedSubscribers(DLFolder.class.getName(), ancestorFolderId);
        }
    }

    if (dlFileEntryType.getFileEntryTypeId() == DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT) {

        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(), fileVersion.getGroupId());
    } else {
        subscriptionSender.addPersistedSubscribers(DLFileEntryType.class.getName(),
                dlFileEntryType.getFileEntryTypeId());
    }

    subscriptionSender.addPersistedSubscribers(DLFileEntry.class.getName(), fileEntry.getFileEntryId());

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.document.library.jaxrs.FolderRepr.java

License:Open Source License

public static FolderRepr fromFolder(Folder folder, List<RepositoryContentObject> repositoryContentObjects,
        UriBuilder uriBuilder) {//  w  w w  .jav  a  2s  . c  o m

    String url = uriBuilder.build(Long.toString(folder.getFolderId())).toString();

    return new FolderRepr(folder.getRepositoryId(), folder.getFolderId(), folder.getDescription(),
            folder.getCreateDate(), folder.getName(), repositoryContentObjects, url);
}

From source file:com.liferay.document.library.jaxrs.FolderResource.java

License:Open Source License

protected RepositoryContentObject toObjectRepository(Object rco) {
    if (rco instanceof FileEntry) {
        FileEntry fileEntry = (FileEntry) rco;

        String url = _fileUriBuilder.build(fileEntry.getFileEntryId()).toString();

        return new RepositoryContentObject(fileEntry.getFileEntryId(), fileEntry.getTitle(), url,
                RepositoryContentObject.RepositoryContentType.FILE, fileEntry.getCreateDate(),
                fileEntry.getModifiedDate());
    } else if (rco instanceof Folder) {
        Folder folder = (Folder) rco;

        String url = _folderUriBuilder.build(Long.toString(folder.getFolderId())).toString();

        return new RepositoryContentObject(folder.getFolderId(), folder.getName(), url,
                RepositoryContentObject.RepositoryContentType.FOLDER, folder.getCreateDate(),
                folder.getModifiedDate());
    } else if (rco instanceof FileShortcut) {
        FileShortcut fileShortcut = (FileShortcut) rco;

        String url = _fileUriBuilder.build(Long.toString(fileShortcut.getToFileEntryId())).toString();

        return new RepositoryContentObject(fileShortcut.getFileShortcutId(), fileShortcut.getToTitle(), url,
                RepositoryContentObject.RepositoryContentType.SHORTCUT, fileShortcut.getCreateDate(),
                fileShortcut.getModifiedDate());
    } else {/*from  www.  ja v a 2s  . c  o  m*/
        throw new IllegalArgumentException(
                "Object must be an instance of FileEntry, Folder of " + "FileShortcut");
    }
}

From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java

License:Open Source License

@Override
public Folder moveFolder(long userId, long folderId, long parentFolderId, ServiceContext serviceContext)
        throws PortalException {

    try {/*from w  ww  . ja  va  2  s  . c om*/
        Session session = getSession();

        org.apache.chemistry.opencmis.client.api.Folder cmisFolder = getCmisFolder(session, folderId);

        validateTitle(session, parentFolderId, cmisFolder.getName());

        org.apache.chemistry.opencmis.client.api.Folder parentCmisFolder = cmisFolder.getFolderParent();

        if (parentCmisFolder == null) {
            throw new RepositoryException("Unable to move CMIS root folder with {folderId=" + folderId + "}");
        }

        String objectId = toFolderId(session, folderId);

        String sourceFolderId = parentCmisFolder.getId();

        String targetFolderId = toFolderId(session, parentFolderId);

        if (!sourceFolderId.equals(targetFolderId) && !targetFolderId.equals(objectId)) {

            cmisFolder = (org.apache.chemistry.opencmis.client.api.Folder) cmisFolder
                    .move(new ObjectIdImpl(sourceFolderId), new ObjectIdImpl(targetFolderId));
        }

        return toFolder(cmisFolder);
    } catch (CmisObjectNotFoundException confe) {
        throw new NoSuchFolderException("No CMIS folder with {folderId=" + parentFolderId + "}", confe);
    } catch (PortalException | SystemException e) {
        throw e;
    } catch (Exception e) {
        processException(e);

        throw new RepositoryException(e);
    }
}

From source file:com.liferay.document.library.repository.cmis.internal.CMISRepository.java

License:Open Source License

@Override
public Folder updateFolder(long folderId, String name, String description, ServiceContext serviceContext)
        throws PortalException {

    try {// w w w .jav a 2  s .co  m
        Session session = getSession();

        String objectId = toFolderId(session, folderId);

        org.apache.chemistry.opencmis.client.api.Folder cmisFolder = (org.apache.chemistry.opencmis.client.api.Folder) session
                .getObject(objectId);

        String currentTitle = cmisFolder.getName();

        Map<String, Object> properties = new HashMap<>();

        if (Validator.isNotNull(name) && !name.equals(currentTitle)) {
            properties.put(PropertyIds.NAME, name);
        }

        ObjectId cmisFolderObjectId = cmisFolder.updateProperties(properties, true);

        String newObjectId = cmisFolderObjectId.getId();

        if (!objectId.equals(newObjectId)) {
            cmisFolder = (org.apache.chemistry.opencmis.client.api.Folder) session.getObject(newObjectId);

            updateMappedId(folderId, newObjectId);
        }

        return toFolder(cmisFolder);
    } catch (CmisObjectNotFoundException confe) {
        throw new NoSuchFolderException("No CMIS folder with {folderId=" + folderId + "}", confe);
    } catch (PortalException | SystemException e) {
        throw e;
    } catch (Exception e) {
        processException(e);

        throw new RepositoryException(e);
    }
}

From source file:com.liferay.document.library.repository.cmis.internal.model.CMISFolder.java

License:Open Source License

@Override
public String getName() {
    if (_cmisFolder.isRootFolder()) {
        try {/*w w  w .  j a  va2 s. c  om*/
            Folder folder = DLAppLocalServiceUtil.getMountFolder(getRepositoryId());

            return folder.getName();
        } catch (Exception e) {
            _log.error(e, e);
        }
    }

    return _cmisFolder.getName();
}