KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > ui > web > admin > approval > ApprovalDataVOView


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13
14 package org.ejbca.ui.web.admin.approval;
15
16 import java.io.Serializable JavaDoc;
17 import java.io.UnsupportedEncodingException JavaDoc;
18 import java.security.cert.CertificateException JavaDoc;
19 import java.text.DateFormat JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.Date JavaDoc;
22 import java.util.List JavaDoc;
23
24 import javax.ejb.EJBException JavaDoc;
25 import javax.faces.application.Application;
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28
29 import org.apache.log4j.Logger;
30 import org.ejbca.core.model.approval.ApprovalDataText;
31 import org.ejbca.core.model.approval.ApprovalDataVO;
32 import org.ejbca.core.model.approval.ApprovalRequest;
33 import org.ejbca.core.model.approval.approvalrequests.DummyApprovalRequest;
34 import org.ejbca.core.model.log.Admin;
35 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper;
36 import org.ejbca.util.Base64;
37 import org.ejbca.util.CertTools;
38
39
40 /**
41  * Class representing the view of one ApprovalDataVO data
42  *
43  * @author Philip Vendil
44  *
45  * $id$
46  */

47 public class ApprovalDataVOView implements Serializable JavaDoc{
48     
49     private static final Logger log = Logger.getLogger(ApprovalDataVOView.class);
50     
51     private ApprovalDataVO data;
52     
53     private boolean initialized = false;
54     
55     public ApprovalDataVOView( ApprovalDataVO data){
56         this.data= data;
57         initialized = true;
58     }
59     
60     /**
61      * Constructor used for initialization of dummy values.
62      */

63     public ApprovalDataVOView(){}{}
64     
65     public String JavaDoc getRequestDate(){
66       DateFormat JavaDoc dateformat = DateFormat.getDateTimeInstance();
67       if(!initialized){
68         return dateformat.format(new Date JavaDoc());
69       }
70       
71       return dateformat.format(data.getRequestDate());
72     }
73     
74     public String JavaDoc getExpireDate(){
75       DateFormat JavaDoc dateformat = DateFormat.getDateTimeInstance();
76       if(!initialized){
77          return dateformat.format(new Date JavaDoc());
78        }
79       
80        return dateformat.format(data.getExpireDate());
81     }
82     
83     public String JavaDoc getCaName(){
84         if(!initialized){
85           return "TestCA";
86         }
87         
88         EjbcaJSFHelper helpBean = EjbcaJSFHelper.getBean();
89         if(data.getCAId() == ApprovalDataVO.ANY_CA){
90             return helpBean.getEjbcaWebBean().getText("ANYCA", true);
91         }
92         
93             
94         return helpBean.getCAAdminSession().getCAInfo(helpBean.getAdmin(), data.getCAId()).getName();
95     }
96     
97     public String JavaDoc getEndEntityProfileName(){
98         if(!initialized){
99           return "TestProfile";
100         }
101         EjbcaJSFHelper helpBean = EjbcaJSFHelper.getBean();
102         if(data.getEndEntityProfileiId() == ApprovalDataVO.ANY_ENDENTITYPROFILE){
103             return helpBean.getEjbcaWebBean().getText("ANYENDENTITYPROFILE", true);
104         }
105         return helpBean.getRaAdminSession().getEndEntityProfileName(helpBean.getAdmin(), data.getEndEntityProfileiId());
106     }
107     
108     public String JavaDoc getRemainingApprovals(){
109         if(!initialized){
110               return "1";
111         }
112         
113         return "" +data.getRemainingApprovals();
114     }
115     
116     
117     public String JavaDoc getApproveActionName(){
118         if(!initialized){
119               return "DummyAction";
120         }
121         return EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(ApprovalDataVO.APPROVALTYPENAMES[data.getApprovalRequest().getApprovalType()], true);
122     }
123     
124     public String JavaDoc getRequestAdminName(){
125         String JavaDoc retval;
126         if(!initialized){
127               return "DummyAdmin";
128         }
129         
130         if(data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER){
131           String JavaDoc dn = data.getApprovalRequest().getRequestAdminCert().getSubjectDN().toString();
132           String JavaDoc o = CertTools.getPartFromDN(dn, "O");
133           if(o==null){
134             o="";
135           }else{
136             o = ", " + o;
137           }
138           
139           retval = CertTools.getPartFromDN(dn, "CN") + o;
140         }else{
141             retval = EjbcaJSFHelper.getBean().getEjbcaWebBean().getText("CLITOOL", true);
142         }
143         
144        log.debug("getRequestAdminName " + retval);
145        return retval;
146     }
147     
148     public String JavaDoc getStatus(){
149         if(!initialized){
150               return "EXPIRED";
151         }
152         
153         FacesContext context = FacesContext.getCurrentInstance();
154         Application app = context.getApplication();
155         ValueBinding binding = app.createValueBinding("#{approvalActionSession}");
156         Object JavaDoc value = binding.getValue(context);
157         ApproveActionSessionBean approvalActionSession = (ApproveActionSessionBean) value;
158
159         
160       return (String JavaDoc) approvalActionSession.getStatusText().get(new Integer JavaDoc(data.getStatus()));
161     }
162     
163
164
165     /**
166      * @return
167      */

168     public ApprovalDataVO getApproveActionDataVO() {
169         if(!initialized){
170               try {
171                 return new ApprovalDataVO(1,1, ApprovalDataVO.APPROVALTYPE_DUMMY, 0,0,"","",ApprovalDataVO.STATUS_WAITINGFORAPPROVAL,new ArrayList JavaDoc(),new DummyApprovalRequest(new Admin(CertTools.getCertfromByteArray(ApprovalDataVOView.dummycert)),null,ApprovalDataVO.ANY_ENDENTITYPROFILE,ApprovalDataVO.ANY_CA,false),new Date JavaDoc(),new Date JavaDoc(),2);
172             } catch (CertificateException JavaDoc e) {
173                 log.error(e);
174             }
175         }
176         return data;
177     }
178     
179     public int getApprovalId() {
180         if(!initialized){
181               return 1;
182         }
183         return data.getApprovalId();
184     }
185     
186     
187     /**
188      * Constructs javazcript that opens up a new window and opens up actionview there
189      * @return
190      */

191     public String JavaDoc getApproveActionWindowLink(){
192         String JavaDoc link = EjbcaJSFHelper.getBean().getEjbcaWebBean().getBaseUrl() + EjbcaJSFHelper.getBean().getEjbcaWebBean().getGlobalConfiguration().getAdminWebPath() + "approval/approveaction.jsf?uniqueId=" + data.getId();
193         
194         return "window.open('"+link+"', 'ViewApproveAction', 'width=1000,height=800,scrollbars=yes,toolbar=no,resizable=yes').focus()";
195     }
196
197     
198     public boolean getShowViewRequestorCertLink(){
199         return data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER;
200     }
201     
202     public String JavaDoc getViewRequestorCertLink(){
203         String JavaDoc retval = "";
204         if(data.getApprovalRequest().getRequestAdmin().getAdminType() == Admin.TYPE_CLIENTCERT_USER){
205             String JavaDoc link;
206             try {
207                 link = EjbcaJSFHelper.getBean().getEjbcaWebBean().getBaseUrl() + EjbcaJSFHelper.getBean().getEjbcaWebBean().getGlobalConfiguration().getAdminWebPath()
208                 + "viewcertificate.jsp?certsernoparameter=" + java.net.URLEncoder.encode(data.getReqadmincertsn() + "," + data.getReqadmincertissuerdn(),"UTF-8");
209             } catch (UnsupportedEncodingException JavaDoc e) {
210                 throw new EJBException JavaDoc(e);
211             }
212             
213             retval = "viewcert('" + link + "')";
214         }
215         
216         return retval;
217     }
218
219     public List JavaDoc getTextComparisonList(){
220         ArrayList JavaDoc textComparisonList = new ArrayList JavaDoc();
221         if(!initialized){
222               return textComparisonList;
223         }
224         
225         if(data.getApprovalRequest().getApprovalRequestType() == ApprovalRequest.REQUESTTYPE_COMPARING){
226           List JavaDoc newTextRows = data.getApprovalRequest().getNewRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin());
227           List JavaDoc orgTextRows = data.getApprovalRequest().getOldRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin());
228           int size = newTextRows.size();
229           if(orgTextRows.size() > size){
230             size = orgTextRows.size();
231           }
232           
233           for(int i=0;i<size;i++){
234             String JavaDoc orgString ="";
235             try{
236               orgString = translateApprovalDataText((ApprovalDataText) orgTextRows.get(i));
237             }catch(ArrayIndexOutOfBoundsException JavaDoc e){
238               // Do nothing orgstring should be "";
239
}
240             String JavaDoc newString ="";
241             try{
242               newString = translateApprovalDataText((ApprovalDataText) newTextRows.get(i));
243             }catch(ArrayIndexOutOfBoundsException JavaDoc e){
244               // Do nothing orgstring should be "";
245
}
246             textComparisonList.add(new TextComparisonView(orgString, newString));
247           }
248                         
249         }else{
250             List JavaDoc newTextRows = data.getApprovalRequest().getNewRequestDataAsText(EjbcaJSFHelper.getBean().getAdmin());
251             int size = newTextRows.size();
252             for(int i=0;i<size;i++){
253               textComparisonList.add(new TextComparisonView(null, translateApprovalDataText((ApprovalDataText) newTextRows.get(i))));
254             }
255         }
256
257         
258         return textComparisonList;
259     }
260     
261     private String JavaDoc translateApprovalDataText(ApprovalDataText data){
262         String JavaDoc retval = "";
263         if(data.isHeaderTranslateable()){
264             retval = EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(data.getHeader(), true);
265         }else{
266             retval = data.getHeader();
267         }
268         
269         if(data.isDataTranslatable()){
270             retval += " : " + EjbcaJSFHelper.getBean().getEjbcaWebBean().getText(data.getData(), true);
271         }else{
272             retval += " : " + data.getData();
273         }
274         
275         return retval;
276     }
277     
278     private static byte[] dummycert = Base64.decode(("MIIDATCCAmqgAwIBAgIIczEoghAwc3EwDQYJKoZIhvcNAQEFBQAwLzEPMA0GA1UE"
279             + "AxMGVGVzdENBMQ8wDQYDVQQKEwZBbmFUb20xCzAJBgNVBAYTAlNFMB4XDTAzMDky"
280             + "NDA2NDgwNFoXDTA1MDkyMzA2NTgwNFowMzEQMA4GA1UEAxMHcDEydGVzdDESMBAG"
281             + "A1UEChMJUHJpbWVUZXN0MQswCQYDVQQGEwJTRTCBnTANBgkqhkiG9w0BAQEFAAOB"
282             + "iwAwgYcCgYEAnPAtfpU63/0h6InBmesN8FYS47hMvq/sliSBOMU0VqzlNNXuhD8a"
283             + "3FypGfnPXvjJP5YX9ORu1xAfTNao2sSHLtrkNJQBv6jCRIMYbjjo84UFab2qhhaJ"
284             + "wqJgkQNKu2LHy5gFUztxD8JIuFPoayp1n9JL/gqFDv6k81UnDGmHeFcCARGjggEi"
285             + "MIIBHjAPBgNVHRMBAf8EBTADAQEAMA8GA1UdDwEB/wQFAwMHoAAwOwYDVR0lBDQw"
286             + "MgYIKwYBBQUHAwEGCCsGAQUFBwMCBggrBgEFBQcDBAYIKwYBBQUHAwUGCCsGAQUF"
287             + "BwMHMB0GA1UdDgQWBBTnT1aQ9I0Ud4OEfNJkSOgJSrsIoDAfBgNVHSMEGDAWgBRj"
288             + "e/R2qFQkjqV0pXdEpvReD1eSUTAiBgNVHREEGzAZoBcGCisGAQQBgjcUAgOgCQwH"
289             + "Zm9vQGZvbzASBgNVHSAECzAJMAcGBSkBAQEBMEUGA1UdHwQ+MDwwOqA4oDaGNGh0"
290             + "dHA6Ly8xMjcuMC4wLjE6ODA4MC9lamJjYS93ZWJkaXN0L2NlcnRkaXN0P2NtZD1j"
291             + "cmwwDQYJKoZIhvcNAQEFBQADgYEAU4CCcLoSUDGXJAOO9hGhvxQiwjGD2rVKCLR4"
292             + "emox1mlQ5rgO9sSel6jHkwceaq4A55+qXAjQVsuy76UJnc8ncYX8f98uSYKcjxo/"
293             + "ifn1eHMbL8dGLd5bc2GNBZkmhFIEoDvbfn9jo7phlS8iyvF2YhC4eso8Xb+T7+BZ"
294             + "QUOBOvc=").getBytes());
295     
296 }
297
Popular Tags