List of usage examples for com.liferay.portal.kernel.repository.model FileEntry getUuid
@Override
public String getUuid();
From source file:com.custom.portal.verify.CustomVerifyDynamicDataMapping.java
License:Open Source License
protected String getJSON(FileEntry fileEntry) { JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); jsonObject.put("groupId", fileEntry.getGroupId()); jsonObject.put("uuid", fileEntry.getUuid()); return jsonObject.toString(); }
From source file:com.fmdp.webform.portlet.WebFormPortlet.java
License:Open Source License
public void saveData(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest); String portletId = PortalUtil.getPortletId(actionRequest); PortletPreferences preferences = PortletPreferencesFactoryUtil.getPortletSetup(actionRequest, portletId); boolean requireCaptcha = GetterUtil.getBoolean(preferences.getValue("requireCaptcha", StringPool.BLANK)); String successURL = GetterUtil.getString(preferences.getValue("successURL", StringPool.BLANK)); boolean sendAsEmail = GetterUtil.getBoolean(preferences.getValue("sendAsEmail", StringPool.BLANK)); boolean sendThanksEmail = GetterUtil.getBoolean(preferences.getValue("sendThanksEmail", StringPool.BLANK)); boolean saveToDatabase = GetterUtil.getBoolean(preferences.getValue("saveToDatabase", StringPool.BLANK)); String databaseTableName = GetterUtil .getString(preferences.getValue("databaseTableName", StringPool.BLANK)); boolean saveToFile = GetterUtil.getBoolean(preferences.getValue("saveToFile", StringPool.BLANK)); boolean uploadToDisk = GetterUtil.getBoolean(preferences.getValue("uploadToDisk", StringPool.BLANK)); boolean uploadToDM = GetterUtil.getBoolean(preferences.getValue("uploadToDM", StringPool.BLANK)); long newFolderId = GetterUtil.getLong(preferences.getValue("newFolderId", StringPool.BLANK)); String fileName = GetterUtil.getString(preferences.getValue("fileName", StringPool.BLANK)); String uploadDiskDir = GetterUtil.getString(preferences.getValue("uploadDiskDir", StringPool.BLANK)); if (requireCaptcha) { try {/*from www . j ava 2 s . co m*/ CaptchaUtil.check(actionRequest); } catch (CaptchaTextException cte) { SessionErrors.add(actionRequest, CaptchaTextException.class.getName()); return; } } UploadPortletRequest uploadRequest = PortalUtil.getUploadPortletRequest(actionRequest); Map<String, String> fieldsMap = new LinkedHashMap<String, String>(); String fileAttachment = ""; for (int i = 1; true; i++) { String fieldLabel = preferences.getValue("fieldLabel" + i, StringPool.BLANK); String fieldType = preferences.getValue("fieldType" + i, StringPool.BLANK); if (Validator.isNull(fieldLabel)) { break; } if (StringUtil.equalsIgnoreCase(fieldType, "paragraph")) { continue; } if (StringUtil.equalsIgnoreCase(fieldType, "file")) { if (_log.isDebugEnabled()) { _log.debug("Field name for file: " + fieldLabel); } File file = uploadRequest.getFile("field" + i); String sourceFileName = uploadRequest.getFileName("field" + i); if (_log.isDebugEnabled()) { _log.debug("File attachment: " + sourceFileName); } JSONObject jsonObject = JSONFactoryUtil.createJSONObject(); if (Validator.isNotNull(sourceFileName) && !"".equals(sourceFileName)) { if (uploadRequest.getSize("field" + i) == 0) { SessionErrors.add(actionRequest, "uploadToDiskError", "Uploaded file size is 0"); if (_log.isDebugEnabled()) { _log.debug("Uploaded file size is 0"); } return; } // List<String> uploadResults = new ArrayList<String>(); String uploadResult = ""; if (uploadToDisk) { uploadResult = uploadFile(file, sourceFileName, uploadDiskDir); if (uploadResult.equalsIgnoreCase("File Upload Error")) { SessionErrors.add(actionRequest, "uploadToDiskError", uploadResult); return; } fileAttachment = uploadDiskDir + File.separator + uploadResult; //uploadResults.add(uploadResult); jsonObject.put("fsOriginalName", sourceFileName); jsonObject.put("fsName", uploadResult); } if (uploadToDM) { uploadResult = ""; String contentType = MimeTypesUtil.getContentType(file); Folder folderName = DLAppLocalServiceUtil.getFolder(newFolderId); if (_log.isDebugEnabled()) { _log.debug("DM Folder: " + folderName.getName()); } InputStream inputStream = new FileInputStream(file); long repositoryId = folderName.getRepositoryId(); try { String selectedFileName = sourceFileName; while (true) { try { DLAppLocalServiceUtil.getFileEntry(themeDisplay.getScopeGroupId(), newFolderId, selectedFileName); StringBundler sb = new StringBundler(5); sb.append(FileUtil.stripExtension(selectedFileName)); sb.append(StringPool.DASH); sb.append(StringUtil.randomString()); sb.append(StringPool.PERIOD); sb.append(FileUtil.getExtension(selectedFileName)); selectedFileName = sb.toString(); } catch (Exception e) { break; } } FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(themeDisplay.getUserId(), repositoryId, newFolderId, selectedFileName, //file.getName(), contentType, selectedFileName, "", "", inputStream, file.length(), serviceContext); if (_log.isDebugEnabled()) { _log.debug("DM file uploade: " + fileEntry.getTitle()); } //Map<String, Serializable> workflowContext = new HashMap<String, Serializable>(); //workflowContext.put("event",DLSyncConstants.EVENT_UPDATE); //DLFileEntryLocalServiceUtil.updateStatus(themeDisplay.getUserId(), fileEntry.getFileVersion().getFileVersionId(), WorkflowConstants.STATUS_APPROVED, workflowContext, serviceContext); uploadResult = String.valueOf(fileEntry.getFileEntryId()); //uploadResults.add(uploadResult); String docUrl = themeDisplay.getPortalURL() + "/c/document_library/get_file?uuid=" + fileEntry.getUuid() + "&groupId=" + themeDisplay.getScopeGroupId(); jsonObject.put("fe", uploadResult); jsonObject.put("feOriginalName", sourceFileName); jsonObject.put("feName", fileEntry.getTitle()); jsonObject.put("feUrl", docUrl); } catch (PortalException pe) { SessionErrors.add(actionRequest, "uploadToDmError"); _log.error("The upload to DM failed", pe); return; } catch (Exception e) { _log.error("The upload to DM failed", e); return; } } jsonObject.put("Status", "With Attachment"); } else { jsonObject.put("Status", "No Attachment"); } fieldsMap.put(fieldLabel, jsonObject.toString()); } else { fieldsMap.put(fieldLabel, uploadRequest.getParameter("field" + i)); } } Set<String> validationErrors = null; try { validationErrors = validate(fieldsMap, preferences); } catch (Exception e) { SessionErrors.add(actionRequest, "validationScriptError", e.getMessage().trim()); return; } User currentUser = PortalUtil.getUser(actionRequest); String userEmail = ""; if (!Validator.isNull(currentUser)) { userEmail = currentUser.getEmailAddress(); if (_log.isDebugEnabled()) { _log.debug("User email for the form author: " + userEmail); } fieldsMap.put("email-from", userEmail); } else { fieldsMap.put("email-from", "guest"); } DateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); df.setTimeZone(TimeZone.getTimeZone(themeDisplay.getTimeZone().getID())); Date dateobj = new Date(); fieldsMap.put("email-sent-on", df.format(dateobj)); if (validationErrors.isEmpty()) { boolean emailSuccess = true; boolean databaseSuccess = true; boolean fileSuccess = true; boolean emailThanksSuccess = true; if (sendAsEmail) { emailSuccess = WebFormUtil.sendEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, fileAttachment); } if (sendThanksEmail && !Validator.isNull(currentUser)) { emailThanksSuccess = WebFormUtil.sendThanksEmail(themeDisplay.getCompanyId(), fieldsMap, preferences, userEmail); } if (saveToDatabase) { if (Validator.isNull(databaseTableName)) { databaseTableName = WebFormUtil.getNewDatabaseTableName(portletId); preferences.setValue("databaseTableName", databaseTableName); preferences.store(); } databaseSuccess = saveDatabase(themeDisplay.getCompanyId(), fieldsMap, preferences, databaseTableName); } if (saveToFile) { fileSuccess = saveFile(fieldsMap, fileName); } if (emailSuccess && emailThanksSuccess && databaseSuccess && fileSuccess) { if (Validator.isNull(successURL)) { SessionMessages.add(actionRequest, "success"); } else { SessionMessages.add(actionRequest, portletId + SessionMessages.KEY_SUFFIX_HIDE_DEFAULT_SUCCESS_MESSAGE); } } else { SessionErrors.add(actionRequest, "error"); } } else { for (String badField : validationErrors) { SessionErrors.add(actionRequest, "error" + badField); } } if (SessionErrors.isEmpty(actionRequest) && Validator.isNotNull(successURL)) { actionResponse.sendRedirect(successURL); } }
From source file:com.liferay.adaptive.media.blogs.internal.exportimport.data.handler.test.AMBlogsEntryStagedModelDataHandlerTest.java
License:Open Source License
private String _getExpectedDynamicContent(FileEntry... fileEntries) throws Exception { List<FileEntry> importedFileEntries = new ArrayList<>(); for (FileEntry fileEntry : fileEntries) { importedFileEntries.add(/*from w w w . j a v a 2 s. co m*/ _dlAppLocalService.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId())); } return _getDynamicContent(importedFileEntries.toArray(new FileEntry[0])); }
From source file:com.liferay.adaptive.media.blogs.internal.exportimport.data.handler.test.AMBlogsEntryStagedModelDataHandlerTest.java
License:Open Source License
private String _getExpectedStaticContent(FileEntry... fileEntries) throws Exception { StringBundler sb = new StringBundler(fileEntries.length * 2); for (FileEntry fileEntry : fileEntries) { FileEntry importedFileEntry = _dlAppLocalService.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); sb.append(_amImageHTMLTagFactory.create(_getImgTag(importedFileEntry), importedFileEntry)); sb.append(StringPool.NEW_LINE);//from w w w . ja v a 2s.c o m } return sb.toString(); }
From source file:com.liferay.adaptive.media.document.library.internal.document.library.exportimport.data.handler.AMImageDLPluggableContentDataHandler.java
License:Open Source License
private String _getAMBasePath(FileEntry fileEntry, String uuid) { return String.format("adaptive-media/%s/%s/%s", FileEntry.class.getSimpleName(), fileEntry.getUuid(), uuid); }
From source file:com.liferay.adaptive.media.journal.internal.exportimport.data.handler.test.AMJournalArticleStagedModelDataHandlerTest.java
License:Open Source License
private String _getExpectedStaticContent(FileEntry... fileEntries) throws Exception { StringBundler sb = new StringBundler(fileEntries.length * 2); for (FileEntry fileEntry : fileEntries) { FileEntry importedFileEntry = _dlAppLocalService.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); sb.append(_amImageHTMLTagFactory.create(_getImgTag(importedFileEntry), importedFileEntry)); sb.append(StringPool.NEW_LINE);// ww w . ja v a 2 s . co m } return _getContent(sb.toString()); }
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;/* w w w . j a v a 2 s .c o m*/ } 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.document.library.internal.exportimport.data.handler.FileEntryStagedModelDataHandler.java
License:Open Source License
@Override protected void doRestoreStagedModel(PortletDataContext portletDataContext, FileEntry fileEntry) throws Exception { long userId = portletDataContext.getUserId(fileEntry.getUserUuid()); FileEntry existingFileEntry = fetchStagedModelByUuidAndGroupId(fileEntry.getUuid(), portletDataContext.getScopeGroupId()); if ((existingFileEntry == null) || !existingFileEntry.isInTrash()) { return;/*from ww w.ja v a 2 s. c o m*/ } TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(DLFileEntry.class.getName()); if (trashHandler.isRestorable(existingFileEntry.getFileEntryId())) { trashHandler.restoreTrashEntry(userId, existingFileEntry.getFileEntryId()); } }
From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FileEntryStagedModelDataHandlerTest.java
License:Open Source License
@Test public void testExportImportFileExtension() throws Exception { String fileName = "PDF_Test.pdf"; ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(stagingGroup.getGroupId(), TestPropsValues.getUserId()); FileEntry fileEntry = DLAppLocalServiceUtil.addFileEntry(TestPropsValues.getUserId(), stagingGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, fileName, ContentTypes.APPLICATION_PDF, FileUtil.getBytes(getClass(), "dependencies/" + fileName), serviceContext);/*w w w .j a v a 2s . c o m*/ exportImportStagedModel(fileEntry); FileEntry importedFileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); Assert.assertEquals("pdf", importedFileEntry.getExtension()); String title = RandomTestUtil.randomString() + ".awesome"; DLAppServiceUtil.updateFileEntry(fileEntry.getFileEntryId(), StringPool.BLANK, ContentTypes.TEXT_PLAIN, title, StringPool.BLANK, StringPool.BLANK, false, (byte[]) null, serviceContext); exportImportStagedModel(fileEntry); importedFileEntry = DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), liveGroup.getGroupId()); Assert.assertEquals("pdf", importedFileEntry.getExtension()); }
From source file:com.liferay.document.library.internal.exportimport.data.handler.test.FileShortcutStagedModelDataHandlerTest.java
License:Open Source License
@Override protected void validateImport(Map<String, List<StagedModel>> dependentStagedModelsMap, Group group) throws Exception { List<StagedModel> fileEntryDependentStagedModels = dependentStagedModelsMap .get(DLFileEntry.class.getSimpleName()); Assert.assertEquals(fileEntryDependentStagedModels.toString(), 1, fileEntryDependentStagedModels.size()); FileEntry fileEntry = (FileEntry) fileEntryDependentStagedModels.get(0); DLAppLocalServiceUtil.getFileEntryByUuidAndGroupId(fileEntry.getUuid(), group.getGroupId()); List<StagedModel> folderDependentStagedModels = dependentStagedModelsMap .get(DLFolder.class.getSimpleName()); Assert.assertEquals(folderDependentStagedModels.toString(), 1, folderDependentStagedModels.size()); Folder folder = (Folder) folderDependentStagedModels.get(0); DLFolderLocalServiceUtil.getDLFolderByUuidAndGroupId(folder.getUuid(), group.getGroupId()); }