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

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

Introduction

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

Prototype

public void setAssetTagNames(String[] assetTagNames) 

Source Link

Document

Sets an array of asset tag names to be applied to an asset entry if this service context is being passed as a parameter to a method which manipulates the asset entry.

Usage

From source file:com.bemis.portal.fileuploader.service.impl.FileUploaderLocalServiceImpl.java

License:Open Source License

/**
 * Uploads the file into the destination folder
 * If the file does not exist, adds the file. If exists, updates the existing file
 * Adds tags and categories to documents
 *
 * @param companyId/*from w w  w .j av  a  2  s  .com*/
 * @param groupId
 * @param userId
 * @param file
 * @param fileDescription
 * @param title
 * @param folderId
 * @param changeLog
 * @param assetTagNames
 * @return FileEntry
 * @throws PortalException
 */
public FileEntry uploadFile(long companyId, long groupId, long userId, File file, String fileDescription,
        String title, long folderId, String changeLog, String[] assetTagNames) throws PortalException {

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setCompanyId(companyId);
    serviceContext.setScopeGroupId(groupId);
    serviceContext.setUserId(userId);
    serviceContext.setAssetTagNames(assetTagNames);
    serviceContext.setAttribute(FileUploaderConstants.DESTINATION_FOLDER_ID, folderId);

    return uploadFile(file, fileDescription, title, changeLog, serviceContext);
}

From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java

License:Open Source License

@Test
public void testDynamicExportImportAssetTagFiltering() throws Exception {
    AssetTag assetTag = AssetTestUtil.addTag(group.getGroupId());

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext();

    serviceContext.setAssetTagNames(new String[] { assetTag.getName() });

    List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 2, new ArrayList<AssetEntry>(),
            serviceContext);/*from  ww  w . ja v  a  2 s .  c o  m*/

    Map<String, String[]> preferenceMap = new HashMap<>();

    preferenceMap.put("queryContains0", new String[] { Boolean.TRUE.toString() });
    preferenceMap.put("queryValues0", new String[] { assetTag.getName() });

    testDynamicExportImport(preferenceMap, expectedAssetEntries, true);
}

From source file:com.liferay.asset.service.test.AssetEntryQueryTest.java

License:Open Source License

protected void testAssetCategorization(long[] assetCategoryIds, String[] assetTagNames, String title1,
        long[] assetCategoryIds1, String[] assetTagNames1, String title2, long[] assetCategoryIds2,
        String[] assetTagNames2, boolean any, boolean not, int expectedAssetEntriesCount) throws Exception {

    ThreadLocalCache<Object[]> threadLocalCache = ThreadLocalCacheManager.getThreadLocalCache(Lifecycle.REQUEST,
            AssetEntryServiceImpl.class.getName());

    threadLocalCache.removeAll();//from   w  w w .  j  a v  a 2 s  .  c o  m

    AssetEntryQuery assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), assetCategoryIds, assetTagNames,
            any, not);

    int initialAssetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    if (assetCategoryIds1 != null) {
        serviceContext.setAssetCategoryIds(assetCategoryIds1);
    }

    if (assetTagNames1 != null) {
        serviceContext.setAssetTagNames(assetTagNames1);
    }

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title1, StringPool.BLANK, StringPool.BLANK,
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);

    if (assetCategoryIds2 != null) {
        serviceContext.setAssetCategoryIds(assetCategoryIds2);
    }

    if (assetTagNames2 != null) {
        serviceContext.setAssetTagNames(assetTagNames2);
    }

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), title2, StringPool.BLANK, StringPool.BLANK,
            RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true, null, StringPool.BLANK, null, null,
            serviceContext);

    threadLocalCache.removeAll();

    assetEntryQuery = buildAssetEntryQuery(_group.getGroupId(), assetCategoryIds, assetTagNames, any, not);

    int assetEntriesCount = AssetEntryServiceUtil.getEntriesCount(assetEntryQuery);

    Assert.assertEquals(initialAssetEntriesCount + expectedAssetEntriesCount, assetEntriesCount);
}

From source file:com.liferay.asset.service.test.AssetTagFinderTest.java

License:Open Source License

protected void addMBMessage(long groupId, String assetTagName) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId,
            TestPropsValues.getUserId());

    serviceContext.setAssetTagNames(new String[] { assetTagName });

    MBTestUtil.addMessageWithWorkflow(groupId, MBCategoryConstants.DEFAULT_PARENT_CATEGORY_ID,
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), true, serviceContext);
}

From source file:com.liferay.asset.service.test.AssetTagLocalServiceTest.java

License:Open Source License

