@Override public Collection<HistoryByUser> getHistoryByObject( ForeignPK foreignPK, int action, String objectType) { UserDetail[] allUsers = OrganizationControllerProvider.getOrganisationController() .getAllUsers(foreignPK.getInstanceId()); return getHistoryByObject(foreignPK, action, objectType, allUsers); }
public static void moveThumbnail(ForeignPK fromPK, ForeignPK toPK) { ThumbnailDetail thumbnail = ThumbnailController.getCompleteThumbnail( new ThumbnailDetail( fromPK.getInstanceId(), Integer.parseInt(fromPK.getId()), ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE)); try { if (thumbnail != null) { // move thumbnail on disk if (!thumbnail.getOriginalFileName().startsWith("/")) { String path = getImageDirectory(fromPK.getInstanceId()) + File.separatorChar + thumbnail.getOriginalFileName(); String destinationPath = getImageDirectory(toPK.getInstanceId()); SilverpeasFile image = SilverpeasFileProvider.getFile(path); image.moveInto(destinationPath); // move cropped thumbnail if (thumbnail.getCropFileName() != null) { path = getImageDirectory(fromPK.getInstanceId()) + File.separatorChar + thumbnail.getCropFileName(); image = SilverpeasFileProvider.getFile(path); image.moveInto(destinationPath); } } // move thumbnail in DB getThumbnailService().moveThumbnail(thumbnail, toPK.getInstanceId()); } } catch (Exception e) { throw new ThumbnailRuntimeException( "ThumbnailController.moveThumbnail()", SilverpeasRuntimeException.ERROR, "thumbnail_CANT_MOVE_THUMBNAIL", e); } }
public static void copyThumbnail(ForeignPK fromPK, ForeignPK toPK) { ThumbnailDetail vignette = ThumbnailController.getCompleteThumbnail( new ThumbnailDetail( fromPK.getInstanceId(), Integer.parseInt(fromPK.getId()), ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE)); try { if (vignette != null) { ThumbnailDetail thumbDetail = new ThumbnailDetail( toPK.getInstanceId(), Integer.valueOf(toPK.getId()), ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE); if (vignette.getOriginalFileName().startsWith("/")) { thumbDetail.setOriginalFileName(vignette.getOriginalFileName()); thumbDetail.setMimeType(vignette.getMimeType()); } else { String from = getImageDirectory(fromPK.getInstanceId()) + vignette.getOriginalFileName(); String type = FilenameUtils.getExtension(vignette.getOriginalFileName()); String newOriginalImage = String.valueOf(System.currentTimeMillis()) + "." + type; String to = getImageDirectory(toPK.getInstanceId()) + newOriginalImage; FileRepositoryManager.copyFile(from, to); thumbDetail.setOriginalFileName(newOriginalImage); // then copy thumbnail image if exists if (vignette.getCropFileName() != null) { from = getImageDirectory(fromPK.getInstanceId()) + vignette.getCropFileName(); type = FilenameUtils.getExtension(vignette.getCropFileName()); String newThumbnailImage = String.valueOf(System.currentTimeMillis()) + "." + type; to = getImageDirectory(toPK.getInstanceId()) + newThumbnailImage; FileRepositoryManager.copyFile(from, to); thumbDetail.setCropFileName(newThumbnailImage); } thumbDetail.setMimeType(vignette.getMimeType()); thumbDetail.setXLength(vignette.getXLength()); thumbDetail.setYLength(vignette.getYLength()); thumbDetail.setXStart(vignette.getXStart()); thumbDetail.setYStart(vignette.getYStart()); } getThumbnailService().createThumbnail(thumbDetail); } } catch (Exception e) { throw new ThumbnailRuntimeException( "ThumbnailController.copyThumbnail()", SilverpeasRuntimeException.ERROR, "thumbnail_CANT_COPY_THUMBNAIL", e); } }
public static boolean processThumbnail(ForeignPK pk, String objectType, List<FileItem> parameters) throws Exception { boolean thumbnailChanged = false; String mimeType = null; String physicalName = null; FileItem uploadedFile = FileUploadUtil.getFile(parameters, "WAIMGVAR0"); if (uploadedFile != null) { String logicalName = uploadedFile.getName().replace('\\', '/'); if (StringUtil.isDefined(logicalName)) { logicalName = FilenameUtils.getName(logicalName); mimeType = FileUtil.getMimeType(logicalName); String type = FileRepositoryManager.getFileExtension(logicalName); if (FileUtil.isImage(logicalName)) { physicalName = String.valueOf(System.currentTimeMillis()) + '.' + type; SilverpeasFileDescriptor descriptor = new SilverpeasFileDescriptor(pk.getInstanceId()) .mimeType(mimeType) .parentDirectory(publicationSettings.getString("imagesSubDirectory")) .fileName(physicalName); SilverpeasFile target = SilverpeasFileProvider.newFile(descriptor); target.writeFrom(uploadedFile.getInputStream()); } else { throw new ThumbnailRuntimeException( "ThumbnailController.processThumbnail()", SilverpeasRuntimeException.ERROR, "thumbnail_EX_MSG_WRONG_TYPE_ERROR"); } } } // If no image have been uploaded, check if one have been picked up from a gallery if (physicalName == null) { // on a pas d'image, regarder s'il y a une provenant de la galerie String nameImageFromGallery = FileUploadUtil.getParameter(parameters, "valueImageGallery"); if (StringUtil.isDefined(nameImageFromGallery)) { physicalName = nameImageFromGallery; mimeType = "image/jpeg"; } } // If one image is defined, save it through Thumbnail service if (StringUtil.isDefined(physicalName)) { ThumbnailDetail detail = new ThumbnailDetail( pk.getInstanceId(), Integer.parseInt(pk.getId()), ThumbnailDetail.THUMBNAIL_OBJECTTYPE_PUBLICATION_VIGNETTE); detail.setOriginalFileName(physicalName); detail.setMimeType(mimeType); try { ThumbnailController.updateThumbnail(detail); thumbnailChanged = true; } catch (ThumbnailRuntimeException e) { SilverTrace.error( "thumbnail", "KmeliaRequestRouter.processVignette", "thumbnail_MSG_UPDATE_THUMBNAIL_KO", e); try { ThumbnailController.deleteThumbnail(detail); } catch (Exception exp) { } } } return thumbnailChanged; }