List of usage examples for com.liferay.portal.kernel.util FileUtil getBytes
public static byte[] getBytes(InputStream is) throws IOException
From source file:com.liferay.blogs.util.BlogsEntryImageSelectorHelper.java
License:Open Source License
public ImageSelector getImageSelector() throws Exception { if (_imageFileEntryId != _oldImageFileEntryId) { if (_imageFileEntryId != 0) { FileEntry fileEntry = PortletFileRepositoryUtil.getPortletFileEntry(_imageFileEntryId); _fileEntryTempFile = fileEntry.isRepositoryCapabilityProvided(TemporaryFileEntriesCapability.class); return new ImageSelector(FileUtil.getBytes(fileEntry.getContentStream()), fileEntry.getFileName(), fileEntry.getMimeType(), _imageCropRegion); } else {/*from w w w .ja v a 2s.c om*/ return new ImageSelector(); } } else if (!_imageURL.equals(_oldImageURL)) { return new ImageSelector(_imageURL); } return null; }
From source file:com.liferay.contacts.web.internal.portlet.ContactsCenterPortlet.java
License:Open Source License
protected void updateProfile(ActionRequest actionRequest) throws Exception { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); User user = themeDisplay.getUser();//w ww . ja va 2s . c o m boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] portraitBytes = null; long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); if (!deleteLogo && (fileEntryId > 0)) { FileEntry fileEntry = dlAppLocalService.getFileEntry(fileEntryId); try (InputStream inputStream = fileEntry.getContentStream()) { portraitBytes = FileUtil.getBytes(inputStream); } } String comments = BeanParamUtil.getString(user, actionRequest, "comments"); String emailAddress = BeanParamUtil.getString(user, actionRequest, "emailAddress"); String firstName = BeanParamUtil.getString(user, actionRequest, "firstName"); String jobTitle = BeanParamUtil.getString(user, actionRequest, "jobTitle"); String lastName = BeanParamUtil.getString(user, actionRequest, "lastName"); String middleName = BeanParamUtil.getString(user, actionRequest, "middleName"); String screenName = BeanParamUtil.getString(user, actionRequest, "screenName"); Contact contact = user.getContact(); String facebookSn = BeanParamUtil.getString(contact, actionRequest, "facebookSn"); String jabberSn = BeanParamUtil.getString(contact, actionRequest, "jabberSn"); String skypeSn = BeanParamUtil.getString(contact, actionRequest, "skypeSn"); String smsSn = BeanParamUtil.getString(contact, actionRequest, "smsSn"); String twitterSn = BeanParamUtil.getString(contact, actionRequest, "twitterSn"); Calendar cal = CalendarFactoryUtil.getCalendar(); cal.setTime(user.getBirthday()); int birthdayDay = cal.get(Calendar.DATE); int birthdayMonth = cal.get(Calendar.MONTH); int birthdayYear = cal.get(Calendar.YEAR); List<AnnouncementsDelivery> announcementsDeliveries = announcementsDeliveryLocalService .getUserDeliveries(user.getUserId()); userService.updateUser(user.getUserId(), user.getPasswordUnencrypted(), user.getPasswordUnencrypted(), user.getPasswordUnencrypted(), user.getPasswordReset(), user.getReminderQueryQuestion(), user.getReminderQueryAnswer(), screenName, emailAddress, user.getFacebookId(), user.getOpenId(), !deleteLogo, portraitBytes, user.getLanguageId(), user.getTimeZoneId(), user.getGreeting(), comments, firstName, middleName, lastName, contact.getPrefixId(), contact.getSuffixId(), user.isMale(), birthdayMonth, birthdayDay, birthdayYear, smsSn, facebookSn, jabberSn, skypeSn, twitterSn, jobTitle, user.getGroupIds(), user.getOrganizationIds(), user.getRoleIds(), null, user.getUserGroupIds(), user.getAddresses(), null, user.getPhones(), user.getWebsites(), announcementsDeliveries, new ServiceContext()); }
From source file:com.liferay.defaultwebcontent.hook.upgrade.v1_0_0.UpgradeJournal.java
License:Open Source License
protected String getFileAsString(String path) throws Exception { ClassLoader classLoader = getClass().getClassLoader(); InputStream is = classLoader.getResourceAsStream("/resources" + path); return new String(FileUtil.getBytes(is)); }
From source file:com.liferay.document.library.demo.data.creator.internal.UnsplashFileEntryDemoDataCreatorImpl.java
License:Open Source License
private byte[] _getBytes() throws IOException, PortalException { URL url = _getNextUrl();// w ww.j av a2 s . co m InputStream inputStream = null; try { inputStream = url.openStream(); return FileUtil.getBytes(inputStream); } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe, ioe); } String fileName = String.format("dependencies/%d.jpg", RandomUtil.nextInt(5)); try { return FileUtil.getBytes(getClass(), fileName); } catch (Exception e) { throw new PortalException(e); } } finally { if (inputStream != null) { inputStream.close(); } } }
From source file:com.liferay.dynamic.data.mapping.internal.util.DDMImpl.java
License:Open Source License
protected byte[] getImageBytes(UploadRequest uploadRequest, String fieldNameValue) throws Exception { File file = uploadRequest.getFile(fieldNameValue + "File"); byte[] bytes = FileUtil.getBytes(file); if (ArrayUtil.isNotEmpty(bytes)) { return bytes; }/*from w w w . jav a 2 s . co m*/ String url = uploadRequest.getParameter(fieldNameValue + "URL"); long imageId = GetterUtil.getLong(_http.getParameter(url, "img_id", false)); Image image = _imageLocalService.fetchImage(imageId); if (image == null) { return null; } return image.getTextObj(); }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java
License:Open Source License
/** * Adds a template with additional parameters. * * @param userId the primary key of the template's creator/owner * @param groupId the primary key of the group * @param classNameId the primary key of the class name for the template's * related model/*from w w w .jav a 2 s .c o m*/ * @param classPK the primary key of the template's related entity * @param resourceClassNameId the primary key of the class name for * template's resource model * @param templateKey the unique string identifying the template * (optionally <code>null</code>) * @param nameMap the template's locales and localized names * @param descriptionMap the template's locales and localized descriptions * @param type the template's type. For more information, see * DDMTemplateConstants in the dynamic-data-mapping-api module. * @param mode the template's mode. For more information, see * DDMTemplateConstants in the dynamic-data-mapping-api module. * @param language the template's script language. For more information, * see DDMTemplateConstants in the dynamic-data-mapping-api module. * @param script the template's script * @param cacheable whether the template is cacheable * @param smallImage whether the template has a small image * @param smallImageURL the template's small image URL (optionally * <code>null</code>) * @param smallImageFile the template's small image file (optionally * <code>null</code>) * @param serviceContext the service context to be applied. Can set the * UUID, creation date, modification date, guest permissions, and * group permissions for the template. * @return the template * @throws PortalException if a portal exception occurred */ @Override public DDMTemplate addTemplate(long userId, long groupId, long classNameId, long classPK, long resourceClassNameId, String templateKey, Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, String type, String mode, String language, String script, boolean cacheable, boolean smallImage, String smallImageURL, File smallImageFile, ServiceContext serviceContext) throws PortalException { // Template User user = userLocalService.getUser(userId); if (Validator.isNull(templateKey)) { templateKey = String.valueOf(counterLocalService.increment()); } else { templateKey = StringUtil.toUpperCase(templateKey.trim()); } script = formatScript(type, language, script); byte[] smallImageBytes = null; if (smallImage) { try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } if ((smallImageBytes == null) || Validator.isUrl(smallImageURL)) { smallImage = false; } } validate(groupId, classNameId, templateKey, nameMap, script, smallImage, smallImageURL, smallImageFile, smallImageBytes); long templateId = counterLocalService.increment(); DDMTemplate template = ddmTemplatePersistence.create(templateId); template.setUuid(serviceContext.getUuid()); template.setGroupId(groupId); template.setCompanyId(user.getCompanyId()); template.setUserId(user.getUserId()); template.setUserName(user.getFullName()); template.setVersionUserId(user.getUserId()); template.setVersionUserName(user.getFullName()); template.setClassNameId(classNameId); template.setClassPK(classPK); template.setResourceClassNameId(resourceClassNameId); template.setTemplateKey(templateKey); template.setVersion(DDMTemplateConstants.VERSION_DEFAULT); template.setNameMap(nameMap); template.setDescriptionMap(descriptionMap); template.setType(type); template.setMode(mode); template.setLanguage(language); template.setScript(script); template.setCacheable(cacheable); template.setSmallImage(smallImage); template.setSmallImageId(counterLocalService.increment()); template.setSmallImageURL(smallImageURL); ddmTemplatePersistence.update(template); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addTemplateResources(template, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addTemplateResources(template, serviceContext.getModelPermissions()); } // Small image saveImages(smallImage, template.getSmallImageId(), smallImageFile, smallImageBytes); // Template version addTemplateVersion(user, template, DDMTemplateConstants.VERSION_DEFAULT, serviceContext); return template; }
From source file:com.liferay.dynamic.data.mapping.service.impl.DDMTemplateLocalServiceImpl.java
License:Open Source License
/** * Updates the template matching the ID. * * @param userId the primary key of the template's creator/owner * @param templateId the primary key of the template * @param classPK the primary key of the template's related entity * @param nameMap the template's new locales and localized names * @param descriptionMap the template's new locales and localized * description/*from w ww. j a v a 2 s.co m*/ * @param type the template's type. For more information, see * DDMTemplateConstants in the dynamic-data-mapping-api module. * @param mode the template's mode. For more information, see * DDMTemplateConstants in the dynamic-data-mapping-api module. * @param language the template's script language. For more information, * see DDMTemplateConstants in the dynamic-data-mapping-api module. * @param script the template's script * @param cacheable whether the template is cacheable * @param smallImage whether the template has a small image * @param smallImageURL the template's small image URL (optionally * <code>null</code>) * @param smallImageFile the template's small image file (optionally * <code>null</code>) * @param serviceContext the service context to be applied. Can set the * modification date. * @return the updated template * @throws PortalException if a portal exception occurred */ @Override public DDMTemplate updateTemplate(long userId, long templateId, long classPK, Map<Locale, String> nameMap, Map<Locale, String> descriptionMap, String type, String mode, String language, String script, boolean cacheable, boolean smallImage, String smallImageURL, File smallImageFile, ServiceContext serviceContext) throws PortalException { User user = userLocalService.getUser(userId); script = formatScript(type, language, script); byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } DDMTemplate template = ddmTemplateLocalService.getDDMTemplate(templateId); validate(template.getGroupId(), nameMap, script, smallImage, smallImageURL, smallImageFile, smallImageBytes); if ((template.getClassPK() == 0) && (classPK > 0)) { // Allow users to set the structure if and only if it currently does // not have one. Otherwise, you can have bad data because there may // be an existing content that has chosen to use a structure and // template combination that no longer exists. template.setClassPK(classPK); } DDMTemplateVersion latestTemplateVersion = ddmTemplateVersionLocalService .getLatestTemplateVersion(templateId); boolean majorVersion = GetterUtil.getBoolean(serviceContext.getAttribute("majorVersion")); String version = getNextVersion(latestTemplateVersion.getVersion(), majorVersion); template.setVersion(version); template.setVersionUserId(user.getUserId()); template.setVersionUserName(user.getFullName()); template.setNameMap(nameMap); template.setDescriptionMap(descriptionMap); template.setType(type); template.setMode(mode); template.setLanguage(language); template.setScript(script); template.setCacheable(cacheable); template.setSmallImage(smallImage); template.setSmallImageURL(smallImageURL); // Small image saveImages(smallImage, template.getSmallImageId(), smallImageFile, smallImageBytes); // Template version DDMTemplateVersion ddmTemplateVersion = addTemplateVersion(user, template, version, serviceContext); if (ddmTemplateVersion.isApproved()) { ddmTemplatePersistence.update(template); } return template; }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Adds a web content article with additional parameters. * * <p>// w w w .jav a 2s .c o m * The web content articles hold HTML content wrapped in XML. The XML lets * you specify the article's default locale and available locales. Here is a * content example: * </p> * * <p> * <pre> * <code> * <?xml version='1.0' encoding='UTF-8'?> * <root default-locale="en_US" available-locales="en_US"> * <static-content language-id="en_US"> * <![CDATA[<p><b><i>test<i> content<b></p>]]> * </static-content> * </root> * </code> * </pre> * </p> * * @param userId the primary key of the web content article's creator/owner * @param groupId the primary key of the web content article's group * @param folderId the primary key of the web content article folder * @param classNameId the primary key of the DDMStructure class if the web * content article is related to a DDM structure, the primary key of * the class name associated with the article, or * JournalArticleConstants.CLASSNAME_ID_DEFAULT in the journal-api * module otherwise * @param classPK the primary key of the DDM structure, if the primary key * of the DDMStructure class is given as the * <code>classNameId</code> parameter, the primary key of the class * associated with the web content article, or <code>0</code> * otherwise * @param articleId the primary key of the web content article * @param autoArticleId whether to auto generate the web content article ID * @param version the web content article's version * @param titleMap the web content article's locales and localized titles * @param descriptionMap the web content article's locales and localized * descriptions * @param content the HTML content wrapped in XML * @param ddmStructureKey the primary key of the web content article's DDM * structure, if the article is related to a DDM structure, or * <code>null</code> otherwise * @param ddmTemplateKey the primary key of the web content article's DDM * template * @param layoutUuid the unique string identifying the web content * article's display page * @param displayDateMonth the month the web content article is set to * display * @param displayDateDay the calendar day the web content article is set to * display * @param displayDateYear the year the web content article is set to * display * @param displayDateHour the hour the web content article is set to * display * @param displayDateMinute the minute the web content article is set to * display * @param expirationDateMonth the month the web content article is set to * expire * @param expirationDateDay the calendar day the web content article is set * to expire * @param expirationDateYear the year the web content article is set to * expire * @param expirationDateHour the hour the web content article is set to * expire * @param expirationDateMinute the minute the web content article is set to * expire * @param neverExpire whether the web content article is not set to auto * expire * @param reviewDateMonth the month the web content article is set for * review * @param reviewDateDay the calendar day the web content article is set for * review * @param reviewDateYear the year the web content article is set for review * @param reviewDateHour the hour the web content article is set for review * @param reviewDateMinute the minute the web content article is set for * review * @param neverReview whether the web content article is not set for review * @param indexable whether the web content article is searchable * @param smallImage whether the web content article has a small image * @param smallImageURL the web content article's small image URL * @param smallImageFile the web content article's small image file * @param images the web content's images * @param articleURL the web content article's accessible URL * @param serviceContext the service context to be applied. Can set the * UUID, creation date, modification date, expando bridge * attributes, guest permissions, group permissions, asset category * IDs, asset tag names, asset link entry IDs, URL title, and * workflow actions for the web content article. Can also set * whether to add the default guest and group permissions. * @return the web content article */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle addArticle(long userId, long groupId, long folderId, long classNameId, long classPK, String articleId, boolean autoArticleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException { // Article User user = userLocalService.getUser(userId); articleId = StringUtil.toUpperCase(StringUtil.trim(articleId)); Date displayDate = null; Date expirationDate = null; Date reviewDate = null; if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), null); if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), ArticleExpirationDateException.class); } if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), ArticleReviewDateException.class); } } byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } Date now = new Date(); validateDDMStructureId(groupId, folderId, ddmStructureKey); if (autoArticleId) { articleId = String.valueOf(counterLocalService.increment()); } validate(user.getCompanyId(), groupId, classNameId, articleId, autoArticleId, version, titleMap, content, ddmStructureKey, ddmTemplateKey, displayDate, expirationDate, smallImage, smallImageURL, smallImageFile, smallImageBytes, serviceContext); validateReferences(groupId, ddmStructureKey, ddmTemplateKey, layoutUuid, smallImage, smallImageURL, smallImageBytes, 0, content); serviceContext.setAttribute("articleId", articleId); long id = counterLocalService.increment(); String articleResourceUuid = GetterUtil.getString(serviceContext.getAttribute("articleResourceUuid")); long resourcePrimKey = journalArticleResourceLocalService.getArticleResourcePrimKey(articleResourceUuid, groupId, articleId); JournalArticle article = journalArticlePersistence.create(id); Locale locale = getArticleDefaultLocale(content); String title = titleMap.get(locale); article.setUuid(serviceContext.getUuid()); article.setResourcePrimKey(resourcePrimKey); article.setGroupId(groupId); article.setCompanyId(user.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setFolderId(folderId); article.setClassNameId(classNameId); article.setClassPK(classPK); article.setTreePath(article.buildTreePath()); article.setArticleId(articleId); article.setVersion(version); article.setUrlTitle(getUniqueUrlTitle(id, groupId, articleId, title, null, serviceContext)); content = format(user, groupId, article, content); article.setContent(content); article.setDDMStructureKey(ddmStructureKey); article.setDDMTemplateKey(ddmTemplateKey); article.setDefaultLanguageId(LocaleUtil.toLanguageId(locale)); article.setLayoutUuid(layoutUuid); article.setDisplayDate(displayDate); article.setExpirationDate(expirationDate); article.setReviewDate(reviewDate); article.setIndexable(indexable); article.setSmallImage(smallImage); article.setSmallImageId(counterLocalService.increment()); article.setSmallImageURL(smallImageURL); if ((expirationDate == null) || expirationDate.after(now)) { article.setStatus(WorkflowConstants.STATUS_DRAFT); } else { article.setStatus(WorkflowConstants.STATUS_EXPIRED); } article.setStatusByUserId(userId); article.setStatusDate(serviceContext.getModifiedDate(now)); article.setExpandoBridgeAttributes(serviceContext); journalArticlePersistence.update(article); // Article localization _addArticleLocalizedFields(user.getCompanyId(), article.getId(), titleMap, descriptionMap); // Resources if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) { addArticleResources(article, serviceContext.isAddGroupPermissions(), serviceContext.isAddGuestPermissions()); } else { addArticleResources(article, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions()); } // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Asset updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); // Dynamic data mapping if (classNameLocalService.getClassNameId(DDMStructure.class) == classNameId) { updateDDMStructurePredefinedValues(classPK, content, serviceContext); } else { updateDDMLinks(id, groupId, ddmStructureKey, ddmTemplateKey, true); } // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); articleURL = buildArticleURL(articleURL, groupId, folderId, articleId); serviceContext.setAttribute("articleURL", articleURL); sendEmail(article, articleURL, preferences, "requested", serviceContext); // Workflow if (classNameId == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { startWorkflowInstance(userId, article, serviceContext); } else { updateStatus(userId, article, WorkflowConstants.STATUS_APPROVED, null, serviceContext, new HashMap<String, Serializable>()); } return journalArticlePersistence.findByPrimaryKey(article.getId()); }
From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java
License:Open Source License
/** * Updates the web content article with additional parameters. * * @param userId the primary key of the user updating the web content * article// w w w . ja va 2 s . co m * @param groupId the primary key of the web content article's group * @param folderId the primary key of the web content article folder * @param articleId the primary key of the web content article * @param version the web content article's version * @param titleMap the web content article's locales and localized titles * @param descriptionMap the web content article's locales and localized * descriptions * @param content the HTML content wrapped in XML. For more information, * see the content example in the {@link #addArticle(long, long, * long, long, long, String, boolean, double, Map, Map, String, * String, String, String, int, int, int, int, int, int, int, int, * int, int, boolean, int, int, int, int, int, boolean, boolean, * boolean, String, File, Map, String, ServiceContext)} description. * @param ddmStructureKey the primary key of the web content article's DDM * structure, if the article is related to a DDM structure, or * <code>null</code> otherwise * @param ddmTemplateKey the primary key of the web content article's DDM * template * @param layoutUuid the unique string identifying the web content * article's display page * @param displayDateMonth the month the web content article is set to * display * @param displayDateDay the calendar day the web content article is set to * display * @param displayDateYear the year the web content article is set to * display * @param displayDateHour the hour the web content article is set to * display * @param displayDateMinute the minute the web content article is set to * display * @param expirationDateMonth the month the web content article is set to * expire * @param expirationDateDay the calendar day the web content article is set * to expire * @param expirationDateYear the year the web content article is set to * expire * @param expirationDateHour the hour the web content article is set to * expire * @param expirationDateMinute the minute the web content article is set to * expire * @param neverExpire whether the web content article is not set to auto * expire * @param reviewDateMonth the month the web content article is set for * review * @param reviewDateDay the calendar day the web content article is set for * review * @param reviewDateYear the year the web content article is set for review * @param reviewDateHour the hour the web content article is set for review * @param reviewDateMinute the minute the web content article is set for * review * @param neverReview whether the web content article is not set for review * @param indexable whether the web content is searchable * @param smallImage whether to update web content article's a small image. * A file must be passed in as <code>smallImageFile</code> value, * otherwise the current small image is deleted. * @param smallImageURL the web content article's small image URL * (optionally <code>null</code>) * @param smallImageFile the web content article's new small image file * (optionally <code>null</code>). Must pass in * <code>smallImage</code> value of <code>true</code> to replace the * article's small image file. * @param images the web content's images (optionally <code>null</code>) * @param articleURL the web content article's accessible URL (optionally * <code>null</code>) * @param serviceContext the service context to be applied. Can set the * modification date, expando bridge attributes, asset category IDs, * asset tag names, asset link entry IDs, asset priority, workflow * actions, URL title , and can set whether to add the default * command update for the web content article. With respect to * social activities, by setting the service context's command to * {@link Constants#UPDATE}, the invocation is considered a web * content update activity; otherwise it is considered a web content * add activity. * @return the updated web content article */ @Indexable(type = IndexableType.REINDEX) @Override public JournalArticle updateArticle(long userId, long groupId, long folderId, String articleId, double version, Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey, String layoutUuid, int displayDateMonth, int displayDateDay, int displayDateYear, int displayDateHour, int displayDateMinute, int expirationDateMonth, int expirationDateDay, int expirationDateYear, int expirationDateHour, int expirationDateMinute, boolean neverExpire, int reviewDateMonth, int reviewDateDay, int reviewDateYear, int reviewDateHour, int reviewDateMinute, boolean neverReview, boolean indexable, boolean smallImage, String smallImageURL, File smallImageFile, Map<String, byte[]> images, String articleURL, ServiceContext serviceContext) throws PortalException { // Article User user = userLocalService.getUser(userId); articleId = StringUtil.toUpperCase(StringUtil.trim(articleId)); byte[] smallImageBytes = null; try { smallImageBytes = FileUtil.getBytes(smallImageFile); } catch (IOException ioe) { } JournalArticle latestArticle = getLatestArticle(groupId, articleId, WorkflowConstants.STATUS_ANY); JournalArticle article = latestArticle; boolean imported = ExportImportThreadLocal.isImportInProcess(); double latestVersion = latestArticle.getVersion(); boolean addNewVersion = false; if (imported) { article = getArticle(groupId, articleId, version); } else { if ((version > 0) && (version != latestVersion)) { StringBundler sb = new StringBundler(4); sb.append("Version "); sb.append(version); sb.append(" is not the same as "); sb.append(latestVersion); throw new ArticleVersionException(sb.toString()); } serviceContext.validateModifiedDate(latestArticle, ArticleVersionException.class); if (latestArticle.isApproved() || latestArticle.isExpired() || latestArticle.isScheduled()) { addNewVersion = true; version = getNextVersion(article); } } Date displayDate = null; Date expirationDate = null; Date reviewDate = null; if (article.getClassNameId() == JournalArticleConstants.CLASSNAME_ID_DEFAULT) { displayDate = PortalUtil.getDate(displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute, user.getTimeZone(), null); if (!neverExpire) { expirationDate = PortalUtil.getDate(expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute, user.getTimeZone(), ArticleExpirationDateException.class); } if (!neverReview) { reviewDate = PortalUtil.getDate(reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, user.getTimeZone(), ArticleReviewDateException.class); } } Date now = new Date(); boolean expired = false; if ((expirationDate != null) && expirationDate.before(now)) { expired = true; } validate(user.getCompanyId(), groupId, latestArticle.getClassNameId(), titleMap, content, ddmStructureKey, ddmTemplateKey, displayDate, expirationDate, smallImage, smallImageURL, smallImageFile, smallImageBytes, serviceContext); validateReferences(groupId, ddmStructureKey, ddmTemplateKey, layoutUuid, smallImage, smallImageURL, smallImageBytes, latestArticle.getSmallImageId(), content); if (addNewVersion) { long id = counterLocalService.increment(); article = journalArticlePersistence.create(id); article.setResourcePrimKey(latestArticle.getResourcePrimKey()); article.setGroupId(latestArticle.getGroupId()); article.setCompanyId(latestArticle.getCompanyId()); article.setUserId(user.getUserId()); article.setUserName(user.getFullName()); article.setCreateDate(latestArticle.getCreateDate()); article.setClassNameId(latestArticle.getClassNameId()); article.setClassPK(latestArticle.getClassPK()); article.setArticleId(articleId); article.setVersion(version); article.setSmallImageId(latestArticle.getSmallImageId()); _addArticleLocalizedFields(article.getCompanyId(), article.getId(), titleMap, descriptionMap); } else { _updateArticleLocalizedFields(article.getCompanyId(), article.getId(), titleMap, descriptionMap); } Locale locale = getArticleDefaultLocale(content); String title = titleMap.get(locale); content = format(user, groupId, article, content); article.setFolderId(folderId); article.setTreePath(article.buildTreePath()); article.setUrlTitle(getUniqueUrlTitle(article.getId(), groupId, article.getArticleId(), title, latestArticle.getUrlTitle(), serviceContext)); article.setContent(content); article.setDDMStructureKey(ddmStructureKey); article.setDDMTemplateKey(ddmTemplateKey); article.setDefaultLanguageId(LocaleUtil.toLanguageId(locale)); article.setLayoutUuid(layoutUuid); article.setDisplayDate(displayDate); article.setExpirationDate(expirationDate); article.setReviewDate(reviewDate); article.setIndexable(indexable); article.setSmallImage(smallImage); if (smallImage) { if ((smallImageFile != null) && (smallImageBytes != null)) { article.setSmallImageId(counterLocalService.increment()); } } else { article.setSmallImageId(0); } article.setSmallImageURL(smallImageURL); if (latestArticle.isPending()) { article.setStatus(latestArticle.getStatus()); } else if (!expired) { article.setStatus(WorkflowConstants.STATUS_DRAFT); } else { article.setStatus(WorkflowConstants.STATUS_EXPIRED); } ExpandoBridgeUtil.setExpandoBridgeAttributes(latestArticle.getExpandoBridge(), article.getExpandoBridge(), serviceContext); journalArticlePersistence.update(article); // Asset if (hasModifiedLatestApprovedVersion(groupId, articleId, version)) { updateAsset(userId, article, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), serviceContext.getAssetLinkEntryIds(), serviceContext.getAssetPriority()); } // Dynamic data mapping if (classNameLocalService.getClassNameId(DDMStructure.class) == article.getClassNameId()) { updateDDMStructurePredefinedValues(article.getClassPK(), content, serviceContext); } else { updateDDMLinks(article.getId(), groupId, ddmStructureKey, ddmTemplateKey, addNewVersion); } // Small image saveImages(smallImage, article.getSmallImageId(), smallImageFile, smallImageBytes); // Email PortletPreferences preferences = ServiceContextUtil.getPortletPreferences(serviceContext); // Workflow if (expired && imported) { updateStatus(userId, article, article.getStatus(), articleURL, serviceContext, new HashMap<String, Serializable>()); } if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) { articleURL = buildArticleURL(articleURL, groupId, folderId, articleId); serviceContext.setAttribute("articleURL", articleURL); sendEmail(article, articleURL, preferences, "requested", serviceContext); startWorkflowInstance(userId, article, serviceContext); } return journalArticlePersistence.findByPrimaryKey(article.getId()); }
From source file:com.liferay.layout.admin.web.internal.portlet.action.EditLayoutMVCActionCommand.java
License:Open Source License
@Override protected void doProcessAction(ActionRequest actionRequest, ActionResponse actionResponse) throws Exception { UploadPortletRequest uploadPortletRequest = _portal.getUploadPortletRequest(actionRequest); ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); long groupId = ParamUtil.getLong(actionRequest, "groupId"); long liveGroupId = ParamUtil.getLong(actionRequest, "liveGroupId"); long stagingGroupId = ParamUtil.getLong(actionRequest, "stagingGroupId"); boolean privateLayout = ParamUtil.getBoolean(actionRequest, "privateLayout"); long layoutId = ParamUtil.getLong(actionRequest, "layoutId"); Map<Locale, String> nameMap = LocalizationUtil.getLocalizationMap(actionRequest, "name"); Map<Locale, String> titleMap = LocalizationUtil.getLocalizationMap(actionRequest, "title"); Map<Locale, String> descriptionMap = LocalizationUtil.getLocalizationMap(actionRequest, "description"); Map<Locale, String> keywordsMap = LocalizationUtil.getLocalizationMap(actionRequest, "keywords"); Map<Locale, String> robotsMap = LocalizationUtil.getLocalizationMap(actionRequest, "robots"); String type = ParamUtil.getString(uploadPortletRequest, "type"); boolean hidden = ParamUtil.getBoolean(uploadPortletRequest, "hidden"); Map<Locale, String> friendlyURLMap = LocalizationUtil.getLocalizationMap(actionRequest, "friendlyURL"); boolean deleteLogo = ParamUtil.getBoolean(actionRequest, "deleteLogo"); byte[] iconBytes = null; long fileEntryId = ParamUtil.getLong(uploadPortletRequest, "fileEntryId"); if (fileEntryId > 0) { FileEntry fileEntry = _dlAppLocalService.getFileEntry(fileEntryId); iconBytes = FileUtil.getBytes(fileEntry.getContentStream()); }/*w ww. j av a 2 s . c o m*/ ServiceContext serviceContext = ServiceContextFactory.getInstance(Layout.class.getName(), actionRequest); Layout layout = _layoutLocalService.getLayout(groupId, privateLayout, layoutId); String currentType = layout.getType(); layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layout.getParentLayoutId(), nameMap, titleMap, descriptionMap, keywordsMap, robotsMap, type, hidden, friendlyURLMap, !deleteLogo, iconBytes, serviceContext); themeDisplay.clearLayoutFriendlyURL(layout); UnicodeProperties layoutTypeSettingsProperties = layout.getTypeSettingsProperties(); UnicodeProperties formTypeSettingsProperties = PropertiesParamUtil.getProperties(actionRequest, "TypeSettingsProperties--"); String linkToLayoutUuid = ParamUtil.getString(actionRequest, "linkToLayoutUuid"); if (Validator.isNotNull(linkToLayoutUuid)) { Layout linkToLayout = _layoutLocalService.getLayoutByUuidAndGroupId(linkToLayoutUuid, groupId, privateLayout); formTypeSettingsProperties.put("linkToLayoutId", String.valueOf(linkToLayout.getLayoutId())); } LayoutTypePortlet layoutTypePortlet = (LayoutTypePortlet) layout.getLayoutType(); if (type.equals(LayoutConstants.TYPE_PORTLET)) { String layoutTemplateId = ParamUtil.getString(uploadPortletRequest, "layoutTemplateId", PropsValues.DEFAULT_LAYOUT_TEMPLATE_ID); layoutTypePortlet.setLayoutTemplateId(themeDisplay.getUserId(), layoutTemplateId); layoutTypeSettingsProperties.putAll(formTypeSettingsProperties); boolean layoutCustomizable = GetterUtil .getBoolean(layoutTypeSettingsProperties.get(LayoutConstants.CUSTOMIZABLE_LAYOUT)); if (!layoutCustomizable) { layoutTypePortlet.removeCustomization(layoutTypeSettingsProperties); } layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString()); if (!currentType.equals(LayoutConstants.TYPE_PORTLET)) { _portletPreferencesLocalService.deletePortletPreferences(0, PortletKeys.PREFS_OWNER_TYPE_LAYOUT, layout.getPlid()); } } else { layoutTypeSettingsProperties.putAll(formTypeSettingsProperties); layoutTypeSettingsProperties.putAll(layout.getTypeSettingsProperties()); layout = _layoutService.updateLayout(groupId, privateLayout, layoutId, layoutTypeSettingsProperties.toString()); } HttpServletResponse response = _portal.getHttpServletResponse(actionResponse); EventsProcessorUtil.process(PropsKeys.LAYOUT_CONFIGURATION_ACTION_UPDATE, layoutTypePortlet.getConfigurationActionUpdate(), uploadPortletRequest, response); _actionUtil.updateLookAndFeel(actionRequest, themeDisplay.getCompanyId(), liveGroupId, stagingGroupId, privateLayout, layout.getLayoutId(), layout.getTypeSettingsProperties()); String redirect = ParamUtil.getString(actionRequest, "redirect"); if (Validator.isNull(redirect)) { redirect = _portal.getLayoutFullURL(layout, themeDisplay); } String portletResource = ParamUtil.getString(actionRequest, "portletResource"); MultiSessionMessages.add(actionRequest, portletResource + "layoutUpdated", layout); actionRequest.setAttribute(WebKeys.REDIRECT, redirect); }