@Test
public void testDeleteTag() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(),
            TestPropsValues.getUserId());

    AssetTag assetTag = AssetTagLocalServiceUtil.addTag(TestPropsValues.getUserId(), _group.getGroupId(), "Tag",
            serviceContext);/*  w  ww .j  a  v a  2  s .  co m*/

    serviceContext.setAssetTagNames(new String[] { assetTag.getName() });

    _organization = OrganizationLocalServiceUtil.addOrganization(TestPropsValues.getUserId(),
            OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID, RandomTestUtil.randomString(),
            OrganizationConstants.TYPE_ORGANIZATION, 0, 0, ListTypeConstants.ORGANIZATION_STATUS_DEFAULT,
            RandomTestUtil.randomString(), true, serviceContext);

    TestAssetIndexer testAssetIndexer = new TestAssetIndexer();

    testAssetIndexer.setExpectedValues(Organization.class.getName(), _organization.getOrganizationId());

    if (_organizationIndexer == null) {
        _organizationIndexer = IndexerRegistryUtil.getIndexer(Organization.class);
    }

    IndexerRegistryUtil.register(testAssetIndexer);

    AssetTagLocalServiceUtil.deleteTag(assetTag);

    Assert.assertNull(AssetTagLocalServiceUtil.fetchAssetTag(assetTag.getTagId()));

    long classNameId = PortalUtil.getClassNameId(Organization.class);

    AssetTagStats assetTagStats = AssetTagStatsLocalServiceUtil.getTagStats(assetTag.getTagId(), classNameId);

    Assert.assertEquals(0, assetTagStats.getAssetCount());
}

From source file:com.liferay.asset.tag.stats.service.test.AssetTagStatsServiceTest.java

License:Open Source License

@Ignore
@Test/*w  ww.  j  a  v a2s . c  om*/
public void testGetTagStats() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    serviceContext.setAssetTagNames(new String[] { "basketball" });

    FileEntry fileEntry = DLAppTestUtil.addFileEntryWithWorkflow(TestPropsValues.getUserId(),
            _group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), true, serviceContext);

    AssetTag tag = AssetTagLocalServiceUtil.getTag(_group.getGroupId(), "basketball");

    long classNameId = PortalUtil.getClassNameId(DLFileEntry.class);

    AssetTagStats tagStats = AssetTagStatsLocalServiceUtil.getTagStats(tag.getTagId(), classNameId);

    Assert.assertEquals(1, tagStats.getAssetCount());

    DLAppHelperLocalServiceUtil.deleteFileEntry(fileEntry);

    tagStats = AssetTagStatsLocalServiceUtil.getTagStats(tag.getTagId(), classNameId);

    Assert.assertEquals(0, tagStats.getAssetCount());
}

From source file:com.liferay.asset.test.util.BaseAssetSearchTestCase.java

License:Open Source License

protected void testAssetCategorization(Group[] groups, AssetEntryQuery assetEntryQuery, int expectedResults)
        throws Exception {

    SearchContext searchContext = SearchContextTestUtil.getSearchContext();

    searchContext.setGroupIds(assetEntryQuery.getGroupIds());

    int initialEntries = 0;

    assertCount(initialEntries, assetEntryQuery, searchContext);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groups[0].getGroupId());

    serviceContext.setAssetTagNames(_assetTagsNames1);
    serviceContext.setAssetCategoryIds(_assetCategoryIds1);

    addBaseModels(groups, getSearchKeywords(), serviceContext);

    serviceContext.setAssetTagNames(_assetTagsNames2);
    serviceContext.setAssetCategoryIds(_assetCategoryIds2);

    addBaseModels(groups, getSearchKeywords(), serviceContext);

    assertCount(initialEntries + expectedResults, assetEntryQuery, searchContext);
}

From source file:com.liferay.asset.util.test.AssetUtilTest.java

License:Open Source License

@Test
public void testSearchAssetEntries() throws Exception {
    AssetEntryQuery assetEntryQuery = new AssetEntryQuery();

    assetEntryQuery.setGroupIds(new long[] { _group.getGroupId() });

    long[] assetCategoryIds = { _assetCategory.getCategoryId() };
    String[] assetTagNames = { _assetTag.getName() };

    assertCount(0, assetEntryQuery, assetCategoryIds, assetTagNames, null, _group.getCompanyId(),
            StringPool.BLANK, null, null, _group.getGroupId(), null, _group.getCreatorUserId());

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    serviceContext.setAssetCategoryIds(assetCategoryIds);
    serviceContext.setAssetTagNames(assetTagNames);

    BlogsEntryLocalServiceUtil.addEntry(TestPropsValues.getUserId(), RandomTestUtil.randomString(),
            StringPool.BLANK, StringPool.BLANK, RandomTestUtil.randomString(), 1, 1, 1965, 0, 0, true, true,
            null, StringPool.BLANK, null, null, serviceContext);

    assertCount(1, assetEntryQuery, assetCategoryIds, assetTagNames, null, _group.getCompanyId(),
            StringPool.BLANK, null, null, _group.getGroupId(), null, _group.getCreatorUserId());
}

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

License:Open Source License

protected static FileEntry addFileEntry(long groupId, long folderId, String fileName, String title,
        String[] assetTagNames) throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(groupId);

    serviceContext.setAssetTagNames(assetTagNames);

    return DLAppServiceUtil.addFileEntry(groupId, folderId, fileName, ContentTypes.TEXT_PLAIN, title,
            StringPool.BLANK, StringPool.BLANK, CONTENT.getBytes(), 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  ww  w .  j  ava 2s .  c  o  m

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

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