1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.participatoryideation.service.notify;
35
36 import java.util.Locale;
37
38 import javax.inject.Inject;
39 import javax.inject.Named;
40 import javax.servlet.http.HttpServletRequest;
41
42 import org.apache.commons.lang.StringUtils;
43
44 import fr.paris.lutece.plugins.participatoryideation.business.notify.TaskChangeProposalStatusConfig;
45 import fr.paris.lutece.plugins.participatoryideation.business.proposal.Proposal;
46 import fr.paris.lutece.plugins.participatoryideation.business.proposal.ProposalHome;
47 import fr.paris.lutece.plugins.participatoryideation.service.ProposalService;
48 import fr.paris.lutece.plugins.participatoryideation.service.SolrProposalIndexer;
49 import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
50 import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
51 import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
52 import fr.paris.lutece.plugins.workflowcore.service.task.SimpleTask;
53 import fr.paris.lutece.portal.service.i18n.I18nService;
54 import fr.paris.lutece.portal.service.spring.SpringContextService;
55
56
57
58
59
60
61 public class TaskChangeProposalStatus extends SimpleTask
62 {
63
64
65
66 public static final String CONFIG_SERVICE_BEAN_NAME = "participatoryideation.taskChangeProposalStatusConfigService";
67
68 private static final String BEAN_SOLR_PROPOSAL_INDEXER = "participatoryideation.solrProposalIndexer";
69
70
71 private static final String MESSAGE_UNPUBLISHED_PROPOSAL = "module.workflow.ideation.task_change_proposal_status.labelUnpublishedProposal";
72 private static final String MESSAGE_PUBLISHED_PROPOSAL = "module.workflow.ideation.task_change_proposal_status.labelPublishedProposal";
73 @Inject
74 private IResourceHistoryService _resourceHistoryService;
75 @Inject
76 @Named( CONFIG_SERVICE_BEAN_NAME )
77 private ITaskConfigService _taskChangeProposalStatusConfigService;
78
79 @Override
80 public void processTask( int nIdResourceHistory, HttpServletRequest request, Locale locale )
81 {
82 ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdResourceHistory );
83 TaskChangeProposalStatusConfig config = _taskChangeProposalStatusConfigService.findByPrimaryKey( this.getId( ) );
84
85 if ( ( config != null ) && ( resourceHistory != null ) && Proposal.WORKFLOW_RESOURCE_TYPE.equals( resourceHistory.getResourceType( ) ) )
86 {
87
88 Proposal proposal = ProposalHome.findByPrimaryKey( resourceHistory.getIdResource( ) );
89
90 if ( proposal != null )
91 {
92 proposal.setStatusPublic( Proposal.Status.getByValue( config.getProposalStatus( ) ) );
93 ProposalHome.updateBO( proposal );
94
95 SolrProposalIndexer solrProposalIndexer = SpringContextService.getBean( BEAN_SOLR_PROPOSAL_INDEXER );
96 if ( ProposalService.getInstance( ).isPublished( proposal ) )
97 {
98 solrProposalIndexer.writeProposal( proposal );
99 }
100 else
101 {
102 solrProposalIndexer.removeProposal( proposal );
103 }
104 }
105 }
106 }
107
108
109
110
111 @Override
112 public String getTitle( Locale locale )
113 {
114 TaskChangeProposalStatusConfig config = _taskChangeProposalStatusConfigService.findByPrimaryKey( this.getId( ) );
115
116 if ( ( config != null ) && ( config.getProposalStatus( ) != null ) )
117 {
118 return I18nService.getLocalizedString( Proposal.Status.getByValue( config.getProposalStatus( ) ).getLibelle( ), locale );
119 }
120
121 return StringUtils.EMPTY;
122 }
123
124
125
126
127 @Override
128 public void doRemoveConfig( )
129 {
130 _taskChangeProposalStatusConfigService.remove( this.getId( ) );
131 }
132 }