List of usage examples for com.liferay.portal.kernel.service ServiceContext setAssetCategoryIds
public void setAssetCategoryIds(long[] assetCategoryIds)
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportAssetCategoryFiltering() throws Exception { AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); AssetCategory assetCategory = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAssetCategoryIds(new long[] { assetCategory.getCategoryId() }); List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 2, new ArrayList<AssetEntry>(), serviceContext);//from w w w. j ava2s.co m Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("queryContains0", new String[] { "true" }); preferenceMap.put("queryName0", new String[] { "assetCategories" }); preferenceMap.put("queryValues0", new String[] { String.valueOf(assetCategory.getCategoryId()) }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.publisher.lar.test.AssetPublisherExportImportTest.java
License:Open Source License
@Test public void testDynamicExportImportAssetVocabularyFiltering() throws Exception { AssetVocabulary assetVocabulary = AssetTestUtil.addVocabulary(group.getGroupId()); AssetCategory assetCategory1 = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(); serviceContext.setAssetCategoryIds(new long[] { assetCategory1.getCategoryId() }); List<AssetEntry> expectedAssetEntries = addAssetEntries(group, 1, new ArrayList<AssetEntry>(), serviceContext);//from w w w .j a va2 s .com AssetCategory assetCategory2 = AssetTestUtil.addCategory(group.getGroupId(), assetVocabulary.getVocabularyId()); serviceContext.setAssetCategoryIds(new long[] { assetCategory2.getCategoryId() }); expectedAssetEntries = addAssetEntries(group, 1, expectedAssetEntries, serviceContext); Map<String, String[]> preferenceMap = new HashMap<>(); preferenceMap.put("assetVocabularyId", new String[] { String.valueOf(assetVocabulary.getVocabularyId()) }); testDynamicExportImport(preferenceMap, expectedAssetEntries, true); }
From source file:com.liferay.asset.service.test.AssetCategoryLocalServiceTest.java
License:Open Source License
@Test public void testDeleteCategory() throws Exception { Map<Locale, String> titleMap = new HashMap<>(); titleMap.put(LocaleUtil.US, RandomTestUtil.randomString()); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId(), TestPropsValues.getUserId()); AssetVocabulary assetVocabulary = AssetVocabularyLocalServiceUtil.addVocabulary(TestPropsValues.getUserId(), _group.getGroupId(), RandomTestUtil.randomString(), titleMap, null, null, serviceContext); AssetCategory assetCategory = AssetCategoryLocalServiceUtil.addCategory(TestPropsValues.getUserId(), _group.getGroupId(), RandomTestUtil.randomString(), assetVocabulary.getVocabularyId(), serviceContext);/*ww w .ja va 2 s . c o m*/ serviceContext.setAssetCategoryIds(new long[] { assetCategory.getCategoryId() }); _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); AssetCategoryLocalServiceUtil.deleteCategory(assetCategory, 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 www. jav a 2s . 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.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.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; }/* w w w. jav a2s . c om*/ 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) {// w w w. j ava 2 s. c om 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 w w w . ja va 2 s. 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()); }