@Override public void importTaskRecords(ExportImportConfiguration exportImportConfiguration, InputStream inputStream) throws PortalException { File file = null; try { file = FileUtil.createTempFile("lar"); FileUtil.write(file, inputStream); importTaskRecords(exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
@Override public void importContacts(ExportImportConfiguration exportImportConfiguration, InputStream inputStream) throws PortalException { File file = null; try { file = FileUtil.createTempFile("lar"); FileUtil.write(file, inputStream); importContacts(exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
@Override public long importContactsInBackground(long userId, ExportImportConfiguration exportImportConfiguration, InputStream inputStream, String extension) throws PortalException { File file = null; try { file = FileUtil.createTempFile(extension); FileUtil.write(file, inputStream); return importContactsInBackground(userId, exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
@Override public File uploadPhoto(long userId, long companyId, long groupId, long id, InputStream inputStream, String fileName, String fileType, long fileSize, String destination, String desc, ServiceContext serviceContext) throws Exception { File file = null; FileEntry fileEntry = FileUploadUtils.uploadFile(userId, companyId, groupId, inputStream, fileName, fileType, fileSize, destination, desc, serviceContext); User user = UserLocalServiceUtil.fetchUser(id); file = DLFileEntryLocalServiceUtil.getFile(fileEntry.getFileEntryId(), fileEntry.getVersion(), false); UserLocalServiceUtil.updatePortrait(user.getUserId(), FileUtil.getBytes(file)); return file; }
@Override public void importMeasurements( ExportImportConfiguration exportImportConfiguration, InputStream inputStream) throws PortalException { _log.info("importMeasurements()"); File file = null; try { // TODO: use extension from upload file = FileUtil.createTempFile("lar"); FileUtil.write(file, inputStream); importMeasurements(exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
@Override public long importMeasurementsInBackground(long userId, ExportImportConfiguration exportImportConfiguration, InputStream inputStream, String extension) throws PortalException { _log.info("importMeasurementsInBackground()"); File file = null; try { file = FileUtil.createTempFile(extension); FileUtil.write(file, inputStream); return importMeasurementsInBackground(userId, exportImportConfiguration, file); } catch (IOException ioe) { throw new SystemException(ioe); } finally { FileUtil.delete(file); } }
public MultiMedia addMultiMedia(MultiMedia multiMedia, File imageFile) throws SystemException, PortalException { long multiMediaId = CounterLocalServiceUtil.increment(MultiMedia.class.getName()); MultiMedia model = multiMediaPersistence.create(multiMediaId); model.setUserId(multiMedia.getUserId()); model.setCompanyId(multiMedia.getCompanyId()); model.setCreateDate(new Date()); model.setModifiedDate(new Date()); model.setApplicationId(multiMedia.getApplicationId()); model.setName(multiMedia.getName()); model.setType(multiMedia.getType()); try { // DLAppLocalServiceUtil.addFileEntry(userId, repositoryId, folderId, sourceFileName, mimeType, title, description, changeLog, imageFile, serviceContext); // DLAppLocalServiceUtil.addFileEntry(userId, repositoryId, folderId, imageFile.getName(), mimeType, title, description, changeLog, imageFile, serviceContext); byte[] imageBytes = null; imageBytes = FileUtil.getBytes(imageFile); model.setImageId(counterLocalService.increment()); _log.debug("addLink::imageBytes.length: " + imageBytes.length); saveImages(model.getImageId(), imageFile, imageBytes); } catch (Exception e) { _log.info(e.toString()); } return multiMediaPersistence.update(model, true); }
public MultiMedia updateMultiMedia(MultiMedia multiMedia, File imageFile) throws SystemException { MultiMedia model = multiMediaPersistence.fetchByPrimaryKey(multiMedia.getMultiMediaId()); model.setUserId(multiMedia.getUserId()); model.setCompanyId(multiMedia.getCompanyId()); model.setApplicationId(multiMedia.getApplicationId()); model.setType(multiMedia.getType()); model.setModifiedDate(new Date()); try { byte[] imageBytes = null; imageBytes = FileUtil.getBytes(imageFile); model.setImageId(counterLocalService.increment()); _log.debug("addLink::imageBytes.length: " + imageBytes.length); _log.debug("imageFile.getName(): " + imageFile.getName()); model.setName(imageFile.getName()); saveImages(model.getImageId(), imageFile, imageBytes); } catch (Exception e) { _log.info(e.toString()); } return multiMediaPersistence.update(model, true); }
private void importLayouts(long userId,Group grupo,LayoutSetPrototype lsProto) throws PortalException, SystemException { LayoutSet ls = lsProto.getLayoutSet(); Map<String, String[]> parameterMap =getLayoutSetPrototypeParameters(); File fileIni= layoutLocalService.exportLayoutsAsFile(ls.getGroupId(), true, null,parameterMap, null, null); try { layoutLocalService.importLayouts(userId, grupo.getPublicLayoutSet().getGroupId(), grupo.getPublicLayoutSet().isPrivateLayout(), parameterMap, fileIni); } catch(Exception e) { } FileUtil.delete(fileIni); }
public void deleteExportedCourse(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId", 0); String fileName = ParamUtil.getString(actionRequest, "fileName", StringPool.BLANK); String redirect = ParamUtil.getString(actionRequest, "redirect", StringPool.BLANK); File f = new File(PropsUtil.get("liferay.home")+"/data/lms_exports/courses/"+themeDisplay.getCompanyId()+"/"+groupId+"/"+fileName); if (themeDisplay.getPermissionChecker().hasPermission(groupId, Course.class.getName(), groupId, ActionKeys.DELETE) && f != null && f.isFile()) { FileUtil.delete(f); SessionMessages.add(actionRequest, "courseadmin.delete.exported.confirmation.success"); } else { SessionMessages.add(actionRequest, "courseadmin.delete.exported.confirmation.error"); } if (Validator.isNotNull(redirect)) { actionResponse.sendRedirect(redirect); } }
protected void migrateFile( long repositoryId, long companyId, String name, Image image) throws Exception { InputStream is = _sourceHook.getImageAsStream(image); byte[] bytes = FileUtil.getBytes(is); if (name == null) { name = image.getImageId() + StringPool.PERIOD + image.getType(); } if (DLStoreUtil.hasFile(companyId, repositoryId, name)) { DLStoreUtil.deleteFile(companyId, repositoryId, name); } DLStoreUtil.addFile(companyId, repositoryId, name, false, bytes); }
public void buildSQLFile(String sqlDir, String fileName) throws IOException { String template = buildTemplate(sqlDir, fileName); if (Validator.isNull(template)) { return; } template = buildSQL(template); FileUtil.write( sqlDir + "/" + fileName + "/" + fileName + "-" + getServerName() + ".sql", template); }
protected void addDDMStructures( String parentStructureId, String structuresDirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(structuresDirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMStructures( parentStructureId, name, urlConnection.getInputStream()); } }
protected void addDDMTemplates( String ddmStructureKey, String templatesDirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(templatesDirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMTemplates( ddmStructureKey, name, urlConnection.getInputStream()); } }
protected void addDLFileEntry(String resourcePath) throws Exception { Long parentFolderId = _folderIds.get( FileUtil.getPath(resourcePath) + StringPool.SLASH); if (parentFolderId == null) { parentFolderId = 0L; } URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDLFileEntry( parentFolderId, FileUtil.getShortFileName(resourcePath), urlConnection.getInputStream(), urlConnection.getContentLength()); }
protected void addDDLStructures(String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(dirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { File file = new File(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMStructures( FileUtil.stripExtension(file.getName()), urlConnection.getInputStream()); } }
protected void addDDMStructures(String parentStructureId, String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(dirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMStructures( parentStructureId, name, urlConnection.getInputStream()); } }
protected void addDDMTemplates(String ddmStructureKey, String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(dirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { if (resourcePath.endsWith(StringPool.SLASH)) { continue; } String name = FileUtil.getShortFileName(resourcePath); URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addDDMTemplates( ddmStructureKey, name, urlConnection.getInputStream()); } }
protected void addLayoutTemplate(String dirName) throws Exception { Set<String> resourcePaths = servletContext.getResourcePaths( resourcesDir.concat(dirName)); if (resourcePaths == null) { return; } for (String resourcePath : resourcePaths) { String extension = FileUtil.getExtension(resourcePath); if (!extension.equals("json")) { return; } URL url = servletContext.getResource(resourcePath); URLConnection urlConnection = url.openConnection(); addLayoutTemplate(urlConnection.getInputStream()); } }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); List<FileEntry> attachmentsFileEntries = backgroundTask.getAttachmentsFileEntries(); File file = null; for (FileEntry attachmentsFileEntry : attachmentsFileEntries) { try { file = FileUtil.createTempFile("lar"); FileUtil.write(file, attachmentsFileEntry.getContentStream()); _log.info(file.getAbsoluteFile()); TransactionInvokerUtil.invoke(transactionConfig, new TaskRecordImportCallable(exportImportConfiguration, file)); } catch (Throwable t) { if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to import taskRecords: " + t.getMessage()); } throw new SystemException(t); } finally { FileUtil.delete(file); } } return BackgroundTaskResult.SUCCESS; }
@Override public BackgroundTaskResult execute(BackgroundTask backgroundTask) throws Exception { ExportImportConfiguration exportImportConfiguration = getExportImportConfiguration(backgroundTask); List<FileEntry> attachmentsFileEntries = backgroundTask.getAttachmentsFileEntries(); File file = null; for (FileEntry attachmentsFileEntry : attachmentsFileEntries) { try { file = FileUtil.createTempFile("lar"); FileUtil.write(file, attachmentsFileEntry.getContentStream()); _log.info(file.getAbsoluteFile()); TransactionInvokerUtil.invoke(transactionConfig, new ContactImportCallable(exportImportConfiguration, file)); } catch (Throwable t) { if (_log.isDebugEnabled()) { _log.debug(t, t); } else if (_log.isWarnEnabled()) { _log.warn("Unable to import contacts: " + t.getMessage()); } throw new SystemException(t); } finally { FileUtil.delete(file); } } return BackgroundTaskResult.SUCCESS; }