View Javadoc
1   package fr.ifremer.dali.service.control;
2   
3   /*
4    * #%L
5    * Dali :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  import com.google.common.collect.Multimap;
27  import fr.ifremer.dali.dto.configuration.control.ControlRuleDTO;
28  import fr.ifremer.dali.dto.configuration.control.PreconditionRuleDTO;
29  import fr.ifremer.dali.dto.configuration.control.RuleListDTO;
30  import fr.ifremer.dali.dto.data.survey.SurveyDTO;
31  import fr.ifremer.dali.dto.referential.pmfm.QualitativeValueDTO;
32  import fr.ifremer.dali.dto.system.extraction.PmfmPresetDTO;
33  import fr.ifremer.dali.vo.PresetVO;
34  import fr.ifremer.quadrige3.core.dao.technical.factorization.CombinationList;
35  import fr.ifremer.quadrige3.core.dao.technical.factorization.pmfm.AllowedQualitativeValuesMap;
36  import fr.ifremer.quadrige3.core.security.AuthenticationInfo;
37  import org.apache.commons.lang3.mutable.MutableInt;
38  import org.springframework.security.access.prepost.PreAuthorize;
39  import org.springframework.transaction.annotation.Transactional;
40  
41  import java.util.Collection;
42  import java.util.List;
43  
44  /**
45   * Rules control service.
46   */
47  public interface RuleListService {
48  
49      /**
50       * Recupere une liste de regle de controle
51       *
52       * @param ruleListCode une regle de controle
53       * @return a {@link RuleListDTO} object.
54       */
55      @Transactional(readOnly = true)
56      RuleListDTO getRuleList(String ruleListCode);
57  
58      /**
59       * Recupere toute la liste de regles de controle
60       *
61       * @return a {@link List} object.
62       */
63      @Transactional(readOnly = true)
64      List<RuleListDTO> getAllRuleLists();
65  
66      @Transactional(readOnly = true)
67      List<RuleListDTO> getRuleListsForProgram(String programCode);
68  
69      /**
70       * Check the rule list code exists in database
71       * @param ruleListCode the rule list code to check
72       * @return true if rule list code exists
73       */
74      @Transactional(readOnly = true)
75      boolean ruleListCodeExists(String ruleListCode);
76  
77      /**
78       * <p>saveRuleLists.</p>
79       *
80       * @param authenticationInfo authentication info
81       * @param ruleLists a {@link List} object.
82       */
83      @Transactional()
84      @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
85      void saveRuleLists(AuthenticationInfo authenticationInfo, List<? extends RuleListDTO> ruleLists);
86  
87      /**
88       * Delete a list of rules (as well as the included rules)
89       *  @param authenticationInfo authentication info
90       * @param ruleListCodes a {@link List} object.
91       */
92      @Transactional()
93      @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
94      void deleteRuleLists(AuthenticationInfo authenticationInfo, List<String> ruleListCodes);
95  
96      /**
97       * <p>duplicateRuleList.</p>
98       *
99       * @param ruleList a {@link RuleListDTO} object.
100      * @param newCode a {@link String} object.
101      * @param isDuplicateRulesEnabled if true rules included are also duplicated
102      * @return duplicated ruleList
103      */
104     @Transactional(readOnly = true)
105     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
106     RuleListDTO duplicateRuleList(RuleListDTO ruleList, String newCode, boolean isDuplicateRulesEnabled);
107 
108     /**
109      * Instanciates a new ControlRuleDTO with default values without saving it
110      *
111      * @param ruleList rule list used to initiate the control rule (code, ...)
112      * @return a newly instanciated control rule
113      */
114     @PreAuthorize("hasPermission(null, T(fr.ifremer.quadrige3.core.security.QuadrigeUserAuthority).USER)")
115     ControlRuleDTO newControlRule(RuleListDTO ruleList);
116 
117     /**
118      * Check the rule code exists in database
119      * @param ruleCode the rule code to check
120      * @return true if rule code exists
121      */
122     @Transactional(readOnly = true)
123     boolean ruleCodeExists(String ruleCode);
124 
125     /**
126      * Get a new unique MutableInt
127      * @return a MutableInt
128      */
129     MutableInt getUniqueMutableIndex();
130 
131     /**
132      * Get the next non existing rule code with radical and a incremental-able suffix
133      *
134      * @param targetName the base name
135      * @param suffixIndex the suffix
136      * @return the next rule code
137      */
138     @Transactional(readOnly = true)
139     String getNextRuleCode(String targetName, MutableInt suffixIndex);
140 
141     /**
142      * Retrieve all active preconditioned rules for a survey.
143      * Used, for example, to filter values on measurements against another measurement value
144      *
145      * @param survey the survey
146      * @return existing preconditioned rules for survey
147      */
148     @Transactional(readOnly = true)
149     List<ControlRuleDTO> getPreconditionedControlRulesForSurvey(SurveyDTO survey);
150 
151     /**
152      * Retrieve all active preconditioned rules for a list of programs.
153      * Used, for example, to filter values on measurements against another measurement value
154      *
155      * @param programCodes the program codes
156      * @return existing preconditioned rules for programs
157      */
158     @Transactional(readOnly = true)
159     List<ControlRuleDTO> getPreconditionedControlRulesForProgramCodes(List<String> programCodes);
160 
161     /**
162      * Build allowed qualitative values for a list of pmfm against a source value, regarding the precondition rules.
163      * Result is stored in the AllowedQualitativeValuesMap object
164      *
165      * @param sourcePmfmId                the source pmfm id
166      * @param sourceValue                 the source value
167      * @param targetPmfmIds               the target pmfm id list
168      * @param preconditions               the precondition rule list
169      * @param allowedQualitativeValuesMap the result map
170      */
171     void buildAllowedValuesByPmfmId(int sourcePmfmId,
172                                     Object sourceValue,
173                                     Collection<Integer> targetPmfmIds,
174                                     Collection<PreconditionRuleDTO> preconditions,
175                                     AllowedQualitativeValuesMap allowedQualitativeValuesMap);
176 
177     /**
178      * Build a multi map of qualitative values correspondence from the rule preconditions
179      *
180      * @param preconditions rule preconditions
181      * @return a multimap
182      */
183     @Transactional(readOnly = true)
184     Multimap<QualitativeValueDTO, QualitativeValueDTO> buildQualitativeValueMapFromPreconditions(Collection<PreconditionRuleDTO> preconditions);
185 
186     /**
187      * Build qualitative rule preconditions from a multi map of qualitative values correspondence
188      *
189      * @param rule     target rule
190      * @param multimap the multimap
191      */
192     @Transactional(readOnly = true)
193     void buildPreconditionsFromQualitativeValueMap(ControlRuleDTO rule, Multimap<QualitativeValueDTO, QualitativeValueDTO> multimap);
194 
195     CombinationList buildAndFactorizeAllowedValues(PresetVO preset, Multimap<Integer, PreconditionRuleDTO> preconditionRulesByPmfmId, int maxCombinationCount);
196 
197     CombinationList buildAndFactorizeAllowedValues(Collection<PmfmPresetDTO> pmfmPresets, Multimap<Integer, PreconditionRuleDTO> preconditionRulesByPmfmId, int maxCombinationCount);
198 }