Example usage for com.liferay.portal.kernel.service ServiceContext setExpandoBridgeAttributes

List of usage examples for com.liferay.portal.kernel.service ServiceContext setExpandoBridgeAttributes

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContext setExpandoBridgeAttributes.

Prototype

public void setExpandoBridgeAttributes(Map<String, Serializable> expandoBridgeAttributes) 

Source Link

Document

Sets an arbitrary number of attributes of an entity to be persisted.

Usage

From source file:com.liferay.document.library.service.test.DLFileEntryLocalServiceTest.java

License:Open Source License

@Test
public void testCopyFileEntry() throws Exception {
    ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.addDefaultTable(PortalUtil.getDefaultCompanyId(),
            DLFileEntry.class.getName());

    ExpandoColumnLocalServiceUtil.addColumn(expandoTable.getTableId(), "ExpandoAttributeName",
            ExpandoColumnConstants.STRING, StringPool.BLANK);

    try {/*from   w  w w .j  a v  a2  s.com*/
        ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
                TestPropsValues.getUserId());

        Folder folder = DLAppServiceUtil.addFolder(_group.getGroupId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(),
                RandomTestUtil.randomString(), serviceContext);

        long fileEntryTypeId = populateServiceContextFileEntryType(serviceContext);

        Map<String, Serializable> expandoBridgeAttributes = new HashMap<>();

        expandoBridgeAttributes.put("ExpandoAttributeName", "ExpandoAttributeValue");

        serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);

        FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(),
                _group.getGroupId(), folder.getFolderId(), RandomTestUtil.randomString(),
                ContentTypes.TEXT_PLAIN, RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE),
                serviceContext);

        serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
                TestPropsValues.getUserId());

        Folder destinationFolder = DLAppServiceUtil.addFolder(_group.getGroupId(),
                DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(),
                RandomTestUtil.randomString(), serviceContext);

        DLFileEntry copyDLFileEntry = DLFileEntryLocalServiceUtil.copyFileEntry(TestPropsValues.getUserId(),
                _group.getGroupId(), _group.getGroupId(), fileEntry.getFileEntryId(),
                destinationFolder.getFolderId(), serviceContext);

        ExpandoBridge expandoBridge = copyDLFileEntry.getExpandoBridge();

        String attributeValue = GetterUtil.getString(expandoBridge.getAttribute("ExpandoAttributeName"));

        Assert.assertEquals("ExpandoAttributeValue", attributeValue);

        Assert.assertEquals(fileEntryTypeId, copyDLFileEntry.getFileEntryTypeId());

        DLFileVersion copyDLFileVersion = copyDLFileEntry.getFileVersion();

        List<DDMStructure> copyDDMStructures = copyDLFileVersion.getDDMStructures();

        DDMStructure copyDDMStructure = copyDDMStructures.get(0);

        DLFileEntryMetadata dlFileEntryMetadata = DLFileEntryMetadataLocalServiceUtil
                .getFileEntryMetadata(copyDDMStructure.getStructureId(), copyDLFileVersion.getFileVersionId());

        DDMFormValues copyDDMFormValues = StorageEngineManagerUtil
                .getDDMFormValues(dlFileEntryMetadata.getDDMStorageId());

        List<DDMFormFieldValue> ddmFormFieldValues = copyDDMFormValues.getDDMFormFieldValues();

        DDMFormFieldValue ddmFormFieldValue = ddmFormFieldValues.get(0);

        Value value = ddmFormFieldValue.getValue();

        Assert.assertEquals("Text1", ddmFormFieldValue.getName());

        Assert.assertEquals("Text 1 Value", value.getString(LocaleUtil.US));
    } finally {
        ExpandoTableLocalServiceUtil.deleteTable(expandoTable);
    }
}

From source file:com.liferay.document.library.service.test.DLFileVersionTest.java

License:Open Source License

