1 /* 2 * Copyright (c) 2002-2023, City of Paris 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 9 * 1. Redistributions of source code must retain the above copyright notice 10 * and the following disclaimer. 11 * 12 * 2. Redistributions in binary form must reproduce the above copyright notice 13 * and the following disclaimer in the documentation and/or other materials 14 * provided with the distribution. 15 * 16 * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its 17 * contributors may be used to endorse or promote products derived from 18 * this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE 24 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 * 32 * License 1.0 33 */ 34 package fr.paris.lutece.plugins.document.business.rules; 35 36 import fr.paris.lutece.plugins.document.service.DocumentEvent; 37 import fr.paris.lutece.plugins.document.service.DocumentException; 38 import fr.paris.lutece.portal.business.user.AdminUser; 39 import fr.paris.lutece.portal.service.i18n.Localizable; 40 41 import java.util.Locale; 42 43 import javax.servlet.http.HttpServletRequest; 44 45 /** 46 * Interface of rules that can be applied on documents by the RuleEngine 47 */ 48 public interface Rule extends Localizable 49 { 50 //////////////////////////////////////////////////////////////////////////// 51 // Methods implemented by AbstractRule 52 53 /** 54 * Initialize the rule 55 */ 56 void init( ); 57 58 /** 59 * Sets the Rule Id 60 * 61 * @param nId 62 * The rule Id 63 */ 64 void setId( int nId ); 65 66 /** 67 * Gets the Rule Id 68 * 69 * @return the Rule Id 70 */ 71 int getId( ); 72 73 /** 74 * Sets the RuleTypeId 75 * 76 * @param strId 77 * The Rule type Id 78 */ 79 void setRuleTypeId( String strId ); 80 81 /** 82 * Gets the Rule Type Id 83 * 84 * @return the Rule Type Id 85 */ 86 String getRuleTypeId( ); 87 88 /** 89 * Gets a specific attribute by its name 90 * 91 * @param strAttributeName 92 * The attribute name 93 * @return The attribute value 94 */ 95 String getAttribute( String strAttributeName ); 96 97 /** 98 * Sets a specific rule attribute 99 * 100 * @param strAttributeName 101 * The attribute name 102 * @param strAttributeValue 103 * The attribute value 104 */ 105 void setAttribute( String strAttributeName, String strAttributeValue ); 106 107 /** 108 * Reads rule attributes 109 * 110 * @param request 111 * The HTTP request 112 */ 113 void readAttributes( HttpServletRequest request ); 114 115 //////////////////////////////////////////////////////////////////////////// 116 // Method specific to the rule 117 118 /** 119 * Execute the rule 120 * 121 * @param event 122 * The document event 123 * @throws DocumentException 124 * raise when error occurs in event or rule 125 */ 126 void apply( DocumentEvent event ) throws DocumentException; 127 128 /** 129 * Check the rule 130 * 131 * @return null if rule is valid, message if rule not valid 132 */ 133 String validateRule( ); 134 135 /** 136 * Return the HTML form containing specific fields of the rule 137 * 138 * @param user 139 * The current user 140 * @param locale 141 * The Locale 142 * @return The Create HTML form 143 */ 144 String getCreateForm( AdminUser user, Locale locale ); 145 146 /** 147 * Gives all specific attributes of the rule 148 * 149 * @return A string array containing all attributes names 150 */ 151 String [ ] getAttributesList( ); 152 153 /** 154 * Gets the Rule definition 155 * 156 * @return The Rule definition 157 */ 158 String getRule( ); 159 160 /** 161 * Gets the current user 162 * 163 * @return the current user 164 */ 165 AdminUser getUser( ); 166 167 /** 168 * true if the user is authorized to view the rule 169 * 170 * @param user 171 * the current user 172 * @return true if the user is authorized to view the rule 173 */ 174 boolean isAuthorized( AdminUser user ); 175 176 /** 177 * set the admin user who use the rule 178 * 179 * @param user 180 * the admin user who use the rule 181 * 182 */ 183 void setUser( AdminUser user ); 184 185 /** 186 * Gets the Rule name key 187 * 188 * @return The Rule name key 189 */ 190 String getNameKey( ); 191 }