blob: a35451d859dd2beb2298551d5f2f39d95288ff27 [file] [log] [blame]
<?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="genCompDocInstance" short-description="Create CompDoc">
<entity-one entity-name="Content" value-field="rootTemplateContent">
<field-map field-name="contentId" from-field="parameters.instanceOfContentId"/>
</entity-one>
<log message="genCompDocInstance> rootTemplateContent: ${rootTemplateContent}" level="info"/>
<!-- if not passed in, get latest template contentRevisionSeqId from db -->
<if-empty field="parameters.contentRevisionSeqId">
<entity-condition entity-name="ContentRevision" list="contentRevisionList">
<condition-list>
<condition-expr field-name="contentId" operator="equals" from-field="parameters.instanceOfContentId"/>
</condition-list>
<order-by field-name="-contentRevisionSeqId"/>
</entity-condition>
<if-not-empty field="contentRevisionList">
<set from-field="contentRevisionList[0].contentRevisionSeqId" field="contentRevisionSeqId"/>
<else>
<set value="" field="contentRevisionSeqId"/>
</else>
</if-not-empty>
<else>
<set from-field="parameters.contentRevisionSeqId" field="contentRevisionSeqId"/>
</else>
</if-empty>
<log message="genCompDocInstance> contentRevisionSeqId: ${contentRevisionSeqId}" level="info"/>
<make-value entity-name="Content" value-field="rootInstanceContent"/>
<if-empty field="parameters.rootInstanceContentId">
<sequenced-id sequence-name="Content" field="rootInstanceContent.contentId"/>
<log level="info" message="genCompDocInstance 2> rootInstanceContent: ${rootInstanceContent}"/>
<else>
<!-- check to see if it already exists, error if so -->
<entity-one entity-name="Content" value-field="existingContent">
<field-map field-name="contentId" from-field="parameters.rootInstanceContentId"/>
</entity-one>
<if-not-empty field="existingContent">
<add-error>
<fail-property resource="ContentUiLabels" property="ContentCompDocInstanceAlreadyExists"/>
</add-error>
<check-errors/>
</if-not-empty>
<set from-field="parameters.rootInstanceContentId" field="rootInstanceContent.contentId"/>
</else>
</if-empty>
<!-- populate fields -->
<set from-field="parameters.contentName" field="rootInstanceContent.contentName" default-value="${rootTemplateContent.contentName}"/>
<now-timestamp field="nowTimestamp"/>
<set from-field="parameters.instanceOfContentId" field="rootInstanceContent.instanceOfContentId"/>
<set from-field="nowTimestamp" field="rootInstanceContent.createdDate"/>
<set from-field="nowTimestamp" field="rootInstanceContent.lastModifiedDate"/>
<set from-field="rootInstanceContent.createdByUserLogin" field="parameters.userLogin.userLoginId"/>
<set from-field="rootInstanceContent.lastModifiedByUserLogin" field="parameters.userLogin.userLoginId"/>
<set value="COMPDOC_INSTANCE" field="rootInstanceContent.contentTypeId"/>
<create-value value-field="rootInstanceContent"/>
<log message="genCompDocInstance 3> rootInstanceContent: ${rootInstanceContent}" level="info"/>
<field-to-result field="rootInstanceContent.contentId" result-name="contentId"/>
<set from-field="parameters.instanceOfContentId" field="parentTemplateContentId"/>
<set from-field="rootInstanceContent.contentId" field="parentInstanceContentId"/>
<log message="genCompDocInstance 4> parentTemplateContentId: ${parentTemplateContentId}" level="info"/>
<log message="genCompDocInstance 5> parentInstanceContentId: ${parentInstanceContentId}" level="info"/>
<set from-field="parentInstanceContentId" field="revisionMap.contentId"/>
<set from-field="parentInstanceContentId" field="revisionMap.itemContentId"/>
<set from-field="parameters.userLogin" field="revisionMap.userLogin"/>
<log level="info" message="revisionMap : ${revisionMap}"/>
<call-service service-name="persistContentRevisionAndItem" in-map-name="revisionMap">
<result-to-result result-name="contentRevisionSeqId"/>
<result-to-field result-name="contentRevisionSeqId"/>
</call-service>
<!-- This is for traversing tree and creating empty instance content entities
<call-simple-method method-name="genInstanceChildCompDocs"/>
-->
<set from-field="revisionMap.contentId" field="cloneMap.contentId"/>
<set from-field="contentRevisionSeqId" field="cloneMap.contentRevisionSeqId"/>
<set from-field="parameters.userLogin" field="cloneMap.userLogin"/>
<!-- Not for INSTANCE CompDocs. They will be generated on demand.
<call-service service-name="cloneContentApprovals" in-map-name="cloneMap">
</call-service>
-->
</simple-method>
<simple-method method-name="genInstanceChildCompDocs" short-description="Create CompDoc">
<set from-field="parentTemplateContentId" field="thisTemplateContentId"/>
<set from-field="parentInstanceContentId" field="thisInstanceContentId"/>
<log message="genInstanceChildCompDocs 0> thisTemplateContentId: ${thisTemplateContentId}" level="info"/>
<log message="genInstanceChildCompDocs 1> thisInstanceContentId: ${thisInstanceContentId}" level="info"/>
<entity-condition entity-name="ContentAssoc" list="contentAssocList">
<condition-list combine="and">
<condition-expr field-name="contentIdTo" operator="equals" from-field="thisTemplateContentId"/>
<condition-expr field-name="contentAssocTypeId" operator="equals" value="COMPDOC_PART"/>
<condition-list combine="or">
<condition-expr field-name="thruDate" operator="greater" from-field="nowTimestamp"/>
<condition-expr field-name="thruDate" operator="equals" value=""/>
</condition-list>
</condition-list>
</entity-condition>
<log message="genInstanceChildCompDocs 1> contentAssocList: ${contentAssocList}" level="info"/>
<iterate list="contentAssocList" entry="templateContentAssoc">
<clone-value value-field="templateContent" new-value-field="instanceContent"/>
<sequenced-id sequence-name="Content" field="instanceContent.contentId"/>
<set value="TEMPLATE" field="instanceContent.contentTypeId"/>
<create-value value-field="instanceContent"/>
<make-value entity-name="ContentAssoc" value-field="instanceContentAssoc"/>
<set from-field="thisInstanceContentId" field="instanceContentAssoc.contentIdTo"/>
<set from-field="instanceContent.contentId" field="instanceContentAssoc.contentId"/>
<set value="COMPDOC_PART" field="instanceContentAssoc.contentAssocTypeId"/>
<set from-field="nowTimestamp" field="instanceContentAssoc.fromDate"/>
<create-value value-field="instanceContent"/>
<!-- recursively call this method -->
<set from-field="templateContentAssoc.contentId" field="parentTemplateContentId"/>
<set from-field="instanceContent.contentId" field="parentInstanceContentId"/>
<call-simple-method method-name="genInstanceChildCompDocs"/>
</iterate>
</simple-method>
<simple-method method-name="persistCompDoc" short-description="Create CompDoc">
<!-- create the compdoc Content entity -->
<set-service-fields service-name="persistContentAndAssoc" map="parameters" to-map="persistMap"/>
<if-not-empty field="parameters.mimeTypeId">
<if>
<condition>
<or>
<if-compare field="parameters.mimeTypeId" operator="equals" value="application/msword"/>
<if-compare field="parameters.mimeTypeId" operator="equals" value="application/pdf"/>
<if-compare field="parameters.mimeTypeId" operator="equals" value="application/octet-stream"/>
</or>
</condition>
<then>
<set value="IMAGE_OBJECT" field="persistMap.dataResourceTypeId"/>
</then>
<else-if>
<condition>
<or>
<if-compare field="parameters.mimeTypeId" operator="equals" value="image/jpeg"/>
<if-compare field="parameters.mimeTypeId" operator="equals" value="image/gif"/>
<if-compare field="parameters.mimeTypeId" operator="equals" value="image/tiff"/>
<if-compare field="parameters.mimeTypeId" operator="equals" value="image/png"/>
</or>
</condition>
<then>
<set value="IMAGE_OBJECT" field="persistMap.dataResourceTypeId"/>
</then>
</else-if>
<else-if>
<condition>
<if-compare field="parameters.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey"/>
</condition>
<then>
<set value="SURVEY" field="persistMap.dataResourceTypeId"/>
</then>
</else-if>
<else-if>
<condition>
<if-compare field="parameters.mimeTypeId" operator="equals" value="application/vnd.ofbiz.survey.response"/>
</condition>
<then>
<set value="SURVEY_RESPONSE" field="persistMap.dataResourceTypeId"/>
</then>
</else-if>
<else>
<set value="ELECTRONIC_TEXT" field="persistMap.dataResourceTypeId"/>
</else>
</if>
</if-not-empty>
<set from-field="parameters.userLogin" field="persistMap.userLogin"/>
<log level="info" message="persistMap : ${persistMap}"/>
<call-service service-name="persistContentAndAssoc" in-map-name="persistMap">
<results-to-map map-name="pResults"/>
</call-service>
<!-- put all the result fields in this service's result -->
<field-to-result field="pResults.contentRevisionSeqId" result-name="contentRevisionSeqId"/>
<field-to-result field="pResults.contentId" result-name="contentId"/>
<field-to-result field="pResults.dataResourceId" result-name="dataResourceId"/>
<field-to-result field="pResults.drDataResourceId" result-name="drDataResourceId"/>
<field-to-result field="pResults.caContentIdTo" result-name="caContentIdTo"/>
<field-to-result field="pResults.caContentId" result-name="caContentId"/>
<field-to-result field="pResults.caContentAssocTypeId" result-name="caContentAssocTypeId"/>
<field-to-result field="pResults.caFromDate" result-name="caFromDate"/>
<field-to-result field="pResults.caSequenceNum" result-name="caSequenceNum"/>
<field-to-result field="pResults.roleTypeList" result-name="roleTypeList"/>
<log level="info" message="pResults : ${pResults}"/>
<if-not-empty field="pResults.contentIdTo">
<set from-field="pResults.contentIdTo" field="resequenceMap.contentIdTo"/>
<set value="COMPDOC_PART" field="resequenceMap.typeList[]"/>
<set value="10" field="resequenceMap.seqInc" type="Integer"/>
<call-service service-name="resequence" in-map-name="resequenceMap"/>
</if-not-empty>
<if>
<condition>
<or>
<if-compare field="persistMap.contentTypeId" operator="equals" value="COMPDOC_TEMPLATE"/>
<if-compare field="persistMap.contentTypeId" operator="equals" value="COMPDOC_INSTANCE"/>
<if-compare field="persistMap.contentTypeId" operator="equals" value="TEMPLATE"/>
<if-compare field="persistMap.contentTypeId" operator="equals" value="DOCUMENT"/>
</or>
</condition>
<then>
<!-- if no rootTemplateContentId exists, this must be a root op, so set contentId = itemContentId -->
<set from-field="pResults.contentId" field="revisionMap.contentId"/>
</then>
</if>
<set field="revisionMap.contentId" from-field="parameters.rootContentId" default-value="${pResults.caContentIdTo}"/>
<set field="revisionMap.contentId" from-field="revisionMap.contentId" default-value="${pResults.contentId}"/>
<set field="revisionMap.itemContentId" from-field="pResults.contentId"/>
<set field="revisionMap.userLogin" from-field="parameters.userLogin"/>
<log level="info" message="revisionMap : ${revisionMap}"/>
<call-service service-name="persistContentRevisionAndItem" in-map-name="revisionMap">
<result-to-result result-name="contentRevisionSeqId"/>
<result-to-field result-name="contentRevisionSeqId"/>
</call-service>
<if>
<condition>
<or>
<if-compare field="persistMap.contentTypeId" operator="equals" value="COMPDOC_TEMPLATE"/>
<if-compare field="persistMap.contentTypeId" operator="equals" value="TEMPLATE"/>
</or>
</condition>
<then>
<set field="cloneMap.contentId" from-field="revisionMap.contentId"/>
<set field="cloneMap.contentRevisionSeqId" from-field="contentRevisionSeqId"/>
<set field="cloneMap.userLogin" from-field="parameters.userLogin"/>
<call-service service-name="cloneTemplateContentApprovals" in-map-name="cloneMap"/>
</then>
</if>
</simple-method>
<simple-method method-name="persistCompDocContent" short-description="Persist a CompDoc DataResource and data">
<entity-one entity-name="Content" value-field="content" use-cache="false"/>
<set from-field="content.dataResourceId" field="oldDataResourceId"/>
<log level="info" message="persistCompDocContent(0).content : ${content}"/>
<set-service-fields service-name="persistDataResourceAndData" map="parameters" to-map="persistMap"/>
<clear-field field="persistMap.dataResourceId"/>
<clear-field field="persistMap.drDataResourceId"/>
<log level="info" message="persistCompDocContent(0.2).persistMap : ${persistMap}"/>
<call-service service-name="persistDataResourceAndData" in-map-name="persistMap">
<result-to-field result-name="dataResourceId" field="newDataResourceId"/>
</call-service>
<log level="info" message="persistCompDocContent(1).newDataResourceId : ${newDataResourceId}"/>
<set from-field="newDataResourceId" field="content.dataResourceId"/>
<store-value value-field="content"/>
<set from-field="parameters.rootContentId" field="revisionMap.contentId"/>
<set from-field="parameters.contentId" field="revisionMap.itemContentId"/>
<set from-field="parameters.userLogin" field="revisionMap.userLogin"/>
<set from-field="oldDataResourceId" field="revisionMap.oldDataResourceId"/>
<set from-field="newDataResourceId" field="revisionMap.newDataResourceId"/>
<log level="info" message="persistCompDocContent(2).revisionMap : ${revisionMap}"/>
<call-service service-name="persistContentRevisionAndItem" in-map-name="revisionMap">
<result-to-result result-name="contentRevisionSeqId"/>
<result-to-field result-name="contentRevisionSeqId"/>
</call-service>
<log level="info" message="persistCompDocContent(3).contentRevisionSeqId : ${contentRevisionSeqId}"/>
</simple-method>
<simple-method method-name="persistCompDocPdf2Survey" short-description="Upload/save PDF, create Survey, populate Content">
<set field="pdfMap.contentTypeId" value="TEMPLATE"/>
<set field="pdfMap.dataResourceTypeId" value="IMAGE_OBJECT"/>
<set field="pdfMap.mimeTypeId" value="application/vnd.ofbiz.survey"/>
<set field="pdfMap.drMimeTypeId" value="application/vnd.ofbiz.survey"/>
<set field="pdfMap.imageData" from-field="parameters.imageData"/>
<set field="pdfMap._imageData_contentType" from-field="parameters._imageData_contentType"/>
<set field="pdfMap._imageData_fileName" from-field="parameters._imageData_fileName"/>
<set field="pdfMap.contentName" from-field="parameters.pdfName"/>
<log level="info" message="persistCompDocPdf2Survey(1).pdfMap : ${pdfMap}"/>
<call-service service-name="persistContentAndAssoc" in-map-name="pdfMap">
<result-to-field result-name="contentId" field="acroFormContentId"/>
</call-service>
<log level="info" message="persistCompDocPdf2Survey(2).acroFormContentId : ${acroFormContentId}"/>
<set field="acroMap.contentId" from-field="acroFormContentId"/>
<call-service service-name="buildSurveyFromPdf" in-map-name="acroMap">
<result-to-field result-name="surveyId" field="surveyId"/>
</call-service>
<log level="info" message="persistCompDocPdf2Survey(3).surveyId : ${surveyId}"/>
<set-service-fields service-name="persistCompDocContent" map="parameters" to-map="persistMap"/>
<set field="persistMap.relatedDetailId" from-field="surveyId"/>
<set field="persistMap.mimeTypeId" value="application/vnd.ofbiz.survey"/>
<clear-field field="persistMap._imageData_contentType"/>
<clear-field field="persistMap._imageData_fileName"/>
<clear-field field="persistMap.imageData"/>
<log level="info" message="persistCompDocPdf2Survey(4)persistMap : ${persistMap}"/>
<call-service service-name="persistCompDocContent" in-map-name="persistMap"></call-service>
</simple-method>
<!-- =============== =============== =============== --><!-- =============== Revision Services =============== --><!-- =============== =============== =============== -->
<!-- Methods for ContentRevision and ContentRevisionItem -->
<simple-method method-name="persistContentRevisionAndItem" short-description="Update ContentRevision and ContentRevisionItem">
<entity-condition entity-name="ContentRevision" list="contentRevisionList">
<condition-expr field-name="contentId" operator="equals" from-field="parameters.contentId"/>
<order-by field-name="contentRevisionSeqId DESC"/>
</entity-condition>
<log level="info" message="contentRevisionList: ${contentRevisionList}"/>
<if-not-empty field="contentRevisionList">
<set field="newEntity" from-field="contentRevisionList[0]"/>
<set field="incrementedSeq" from-field="newEntity.contentRevisionSeqId"/>
<else>
<make-value entity-name="ContentRevision" value-field="newEntity"/>
</else>
</if-not-empty>
<log level="info" message="incrementedSeq(0): ${incrementedSeq}"/>
<log level="info" message="ContentRevision(0): ${newEntity}"/>
<if-not-empty field="incrementedSeq">
<calculate field="incrementedSeq" type="Long">
<calcop operator="add">
<calcop operator="get" field="incrementedSeq"/>
<number value="1"/>
</calcop>
</calculate>
<else>
<set field="incrementedSeq" value="1" type="Long"/>
</else>
</if-not-empty>
<calculate field="numericPadding" type="Integer">
<number value="6"/>
</calculate>
<call-class-method method-name="padNumberWithLeadingZeros" class-name="org.apache.ofbiz.content.compdoc.CompDocEvents" ret-field="paddedSeqId">
<field field="incrementedSeq" type="Long"/>
<field field="numericPadding" type="Integer"/>
</call-class-method>
<log level="info" message="incrementedSeq(1): ${incrementedSeq}"/>
<log level="info" message="numericPadding(1): ${numericPadding}"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<set field="newEntity.contentRevisionSeqId" from-field="paddedSeqId"/>
<log level="info" message="ContentRevision(1): ${newEntity}"/>
<create-value value-field="newEntity"/>
<if-not-empty field="parameters.itemContentId">
<make-value entity-name="ContentRevisionItem" value-field="newEntity"/>
<set-pk-fields map="parameters" value-field="newEntity"/>
<set field="newEntity.contentRevisionSeqId" from-field="paddedSeqId"/>
<set-nonpk-fields map="parameters" value-field="newEntity"/>
<create-value value-field="newEntity"/>
<log level="info" message="ContentRevisionItem(1): ${newEntity}"/>
</if-not-empty>
<field-to-result field="paddedSeqId" result-name="contentRevisionSeqId"/>
<log level="info" message="paddedSeqId: ${paddedSeqId}"/>
</simple-method>
<simple-method method-name="getRevisionDataResource" short-description="Get version of DataResource that fits overall revision">
<entity-condition entity-name="ContentRevisionItem" list="contentRevisionItems" use-cache="true">
<condition-list combine="and">
<condition-expr field-name="contentId" from-field="parameters.contentId" operator="equals"/>
<condition-expr field-name="itemContentId" from-field="parameters.itemContentId" operator="equals"/>
<condition-expr field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId" operator="less-equals"/>
</condition-list>
<order-by field-name="-contentRevisionSeqId"/>
</entity-condition>
<if-not-empty field="contentRevisionItems">
<set field="contentRevisionItem" from-field="contentRevisionItems[0]"/>
<entity-one entity-name="Content" value-field="content" use-cache="true">
<field-map field-name="contentId" from-field="contentRevisionItem.itemContentId"/>
</entity-one>
<if-not-empty field="content">
<entity-one entity-name="DataResource" value-field="dataResource" use-cache="true">
<field-map field-name="dataResourceId" from-field="content.dataResourceId"/>
</entity-one>
<field-to-result field="dataResource" result-name="dataResource"/>
</if-not-empty>
</if-not-empty>
</simple-method>
<simple-method method-name="getRevisionItemDataResource" short-description="Get version of DataResource that fits overall revision">
<entity-one entity-name="ContentRevisionItem" value-field="contentRevisionItem" use-cache="true">
<field-map field-name="contentId" from-field="parameters.contentId"/>
<field-map field-name="itemContentId" from-field="parameters.itemContentId"/>
<field-map field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId"/>
</entity-one>
<entity-one entity-name="Content" value-field="content" use-cache="true">
<field-map field-name="contentId" from-field="contentRevisionItem.itemContentId"/>
</entity-one>
<if-not-empty field="content">
<entity-one entity-name="DataResource" value-field="dataResource" use-cache="true">
<field-map field-name="dataResourceId" from-field="content.dataResourceId"/>
</entity-one>
<field-to-result field="dataResource" result-name="dataResource"/>
</if-not-empty>
</simple-method>
<!-- =============== =============== =============== --><!-- =============== Approval Services =============== --><!-- =============== =============== =============== -->
<simple-method method-name="getApprovalsWithPermissions" short-description="Get ContentApprovals for approval process">
<!-- this seems like an awkward way to get the previous ContentApproval entities, but
if you are not sure what previous contentRevisionSeqId is, then it is necessary to ask.
I think it is worth not assuming it is 1 less than the passed in value, just for ruggedness.
-->
<entity-condition entity-name="MaxContentApprovalView" list="instanceApprovalList" use-cache="false">
<condition-list>
<condition-expr field-name="contentId" from-field="parameters.rootContentId" operator="equals"/>
<condition-expr field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId" operator="less-equals"/>
</condition-list>
<select-field field-name="contentId"/>
<select-field field-name="partyId"/>
<select-field field-name="roleTypeId"/>
<select-field field-name="maxContentRevisionSeqId"/>
</entity-condition>
<log level="info" message="instanceApprovalList: ${instanceApprovalList}"/>
<log level="info" message="rootContentId: ${parameters.rootContentId}"/>
<log level="info" message="contentRevisionSeqId: ${parameters.contentRevisionSeqId}"/>
<set field="inMap2.userLogin" from-field="userLogin"/>
<!-- since we don't have a primary key from above, go get one -->
<iterate list="instanceApprovalList" entry="maxContentApproval">
<log level="info" message="maxContentApproval: ${maxContentApproval}"/>
<entity-condition entity-name="ContentApproval" list="contentApprovalList2" use-cache="false">
<condition-list>
<condition-expr field-name="contentId" from-field="maxContentApproval.contentId" operator="equals"/>
<condition-expr field-name="contentRevisionSeqId" from-field="maxContentApproval.maxContentRevisionSeqId" operator="equals"/>
<condition-expr field-name="partyId" from-field="maxContentApproval.partyId" operator="equals" ignore-if-empty="true"/>
<condition-expr field-name="roleTypeId" from-field="maxContentApproval.roleTypeId" operator="equals" ignore-if-empty="true"/>
</condition-list>
<order-by field-name="-sequenceNum"/>
</entity-condition>
<log level="info" message="contentApprovalList2: ${contentApprovalList2}"/>
<if-not-empty field="contentApprovalList2">
<set from-field="contentApprovalList2[0].contentApprovalId" field="contentApprovalId"/>
<set from-field="contentApprovalList2[0]" field="contentApproval"/>
<log level="info" message="contentApproval: ${contentApproval}"/>
<set field="contentApprovalList[]" from-field="contentApproval"/>
</if-not-empty>
<!--
<set field="inMap2.contentApprovalId" from-field="contentApproval.contentApprovalId"/>
<call-service service-name="hasApprovalPermission" in-map-name="inMap2">
<result-to-field result-name="approvalPermExists"/>
</call-service>
<set field="gvAndPerm" from-field="contentApproval"/>
<set field="gvAndPerm.permission" from-field="openApprovalExists"/>
<set field="contentApprovalList[]" from-field="gvAndPerm"/>
-->
</iterate>
<field-to-result field="contentApprovalList"/>
</simple-method>
<simple-method method-name="cloneTemplateContentApprovals" short-description="Bump the previous ContentApproval approvals up to current CDI">
<log level="info" message="cloneTemplateContentApprovals-parameters: ${parameters}"/>
<entity-condition entity-name="MaxContentApprovalView" list="maxContentApprovalList">
<condition-list combine="and">
<condition-expr field-name="contentId" operator="equals" from-field="parameters.contentId"/>
</condition-list>
<select-field field-name="maxContentRevisionSeqId"/>
<select-field field-name="contentId"/>
<select-field field-name="partyId"/>
<select-field field-name="roleTypeId"/>
<order-by field-name="-maxContentRevisionSeqId"/>
</entity-condition>
<set from-field="maxContentApprovalList[0].maxContentRevisionSeqId" field="latestContentRevisionSeqId"/>
<log level="info" message="latestContentRevisionSeqId 0aa: ${latestContentRevisionSeqId}"/>
<entity-and entity-name="ContentApproval" list="templateContentApprovalList">
<field-map field-name="contentId" from-field="parameters.contentId"/>
<field-map field-name="contentRevisionSeqId" from-field="latestContentRevisionSeqId"/>
</entity-and>
<log level="info" message="templateContentApprovalList 0aa: ${templateContentApprovalList}"/>
<iterate list="templateContentApprovalList" entry="templateContentApproval">
<clone-value value-field="templateContentApproval" new-value-field="contentApproval"/>
<set from-field="parameters.contentRevisionSeqId" field="contentApproval.contentRevisionSeqId"/>
<set from-field="parameters.contentId" field="contentApproval.contentId"/>
<sequenced-id sequence-name="ContentApproval" field="contentApproval.contentApprovalId"/>
<clear-field field="contentApproval.approvalStatusId"/>
<log level="info" message="contentApproval 2b: ${contentApproval}"/>
<create-value value-field="contentApproval"/>
</iterate>
</simple-method>
<simple-method method-name="cloneInstanceContentApprovals" short-description="Bump the previous ContentApproval approvals up to current CDI">
<entity-one entity-name="Content" value-field="content">
<field-map field-name="contentId" from-field="parameters.contentId"/>
</entity-one>
<set from-field="parameters.contentId" field="thisContentId"/>
<set from-field="parameters.contentRevisionSeqId" field="thisContentRevisionSeqId"/>
<log level="info" message="cloneContentApprovals(0)- thisContentRevisionSeqId : ${thisContentRevisionSeqId}"/>
<log level="info" message="cloneContentApprovals(0b)- parameters : ${parameters} "/>
<now-timestamp field="nowTimestamp"/>
<!-- get previous list of ContentApproval -->
<entity-condition entity-name="MaxContentApprovalView" list="maxContentApprovalList">
<condition-list combine="and">
<condition-expr field-name="contentId" operator="equals" from-field="thisContentId"/>
<condition-expr field-name="contentRevisionSeqId" operator="less" from-field="thisContentRevisionSeqId" ignore-if-null="true"/>
</condition-list>
<select-field field-name="maxContentRevisionSeqId"/>
<select-field field-name="contentId"/>
<select-field field-name="partyId"/>
<select-field field-name="roleTypeId"/>
<order-by field-name="-maxContentRevisionSeqId"/>
</entity-condition>
<set from-field="maxContentApprovalList[0].maxContentRevisionSeqId" field="maxContentRevisionSeqId"/>
<if>
<condition>
<if-empty field="maxContentRevisionSeqId"/>
</condition>
<then>
<!-- if an instance track, check to see if there any new or deleted records on the template -->
<set from-field="content.instanceOfContentId" field="rootTemplateContentId"/>
<log level="info" message="rootTemplateContentId 0aa: ${rootTemplateContentId}"/>
<entity-condition entity-name="ContentRevision" list="templateContentRevisionList" use-cache="true">
<condition-list>
<condition-expr field-name="contentId" from-field="rootTemplateContentId" operator="equals"/>
</condition-list>
<order-by field-name="-contentRevisionSeqId"/>
</entity-condition>
<set from-field="templateContentRevisionList[0].contentRevisionSeqId" field="latestContentRevisionSeqId"/>
<log level="info" message="latestContentRevisionSeqId 0aa: ${latestContentRevisionSeqId}"/>
<entity-and entity-name="ContentApproval" list="templateContentApprovalList">
<field-map field-name="contentId" from-field="rootTemplateContentId"/>
<field-map field-name="contentRevisionSeqId" from-field="latestContentRevisionSeqId"/>
</entity-and>
<log level="info" message="templateContentApprovalList 0aa: ${templateContentApprovalList}"/>
<iterate list="templateContentApprovalList" entry="templateContentApproval">
<clone-value value-field="templateContentApproval" new-value-field="contentApproval"/>
<set from-field="thisContentRevisionSeqId" field="contentApproval.contentRevisionSeqId"/>
<set from-field="thisContentId" field="contentApproval.contentId"/>
<sequenced-id sequence-name="ContentApproval" field="contentApproval.contentApprovalId"/>
<set value="CNTAP_READY" field="contentApproval.approvalStatusId"/>
<set from-field="nowTimestamp" field="contentApproval.approvalDate"/>
<log level="info" message="contentApproval 2b: ${contentApproval}"/>
<create-value value-field="contentApproval"/>
</iterate>
</then>
<else>
<set from-field="thisContentId" field="map.contentId"/>
<set from-field="thisContentRevisionSeqId" field="map.contentRevisionSeqId"/>
<call-service service-name="getFinalApprovalStatus" in-map-name="map">
<result-to-field result-name="approvalStatusId" field="finalApprovalStatusId"/>
<result-to-field result-name="contentApprovalList" field="contentApprovalList"/>
</call-service>
<!-- determine status of previous approvals --><!-- finalApprovalStatusId is the applicable status from previous approvals -->
<log level="info" message="cloneContentApprovals(2)- finalApprovalStatusId : ${finalApprovalStatusId} "/>
<log level="info" message="cloneContentApprovals(2b)- contentApprovalList : ${contentApprovalList} "/>
<!-- conditionally set the contentApprovalId status of each entity -->
<iterate list="contentApprovalList" entry="existingContentApproval">
<clone-value value-field="existingContentApproval" new-value-field="contentApproval"/>
<set from-field="thisContentRevisionSeqId" field="contentApproval.contentRevisionSeqId"/>
<sequenced-id sequence-name="ContentApproval" field="contentApproval.contentApprovalId"/>
<set from-field="nowTimestamp" field="contentApproval.approvalDate"/>
<if-compare field="content.contentTypeId" operator="equals" value="COMPDOC_INSTANCE">
<if>
<!-- not rejected, soft rejected or approved, reset to ready -->
<condition>
<or>
<if-compare field="finalApprovalStatusId" operator="equals" value="CNTAP_REJECTED"/>
<if-compare field="finalApprovalStatusId" operator="equals" value="CNTAP_APPROVED"/>
</or>
</condition>
<then>
<clear-field field="contentApproval.approvalStatusId"/>
</then>
<else-if>
<!-- soft rejected, reset rejected (shouldn't be any) and soft rejected entities to ready -->
<condition>
<and>
<if-compare field="finalApprovalStatusId" operator="equals" value="CNTAP_SOFT_REJ"/>
<or>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_SOFT_REJ"/>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_REJECTED"/>
</or>
</and>
</condition>
<then>
<set value="CNTAP_READY" field="contentApproval.approvalStatusId"/>
</then>
</else-if>
<else-if>
<condition>
<and>
<!-- soft rejected and current record is not soft/rejected, keep currentstatus -->
<if-compare field="finalApprovalStatusId" operator="equals" value="CNTAP_SOFT_REJ"/>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_APPROVED"/>
</and>
</condition>
<then>
<set value="CNTAP_APPROVED" field="contentApproval.approvalStatusId"/>
</then>
</else-if>
</if>
<else>
<set value="CNTAP_READY" field="contentApproval.approvalStatusId"/>
</else>
</if-compare>
<log level="info" message="contentApproval 2: ${contentApproval}"/>
<create-value value-field="contentApproval"/>
</iterate>
<!-- if an instance track, check to see if there any new or deleted records on the template -->
<set from-field="content.instanceOfContentId" field="rootTemplateContentId"/>
<log level="info" message="rootTemplateContentId 0aa: ${rootTemplateContentId}"/>
<entity-condition entity-name="ContentRevision" list="templateContentRevisionList" use-cache="true">
<condition-list>
<condition-expr field-name="contentId" from-field="rootTemplateContentId" operator="equals"/>
</condition-list>
<order-by field-name="-contentRevisionSeqId"/>
</entity-condition>
<set from-field="templateContentRevisionList[0].contentRevisionSeqId" field="latestContentRevisionSeqId"/>
<log level="info" message="latestContentRevisionSeqId 0aa: ${latestContentRevisionSeqId}"/>
<entity-and entity-name="ContentApproval" list="templateContentApprovalList">
<field-map field-name="contentId" from-field="rootTemplateContentId"/>
<field-map field-name="contentRevisionSeqId" from-field="latestContentRevisionSeqId"/>
</entity-and>
<log level="info" message="templateContentApprovalList 0aa: ${templateContentApprovalList}"/>
<iterate list="templateContentApprovalList" entry="templateContentApproval">
<!-- look for this entity in newly created entities -->
<entity-condition entity-name="ContentApproval" list="newContentApprovalList">
<condition-list combine="and">
<condition-expr field-name="contentId" operator="equals" from-field="thisContentId"/>
<condition-expr field-name="contentRevisionSeqId" operator="equals" from-field="thisContentRevisionSeqId"/>
<condition-expr field-name="partyId" operator="equals" from-field="templateContentApproval.partyId" ignore-if-empty="true"/>
<condition-expr field-name="roleTypeId" operator="equals" from-field="templateContentApproval.roleTypeId" ignore-if-empty="true"/>
</condition-list>
</entity-condition>
<if-empty field="newContentApprovalList">
<clone-value value-field="templateContentApproval" new-value-field="contentApproval"/>
<set from-field="thisContentRevisionSeqId" field="contentApproval.contentRevisionSeqId"/>
<set field="contentApproval.contentId" from-field="thisContentId"/>
<sequenced-id sequence-name="ContentApproval" field="contentApproval.contentApprovalId"/>
<set field="contentApproval.approvalStatusId" value="CNTAP_READY"/>
<log level="info" message="contentApproval 2b: ${contentApproval}"/>
<create-value value-field="contentApproval"/>
</if-empty>
</iterate>
<!-- TODO: remove instance approvals that have been deleted from the template set -->
</else>
</if>
</simple-method>
<simple-method method-name="hasApprovalPermission" short-description="Determine ContentApproval permission from passed value">
<make-value entity-name="ContentApproval" value-field="contentApprovalPK"/>
<set field="contentApprovalPK.contentApprovalId" from-field="parameters.contentApprovalId"/>
<find-by-primary-key entity-name="ContentApproval" value-field="contentApproval" map="contentApprovalPK" use-cache="true"/>
<set field="partyId" from-field="parameters.userLogin.partyId"/>
<log level="info" message="contentApproval: ${contentApproval}"/>
<if-compare field="contentApproval.partyId" value="${partyId}" operator="equals">
<set field="approvalPermExists" value="true"/>
<log level="info" message="approvalPermExists: ${approvalPermExists}"/>
<field-to-result field="approvalPermExists" result-name="approvalPermExists"/>
<return/>
</if-compare>
<if-not-empty field="contentApproval.roleTypeId">
<now-timestamp field="nowTimestamp"/>
<entity-condition entity-name="ContentRole" list="contentRoleList">
<condition-list combine="and">
<condition-expr field-name="contentId" from-field="contentId" operator="equals"/>
<condition-expr field-name="partyId" from-field="partyId" operator="equals"/>
<condition-expr field-name="fromDate" from-field="nowTimestamp" operator="less-equals"/>
<condition-list combine="or">
<condition-expr field-name="thruDate" from-field="nowTimestamp" operator="greater"/>
<condition-expr field-name="thruDate" value="" operator="equals"/>
</condition-list>
</condition-list>
</entity-condition>
<if-not-empty field="contentRoleList">
<set field="approvalPermExists" value="true"/>
<field-to-result field="approvalPermExists" result-name="approvalPermExists"/>
<return/>
</if-not-empty>
</if-not-empty>
<set field="approvalPermExists" value="false"/>
<field-to-result field="approvalPermExists" result-name="approvalPermExists"/>
<return/>
</simple-method>
<simple-method method-name="prepForApproval" short-description="Set ContentApprovals for approval process">
<log level="info" message="got into prepForApproval- parameters: ${parameters}"/>
<set field="rootContentId" from-field="parameters.rootContentId"/>
<!-- bump CDI up one for new approval -->
<set field="context2.contentId" from-field="parameters.rootContentId"/>
<call-service service-name="persistContentRevisionAndItem" in-map-name="context2">
<result-to-field result-name="contentRevisionSeqId" field="contentRevisionSeqId"/>
<result-to-result result-name="contentRevisionSeqId" service-result-name="rootContentRevisionSeqId"/>
</call-service>
<log level="info" message="got into prepForApproval- contentRevisionSeqId: ${contentRevisionSeqId}"/>
<!-- create instance approval records for current CDI -->
<set from-field="rootContentId" field="context3.contentId"/>
<set from-field="contentRevisionSeqId" field="context3.contentRevisionSeqId"/>
<log level="info" message="got into prepForApproval(3)- context3: ${context3}"/>
<call-service service-name="cloneInstanceContentApprovals" in-map-name="context3"></call-service>
</simple-method>
<simple-method method-name="getFinalApprovalStatus" short-description="Check to see if any open approval conditions exist">
<!-- iterate thru most recent ContentApproval list and determine its ending status -->
<entity-and entity-name="ContentApproval" list="contentApprovalList">
<field-map field-name="contentId" from-field="parameters.contentId"/>
<field-map field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId"/>
<order-by field-name="sequenceNum"/>
</entity-and>
<if>
<condition>
<not>
<if-empty field="contentApprovalList"/>
</not>
</condition>
<then>
<set value="CNTAP_READY" field="finalApprovalStatusId"/>
<iterate list="contentApprovalList" entry="existingContentApproval">
<if>
<condition>
<or>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_SOFT_REJ"/>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_REJECTED"/>
</or>
</condition>
<then>
<set from-field="existingContentApproval.approvalStatusId" field="finalApprovalStatusId"/>
</then>
<else-if>
<condition>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_APPROVED"/>
</condition>
<then>
<set value="CNTAP_APPROVED" field="finalApprovalStatusId"/>
</then>
</else-if>
<else-if>
<condition>
<and>
<if-compare field="existingContentApproval.approvalStatusId" operator="equals" value="CNTAP_READY"/>
<if-compare field="finalApprovalStatusId" operator="equals" value="CNTAP_APPROVED"/>
</and>
</condition>
<then>
<set value="IN_PROCESS" field="finalApprovalStatusId"/>
</then>
</else-if>
</if>
</iterate>
<field-to-result field="finalApprovalStatusId" result-name="approvalStatusId"/>
<field-to-result field="contentApprovalList" result-name="contentApprovalList"/>
</then>
<else>
<set value="CNTAP_NOT_READY" field="finalApprovalStatusId"/>
<field-to-result field="finalApprovalStatusId" result-name="approvalStatusId"/>
</else>
</if>
</simple-method>
<simple-method method-name="checkForWaitingApprovals" short-description="Check to see if any approval conditions exist for the passed in user">
<set from-field="userLogin.partyId" field="partyId"/>
<entity-and entity-name="PartyRole" list="partyRoleList">
<field-map field-name="partyId" from-field="partyId"/>
</entity-and>
<log level="info" message="userLogin.partyId: ${partyId}"/>
<iterate list="partyRoleList" entry="partyRole">
<set from-field="partyRole.roleTypeId" field="roles[]"/>
</iterate>
<log level="info" message="roles: ${roles}"/>
<!-- find approvals belonging to roles that the user has or to the user -->
<entity-condition entity-name="MaxContentApprovalView" list="compdocApprovalList" use-cache="false">
<condition-list>
<condition-expr field-name="contentRevisionSeqId" from-field="parameters.contentRevisionSeqId" operator="less-equals" ignore-if-empty="true"/>
<condition-expr field-name="contentTypeId" operator="equals" value="COMPDOC_INSTANCE"/>
<condition-list combine="or">
<condition-expr field-name="partyId" operator="equals" from-field="partyId"/>
<condition-expr field-name="roleTypeId" operator="in" from-field="roles"/>
</condition-list>
</condition-list>
<select-field field-name="contentId"/>
<select-field field-name="contentTypeId"/>
<select-field field-name="partyId"/>
<select-field field-name="roleTypeId"/>
<select-field field-name="maxContentRevisionSeqId"/>
</entity-condition>
<log level="info" message="compdocApprovalList: ${compdocApprovalList}"/>
<!-- above query does not get contentApprovalId. For each row find it -->
<iterate list="compdocApprovalList" entry="maxContentApproval">
<log level="info" message="maxContentApproval: ${maxContentApproval}"/>
<entity-condition entity-name="ContentApproval" list="contentApprovalList2" use-cache="false">
<condition-list>
<condition-expr field-name="contentId" from-field="maxContentApproval.contentId" operator="equals"/>
<condition-expr field-name="contentRevisionSeqId" from-field="maxContentApproval.maxContentRevisionSeqId" operator="equals"/>
<condition-expr field-name="partyId" from-field="maxContentApproval.partyId" operator="equals" ignore-if-empty="true"/>
<condition-expr field-name="roleTypeId" from-field="maxContentApproval.roleTypeId" operator="equals" ignore-if-empty="true"/>
</condition-list>
<order-by field-name="-sequenceNum"/>
</entity-condition>
<log level="info" message="contentApprovalList2: ${contentApprovalList2}"/>
<if-not-empty field="contentApprovalList2">
<set from-field="contentApprovalList2[0].contentApprovalId" field="contentApprovalId"/>
<log level="info" message="contentApproval: ${contentApproval}"/>
<set field="contentApprovalIdList[]" from-field="contentApprovalId"/>
</if-not-empty>
</iterate>
<log level="info" message="contentApprovalIdList: ${contentApprovalIdList}"/>
<!-- find the entries that match the user's partyId or associated roleTypes -->
<entity-condition entity-name="ContentApproval" list="contentApprovalList">
<condition-list combine="and">
<condition-expr field-name="contentApprovalId" operator="in" from-field="contentApprovalIdList"/>
<condition-expr field-name="approvalStatusId" operator="equals" value="CNTAP_READY"/>
</condition-list>
</entity-condition>
<log level="info" message="contentApprovalList: ${contentApprovalList}"/>
<field-to-result field="contentApprovalList" result-name="contentApprovalList"/>
</simple-method>
<simple-method method-name="getMostRecentRevision" short-description="Look for most recent revision for contentId">
<entity-condition entity-name="ContentRevision" list="contentRevisions" use-cache="true">
<condition-list combine="and">
<condition-expr field-name="contentId" from-field="parameters.contentId" operator="equals"/>
</condition-list>
<order-by field-name="-contentRevisionSeqId"/>
</entity-condition>
<log level="info" message="contentRevisions: ${contentRevisions}"/>
<if-not-empty field="contentRevisions">
<set from-field="contentRevisions[0].contentRevisionSeqId" field="mostRecentRevisionSeqId"/>
</if-not-empty>
<field-to-result field="mostRecentRevisionSeqId" result-name="mostRecentRevisionSeqId"/>
</simple-method>
</simple-methods>