protected ServiceContext getServiceContext() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    serviceContext.setAttribute("fileEntryTypeId", _contractDLFileEntryTypeId);

    Map<String, Serializable> expandoBridgeAttributes = serviceContext.getExpandoBridgeAttributes();

    expandoBridgeAttributes.put(_EXPANDO_ATTRIBUTE_NAME, StringPool.BLANK);

    serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);

    DLFileEntryType fileEntryType = DLFileEntryTypeLocalServiceUtil
            .getFileEntryType(_contractDLFileEntryTypeId);

    List<DDMStructure> ddmStructures = fileEntryType.getDDMStructures();

    for (DDMStructure ddmStructure : ddmStructures) {
        DDMFormValues ddmFormValues = createDDMFormValues(ddmStructure.getDDMForm());

        for (String fieldName : ddmStructure.getFieldNames()) {
            DDMFormFieldValue ddmFormFieldValue = createDDMFormFieldValue(fieldName);

            ddmFormValues.addDDMFormFieldValue(ddmFormFieldValue);
        }/* w  w  w .j a va  2  s.c  o m*/

        serviceContext.setAttribute(DDMFormValues.class.getName() + ddmStructure.getStructureId(),
                ddmFormValues);
    }

    return serviceContext;
}

From source file:com.liferay.document.library.web.internal.webdav.DLWebDAVStorageImpl.java

License:Open Source License

protected void populateServiceContext(ServiceContext serviceContext, FileEntry fileEntry)
        throws PortalException {

    serviceContext.setScopeGroupId(fileEntry.getGroupId());

    String className = DLFileEntryConstants.getClassName();

    long[] assetCategoryIds = _assetCategoryLocalService.getCategoryIds(className, fileEntry.getFileEntryId());

    serviceContext.setAssetCategoryIds(assetCategoryIds);

    AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(className, fileEntry.getFileEntryId());

    List<AssetLink> assetLinks = _assetLinkLocalService.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    serviceContext.setAssetLinkEntryIds(assetLinkEntryIds);

    String[] assetTagNames = _assetTagLocalService.getTagNames(className, fileEntry.getFileEntryId());

    serviceContext.setAssetTagNames(assetTagNames);

    ExpandoBridge expandoBridge = fileEntry.getExpandoBridge();

    serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes());

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

    long fileEntryTypeId = dlFileEntry.getFileEntryTypeId();

    if (fileEntryTypeId > 0) {
        serviceContext.setAttribute("fileEntryTypeId", dlFileEntry.getFileEntryTypeId());

        DLFileVersion dlFileVersion = _dlFileVersionLocalService
                .getLatestFileVersion(fileEntry.getFileEntryId(), !dlFileEntry.isCheckedOut());

        DLFileEntryType dlFileEntryType = _dlFileEntryTypeLocalService.getFileEntryType(fileEntryTypeId);

        List<DDMStructure> ddmStructures = dlFileEntryType.getDDMStructures();

        for (DDMStructure ddmStructure : ddmStructures) {
            DLFileEntryMetadata dlFileEntryMetadata = _dlFileEntryMetadataLocalService
                    .fetchFileEntryMetadata(ddmStructure.getStructureId(), dlFileVersion.getFileVersionId());

            if (dlFileEntryMetadata == null) {
                continue;
            }//from   w w  w  .j ava 2 s . c  o m

            DDMFormValues ddmFormValues = StorageEngineManagerUtil
                    .getDDMFormValues(dlFileEntryMetadata.getDDMStorageId());

            serviceContext.setAttribute(
                    DDMFormValues.class.getName() + StringPool.POUND + ddmStructure.getStructureId(),
                    ddmFormValues);
        }
    }
}

From source file:com.liferay.document.library.web.webdav.DLWebDAVStorageImpl.java

License:Open Source License

protected void populateServiceContext(ServiceContext serviceContext, FileEntry fileEntry) {

    serviceContext.setScopeGroupId(fileEntry.getGroupId());

    String className = DLFileEntryConstants.getClassName();

    long[] assetCategoryIds = _assetCategoryLocalService.getCategoryIds(className, fileEntry.getFileEntryId());

    serviceContext.setAssetCategoryIds(assetCategoryIds);

    AssetEntry assetEntry = _assetEntryLocalService.fetchEntry(className, fileEntry.getFileEntryId());

    List<AssetLink> assetLinks = _assetLinkLocalService.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    serviceContext.setAssetLinkEntryIds(assetLinkEntryIds);

    String[] assetTagNames = _assetTagLocalService.getTagNames(className, fileEntry.getFileEntryId());

    serviceContext.setAssetTagNames(assetTagNames);

    ExpandoBridge expandoBridge = fileEntry.getExpandoBridge();

    serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes());
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

