List of usage examples for com.liferay.portal.kernel.util StringPool PERIOD
String PERIOD
To view the source code for com.liferay.portal.kernel.util StringPool PERIOD.
Click Source Link
From source file:com.inikah.slayer.model.impl.ProfileImpl.java
License:Open Source License
public String getS3URL(long imageId) { String s3URL = StringPool.BLANK; if (imageId > 0l) { Photo photo = null;/*from www .j a va 2 s . co m*/ try { photo = PhotoLocalServiceUtil.fetchPhoto(imageId); } catch (SystemException e) { e.printStackTrace(); } StringBuilder sb = new StringBuilder().append("http://") .append(AppConfig.get(IConstants.CFG_AWS_CLOUDFRONT_DOMAIN)).append(StringPool.SLASH) .append(getProfileId()).append(StringPool.SLASH).append(photo.getUploadDate().getTime()) .append(StringPool.SLASH).append(imageId).append(StringPool.PERIOD) .append(photo.getContentType()); s3URL = sb.toString(); } return s3URL; }
From source file:com.inikah.slayer.service.impl.BridgeServiceImpl.java
License:Open Source License
public int getListTypeId(String listName, String suffix) { int listTypeId = 0; try {/*from w w w . j a v a 2 s.c o m*/ List<ListType> listTypes = listTypePersistence .findByType(Profile.class.getName() + StringPool.PERIOD + listName); for (ListType listType : listTypes) { if (listType.getName().endsWith(suffix)) { listTypeId = listType.getListTypeId(); break; } } } catch (SystemException e) { e.printStackTrace(); } return listTypeId; }
From source file:com.inikah.slayer.service.impl.BridgeServiceImpl.java
License:Open Source License
public List<ListType> getList(String listName) { List<ListType> listTypes = null; String _listName = Profile.class.getName() + StringPool.PERIOD + listName; try {//from w w w . j a v a 2 s . c om listTypes = listTypeService.getListTypes(_listName); } catch (SystemException e) { e.printStackTrace(); } return listTypes; }
From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java
License:Open Source License
private void transferToS3(long imageId) { Image image = null;/*w ww . j av a 2s .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 w w w. ja v a 2s . c om 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
private long savePortrait(long imageId, long profileId) { Photo photo = null;/*from w ww . jav a 2s .co m*/ try { photo = fetchPhoto(imageId); } catch (SystemException e) { e.printStackTrace(); } String publicId = String.valueOf(imageId) + StringPool.PERIOD + photo.getContentType(); URL url = null; try { url = new URL("http://res.cloudinary.com/" + AppConfig.get(IConstants.CFG_CLDY_CLOUD_NAME) + "/image/upload/w_80,h_100,c_thumb,g_face/" + publicId); } catch (MalformedURLException e) { e.printStackTrace(); } File file = FileUtils.getFile(publicId); try { FileUtils.copyURLToFile(url, file); } catch (IOException e) { e.printStackTrace(); } long portraitId = 0l; try { portraitId = counterLocalService.increment(Image.class.getName()); } catch (SystemException e) { e.printStackTrace(); } try { imageLocalService.updateImage(portraitId, file); Profile profile = profileLocalService.fetchProfile(profileId); profile.setPortraitId(portraitId); profileLocalService.updateProfile(profile); } catch (PortalException e) { e.printStackTrace(); } catch (SystemException e) { e.printStackTrace(); } file.delete(); return portraitId; }
From source file:com.inikah.slayer.service.impl.PhotoLocalServiceImpl.java
License:Open Source License
@Override @Indexable(type = IndexableType.DELETE)/* w ww. j a v a 2 s . c om*/ 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.akismet.util.AkismetUtil.java
License:Open Source License
public static boolean isSpam(long userId, String content, AkismetData akismetData) throws PortalException { User user = UserLocalServiceUtil.getUser(userId); StringBundler sb = new StringBundler(5); sb.append(Http.HTTP_WITH_SLASH);//from ww w . ja v a2 s.c om sb.append(PrefsPortletPropsUtil.getString(user.getCompanyId(), PortletPropsKeys.AKISMET_API_KEY)); sb.append(StringPool.PERIOD); sb.append(AkismetConstants.URL_REST); sb.append(AkismetConstants.PATH_CHECK_SPAM); String location = sb.toString(); String response = _sendRequest(location, user.getCompanyId(), akismetData.getUserIP(), akismetData.getUserAgent(), akismetData.getReferrer(), akismetData.getPermalink(), akismetData.getType(), user.getFullName(), user.getEmailAddress(), content); if (Validator.isNull(response) || response.equals("invalid")) { _log.error("There was an issue with Akismet comment validation"); return false; } else if (response.equals("true")) { if (_log.isDebugEnabled()) { _log.debug("Spam detected: " + akismetData.getPermalink()); } return true; } if (_log.isDebugEnabled()) { _log.debug("Passed: " + akismetData.getPermalink()); } return false; }
From source file:com.liferay.akismet.util.AkismetUtil.java
License:Open Source License
public static void submitHam(long companyId, String ipAddress, String userAgent, String referrer, String permalink, String commentType, String userName, String emailAddress, String content) throws PortalException { if (_log.isDebugEnabled()) { _log.debug("Submitting message as ham: " + permalink); }//from w ww . j av a 2s .co m StringBundler sb = new StringBundler(5); sb.append(Http.HTTP_WITH_SLASH); sb.append(PrefsPortletPropsUtil.getString(companyId, PortletPropsKeys.AKISMET_API_KEY)); sb.append(StringPool.PERIOD); sb.append(AkismetConstants.URL_REST); sb.append(AkismetConstants.PATH_SUBMIT_HAM); String location = sb.toString(); String response = _sendRequest(location, companyId, ipAddress, userAgent, referrer, permalink, commentType, userName, emailAddress, content); if (Validator.isNull(response)) { _log.error("There was an issue submitting message as ham"); } }
From source file:com.liferay.akismet.util.AkismetUtil.java
License:Open Source License
public static void submitSpam(long companyId, String ipAddress, String userAgent, String referrer, String permalink, String commentType, String userName, String emailAddress, String content) throws PortalException { if (_log.isDebugEnabled()) { _log.debug("Submitting message as spam: " + permalink); }/*from w ww. j a va 2 s . co m*/ StringBundler sb = new StringBundler(5); sb.append(Http.HTTP_WITH_SLASH); sb.append(PrefsPortletPropsUtil.getString(companyId, PortletPropsKeys.AKISMET_API_KEY)); sb.append(StringPool.PERIOD); sb.append(AkismetConstants.URL_REST); sb.append(AkismetConstants.PATH_SUBMIT_SPAM); String location = sb.toString(); String response = _sendRequest(location, companyId, ipAddress, userAgent, referrer, permalink, commentType, userName, emailAddress, content); if (Validator.isNull(response)) { _log.error("There was an issue submitting message as spam"); } }