View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de 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.genericattributes.modules.forms.ocr.service;
35  
36  
37  import java.util.ArrayList;
38  import java.util.Arrays;
39  import java.util.List;
40  import java.util.regex.Pattern;
41  import java.util.stream.Collectors;
42  
43  import fr.paris.lutece.plugins.genericattributes.business.ITypeDocumentOcrProvider;
44  import fr.paris.lutece.portal.service.util.AppPropertiesService;
45  import fr.paris.lutece.util.ReferenceItem;
46  import fr.paris.lutece.util.ReferenceList;
47  
48  
49  /**
50   * 
51   * OcrProvider : provides ocr RIB support for Generic Attributes
52   * 
53   */
54  public class OcrRibProvider implements ITypeDocumentOcrProvider
55  {
56      private static final long serialVersionUID = 6224042984367506762L;
57      private static final String PROPERTY_KEY = "genericattributes-ocr.RIB.key";
58      private static final String PROPERTY_DISPLAYED_NAME = "genericattributes-ocr.RIB.displayName";
59      private static final String PROPERTY_AUTHORIZED_ENTRY_TYPE = "genericattributes-ocr.RIB.authorizedEntryType";
60      
61      /**
62       * {@inheritDoc}
63       */
64      public String getKey( )
65      {
66          return AppPropertiesService.getProperty( PROPERTY_KEY );
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      public String getDisplayedName( )
73      {
74          return AppPropertiesService.getProperty( PROPERTY_DISPLAYED_NAME );
75      }
76  
77      /**
78       * {@inheritDoc}
79       */
80      public ReferenceItem toRefItem( )
81      {
82          ReferenceItem refItem = new ReferenceItem( );
83  
84          refItem.setCode( getKey( ) );
85          refItem.setName( getDisplayedName( ) );
86  
87          return refItem;
88      }
89  
90      /**
91       * {@inheritDoc}
92       */
93      @Override
94      public String toString( )
95      {
96          return "Ocr RIB Provider";
97      }
98  
99      /**
100      * {@inheritDoc}
101      */
102 	@Override
103 	public Object getParameter(int nKey) {
104 		// TODO Auto-generated method stub
105 		return null;
106 	}
107 
108 	/**
109      * {@inheritDoc}
110      */
111 	@Override
112 	public ReferenceList getListField() {
113 		ReferenceList refListField = new ReferenceList( );
114 		
115 		//TODO récupérer la liste des champs
116 		refListField.addItem(0, "Rib result");
117 		refListField.addItem(1, "Code Banque");
118 		refListField.addItem(2, "Code Guichet");
119 		refListField.addItem(3, "Account number");
120 		refListField.addItem(4, "Clé RIB");
121 		refListField.addItem(5, "IBAN");
122 		refListField.addItem(6, "BIC");
123 		refListField.addItem(7, "RIB Address");
124 		
125 		return refListField;
126 	}
127 
128 	/**
129      * {@inheritDoc}
130      */
131 	@Override
132 	public ReferenceItem getFieldById(int idField) {
133 		return getListField().get(idField);
134 	}
135 
136 	/**
137      * {@inheritDoc}
138      */
139 	@Override
140 	public List<Integer> getAuthorizedEntryType() {
141 		String strAuthorizedEntryType = AppPropertiesService.getProperty( PROPERTY_AUTHORIZED_ENTRY_TYPE );
142 		Pattern pattern = Pattern.compile("-");
143 		return pattern.splitAsStream(strAuthorizedEntryType).map(Integer::valueOf).collect(Collectors.toList());
144 	}
145 }