protected ServiceContext createServiceContext(Element element, String path, ClassedModel classedModel,
        Class<?> clazz) {/*from w w w. jav a2  s  .co  m*/

    ServiceContext serviceContext = new ServiceContext();

    // Theme display

    serviceContext.setCompanyId(getCompanyId());
    serviceContext.setScopeGroupId(getScopeGroupId());

    // Dates

    if (classedModel instanceof AuditedModel) {
        AuditedModel auditedModel = (AuditedModel) classedModel;

        serviceContext.setUserId(getUserId(auditedModel));
        serviceContext.setCreateDate(auditedModel.getCreateDate());
        serviceContext.setModifiedDate(auditedModel.getModifiedDate());
    }

    // Permissions

    if (!MapUtil.getBoolean(_parameterMap, PortletDataHandlerKeys.PERMISSIONS)) {

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

    // Asset

    if (isResourceMain(classedModel)) {
        Serializable classPKObj = ExportImportClassedModelUtil.getPrimaryKeyObj(classedModel);

        long[] assetCategoryIds = getAssetCategoryIds(clazz, classPKObj);

        serviceContext.setAssetCategoryIds(assetCategoryIds);

        String[] assetTagNames = getAssetTagNames(clazz, classPKObj);

        serviceContext.setAssetTagNames(assetTagNames);
    }

    if (element != null) {
        Attribute assetPriorityAttribute = element.attribute("asset-entry-priority");

        if (assetPriorityAttribute != null) {
            double assetPriority = GetterUtil.getDouble(assetPriorityAttribute.getValue());

            serviceContext.setAssetPriority(assetPriority);
        }
    }

    // Expando

    String expandoPath = null;

    if (element != null) {
        expandoPath = element.attributeValue("expando-path");
    } else {
        expandoPath = ExportImportPathUtil.getExpandoPath(path);
    }

    if (Validator.isNotNull(expandoPath)) {
        try {
            Map<String, Serializable> expandoBridgeAttributes = (Map<String, Serializable>) getZipEntryAsObject(
                    expandoPath);

            if (expandoBridgeAttributes != null) {
                serviceContext.setExpandoBridgeAttributes(expandoBridgeAttributes);
            }
        } catch (Exception e) {
            if (_log.isDebugEnabled()) {
                _log.debug(e, e);
            }
        }
    }

    // Workflow

    if (classedModel instanceof WorkflowedModel) {
        WorkflowedModel workflowedModel = (WorkflowedModel) classedModel;

        if (workflowedModel.getStatus() == WorkflowConstants.STATUS_APPROVED) {

            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);
        } else if (workflowedModel.getStatus() == WorkflowConstants.STATUS_DRAFT) {

            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }
    }

    return serviceContext;
}

From source file:com.liferay.wiki.service.impl.WikiPageLocalServiceImpl.java

License:Open Source License

protected void populateServiceContext(ServiceContext serviceContext, WikiPage page) throws PortalException {

    long[] assetCategoryIds = assetCategoryLocalService.getCategoryIds(WikiPage.class.getName(),
            page.getResourcePrimKey());/*from   www.  j a v a 2s.  c o  m*/

    serviceContext.setAssetCategoryIds(assetCategoryIds);

    AssetEntry assetEntry = assetEntryLocalService.getEntry(WikiPage.class.getName(),
            page.getResourcePrimKey());

    List<AssetLink> assetLinks = assetLinkLocalService.getLinks(assetEntry.getEntryId());

    long[] assetLinkEntryIds = ListUtil.toLongArray(assetLinks, AssetLink.ENTRY_ID2_ACCESSOR);

    serviceContext.setAssetLinkEntryIds(assetLinkEntryIds);

    String[] assetTagNames = assetTagLocalService.getTagNames(WikiPage.class.getName(),
            page.getResourcePrimKey());

    serviceContext.setAssetTagNames(assetTagNames);

    ExpandoBridge expandoBridge = page.getExpandoBridge();

    serviceContext.setExpandoBridgeAttributes(expandoBridge.getAttributes());
}