update blogentry now added which replaces persistBlogAll and renaming of some files to be more to the ofbiz standard. blog Still not complete......

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@735627 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hans Bakker
2009-01-19 08:09:48 +00:00
parent de66fb8889
commit bfa00a72b6
8 changed files with 242 additions and 490 deletions
@@ -19,25 +19,22 @@
-->
<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ofbiz.apache.org/dtds/simple-methods.xsd">
<simple-method method-name="postBlogEntry" short-description="Post a new Blog Entry">
<set field="contentAssocTypeId" from-field="parameters.contentAssocTypeId"/>
<simple-method method-name="createBlogEntry" short-description="Create a new Blog Entry">
<set field="contentAssocTypeId" value="PUBLISH_LINK"/>
<set field="ownerContentId" from-field="parameters.blogContentId"/>
<set field="contentIdFrom" from-field="parameters.blogContentId"/>
<set field="contentIdFrom" from-field="parameters.blogContentId"/>
<if-empty field="parameters.statusId">
<set field="parameters.statusId" value="CTNT_INITIAL_DRAFT"/>
</if-empty>
<if-empty field="parameters.templateDataResourceId">
<set field="parameters.templateDataResourceId" value="BLOG_TPL_TOPLEFT"/>
</if-empty>
<!-- determine of we need to create complex template structure or simple content structure -->
<if>
<condition>
<and>
<not>
<if-empty field="parameters._uploadedFile_fileName"/>
</not>
<not>
<if-empty field="parameters.textData"/>
</not>
</and>
</condition>
<then>
<if-not-empty field="parameters._uploadedFile_fileName">
<if-not-empty field="parameters.articleData">
<!-- complex template structure (image & text) -->
<set field="createMain.dataResourceId" from-field="parameters.dataResourceId"/>
<set field="createMain.dataResourceId" from-field="parameters.templateDataResourceId"/>
<set field="createMain.contentAssocTypeId" from-field="contentAssocTypeId"/>
<set field="createMain.contentName" from-field="parameters.contentName"/>
<set field="createMain.description" from-field="parameters.description"/>
@@ -53,87 +50,62 @@
<!-- reset contentIdFrom to new contentId -->
<set field="contentAssocTypeId" value="SUB_CONTENT"/>
<set field="contentIdFrom" from-field="contentId"/>
</then>
</if>
</if-not-empty>
</if-not-empty>
<if-not-empty field="parameters._uploadedFile_fileName">
<!-- upload a picture -->
<set field="createImage.dataResourceTypeId" value="LOCAL_FILE"/>
<set field="createImage.dataTemplateTypeId" value="NONE"/>
<set field="createImage.mapKey" value="IMAGE"/>
<set field="createImage.ownerContentId" from-field="ownerContentId"/>
<set field="createImage.contentName" from-field="parameters.contentName"/>
<set field="createImage.description" from-field="parameters.description"/>
<set field="createImage.statusId" from-field="parameters.statusId"/>
<set field="createImage.contentAssocTypeId" from-field="contentAssocTypeId"/>
<set field="createImage.contentIdFrom" from-field="contentIdFrom"/>
<set field="createImage.partyId" from-field="userLogin.partyId"/>
<set field="createImage.isPublic" value="Y"/>
<set field="createImage.uploadedFile" from-field="parameters.uploadedFile"/>
<set field="createImage._uploadedFile_fileName" from-field="parameters._uploadedFile_fileName"/>
<set field="createImage._uploadedFile_contentType" from-field="parameters._uploadedFile_contentType"/>
<call-service service-name="createContentFromUploadedFile" in-map-name="createImage">
<result-to-field result-name="contentId" field="imageContentId"/>
</call-service>
<if-empty field="contentId">
<set field="contentIdFrom" from-field="imageContentId"/>
<set field="contentId" from-field="imageContentId"/>
<set field="contentAssocTypeId" value="SUB_CONTENT"/>
</if-empty>
</if-not-empty>
<if>
<condition>
<not>
<if-empty field="parameters._uploadedFile_fileName"/>
</not>
</condition>
<then>
<!-- upload a picture -->
<set field="createImage.dataResourceTypeId" value="LOCAL_FILE"/>
<set field="createImage.dataTemplateTypeId" value="NONE"/>
<set field="createImage.mapKey" value="IMAGE"/>
<set field="createImage.ownerContentId" from-field="ownerContentId"/>
<set field="createImage.contentName" from-field="parameters.contentName"/>
<set field="createImage.description" from-field="parameters.description"/>
<set field="createImage.statusId" from-field="parameters.statusId"/>
<set field="createImage.contentAssocTypeId" from-field="contentAssocTypeId"/>
<set field="createImage.contentIdFrom" from-field="contentIdFrom"/>
<set field="createImage.partyId" from-field="userLogin.partyId"/>
<set field="createImage.isPublic" value="Y"/>
<set field="createImage.uploadedFile" from-field="parameters.uploadedFile"/>
<set field="createImage._uploadedFile_fileName" from-field="parameters._uploadedFile_fileName"/>
<set field="createImage._uploadedFile_contentType" from-field="parameters._uploadedFile_contentType"/>
<call-service service-name="createContentFromUploadedFile" in-map-name="createImage">
<result-to-field result-name="contentId" field="imageContentId"/>
</call-service>
<if-empty field="contentId">
<set field="contentIdFrom" from-field="imageContentId"/>
<set field="contentId" from-field="imageContentId"/>
<set field="contentAssocTypeId" value="SUB_CONTENT"/>
</if-empty>
</then>
</if>
<if-not-empty field="parameters.articleData">
<!-- create text data -->
<set field="createText.dataResourceTypeId" value="ELECTRONIC_TEXT"/>
<set field="createText.contentPurposeTypeId" value="ARTICLE"/>
<set field="createText.dataTemplateTypeId" value="NONE"/>
<set field="createText.mapKey" value="MAIN"/>
<set field="createText.ownerContentId" from-field="ownerContentId"/>
<set field="createText.contentName" from-field="parameters.contentName"/>
<set field="createText.description" from-field="parameters.description"/>
<set field="createText.statusId" from-field="parameters.statusId"/>
<set field="createText.contentAssocTypeId" from-field="contentAssocTypeId"/>
<set field="createText.textData" from-field="parameters.articleData"/>
<set field="createText.contentIdFrom" from-field="contentIdFrom"/>
<set field="createText.partyId" from-field="userLogin.partyId"/>
<log level="always" message="calling createTextContent with map: ${createText}"/>
<call-service service-name="createTextContent" in-map-name="createText">
<result-to-field result-name="contentId" field="textContentId"/>
</call-service>
<if-empty field="contentId">
<set field="contentIdFrom" from-field="textContentId"/>
<set field="contentId" from-field="textContentId"/>
<set field="contentAssocTypeId" value="SUB_CONTENT"/>
</if-empty>
</if-not-empty>
<if>
<condition>
<not>
<if-empty field="parameters.textData"/>
</not>
</condition>
<then>
<!-- create text data -->
<set field="createText.dataResourceTypeId" value="ELECTRONIC_TEXT"/>
<set field="createText.contentPurposeTypeId" value="ARTICLE"/>
<set field="createText.dataTemplateTypeId" value="NONE"/>
<set field="createText.mapKey" value="MAIN"/>
<set field="createText.ownerContentId" from-field="ownerContentId"/>
<set field="createText.contentName" from-field="parameters.contentName"/>
<set field="createText.description" from-field="parameters.description"/>
<set field="createText.statusId" from-field="parameters.statusId"/>
<set field="createText.contentAssocTypeId" from-field="contentAssocTypeId"/>
<set field="createText.textData" from-field="parameters.textData"/>
<set field="createText.contentIdFrom" from-field="contentIdFrom"/>
<set field="createText.partyId" from-field="userLogin.partyId"/>
<log level="always" message="calling createTextContent with map: ${createText}"/>
<call-service service-name="createTextContent" in-map-name="createText">
<result-to-field result-name="contentId" field="textContentId"/>
</call-service>
<if-empty field="contentId">
<set field="contentIdFrom" from-field="textContentId"/>
<set field="contentId" from-field="textContentId"/>
<set field="contentAssocTypeId" value="SUB_CONTENT"/>
</if-empty>
</then>
</if>
<!-- we should have a primary (at least) contentId -->
<if>
<condition>
<and>
<not>
<if-empty field="contentId"/>
</not>
<not>
<if-empty field="parameters.summaryData"/>
</not>
</and>
</condition>
<then>
<if-not-empty field="contentId">
<if-not-empty field="parameters.summaryData">
<!-- create the summary data -->
<set field="createSummary.dataResourceTypeId" value="ELECTRONIC_TEXT"/>
<set field="createSummary.contentPurposeTypeId" value="ARTICLE"/>
@@ -148,11 +120,100 @@
<set field="createSummary.contentIdFrom" from-field="contentIdFrom"/>
<set field="createSummary.partyId" from-field="userLogin.partyId"/>
<call-service service-name="createTextContent" in-map-name="createSummary"/>
</if-not-empty>
</if-not-empty>
<field-to-result field="contentId"/>
<field-to-result field="parameters.blogContentId" result-name="blogContentId"/>
</simple-method>
<simple-method method-name="updateBlogEntry" short-description="Update a existing Blog Entry">
<set field="showNoResult" value="Y"/>
<call-simple-method method-name="getBlogEntry"/>
<if>
<condition>
<or>
<if-compare-field field="parameters.contentName" operator="not-equals" to-field="contentName"/>
<if-compare-field field="parameters.description" operator="not-equals" to-field="description"/>
<if-compare-field field="parameters.templateDataResourceId" operator="not-equals" to-field="templateDataResourceId"/>
<if-compare-field field="parameters.statusId" operator="not-equals" to-field="statusId"/>
</or>
</condition>
<then>
<set-service-fields service-name="updateContent" map="parameters" to-map="updContent"/>
<set field="updContent.dataResourceId" from-field="parameters.templateDataResourceId"/>
<call-service service-name="updateContent" in-map-name="updContent"/>
</then>
</if>
<field-to-result field="contentId"/>
<!-- new article text -->
<if-empty field="articleText">
<if-not-empty field="parameters.articleData">
<set field="createText.dataResourceTypeId" value="ELECTRONIC_TEXT"/>
<set field="createText.contentPurposeTypeId" value="ARTICLE"/>
<set field="createText.dataTemplateTypeId" value="NONE"/>
<set field="createText.mapKey" value="MAIN"/>
<set field="createSummary.ownerContentId" from-field="parameters.contentId"/>
<set field="createSummary.contentName" from-field="parameters.contentName" default-value="${contentName}"/>
<set field="createSummary.description" from-field="parameters.description" default-value="${description}"/>
<set field="createSummary.statusId" from-field="parameters.statusId" default-value="${statusId}"/>
<set field="createSummary.contentAssocTypeId" value="SUB_CONTENT"/>
<set field="createText.textData" from-field="parameters.articleData"/>
<set field="createText.contentIdFrom" from-field="contentIdFrom"/>
<set field="createText.partyId" from-field="userLogin.partyId"/>
<log level="always" message="calling createTextContent with map: ${createText}"/>
<call-service service-name="createTextContent" in-map-name="createText"/>
</if-not-empty>
</if-empty>
<!-- update article text -->
<if-not-empty field="articleText">
<if-compare-field field="parameters.articleData" operator="not-equals" to-field="articleData">
<set field="articleText.textData" from-field="parameters.articleData"/>
<store-value value-field="articleText"/>
</if-compare-field>
</if-not-empty>
<!-- update summary text -->
<if-not-empty field="summaryText">
<if-compare-field field="parameters.summaryData" operator="not-equals" to-field="summaryData">
<set field="summaryText.textData" from-field="parameters.summaryData"/>
<store-value value-field="summaryText"/>
</if-compare-field>
</if-not-empty>
<if-not-empty field="parameters._uploadedFile_fileName">
<if-not-empty field="imageContent">
<entity-and entity-name="ContentAssoc" list="oldAssocs" filter-by-date="true">
<field-map field-name="contentId" from-field="contentId"/>
<field-map field-name="contentIdTo" from-field="imageContent.contentId"/>
<field-map field-name="mapKey" value="IMAGE"/>
</entity-and>
<first-from-list entry="oldAssoc" list="oldAssocs"/>
<now-date-to-env field="oldAssoc.thruDate"/>
<store-value value-field="oldAssoc"/>
</if-not-empty>
<!-- upload a picture -->
<set field="createImage.dataResourceTypeId" value="LOCAL_FILE"/>
<set field="createImage.dataTemplateTypeId" value="NONE"/>
<set field="createImage.mapKey" value="IMAGE"/>
<set field="createImage.ownerContentId" from-field="parameters.contentId"/>
<set field="createImage.contentName" from-field="parameters.contentName" default-value="${contentName}"/>
<set field="createImage.description" from-field="parameters.description" default-value="${description}"/>
<set field="createImage.statusId" from-field="parameters.statusId" default-value="${statusId}"/>
<set field="createImage.contentAssocTypeId" value="SUB_CONTENT"/>
<set field="createImage.contentIdFrom" from-field="parameters.contentId"/>
<set field="createImage.partyId" from-field="userLogin.partyId"/>
<set field="createImage.isPublic" value="Y"/>
<set field="createImage.uploadedFile" from-field="parameters.uploadedFile"/>
<set field="createImage._uploadedFile_fileName" from-field="parameters._uploadedFile_fileName"/>
<set field="createImage._uploadedFile_contentType" from-field="parameters._uploadedFile_contentType"/>
<call-service service-name="createContentFromUploadedFile" in-map-name="createImage"/>
</if-not-empty>
<field-to-result field="parameters.contentId" result-name="contentId"/>
<field-to-result field="parameters.blogContentId" result-name="blogContentId"/>
</simple-method>
<simple-method method-name="getOwnedOrPublishedBlogEntries" short-description="Get blog entries that the user owns or are published">
<entity-condition entity-name="ContentAssocViewTo" use-cache="false" list="unfilteredList">
<condition-list combine="and">
@@ -183,36 +244,49 @@
</if-compare>
</iterate>
<field-to-result field="blogList" result-name="blogList"/>
<field-to-result field="parameters.blogContentId" result-name="blogContentId"/>
</simple-method>
<simple-method method-name="getBlogEntry" short-description="Get all the info for a blog article">
<entity-one entity-name="Content" value-field="content"/>
<field-to-result field="content.contentId" result-name="contentId"/>
<field-to-result field="content.contentName" result-name="contentName"/>
<field-to-result field="content.description" result-name="description"/>
<field-to-result field="content.statusId" result-name="statusId"/>
<field-to-result field="content.datResourceId" result-name="templateDataResourceId"/>
<get-related value-field="Content" relation-name="ContentAssoc" list="rawAssocs"/>
<get-related value-field="content" relation-name="FromContentAssoc" list="rawAssocs"/>
<filter-list-by-date list="rawAssocs" to-list="assocs"/>
<iterate entry="assoc" list="assocs">
<if-compare field="assoc.mapKey" value="MAIN" operator="equals">
<get-related-one value-field="assoc" relation-name="Content" to-value-field="content"/>
<get-related-one value-field="content" relation-name="DataResource" to-value-field="dataResource"/>
<get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="text"/>
<field-to-result field="text.textData" result-name="article"/>
<get-related-one value-field="assoc" relation-name="ToContent" to-value-field="mainContent"/>
<get-related-one value-field="mainContent" relation-name="DataResource" to-value-field="dataResource"/>
<get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="articleText"/>
</if-compare>
<if-compare field="assoc.mapKey" value="SUMMARY" operator="equals">
<get-related-one value-field="assoc" relation-name="Content" to-value-field="content"/>
<get-related-one value-field="content" relation-name="DataResource" to-value-field="dataResource"/>
<get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="text"/>
<field-to-result field="text.textData" result-name="summary"/>
<get-related-one value-field="assoc" relation-name="ToContent" to-value-field="summaryContent"/>
<get-related-one value-field="summaryContent" relation-name="DataResource" to-value-field="dataResource"/>
<get-related-one value-field="dataResource" relation-name="ElectronicText" to-value-field="summaryText"/>
</if-compare>
<if-compare field="assoc.mapKey" value="IMAGE" operator="equals">
<get-related-one value-field="assoc" relation-name="Content" to-value-field="content"/>
<get-related-one value-field="content" relation-name="DataResource" to-value-field="dataResource"/>
<field-to-result field="dataResource.dataResourceId" result-name="imageDataResourceId"/>
<get-related-one value-field="assoc" relation-name="ToContent" to-value-field="imageContent"/>
</if-compare>
</iterate>
<if-empty field="showNoResult">
<field-to-result field="content.contentId" result-name="contentId"/>
<field-to-result field="content.contentName" result-name="contentName"/>
<field-to-result field="content.description" result-name="description"/>
<field-to-result field="content.statusId" result-name="statusId"/>
<field-to-result field="content.dataResourceId" result-name="templateDataResourceId"/>
<field-to-result field="articleText.textData" result-name="articleData"/>
<field-to-result field="summaryText.textData" result-name="summaryData"/>
<field-to-result field="imageContent.dataResourceId" result-name="imageDataResourceId"/>
<field-to-result field="parameters.blogContentId" result-name="blogContentId"/>
<else>
<set from-field="content.contentId" field="contentId"/>
<set from-field="content.contentName" field="contentName"/>
<set from-field="content.description" field="description"/>
<set from-field="content.statusId" field="statusId"/>
<set from-field="content.dataResourceId" field="templateDataResourceId"/>
<set from-field="articleText.textData" field="articleData"/>
<set from-field="summaryText.textData" field="summaryData"/>
<set from-field="imageContent.dataResourceId" field="imageDataResourceId"/>
</else>
</if-empty>
</simple-method>
</simple-methods>
+28 -33
View File
@@ -1058,50 +1058,45 @@
</service>
<!-- blog services -->
<service name="postBlogEntry" engine="simple" transaction-timeout="300" auth="true"
location="org/ofbiz/content/blog/BlogServices.xml" invoke="postBlogEntry">
<service name="createBlogEntry" engine="simple" auth="true"
location="org/ofbiz/content/blog/BlogServices.xml" invoke="createBlogEntry">
<description>Creates content records for a blog entry</description>
<implements service="createContentFromUploadedFile" optional="true"/>
<implements service="createTextContent" optional="true"/>
<attribute name="blogContentId" type="String" mode="IN" optional="false"/>
<implements service="uploadFileInterface" optional="true"/>
<attribute name="blogContentId" type="String" mode="INOUT" optional="false"/>
<attribute name="contentId" type="String" mode="OUT" optional="false"/>
<attribute name="contentName" type="String" mode="IN" optional="true"/>
<attribute name="statusId" type="String" mode="IN" optional="true"/>
<attribute name="description" type="String" mode="IN" optional="true"/>
<attribute name="templateDataResourceId" type="String" mode="IN" optional="true"/>
<attribute name="articleData" type="String" mode="IN" optional="true"/>
<attribute name="summaryData" type="String" mode="IN" optional="true"/>
</service>
<service name="getBlogEntry" engine="simple" transaction-timeout="300" auth="true"
<service name="updateBlogEntry" engine="simple" auth="true"
location="org/ofbiz/content/blog/BlogServices.xml" invoke="updateBlogEntry">
<description>Updates content records for a blog entry</description>
<implements service="uploadFileInterface" optional="true"/>
<attribute name="blogContentId" type="String" mode="INOUT" optional="false"/>
<attribute name="contentId" type="String" mode="INOUT" optional="false"/>
<attribute name="contentName" type="String" mode="IN" optional="true"/>
<attribute name="statusId" type="String" mode="IN" optional="true"/>
<attribute name="description" type="String" mode="IN" optional="true"/>
<attribute name="templateDataResourceId" type="String" mode="IN" optional="true"/>
<attribute name="articleData" type="String" mode="IN" optional="true"/>
<attribute name="summaryData" type="String" mode="IN" optional="true"/>
</service>
<service name="getBlogEntry" engine="simple" auth="true"
location="org/ofbiz/content/blog/BlogServices.xml" invoke="getBlogEntry">
<description>Creates content records for a blog entry</description>
<description>Retrieves content records for a blog entry</description>
<attribute name="blogContentId" type="String" mode="INOUT" optional="false"/>
<attribute name="contentId" type="String" mode="INOUT" optional="false"/>
<attribute name="contentName" type="String" mode="OUT" optional="true"/>
<attribute name="statusId" type="String" mode="OUT" optional="true"/>
<attribute name="description" type="String" mode="OUT" optional="true"/>
<attribute name="templateDataResourceId" type="String" mode="OUT" optional="true"/>
<attribute name="summary" type="String" mode="OUT" optional="true"/>
<attribute name="article" type="String" mode="OUT" optional="true"/>
<attribute name="summaryData" type="String" mode="OUT" optional="true"/>
<attribute name="articleData" type="String" mode="OUT" optional="true"/>
<attribute name="imageDataResourceId" type="String" mode="OUT" optional="true"/>
</service>
<!-- TO BE REMOVED
<service name="updateBlogEntry" engine="simple" transaction-timeout="300" auth="true"
location="org/ofbiz/content/blog/BlogServices.xml" invoke="updateBlogEntry">
<description>Creates content records for a blog entry</description>
<implements service="createContentFromUploadedFile" optional="true"/>
<implements service="createTextContent" optional="true"/>
<attribute name="blogContentId" type="String" mode="IN" optional="false"/>
<attribute name="summaryData" type="String" mode="IN" optional="true"/>
</service>
-->
<service name="persistBlogAll" engine="java" location="org.ofbiz.content.blog.BlogServices" invoke="persistBlogAll"
auth="true" transaction-timeout="72000">
<implements service="persistContentAndAssoc"/>
<attribute type="String" mode="IN" name="summaryData" optional="true"/>
<attribute type="String" mode="IN" name="mainData" optional="true"/>
<attribute type="String" mode="IN" name="drMimeTypeId_TEXT" optional="true"/>
<attribute type="String" mode="IN" name="drMimeTypeId_IMAGE" optional="true"/>
<attribute type="String" mode="IN" name="templateId" optional="true"/>
<attribute type="String" mode="INOUT" name="textContentId" optional="true"/>
<attribute type="String" mode="INOUT" name="imageContentId" optional="true"/>
<attribute type="String" mode="INOUT" name="textDataResourceId" optional="true"/>
<attribute type="String" mode="INOUT" name="imageDataResourceId" optional="true"/>
</service>
<service name="getOwnedOrPublishedBlogEntries" engine="simple" location="org/ofbiz/content/blog/BlogServices.xml" invoke="getOwnedOrPublishedBlogEntries"
auth="true" transaction-timeout="72000">
<attribute type="String" mode="IN" name="contentId" optional="false"/>
@@ -1,232 +0,0 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.content.blog;
import java.util.Map;
import javolution.util.FastMap;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.GenericDelegator;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceUtil;
public class BlogServices {
/**
* This service persists a blog article.
*
* It can persist text only, image only or a combination of content types.
* If text or image only, that content is attached directly to the main
* content as an ElectronicText or ImageDataResource entity.
* If a combination is desired, the two content pieces (image and text) are associated
* through a predefined screen widget template (ie. drDataTemplateTypeId="SCREEN_COMBINED").
*/
public static Map<String, Object> persistBlogAll(DispatchContext dctx, Map<String, ? extends Object> context) throws GenericServiceException {
Map result = FastMap.newInstance();
GenericDelegator delegator = dctx.getDelegator();
LocalDispatcher dispatcher = dctx.getDispatcher();
GenericValue userLogin = (GenericValue)context.get("userLogin");
ModelService modelPersistContent = dispatcher.getDispatchContext().getModelService("persistContentAndAssoc");
Map ctx = modelPersistContent.makeValid(context, "IN");
ctx.put("userLogin", userLogin);
ctx.put("textData", context.get("mainData"));
ctx.put("deactivateExisting", "false");
String drMimeTypeId_TEXT = (String)context.get("drMimeTypeId_TEXT");
boolean bTextMimeType = "Y".equals(drMimeTypeId_TEXT);
String drMimeTypeId_IMAGE = (String)context.get("drMimeTypeId_IMAGE");
boolean bImageMimeType = "Y".equals(drMimeTypeId_IMAGE);
String mainData = (String)context.get("mainData");
String imageMimeTypeId = (String)context.get("_imageData_contentType");
if (UtilValidate.isEmpty(imageMimeTypeId)) imageMimeTypeId = "image/jpeg";
String contentId = (String)context.get("contentId");
if (UtilValidate.isEmpty(contentId)) ctx.put("contentId", context.get("contentIdTo"));
// if the content already exists, these will identify it.
// They are stored in the form
String textContentId = (String)context.get("textContentId");
String imageContentId = (String)context.get("imageContentId");
String textDataResourceId = (String)context.get("textDataResourceId");
String imageDataResourceId = (String)context.get("imageDataResourceId");
String drDataResourceId = (String)context.get("drDataResourceId");
String drDataTemplateTypeId = (String)context.get("drDataTemplateTypeId");
String templateId = (String)context.get("templateId");
if ("SCREEN_COMBINED".equals(drDataTemplateTypeId) && !bImageMimeType) {
if (bTextMimeType) {
ctx.put("dataResourceId", textDataResourceId);
ctx.put("drDataResourceId", textDataResourceId);
ctx.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("drMimeTypeId", "text/html");
}
} else if ("SCREEN_COMBINED".equals(drDataTemplateTypeId) && !bTextMimeType) {
if (bImageMimeType) {
ctx.put("dataResourceId", imageDataResourceId);
ctx.put("drDataResourceId", imageDataResourceId);
ctx.put("drDataResourceTypeId", "IMAGE_OBJECT");
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("drMimeTypeId", imageMimeTypeId);
ctx.put("drIsPublic", "Y");
}
} else if (!"SCREEN_COMBINED".equals(drDataTemplateTypeId) ) {
// Store the main record
// either text or image or both
if (bTextMimeType && !bImageMimeType) {
ctx.put("dataResourceId", drDataResourceId);
ctx.put("drDataResourceId", drDataResourceId);
ctx.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("drMimeTypeId", "text/html");
} else if (!bTextMimeType && bImageMimeType) {
ctx.put("dataResourceId", drDataResourceId);
ctx.put("drDataResourceId", drDataResourceId);
ctx.put("drDataResourceTypeId", "IMAGE_OBJECT");
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("drMimeTypeId", imageMimeTypeId);
ctx.put("drIsPublic", "Y");
} else if (bTextMimeType && bImageMimeType) {
// if both then set up for and choose a template
ctx.put("drDataResourceTypeId", null);
ctx.put("dataResourceTypeId", null);
ctx.put("textData", null);
ctx.put("dataResourceId", templateId);
ctx.put("drDataResourceId", templateId);
ctx.put("drIsPublic", "Y");
}
} else if ("SCREEN_COMBINED".equals(drDataTemplateTypeId) ) {
if (bTextMimeType && bImageMimeType) {
// if both then set up for and choose a template
ctx.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
ctx.put("drDataTemplateTypeId", "SCREEN_COMBINED");
ctx.put("drMimeTypeId", "text/html");
ctx.put("textData", null);
ctx.put("dataResourceId", templateId);
ctx.put("drDataResourceId", templateId);
ctx.put("drIsPublic", "Y");
}
}
// store the main content entity
result = dispatcher.runSync("persistContentAndAssoc", ctx);
if (ServiceUtil.isError(result)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(result));
}
String mainContentId = (String)result.get("contentId");
// If both, then that content needs to be persisted
if (bTextMimeType && bImageMimeType) {
ctx = modelPersistContent.makeValid(context, "IN");
// first store the text
ctx.put("caContentId", mainContentId);
ctx.put("contentId", textContentId);
ctx.put("dataResourceId", textDataResourceId);
ctx.put("drDataResourceId", textDataResourceId);
ctx.put("caContentId", mainContentId);
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("caContentAssocTypeId", "SUB_CONTENT");
ctx.put("drDataResourceTypeId", "ELECTRONIC_TEXT");
ctx.put("drMimeTypeId", "text/html");
ctx.put("caMapKey", "MAIN");
ctx.put("textData", mainData);
Map textResult = dispatcher.runSync("persistContentAndAssoc", ctx);
if (ServiceUtil.isError(textResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(textResult));
}
textContentId = (String)textResult.get("contentId");
textDataResourceId = (String)textResult.get("drDataResourceId");
// persist the image
String imageData_fileName = (String)context.get("_imageData_fileName");
// In the update mode, if no upload file is given, do not upload
if (UtilValidate.isNotEmpty(imageData_fileName)) {
ctx = modelPersistContent.makeValid(context, "IN");
ctx.put("caContentId", mainContentId);
ctx.put("contentId", imageContentId);
ctx.put("dataResourceId", imageDataResourceId);
ctx.put("drDataResourceId", imageDataResourceId);
ctx.put("drDataTemplateTypeId", "NONE");
ctx.put("drDataResourceTypeId", "IMAGE_OBJECT");
ctx.put("caContentAssocTypeId", "SUB_CONTENT");
ctx.put("drMimeTypeId", imageMimeTypeId);
ctx.put("caMapKey", "IMAGE");
ctx.put("textData", null);
ctx.put("drIsPublic", "Y");
Map imageResult = dispatcher.runSync("persistContentAndAssoc", ctx);
if (ServiceUtil.isError(imageResult)) {
return ServiceUtil.returnError(ServiceUtil.getErrorMessage(imageResult));
}
imageContentId = (String)imageResult.get("contentId");
imageDataResourceId = (String)imageResult.get("drDataResourceId");
}
}
// persist the summary info.
String summaryData = (String)context.get("summaryData");
String summaryParentContentId = mainContentId;
if (UtilValidate.isNotEmpty(summaryData) && UtilValidate.isNotEmpty(summaryParentContentId) ) {
Map subContentIn = FastMap.newInstance();
subContentIn.put("contentId", summaryParentContentId);
subContentIn.put("mapKey", "SUMMARY");
Map thisResult = dispatcher.runSync("getSubContent", subContentIn);
GenericValue view = (GenericValue)thisResult.get("view");
Map summaryContext = null;
if (view != null) {
summaryContext = modelPersistContent.makeValid(view, "IN");
summaryContext.put("textData", summaryData);
summaryContext.put("contentTypeId", null);
summaryContext.put("caContentAssocTypeId", null);
} else {
summaryContext = modelPersistContent.makeValid(result, "IN");
summaryContext.put("textData", summaryData);
summaryContext.put("caContentId", summaryParentContentId);
summaryContext.put("caMapKey", "SUMMARY");
summaryContext.put("caContentAssocTypeId", "SUB_CONTENT");
summaryContext.put("contentTypeId", "DOCUMENT");
summaryContext.put("dataResourceTypeId", "ELECTRONIC_TEXT");
summaryContext.put("contentId", null);
summaryContext.put("caFromDate", null);
summaryContext.put("drDataResourceId", null);
summaryContext.put("dataResourceId", null);
summaryContext.put("statusId", context.get("statusId"));
summaryContext.put("ownerContentId", context.get("ownerContentId"));
summaryContext.put("contentPurposeString", "ARTICLE");
}
summaryContext.put("userLogin", userLogin);
Map summaryResult = dispatcher.runSync("persistContentAndAssoc", summaryContext);
if (ServiceUtil.isError(summaryResult)) {
String errMsg = ServiceUtil.getErrorMessage(summaryResult);
return ServiceUtil.returnError(errMsg);
}
}
return result;
}
}
@@ -94,13 +94,13 @@ under the License.
</request-map>
<request-map uri="createBlogArticle">
<security https="true" auth="true"/>
<event type="service" invoke="postBlogEntry"/>
<event type="service" invoke="createBlogEntry"/>
<response name="success" type="view" value="blogContent"/>
<response name="error" type="view" value="NewBlogArticle"/>
</request-map>
<request-map uri="updateBlogArticle">
<security https="true" auth="true"/>
<event type="service" invoke="persistBlogAll"/>
<event type="service" invoke="updateBlogEntry"/>
<response name="success" type="view" value="blogContent"/>
<response name="error" type="view" value="EditBlogArticle"/>
</request-map>
@@ -1334,14 +1334,14 @@ under the License.
<request-map uri="createBlogArticle">
<security https="true" auth="true"/>
<event type="service" invoke="postBlogEntry"/>
<event type="service" invoke="createBlogEntry"/>
<response name="success" type="view" value="ViewBlogArticle"/>
<response name="error" type="view" value="EditBlogArticle"/>
</request-map>
<request-map uri="updateBlogArticle">
<security https="true" auth="true"/>
<event type="service" invoke="persistBlogAll"/>
<event type="service" invoke="updateBlogEntry"/>
<response name="success" type="view" value="ViewBlogArticle"/>
<response name="error" type="view" value="EditBlogArticle"/>
</request-map>
@@ -190,25 +190,18 @@
</sort-order>
</form>
<form name="CreateArticle" target="createBlogArticle" title="" type="upload" skip-end="true"
<form name="EditArticle" target="createBlogArticle" title="" type="upload" skip-end="true" default-map-name="blogEntry"
default-title-style="treeHeader" default-tooltip-style="tabletext" default-widget-style="inputBox">
<field name="contentName" title="Short title">
<text size="40"/>
</field>
<field name="description" title="Slightly longer title (250 chars max)">
<textarea cols="40" rows="2"/>
</field>
<field name="summaryData" title="Summary" widget-style="inputBox dojo-ResizableTextArea">
<textarea cols="60" rows="4"/>
</field>
<field name="textData" title="Article" widget-style="inputBox dojo-ResizableTextArea">
<textarea cols="60" rows="12"/>
</field>
<field name="uploadedFile" title="Image">
<file size="25"/>
</field>
<field name="dataResourceId" title="Template">
<drop-down allow-empty="true">
<alt-target use-when="contentId!=void" target="updateBlogArticle"/>
<field name="blogContentId"><hidden value="${parameters.blogContentId}"/></field>
<field name="contentId" title="Blog entry Id" use-when="contentId!=void"><display/></field>
<field name="contentName" title="Short title"><text size="40"/></field>
<field name="description" title="Slightly longer title (250 chars max)"><textarea cols="40" rows="2"/></field>
<field name="summaryData" title="Summary" widget-style="inputBox dojo-ResizableTextArea"><textarea cols="60" rows="4"/></field>
<field name="articleData" title="Article" widget-style="inputBox dojo-ResizableTextArea"><textarea cols="60" rows="12"/></field>
<field name="uploadedFile" title="Image"><file size="25"/></field>
<field name="templateDataResourceId" title="Template">
<drop-down>
<option key="BLOG_TPL_TOPLEFT" description="Top Left"/>
<option key="BLOG_TPL_TOPCENTER" description="Top Center"/>
</drop-down>
@@ -219,85 +212,7 @@
<option key="CTNT_INITIAL_DRAFT" description="Preview"/>
</drop-down>
</field>
<field name="submitButton" title="Submit" widget-style="smallSubmit">
<submit button-type="button"/>
</field>
<field name="contentPurposeString">
<hidden value="ARTICLE"/>
</field>
<field name="contentAssocTypeId">
<hidden value="PUBLISH_LINK"/>
</field>
<field name="blogContentId" entry-name="blogContentId">
<hidden/>
</field>
<field name="contentIdFrom" entry-name="blogContentId">
<hidden/>
</field>
<sort-order>
<sort-field name="contentName"/>
<sort-field name="description"/>
<sort-field name="summaryData"/>
<sort-field name="textData"/>
<sort-field name="uploadedFile"/>
<sort-field name="dataResourceId"/>
<sort-field name="statusId"/>
<sort-field name="submitButton"/>
</sort-order>
</form>
<form name="EditArticle" target="updateBlogArticle" title="" type="upload" skip-end="true" default-map-name="blogEntry"
default-title-style="treeHeader" default-tooltip-style="tabletext" default-widget-style="inputBox">
<field name="contentId" title="Blog ID" use-when="contentId!=null&amp;&amp;contentId!=&quot;&quot;">
<display/>
</field>
<field name="contentName" title="Short title">
<text size="40"/>
</field>
<field name="description" title="Slightly longer title (250 chars max)">
<textarea cols="40" rows="2"/>
</field>
<field name="summaryData" title="Summary" entry-name="summary" widget-style="inputBox dojo-ResizableTextArea">
<textarea cols="60" rows="4"/>
</field>
<field name="textData" title="Article" entry-name="article" widget-style="inputBox dojo-ResizableTextArea">
<textarea cols="60" rows="12"/>
</field>
<field name="uploadedFile" title="Image">
<file size="25"/>
</field>
<field name="dataResourceId" title="Template" entry-name="templateDataResourceId">
<drop-down allow-empty="true">
<option key="BLOG_TPL_TOPLEFT" description="Top Left"/>
<option key="BLOG_TPL_TOPCENTER" description="Top Center"/>
</drop-down>
</field>
<field name="statusId" title="Status">
<drop-down no-current-selected-key="CTNT_INITIAL_DRAFT">
<option key="CTNT_PUBLISHED" description="Publish"/>
<option key="CTNT_INITIAL_DRAFT" description="Preview"/>
</drop-down>
</field>
<field name="submitButton" title="Submit" widget-style="smallSubmit">
<submit button-type="button"/>
</field>
<field name="contentPurposeString">
<hidden value="ARTICLE"/>
</field>
<field name="blogContentId" entry-name="blogContentId">
<hidden/>
</field>
<sort-order>
<sort-field name="contentId"/>
<sort-field name="contentName"/>
<sort-field name="description"/>
<sort-field name="summaryData"/>
<sort-field name="textData"/>
<sort-field name="uploadedFile"/>
<sort-field name="dataResourceId"/>
<sort-field name="statusId"/>
<sort-field name="submitButton"/>
</sort-order>
<field name="submitButton" title="Submit" widget-style="smallSubmit"><submit button-type="button"/></field>
</form>
<form name="editFormSubmit" target="" title="" type="single" skip-start="true" skip-end="true"
@@ -27,7 +27,7 @@
<if-entity-permission entity-id="${blog.contentId}" entity-name="Content" target-operation="CONTENT_UPDATE"/>
</or>
</condition>
<link text="Edit" target="EditBlogArticle?articleContentId=${blog.contentId}&amp;blogContentId=${blog.contentIdStart}" style="buttontext"/>
<link text="Edit" target="EditBlogArticle?contentId=${blog.contentId}&amp;blogContentId=${parameters.blogContentId}" style="buttontext"/>
</menu-item>
</menu>
</menus>
@@ -111,7 +111,7 @@
<container style="blogwrapper">
<include-menu name="view_edit" location="component://ecommerce/widget/blog/BlogMenus.xml"/>
<label text="&lt;p/&gt;"/>
<link text="${blog.contentName} [${blog.contentId}]" target="ViewBlogArticle?articleContentId=${blog.contentId}&amp;blogContentId=${blogContentId}" style="blogheader"/>
<link text="${blog.contentName} [${blog.contentId}]" target="ViewBlogArticle?contentId=${blog.contentId}&amp;blogContentId=${blogContentId}" style="blogheader"/>
<!--
<link text="Latest" target="LatestResponses?ownerContentId=${blog.ownerContentId}" />
-->
@@ -131,7 +131,7 @@
<include-menu name="view_edit" location="component://ecommerce/widget/blog/BlogMenus.xml"/>
<label text="&lt;p/&gt;"/>
<!--<label text="${blog.contentName} [${blog.contentId}]" style="blogheader"/>-->
<link text="${blog.contentName} [${blog.contentId}]" target="ViewBlogArticle?articleContentId=${blog.contentId}&amp;blogContentId=${blogContentId}" style="blogheader"/>
<link text="${blog.contentName} [${blog.contentId}]" target="ViewBlogArticle?contentId=${blog.contentId}&amp;blogContentId=${blogContentId}" style="blogheader"/>
<!--
<link text="Latest" target="LatestResponses?ownerContentId=${blog.ownerContentId}" />
-->
@@ -152,7 +152,6 @@
<screen name="NewArticle">
<section>
<actions>
<set field="blogContentId" from-field="parameters.blogContentId"/>
<set field="crPerm.ownerContentId" from-field="parameters.blogContentId"/>
<set field="crPerm.contentOperationId" value="CONTENT_CREATE"/>
<set field="crPerm.contentPurposeTypeId" value="ARTICLE"/>
@@ -165,7 +164,7 @@
<widgets>
<decorator-screen name="CommonBlog" location="${parameters.mainDecoratorLocation}">
<decorator-section name="body">
<include-form name="CreateArticle" location="component://ecommerce/widget/blog/BlogForms.xml"/>
<include-form name="EditArticle" location="component://ecommerce/widget/blog/BlogForms.xml"/>
</decorator-section>
</decorator-screen>
</widgets>
@@ -181,28 +180,29 @@
<section>
<actions>
<set field="blogContentId" from-field="parameters.blogContentId"/>
<set field="upPerm.contentId" from-field="parameters.blogContentId"/>
<set field="upPerm.contentOperationId" value="CONTENT_UPDATE"/>
<set field="upPerm.contentPurposeTypeId" value="ARTICLE"/>
<set field="contentId" from-field="parameters.contentId"/>
</actions>
<widgets>
<section>
<condition>
<if-service-permission service-name="genericContentPermission" main-action="UPDATE" context-map="upPerm"/>
</condition>
<!--condition>
<if-service-permission service-name="genericContentPermission" main-action="UPDATE"/>
</condition-->
<actions>
<service service-name="getBlogEntry" result-map-name="blogEntry" auto-field-map="true"/>
</actions>
<widgets>
<decorator-screen name="CommonBlog" location="${parameters.mainDecoratorLocation}">
<decorator-section name="body">
<sub-content content-id="${parameters.contentId}" map-key="IMAGE"/>
<include-form name="EditArticle" location="component://ecommerce/widget/blog/BlogForms.xml"/>
</decorator-section>
</decorator-screen>
</widgets>
<fail-widgets>
<label text="Permissions failed."></label>
<label text="Permissions failed to edit Article: ${contentId} in Blog: ${blogContentId}"></label>
</fail-widgets>
</section>
</widgets>