This is an automated email from the ASF dual-hosted git repository. nmalin pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git
The following commit(s) were added to refs/heads/trunk by this push: new a4cbdec636 Improved: Convert BlogServices.xml mini lang to groovy DSL (OFBIZ-12623) a4cbdec636 is described below commit a4cbdec63650e044f6a09619fc44bdfca19c41a5 Author: Nicolas Malin <nicolas.ma...@nereide.fr> AuthorDate: Fri Apr 22 16:09:00 2022 +0200 Improved: Convert BlogServices.xml mini lang to groovy DSL (OFBIZ-12623) Convert service createBlogEntry, updateBlogEntry, getBlogEntry and getOwnedOrPublishedBlogEntries from mini lang to --- .../content/minilang/blog/BlogServices.xml | 325 --------------------- applications/content/servicedef/services.xml | 33 +-- .../org/apache/ofbiz/content/BlogServices.groovy | 273 +++++++++++++++++ 3 files changed, 289 insertions(+), 342 deletions(-) diff --git a/applications/content/minilang/blog/BlogServices.xml b/applications/content/minilang/blog/BlogServices.xml deleted file mode 100644 index 63f7951b0c..0000000000 --- a/applications/content/minilang/blog/BlogServices.xml +++ /dev/null @@ -1,325 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - 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. - --> - -<simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <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"/> - <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-empty field="parameters.contentName"> - <add-error> - <fail-property resource="ContentUiLabels" property="ContentArticleNameIsMissing"/> - </add-error> - </if-empty> - <check-errors/> - <!-- complex template structure (image & text) --> - <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"/> - <set field="createMain.statusId" from-field="parameters.statusId"/> - <set field="createMain.contentIdFrom" from-field="contentIdFrom"/> - <set field="createMain.partyId" from-field="userLogin.partyId"/> - <set field="createMain.ownerContentId" from-field="ownerContentId"/> - <set field="createMain.dataTemplateTypeId" value="SCREEN_COMBINED"/> - <set field="createMain.mapKey" value="MAIN"/> - <call-service service-name="createContent" in-map-name="createMain"> - <result-to-field result-name="contentId" field="contentId"/> - </call-service> - <!-- reset contentIdFrom to new contentId --> - <set field="contentAssocTypeId" value="SUB_CONTENT"/> - <set field="contentIdFrom" from-field="contentId"/> - - <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-not-empty> - - <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"/> - <set field="createText.mapKey" value="ARTICLE"/> - <log level="info" 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-not-empty> - - <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.dataTemplateTypeId" value="NONE"/> - <set field="createSummary.mapKey" value="SUMMARY"/> - <set field="createSummary.ownerContentId" from-field="ownerContentId"/> - <set field="createSummary.contentName" from-field="parameters.contentName"/> - <set field="createSummary.description" from-field="parameters.description"/> - <set field="createSummary.statusId" from-field="parameters.statusId"/> - <set field="createSummary.contentAssocTypeId" from-field="contentAssocTypeId"/> - <set field="createSummary.textData" from-field="parameters.summaryData"/> - <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="contentIdFrom" result-name="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.summaryData" operator="not-equals" to-field="summaryData"/> - <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"/> - <if-compare-field field="parameters.statusId" operator="not-equals" to-field="statusId"> - <if-not-empty field="imageContent"> - <set field="imageContent.status.Id" from-field="parameters.statusId"/> - <store-value value-field="imageContent"/> - </if-not-empty> - </if-compare-field> - </then> - </if> - - <!-- new article text --> - <if-empty field="articleText"> - <if-not-empty field="parameters.articleData"> - <set field="ownerContentId" from-field="parameters.blogContentId"/> - <set field="contentAssocTypeId" value="SUB_CONTENT"/> - <set field="contentIdFrom" from-field="contentId"/> - <set field="createText.dataResourceTypeId" value="ELECTRONIC_TEXT"/> - <set field="createText.contentPurposeTypeId" value="ARTICLE"/> - <set field="createText.dataTemplateTypeId" value="NONE"/> - <set field="createText.mapKey" value="ARTICLE"/> - <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"/> - <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> - - <!-- create summary text --> - <if-empty field="summaryData"> - <if-not-empty field="parameters.summaryData"> - <!-- create the summary data --> - <set field="ownerContentId" from-field="parameters.blogContentId"/> - <set field="contentAssocTypeId" value="SUB_CONTENT"/> - <set field="contentIdFrom" from-field="contentId"/> - <set field="createSummary.dataResourceTypeId" value="ELECTRONIC_TEXT"/> - <set field="createSummary.contentPurposeTypeId" value="ARTICLE"/> - <set field="createSummary.dataTemplateTypeId" value="NONE"/> - <set field="createSummary.mapKey" value="SUMMARY"/> - <set field="createSummary.ownerContentId" from-field="ownerContentId"/> - <set field="createSummary.contentName" from-field="parameters.contentName"/> - <set field="createSummary.description" from-field="parameters.description"/> - <set field="createSummary.statusId" from-field="parameters.statusId"/> - <set field="createSummary.contentAssocTypeId" from-field="contentAssocTypeId"/> - <set field="createSummary.textData" from-field="parameters.summaryData"/> - <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-empty> - - <!-- update summary text --> - <if-not-empty field="summaryData"> - <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 list="oldAssocs" entry="oldAssoc"/> - <now-timestamp 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"> - <condition-expr field-name="contentIdStart" operator="equals" from-field="parameters.contentId"/> - <condition-expr field-name="caContentAssocTypeId" operator="equals" value="PUBLISH_LINK"/> - </condition-list> - <order-by field-name="caFromDate DESC"/> - </entity-condition> - <filter-list-by-date list="unfilteredList" to-list="blogItems"/> - <set field="blogList[]"/> - <iterate list="blogItems" entry="blogItem"> - <set-service-fields service-name="genericContentPermission" map="blogItem" to-map="mapIn"/> - <set field="mapIn.ownerContentId" from-field="parameters.contentId"/> - <set field="mapIn.mainAction" value="VIEW"/> - <call-service service-name="genericContentPermission" in-map-name="mapIn"> - <result-to-field result-name="hasPermission" field="hasPermission"/> - </call-service> - <if-compare field="hasPermission" operator="equals" value="true" type="Boolean"> - <set field="blogList[]" from-field="blogItem"/> - <else> - <set field="mapIn.mainAction" value="UPDATE"/> - <call-service service-name="genericContentPermission" in-map-name="mapIn"> - <result-to-field result-name="hasPermission" field="hasPermission"/> - </call-service> - <if-compare field="hasPermission" operator="equals" value="true" type="Boolean"> - <set field="blogList[]" from-field="blogItem"/> - </if-compare> - </else> - </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"> - <if-empty field="parameters.contentId"> - <field-to-result field="parameters.blogContentId" result-name="blogContentId"/> - <return/> - </if-empty> - <entity-one entity-name="Content" value-field="content"/> - <get-related value-field="content" relation-name="FromContentAssoc" list="rawAssocs"/> - <filter-list-by-date list="rawAssocs" to-list="assocs"/> - <iterate list="assocs" entry="assoc"> - <if-compare field="assoc.mapKey" value="ARTICLE" operator="equals"> - <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="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="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"/> - <if-not-empty field="imageContent"> - <field-to-result field="content.dataResourceId" result-name="templateDataResourceId"/> - </if-not-empty> - <field-to-result field="articleText.textData" result-name="articleData"/> - <field-to-result field="summaryText.textData" result-name="summaryData"/> - <field-to-result field="imageContent.contentId" result-name="imageContentId"/> - <field-to-result field="mainContent.contentId" result-name="articleContentId"/> - <field-to-result field="summaryContent.contentId" result-name="summaryContentId"/> - <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> diff --git a/applications/content/servicedef/services.xml b/applications/content/servicedef/services.xml index b53fcbbad2..a812326b9a 100644 --- a/applications/content/servicedef/services.xml +++ b/applications/content/servicedef/services.xml @@ -818,8 +818,8 @@ </service> <!-- blog services --> - <service name="createBlogEntry" engine="simple" auth="true" - location="component://content/minilang/blog/BlogServices.xml" invoke="createBlogEntry"> + <service name="createBlogEntry" engine="groovy" auth="true" + location="component://content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy" invoke="createBlogEntry"> <description>Creates content records for a blog entry</description> <required-permissions join-type="AND"> <check-permission permission="CONTENTMGR" action="_CREATE"/> @@ -838,8 +838,8 @@ <attribute name="articleData" type="String" mode="IN" optional="true" allow-html="safe"/> <attribute name="summaryData" type="String" mode="IN" optional="true" allow-html="safe"/> </service> - <service name="updateBlogEntry" engine="simple" auth="true" - location="component://content/minilang/blog/BlogServices.xml" invoke="updateBlogEntry"> + <service name="updateBlogEntry" engine="groovy" auth="true" + location="component://content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy" invoke="updateBlogEntry"> <description>Updates content records for a blog entry</description> <required-permissions join-type="AND"> <check-permission permission="CONTENTMGR" action="_UPDATE"/> @@ -862,8 +862,8 @@ <attribute name="articleData" type="String" mode="IN" optional="true" allow-html="safe"/> <attribute name="summaryData" type="String" mode="IN" optional="true" allow-html="safe"/> </service> - <service name="getBlogEntry" engine="simple" auth="true" - location="component://content/minilang/blog/BlogServices.xml" invoke="getBlogEntry"> + <service name="getBlogEntry" engine="groovy" auth="true" + location="component://content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy" invoke="getBlogEntry"> <description>Retrieves content records for a blog entry</description> <attribute name="blogContentId" type="String" mode="INOUT" optional="false"> <type-validate> @@ -875,25 +875,24 @@ <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="summaryData" type="String" mode="OUT" optional="true"/> - <attribute name="articleData" type="String" mode="OUT" optional="true"/> <attribute name="imageContentId" type="String" mode="OUT" optional="true"/> + <attribute name="imageDataResourceId" type="String" mode="IN" optional="true"/> + <attribute name="articleData" type="String" mode="OUT" optional="true"/> <attribute name="articleContentId" type="String" mode="OUT" optional="true"/> + <attribute name="articleDataResourceId" type="String" mode="OUT" optional="true"/> + <attribute name="summaryData" type="String" mode="OUT" optional="true"/> <attribute name="summaryContentId" type="String" mode="OUT" optional="true"/> + <attribute name="summaryDataResourceId" type="String" mode="OUT" optional="true"/> </service> - <service name="getOwnedOrPublishedBlogEntries" engine="simple" location="component://content/minilang/blog/BlogServices.xml" invoke="getOwnedOrPublishedBlogEntries" - auth="true" transaction-timeout="7200"> - <attribute type="String" mode="IN" name="contentId" optional="false"> + <service name="getOwnedOrPublishedBlogEntries" engine="groovy" auth="true" transaction-timeout="7200" + location="component://content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy" invoke="getOwnedOrPublishedBlogEntries"> + <attribute name="contentId" type="String" mode="IN" > <type-validate> <fail-property resource="ContentErrorUiLabels" property="ContentRequiredFieldMissingContentId"/> </type-validate> </attribute> - <attribute mode="IN" name="userLogin" optional="false" type="org.apache.ofbiz.entity.GenericValue"> - <type-validate> - <fail-property resource="ContentErrorUiLabels" property="ContentRequiredFieldMissingUserLogin"/> - </type-validate> - </attribute> - <attribute mode="OUT" name="blogList" optional="true" type="List"/> + <attribute name="blogContentId" type="String" mode="OUT" optional="true"/> + <attribute name="blogList" type="List" mode="OUT" optional="true"/> </service> <!-- blog RSS services --> diff --git a/applications/content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy b/applications/content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy new file mode 100644 index 0000000000..400c1094be --- /dev/null +++ b/applications/content/src/main/groovy/org/apache/ofbiz/content/BlogServices.groovy @@ -0,0 +1,273 @@ +/******************************************************************************* + * 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.apache.ofbiz.content + +import org.apache.ofbiz.base.util.UtilDateTime +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.entity.condition.EntityCondition +import org.apache.ofbiz.entity.condition.EntityConditionBuilder + +def createBlogEntry() { + String ownerContentId = parameters.blogContentId + String contentIdFrom = parameters.blogContentId + parameters.statusId = parameters.statusId ?: "CTNT_INITIAL_DRAFT" + parameters.templateDataResourceId = parameters.templateDataResourceId ?: "BLOG_TPL_TOPLEFT" + + if (!parameters.contentName) { + return error(label("ContentUiLabels", "ContentArticleNameIsMissing")) + } + Map serviceResult = run service: "createContent", + with: [dataResourceId : parameters.templateDataResourceId, + contentAssocTypeId: "PUBLISH_LINK", + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentIdFrom : contentIdFrom, + partyId : userLogin.partyId, + ownerContentId : ownerContentId, + dataTemplateTypeId: "SCREEN_COMBINED", + mapKey : "MAIN"] + contentIdFrom = serviceResult.contentId + + if (parameters._uploadedFile_fileName) { + run service: "createContentFromUploadedFile", + with: [ + dataResourceTypeId : "LOCAL_FILE", + dataTemplateTypeId : "NONE", + mapKey : "IMAGE", + ownerContentId : ownerContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentAssocTypeId : "SUB_CONTENT", + contentIdFrom : contentIdFrom, + partyId : userLogin.partyId, + isPublic : "Y", + uploadedFile : parameters.uploadedFile, + _uploadedFile_fileName : parameters._uploadedFile_fileName, + _uploadedFile_contentType: parameters._uploadedFile_contentType] + } + if (parameters.articleData) { + run service: "createTextContent", + with: [ + dataResourceTypeId : "ELECTRONIC_TEXT", + contentPurposeTypeId: "ARTICLE", + dataTemplateTypeId : "NONE", + mapKey : "MAIN", + ownerContentId : ownerContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentAssocTypeId : "SUB_CONTENT", + textData : parameters.articleData, + contentIdFrom : contentIdFrom, + partyId : userLogin.partyId, + mapKey : "ARTICLE"] + } + if (parameters.summaryData) { + run service: "createTextContent", + with: [ + dataResourceTypeId: "ELECTRONIC_TEXT", + dataTemplateTypeId: "NONE", + mapKey : "SUMMARY", + ownerContentId : ownerContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentAssocTypeId: "SUB_CONTENT", + textData : parameters.summaryData, + contentIdFrom : contentIdFrom, + partyId : userLogin.partyId] + } + return success([blogContentId: ownerContentId, contentId: contentIdFrom]) +} + +/** + * Get all the info for a blog article + */ +def getBlogEntry() { + if (!parameters.contentId) { + return success([blogContentId: parameters.blogContentId]) + } + GenericValue content = from("Content").where(parameters).cache().queryOne() + GenericValue mainContent, articleText, dataResource, summaryContent, summaryText, imageContent + from("ContentAssoc") + .where(contentId: content.contentId) + .filterByDate() + .cache() + .queryList() + .each { + switch (it.mapKey) { + case "ARTICLE": + mainContent = it.getRelatedOne("ToContent", true) + dataResource = mainContent.getRelatedOne("DataResource", true) + articleText = dataResource.getRelatedOne("ElectronicText", true) + break + case "SUMMARY": + summaryContent = it.getRelatedOne("ToContent", true) + dataResource = summaryContent.getRelatedOne("DataResource", true) + summaryText = dataResource.getRelatedOne("ElectronicText", true) + break + case "IMAGE": + imageContent = it.getRelatedOne("ToContent", true) + break + } + } + + Map resultMap = [blogContentId: parameters.blogContentId, + contentId : content.contentId, + contentName : content.contentName, + description : content.description, + statusId : content.statusId] + if (imageContent) { + resultMap.templateDataResourceId = content.dataResourceId + resultMap.imageContentId = imageContent.contentId + resultMap.imageDataResourceId = imageContent.dataResourceId + } + if (mainContent) { + resultMap.articleData = articleText.textData + resultMap.articleContentId = mainContent.contentId + resultMap.articleDataResourceId = mainContent.dataResourceId + } + if (summaryContent) { + resultMap.summaryData = summaryText.textData + resultMap.summaryContentId = summaryContent.contentId + resultMap.summaryDataResourceId = summaryContent.dataResourceId + } + return success(resultMap) +} + +/** + * Update a existing Blog Entry + */ +def updateBlogEntry() { + Map blog = run service: "getBlogEntry", with: parameters + if (['contentName', 'description', 'summaryData', 'templateDataResourceId', 'statusId'] + .stream().anyMatch { blog[it] != parameters[it] }) { + run service: "updateContent", with: [* : parameters, + dataResourceId: parameters.templateDataResourceId] + if (parameters.statusId != blog.statusId + && blog.imageContentId) { + delegator.storeByCondition("Content", [statusId: parameters.statusId], + EntityCondition.makeCondition("contentId", blog.imageContentId)) + } + } + + if (!blog.articleText && parameters.articleData) { + run service: "createTextContent", + with: [ + dataResourceTypeId : "ELECTRONIC_TEXT", + contentPurposeTypeId: "ARTICLE", + dataTemplateTypeId : "NONE", + mapKey : "MAIN", + ownerContentId : parameters.blogContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentAssocTypeId : "SUB_CONTENT", + textData : parameters.articleData, + contentIdFrom : blog.contentId, + partyId : userLogin.partyId, + mapKey : "ARTICLE"] + } + if (blog.articleData && parameters.articleData != blog.articleData) { + run service: 'updateElectronicText', with: [dataResourceId: blog.articleDataResourceId, + textData : parameters.articleData] + } + if (!blog.summaryData && parameters.summaryData) { + run service: "createTextContent", + with: [ + dataResourceTypeId: "ELECTRONIC_TEXT", + dataTemplateTypeId: "NONE", + mapKey : "SUMMARY", + ownerContentId : parameters.blogContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentAssocTypeId: "SUB_CONTENT", + textData : parameters.summaryData, + contentIdFrom : blog.contentId, + partyId : userLogin.partyId] + } + if (blog.summaryData && parameters.summaryData != blog.summaryData) { + run service: 'updateElectronicText', with: [dataResourceId: blog.summaryDataResourceId, + textData : parameters.summaryData] + } + + if (parameters._uploadedFile_fileName) { + if (blog.imageContentId) { + EntityCondition condition = new EntityConditionBuilder().AND() { + EQUALS(contentId: blog.contentId) + EQUALS(contentIdTo: blog.imageContentId) + EQUALS(mapKey: "IMAGE") + EQUALS(thruDate: null) + } + delegator.storeByCondition("ContentAssoc", [thruDate: UtilDateTime.nowTimestamp()], condition) + } + run service: "createContentFromUploadedFile", + with: [ + isPublic : "Y", + dataTemplateTypeId : "NONE", + mapKey : "IMAGE", + dataResourceTypeId : "LOCAL_FILE", + contentAssocTypeId : "SUB_CONTENT", + ownerContentId : parameters.blogContentId, + contentName : parameters.contentName, + description : parameters.description, + statusId : parameters.statusId, + contentIdFrom : blog.contentId, + partyId : userLogin.partyId, + uploadedFile : parameters.uploadedFile, + _uploadedFile_fileName : parameters._uploadedFile_fileName, + _uploadedFile_contentType: parameters._uploadedFile_contentType] + } + return success([blogContentId: parameters.blogContentId, contentId: blog.contentId]) +} + +/** + * Get blog entries that the user owns or are published + * @return + */ +def getOwnedOrPublishedBlogEntries() { + List blogList = [] + from("ContentAssocViewTo") + .where(contentIdStart: parameters.contentId, + caContentAssocTypeId: "PUBLISH_LINK") + .orderBy("-caFromDate") + .filterByDate() + .cache() + .queryList() + .each { + Map serviceResult = run service: "genericContentPermission", + with: [* : it.getAllFields(), + ownerContentId: parameters.contentId, + mainAction : "VIEW"] + if (!serviceResult.hasPermission) { + serviceResult = run service: "genericContentPermission", + with: [* : it.getAllFields(), + ownerContentId: parameters.contentId, + mainAction : "UPDATE"] + } + if (serviceResult.hasPermission) { + blogList << it + } + } + return success([blogList : blogList, + blogContentId: parameters.blogContentId]) +} \ No newline at end of file