1 /* 2 * Copyright (c) 2002-2020, 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 /** 47 * Interface of rules that can be applied on documents by the RuleEngine 48 */ 49 public interface Rule extends Localizable 50 { 51 //////////////////////////////////////////////////////////////////////////// 52 // Methods implemented by AbstractRule 53 54 /** 55 * Initialize the rule 56 */ 57 void init( ); 58 59 /** 60 * Sets the Rule Id 61 * @param nId The rule Id 62 */ 63 void setId( int nId ); 64 65 /** 66 * Gets the Rule Id 67 * @return the Rule Id 68 */ 69 int getId( ); 70 71 /** 72 * Sets the RuleTypeId 73 * @param strId The Rule type Id 74 */ 75 void setRuleTypeId( String strId ); 76 77 /** 78 * Gets the Rule Type Id 79 * @return the Rule Type Id 80 */ 81 String getRuleTypeId( ); 82 83 /** 84 * Gets a specific attribute by its name 85 * @param strAttributeName The attribute name 86 * @return The attribute value 87 */ 88 String getAttribute( String strAttributeName ); 89 90 /** 91 * Sets a specific rule attribute 92 * @param strAttributeName The attribute name 93 * @param strAttributeValue The attribute value 94 */ 95 void setAttribute( String strAttributeName, String strAttributeValue ); 96 97 /** 98 * Reads rule attributes 99 * @param request The HTTP request 100 */ 101 void readAttributes( HttpServletRequest request ); 102 103 //////////////////////////////////////////////////////////////////////////// 104 // Method specific to the rule 105 106 /** 107 * Execute the rule 108 * @param event The document event 109 * @throws DocumentException raise when error occurs in event or rule 110 */ 111 void apply( DocumentEvent event ) throws DocumentException; 112 113 /** 114 * Check the rule 115 * @return null if rule is valid, message if rule not valid 116 */ 117 String validateRule( ); 118 119 /** 120 * Return the HTML form containing specific fields of the rule 121 * @param user The current user 122 * @param locale The Locale 123 * @return The Create HTML form 124 */ 125 String getCreateForm( AdminUser user, Locale locale ); 126 127 /** 128 * Gives all specific attributes of the rule 129 * @return A string array containing all attributes names 130 */ 131 String[] getAttributesList( ); 132 133 /** 134 * Gets the Rule definition 135 * @return The Rule definition 136 */ 137 String getRule( ); 138 139 /** 140 * Gets the current user 141 * @return the current user 142 */ 143 AdminUser getUser( ); 144 145 /** 146 * true if the user is authorized to view the rule 147 * @param user the current user 148 * @return true if the user is authorized to view the rule 149 */ 150 boolean isAuthorized( AdminUser user ); 151 152 /** 153 * set the admin user who use the rule 154 * @param user the admin user who use the rule 155 * 156 */ 157 void setUser( AdminUser user ); 158 159 /** 160 * Gets the Rule name key 161 * @return The Rule name key 162 */ 163 String getNameKey( ); 164 }