List of usage examples for com.liferay.portal.kernel.util StringPool SLASH
String SLASH
To view the source code for com.liferay.portal.kernel.util StringPool SLASH.
Click Source Link
From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java
License:Open Source License
private void transferToS3(long imageId) { Image image = null;/*from w ww .ja v a 2 s . c o m*/ try { image = imageLocalService.fetchImage(imageId); } catch (SystemException e) { e.printStackTrace(); } Photo photo = null; try { photo = fetchPhoto(imageId); } catch (SystemException e) { e.printStackTrace(); } String storagePath = photo.getClassPK() + StringPool.SLASH + photo.getUploadDate().getTime() + StringPool.SLASH + photo.getImageId() + StringPool.PERIOD + image.getType(); String bucketName = AppConfig.get(IConstants.CFG_AWS_S3_BUCKET_PHOTO_PROFILE); S3Util.uploadToS3(bucketName, image.getTextObj(), image.getType(), storagePath); // delete the original image after successful upload to S3 if (photo.getImageId() != photo.getThumbnailId()) { try { imageLocalService.deleteImage(imageId); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } } }
From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java
License:Open Source License
public long createPortrait(long imageId) { Photo photo = null;/*from ww w.j a v a2s .com*/ try { photo = fetchPhoto(imageId); } catch (SystemException e) { e.printStackTrace(); } if (Validator.isNull(photo)) return 0l; long profileId = photo.getClassPK(); String fileName = imageId + StringPool.PERIOD + photo.getContentType(); StringBuilder sb = new StringBuilder().append("http://") .append(AppConfig.get(IConstants.CFG_AWS_CLOUDFRONT_DOMAIN)).append(StringPool.SLASH) .append(profileId).append(StringPool.SLASH).append(photo.getUploadDate().getTime()) .append(StringPool.SLASH).append(fileName); URL url = null; try { url = new URL(sb.toString()); } catch (MalformedURLException e) { e.printStackTrace(); } File file = FileUtils.getFile(fileName); try { FileUtils.copyURLToFile(url, file); } catch (IOException e) { e.printStackTrace(); } String publicId = String.valueOf(imageId); try { CloudinaryUtil.getService().uploader().upload(file, Cloudinary.asMap("public_id", publicId)); } catch (IOException e) { e.printStackTrace(); } file.delete(); long thumbnailId = savePortrait(imageId, profileId); try { CloudinaryUtil.getService().uploader().destroy(publicId, Cloudinary.asMap("public_id", publicId)); } catch (IOException e) { e.printStackTrace(); } return thumbnailId; }
From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java
License:Open Source License
@Override @Indexable(type = IndexableType.DELETE)/*from w w w . j a v a 2s .co m*/ public Photo deletePhoto(long imageId) throws PortalException, SystemException { Photo photo = fetchPhoto(imageId); if (Validator.isNotNull(photo)) { if (photo.getThumbnailId() > 0l) { imageLocalService.deleteImage(photo.getThumbnailId()); } // delete image from S3 StringBuilder sb = new StringBuilder().append(photo.getClassPK()).append(StringPool.SLASH) .append(photo.getUploadDate().getTime()).append(StringPool.SLASH).append(photo.getImageId()) .append(StringPool.PERIOD).append(photo.getContentType()); S3Util.removeFromS3(AppConfig.get(IConstants.CFG_AWS_S3_BUCKET_PHOTO_PROFILE), sb.toString()); } return super.deletePhoto(imageId); }
From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.commands.AdaptiveMediaThumbnailsOSGiCommands.java
License:Open Source License
public void check(String... companyIds) { System.out.println("Company ID\t# of thumbnails pending migration"); System.out.println("-------------------------------------------------"); int total = 0; for (long companyId : _getCompanyIds(companyIds)) { try {/* w w w . j ava2s .com*/ String[] fileNames = DLStoreUtil.getFileNames(companyId, DLPreviewableProcessor.REPOSITORY_ID, DLPreviewableProcessor.THUMBNAIL_PATH); int companyTotal = 0; for (String fileName : fileNames) { // See LPS-70788 String actualFileName = StringUtil.replace(fileName, "//", StringPool.SLASH); for (ThumbnailConfiguration thumbnailConfiguration : _getThumbnailConfigurations()) { FileVersion fileVersion = _getFileVersion( thumbnailConfiguration.getFileVersionId(actualFileName)); if (fileVersion != null) { companyTotal += 1; } } } System.out.printf("%d\t\t%d%n", companyId, companyTotal); total += companyTotal; } catch (Exception e) { _log.error(e); } } System.out.printf("%nTOTAL: %d%n", total); }
From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.commands.AdaptiveMediaThumbnailsOSGiCommands.java
License:Open Source License
public void cleanUp(String... companyIds) { for (long companyId : _getCompanyIds(companyIds)) { try {//from w w w . j a va 2 s . c o m String[] fileNames = DLStoreUtil.getFileNames(companyId, DLPreviewableProcessor.REPOSITORY_ID, DLPreviewableProcessor.THUMBNAIL_PATH); for (String fileName : fileNames) { // See LPS-70788 String actualFileName = StringUtil.replace(fileName, "//", StringPool.SLASH); for (ThumbnailConfiguration thumbnailConfiguration : _getThumbnailConfigurations()) { FileVersion fileVersion = _getFileVersion( thumbnailConfiguration.getFileVersionId(actualFileName)); if (fileVersion != null) { DLStoreUtil.deleteFile(companyId, DLPreviewableProcessor.REPOSITORY_ID, actualFileName); } } } } catch (Exception e) { _log.error(e); } } }
From source file:com.liferay.adaptive.media.document.library.thumbnails.internal.commands.AdaptiveMediaThumbnailsOSGiCommands.java
License:Open Source License
public void migrate(String... companyIds) throws PortalException { for (long companyId : _getCompanyIds(companyIds)) { Collection<AdaptiveMediaImageConfigurationEntry> configurationEntries = _adaptiveMediaImageConfigurationHelper .getAdaptiveMediaImageConfigurationEntries(companyId); if (!_isValidConfigurationEntries(configurationEntries)) { throw new PortalException("No valid Adaptive Media configuration found. Please " + "refer to the upgrade documentation for the details."); }//w w w . j av a 2 s . co m try { String[] fileNames = DLStoreUtil.getFileNames(companyId, DLPreviewableProcessor.REPOSITORY_ID, DLPreviewableProcessor.THUMBNAIL_PATH); for (String fileName : fileNames) { // See LPS-70788 String actualFileName = StringUtil.replace(fileName, "//", StringPool.SLASH); for (ThumbnailConfiguration thumbnailConfiguration : _getThumbnailConfigurations()) { Optional<AdaptiveMediaImageConfigurationEntry> configurationEntryOptional = thumbnailConfiguration .selectMatchingConfigurationEntry(configurationEntries); configurationEntryOptional.ifPresent(configurationEntry -> _migrate(actualFileName, configurationEntry, thumbnailConfiguration)); } } } catch (PortalException pe) { _log.error(pe); } } }
From source file:com.liferay.adaptive.media.web.internal.processor.DefaultAdaptiveMediaURIResolver.java
License:Open Source License
@Override public URI resolveURI(URI relativeURI) { String pathModule = _portal.getPathModule(); if (!pathModule.endsWith(StringPool.SLASH)) { pathModule += StringPool.SLASH;/*from w w w . j a v a 2 s . c o m*/ } String servletPath = pathModule + AdaptiveMediaWebConstants.SERVLET_PATH + StringPool.SLASH; URI moduleURI = URI.create(servletPath); return moduleURI.resolve(relativeURI); }
From source file:com.liferay.adaptive.media.web.internal.processor.DefaultAdaptiveMediaURIResolverTest.java
License:Open Source License
@Test public void testMediaURIWhenPathDoesNotEndInSlash() { String pathModule = StringPool.SLASH + StringUtil.randomString(); Mockito.when(_portal.getPathModule()).thenReturn(pathModule); URI relativeURI = URI.create(StringUtil.randomString()); URI uri = _uriResolver.resolveURI(relativeURI); String uriString = uri.toString(); Assert.assertTrue(uriString.contains(pathModule)); Assert.assertTrue(uriString.contains(AdaptiveMediaWebConstants.SERVLET_PATH)); Assert.assertTrue(uriString.contains(relativeURI.toString())); }
From source file:com.liferay.adaptive.media.web.internal.processor.DefaultAdaptiveMediaURIResolverTest.java
License:Open Source License
@Test public void testMediaURIWhenPathEndsInSlash() { String pathModule = StringPool.SLASH + StringUtil.randomString() + StringPool.SLASH; Mockito.when(_portal.getPathModule()).thenReturn(pathModule); URI relativeURI = URI.create(StringUtil.randomString()); URI uri = _uriResolver.resolveURI(relativeURI); String uriString = uri.toString(); Assert.assertTrue(uriString.contains(pathModule)); Assert.assertTrue(uriString.contains(AdaptiveMediaWebConstants.SERVLET_PATH)); Assert.assertTrue(uriString.contains(relativeURI.toString())); }
From source file:com.liferay.alloy.mvc.AlloyFriendlyURLMapper.java
License:Open Source License
@Override public String buildPath(LiferayPortletURL liferayPortletURL) { Map<String, String> routeParameters = new HashMap<String, String>(); buildRouteParameters(liferayPortletURL, routeParameters); // Populate method parameter based on the portlet lifecycle String lifecycle = liferayPortletURL.getLifecycle(); if (lifecycle.equals(PortletRequest.ACTION_PHASE)) { routeParameters.put("method", HttpMethods.POST); } else {// w ww . ja v a 2s . c om routeParameters.put("method", HttpMethods.GET); } // Map URL with router String friendlyURLPath = router.parametersToUrl(routeParameters); if (friendlyURLPath == null) { return null; } // Remove mapped parameters from URL addParametersIncludedInPath(liferayPortletURL, routeParameters); // Remove method int pos = friendlyURLPath.indexOf(CharPool.SLASH); if (pos != -1) { friendlyURLPath = friendlyURLPath.substring(pos); } else { friendlyURLPath = StringPool.BLANK; } // Add mapping friendlyURLPath = StringPool.SLASH.concat(getMapping()).concat(friendlyURLPath); return friendlyURLPath; }