List of usage examples for com.liferay.portal.kernel.service ServiceContext setIndexingEnabled
public void setIndexingEnabled(boolean indexingEnabled)
From source file:com.liferay.document.library.internal.exportimport.data.handler.FileEntryStagedModelDataHandler.java
License:Open Source License
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry) throws Exception { long userId = portletDataContext.getUserId(fileEntry.getUserUuid()); if (!fileEntry.isDefaultRepository()) { // References has been automatically imported, nothing to do here return;/*from w ww. ja v a 2 s .com*/ } Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Folder.class); long folderId = MapUtil.getLong(folderIds, fileEntry.getFolderId(), fileEntry.getFolderId()); long[] assetCategoryIds = portletDataContext.getAssetCategoryIds(DLFileEntry.class, fileEntry.getFileEntryId()); String[] assetTagNames = portletDataContext.getAssetTagNames(DLFileEntry.class, fileEntry.getFileEntryId()); ServiceContext serviceContext = portletDataContext.createServiceContext(fileEntry, DLFileEntry.class); serviceContext.setAttribute("sourceFileName", "A." + fileEntry.getExtension()); serviceContext.setUserId(userId); Element fileEntryElement = portletDataContext.getImportDataElement(fileEntry); String binPath = fileEntryElement.attributeValue("bin-path"); InputStream is = null; try { if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) { try { is = FileEntryUtil.getContentStream(fileEntry); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to retrieve content for file entry " + fileEntry.getFileEntryId(), e); } return; } } else { is = portletDataContext.getZipEntryAsInputStream(binPath); } if (is == null) { if (_log.isWarnEnabled()) { _log.warn("No file found for file entry " + fileEntry.getFileEntryId()); } return; } importMetaData(portletDataContext, fileEntryElement, fileEntry, serviceContext); FileEntry importedFileEntry = null; if (portletDataContext.isDataStrategyMirror()) { FileEntry existingFileEntry = fetchStagedModelByUuidAndGroupId(fileEntry.getUuid(), portletDataContext.getScopeGroupId()); FileVersion fileVersion = fileEntry.getFileVersion(); if (existingFileEntry == null) { if (portletDataContext.isDataStrategyMirrorWithOverwriting()) { FileEntry existingTitleFileEntry = FileEntryUtil .fetchByR_F_T(portletDataContext.getScopeGroupId(), folderId, fileEntry.getTitle()); if (existingTitleFileEntry == null) { existingTitleFileEntry = FileEntryUtil.fetchByR_F_FN( portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName()); } if (existingTitleFileEntry != null) { _dlAppLocalService.deleteFileEntry(existingTitleFileEntry.getFileEntryId()); } } serviceContext.setAttribute("fileVersionUuid", fileVersion.getUuid()); serviceContext.setUuid(fileEntry.getUuid()); String fileEntryTitle = _dlFileEntryLocalService.getUniqueTitle( portletDataContext.getScopeGroupId(), folderId, 0, fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = _dlAppLocalService.addFileEntry(userId, portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); if (fileEntry.isInTrash()) { importedFileEntry = _dlTrashService .moveFileEntryToTrash(importedFileEntry.getFileEntryId()); } } else { FileVersion latestExistingFileVersion = existingFileEntry.getLatestFileVersion(true); boolean indexEnabled = serviceContext.isIndexingEnabled(); boolean deleteFileEntry = false; boolean updateFileEntry = false; if (!Objects.equals(fileVersion.getUuid(), latestExistingFileVersion.getUuid())) { deleteFileEntry = true; updateFileEntry = true; } else { InputStream existingFileVersionInputStream = null; try { existingFileVersionInputStream = latestExistingFileVersion.getContentStream(false); } catch (Exception e) { if (_log.isDebugEnabled()) { _log.debug(e, e); } } finally { if (existingFileVersionInputStream != null) { existingFileVersionInputStream.close(); } } if (existingFileVersionInputStream == null) { updateFileEntry = true; } } try { serviceContext.setIndexingEnabled(false); if (updateFileEntry) { DLFileVersion alreadyExistingFileVersion = _dlFileVersionLocalService .getFileVersionByUuidAndGroupId(fileVersion.getUuid(), existingFileEntry.getGroupId()); if (alreadyExistingFileVersion != null) { serviceContext.setAttribute("existingDLFileVersionId", alreadyExistingFileVersion.getFileVersionId()); } serviceContext.setUuid(fileVersion.getUuid()); String fileEntryTitle = _dlFileEntryLocalService.getUniqueTitle( portletDataContext.getScopeGroupId(), existingFileEntry.getFolderId(), existingFileEntry.getFileEntryId(), fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = _dlAppLocalService.updateFileEntry(userId, existingFileEntry.getFileEntryId(), fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, false, is, fileEntry.getSize(), serviceContext); } else { _dlAppLocalService.updateAsset(userId, existingFileEntry, latestExistingFileVersion, assetCategoryIds, assetTagNames, null); importedFileEntry = existingFileEntry; } if (importedFileEntry.getFolderId() != folderId) { importedFileEntry = _dlAppLocalService.moveFileEntry(userId, importedFileEntry.getFileEntryId(), folderId, serviceContext); } if (importedFileEntry instanceof LiferayFileEntry) { LiferayFileEntry liferayFileEntry = (LiferayFileEntry) importedFileEntry; Indexer<DLFileEntry> indexer = IndexerRegistryUtil .nullSafeGetIndexer(DLFileEntry.class); indexer.reindex((DLFileEntry) liferayFileEntry.getModel()); } if (deleteFileEntry && ExportImportThreadLocal.isStagingInProcess()) { _dlAppService.deleteFileVersion(latestExistingFileVersion.getFileEntryId(), latestExistingFileVersion.getVersion()); } } finally { serviceContext.setIndexingEnabled(indexEnabled); } } } else { String fileEntryTitle = _dlFileEntryLocalService.getUniqueTitle( portletDataContext.getScopeGroupId(), folderId, 0, fileEntry.getTitle(), fileEntry.getExtension()); importedFileEntry = _dlAppLocalService.addFileEntry(userId, portletDataContext.getScopeGroupId(), folderId, fileEntry.getFileName(), fileEntry.getMimeType(), fileEntryTitle, fileEntry.getDescription(), null, is, fileEntry.getSize(), serviceContext); } for (DLPluggableContentDataHandler dlPluggableContentDataHandler : _serviceTrackerList) { dlPluggableContentDataHandler.importContent(portletDataContext, fileEntryElement, fileEntry, importedFileEntry); } portletDataContext.importClassedModel(fileEntry, importedFileEntry, DLFileEntry.class); Map<Long, Long> fileEntryIds = (Map<Long, Long>) portletDataContext .getNewPrimaryKeysMap(FileEntry.class); fileEntryIds.put(fileEntry.getFileEntryId(), importedFileEntry.getFileEntryId()); } finally { try { is.close(); } catch (IOException ioe) { _log.error(ioe, ioe); } } }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
protected void updateDDMStructurePredefinedValues(long ddmStructureId, String content, ServiceContext serviceContext) throws PortalException { DDMStructure ddmStructure = ddmStructureLocalService.fetchDDMStructure(ddmStructureId); if (ddmStructure == null) { return;//from w ww. j av a2 s .c om } DDMForm ddmForm = ddmStructure.getDDMForm(); Map<String, DDMFormField> ddmFormFieldsMap = ddmForm.getDDMFormFieldsMap(true); Map<String, DDMFormField> fullHierarchyDDMFormFieldsMap = ddmStructure .getFullHierarchyDDMFormFieldsMap(true); Map<String, LocalizedValue> fieldsValuesMap = createFieldsValuesMap(content); for (Map.Entry<String, LocalizedValue> fieldValue : fieldsValuesMap.entrySet()) { String ddmFormFieldName = fieldValue.getKey(); LocalizedValue ddmFormFieldValue = fieldValue.getValue(); if (fullHierarchyDDMFormFieldsMap.containsKey(ddmFormFieldName)) { updateDDMFormFieldPredefinedValue(fullHierarchyDDMFormFieldsMap.get(ddmFormFieldName), ddmFormFieldValue); } if (ddmFormFieldsMap.containsKey(ddmFormFieldName)) { updateDDMFormFieldPredefinedValue(ddmFormFieldsMap.get(ddmFormFieldName), ddmFormFieldValue); } } boolean indexingEnabled = serviceContext.isIndexingEnabled(); try { serviceContext.setIndexingEnabled(false); ddmStructureLocalService.updateStructure(serviceContext.getUserId(), ddmStructureId, ddmForm, ddmStructure.getDDMFormLayout(), serviceContext); } finally { serviceContext.setIndexingEnabled(indexingEnabled); } }
From source file:eu.gerhards.liferay.services.angular.service.impl.AngularOrganizationServiceImpl.java
License:Open Source License
@Override public Organization updateOrganization(long organizationId, String name, String type, long regionId, long countryId, long statusId, String comment, boolean site, long[] addresses, long[] emailAddresses, long[] phones, long[] websites, long[] orgLabors) throws PortalException { _log.info("Updating organization ... "); _log.debug(" ... security check ..."); PortalPermissionUtil.check(getPermissionChecker(), AngularActionKeys.UPDATE_COMMUNITY); _log.debug(" ... saving information ... "); User creator = this.getGuestOrUser(); ServiceContext serviceContext = new ServiceContext(); boolean indexingEnabled = true; if (serviceContext != null) { indexingEnabled = serviceContext.isIndexingEnabled(); serviceContext.setIndexingEnabled(false); }//from w w w . j av a 2 s.co m try { _log.debug(" ... organization ..."); serviceContext.setUserId(this.getGuestOrUserId()); Organization organization = null; // Organization organization = organizationLocalService.updateOrganization(creator.getCompanyId(),organizationId,OrganizationConstants.DEFAULT_PARENT_ORGANIZATION_ID ,name, type, regionId, countryId, statusId, comment,false, null, site,serviceContext); this.updateOrganizationParts(organization, addresses, emailAddresses, phones, websites, orgLabors); if (indexingEnabled) { Indexer<Organization> indexer = IndexerRegistryUtil.nullSafeGetIndexer(Organization.class); indexer.reindex(organization); } OrganizationMembershipPolicyUtil.verifyPolicy(organization); return organization; } finally { if (serviceContext != null) { serviceContext.setIndexingEnabled(indexingEnabled); } } }