<?xml version="1.0"?>
<workflow-definition
	xmlns="urn:liferay.com:liferay-workflow_7.1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:liferay.com:liferay-workflow_7.1.0 http://www.liferay.com/dtd/liferay-workflow-definition_7_1_0.xsd">
	<name>Agenzia Notizie Invio Email al Pubblica</name>
	<description>Al pubblica invia una mail a tutti i contatti.</description>
	<version>1</version>
	<state>
		<name>created</name>
		<metadata>
			<![CDATA[{"xy":[36,51]}]]>
		</metadata>
		<initial>true</initial>
		<transitions>
			<transition>
				<name>publish</name>
				<target>publish</target>
			</transition>
		</transitions>
	</state>
	<task>
		<name>publish</name>
		<metadata>
			<![CDATA[{"xy":[168,36]}]]>
		</metadata>
		<actions>
			<notification>
				<name>Publish Notification</name>
				<template>${userName} sent you a ${entryType} for review in the workflow.</template>
				<template-language>freemarker</template-language>
				<notification-type>email</notification-type>
				<notification-type>user-notification</notification-type>
				<recipients receptionType="to">
					<assignees/>
				</recipients>
				<execution-type>onAssignment</execution-type>
			</notification>
			<notification>
				<name>Publish Completion Notification</name>
				<template>
					<![CDATA[Your submission was reviewed
					
					
					<#if taskComments?has_content> and the reviewer applied the following ${taskComments}</#if>.]]>
				</template>
				<template-language>freemarker</template-language>
				<notification-type>email</notification-type>
				<recipients receptionType="to">
					<scripted-recipient>
					  <script>						  
						<![CDATA[
							import com.liferay.dynamic.data.lists.service.DDLRecordLocalServiceUtil;
							import com.liferay.dynamic.data.lists.model.DDLRecord;
							import com.liferay.portal.kernel.workflow.WorkflowConstants;
							import com.liferay.portal.kernel.dao.orm.QueryUtil;
							import java.util.List;
							
							List<DDLRecord> records = DDLRecordLocalServiceUtil.getRecords(36839, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
							for (DDLRecord questionRecord : records) {
							  try {
								questionRecord.getFieldType("Email").toString();
								
							  } catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							  }
							}
							
						   ]]>
						   </script>
					  <script-language>groovy</script-language>
				  </scripted-recipient>
				</recipients>
				<execution-type>onExit</execution-type>
			</notification>
		</actions>
		<assignments>
			<user/>
		</assignments>
		<transitions>
			<transition>
				<name>approve</name>
				<target>approved</target>
			</transition>
		</transitions>
	</task>
	<state>
		<name>approved</name>
		<metadata>
			<![CDATA[
				{"xy":[380,51]}
			]]>
		</metadata>
		<actions>
			<action>
				<name>approve</name>
				<script>
					<![CDATA[
						import com.liferay.portal.kernel.workflow.WorkflowStatusManagerUtil;
						import com.liferay.portal.kernel.workflow.WorkflowConstants;

						WorkflowStatusManagerUtil.updateStatus(WorkflowConstants.getLabelStatus("approved"), workflowContext);
					]]>
				</script>
				<script-language>groovy</script-language>
				<execution-type>onEntry</execution-type>
			</action>
		</actions>
	</state>
</workflow-definition>