KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.ArrayList JavaDoc;
17 import java.util.HashMap JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20
21 import org.apache.log4j.Logger;
22 import org.ejbca.core.model.approval.AdminAlreadyApprovedRequestException;
23 import org.ejbca.core.model.approval.Approval;
24 import org.ejbca.core.model.approval.ApprovalDataVO;
25 import org.ejbca.core.model.approval.ApprovalException;
26 import org.ejbca.core.model.approval.ApprovalRequest;
27 import org.ejbca.core.model.approval.ApprovalRequestExecutionException;
28 import org.ejbca.core.model.approval.ApprovalRequestExpiredException;
29 import org.ejbca.core.model.authorization.AuthorizationDeniedException;
30 import org.ejbca.ui.web.admin.BaseManagedBean;
31 import org.ejbca.ui.web.admin.configuration.EjbcaJSFHelper;
32 import org.ejbca.ui.web.admin.configuration.EjbcaWebBean;
33 import org.ejbca.util.query.ApprovalMatch;
34 import org.ejbca.util.query.BasicMatch;
35 import org.ejbca.util.query.IllegalQueryException;
36 import org.ejbca.util.query.Query;
37
38
39 /**
40  * Seesion scoped bean for displaying information about an approval request.
41  *
42  * @author Philip Vendil
43  * @version $Id: ApproveActionSessionBean.java,v 1.3 2006/09/05 09:23:27 anatom Exp $
44  */

45 public class ApproveActionSessionBean extends BaseManagedBean {
46     private static final Logger log = Logger.getLogger(ApproveActionSessionBean.class);
47
48     private String JavaDoc comment = "";
49
50     public ApproveActionSessionBean() {
51         super();
52         
53         approveRequestData = new ApprovalDataVOView();
54     }
55
56
57     private HashMap JavaDoc statustext = null;
58     
59     public HashMap JavaDoc getStatusText(){
60         if(statustext == null){
61             EjbcaWebBean ejbcawebbean = EjbcaJSFHelper.getBean().getEjbcaWebBean();
62             statustext = new HashMap JavaDoc();
63             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_WAITINGFORAPPROVAL), ejbcawebbean.getText("WAITING", true));
64             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_EXPIRED), ejbcawebbean.getText("EXPIRED", true));
65             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_EXPIREDANDNOTIFIED), ejbcawebbean.getText("EXPIREDANDNOTIFIED", true));
66             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_EXECUTED), ejbcawebbean.getText("EXECUTED", true));
67             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_APPROVED), ejbcawebbean.getText("APPROVED", true));
68             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_REJECTED), ejbcawebbean.getText("REJECTED", true));
69             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_EXECUTIONFAILED), ejbcawebbean.getText("EXECUTIONFAILED", true));
70             statustext.put(new Integer JavaDoc(ApprovalDataVO.STATUS_EXECUTIONDENIED), ejbcawebbean.getText("EXECUTIONDENIED", true));
71         }
72         return statustext;
73     }
74
75     private ApprovalDataVOView approveRequestData;
76     
77     
78     public ApprovalDataVOView getApproveRequestData() {
79         return approveRequestData;
80     }
81     
82
83
84     public boolean isApprovalRequestComparable() {
85         return approveRequestData.getApproveActionDataVO().getApprovalRequest().getApprovalRequestType() == ApprovalRequest.REQUESTTYPE_COMPARING;
86         
87     }
88     
89
90
91    public String JavaDoc getWindowWidth(){
92      if(isApprovalRequestComparable()){
93        return "1000";
94      }
95      
96      return "600";
97    }
98    
99
100 public List JavaDoc getApprovalViews(){
101       List JavaDoc approvalViews = new ArrayList JavaDoc();
102      
103      if(approveRequestData != null &&
104         approveRequestData.getApproveActionDataVO().getApprovals() != null){
105         Iterator JavaDoc iter = approveRequestData.getApproveActionDataVO().getApprovals().iterator();
106         while(iter.hasNext())
107         {
108             approvalViews.add(new ApprovalView((Approval) iter.next()));
109         }
110       }
111       return approvalViews;
112    }
113    
114    public boolean isExistsApprovals(){
115       return approveRequestData.getApproveActionDataVO().getApprovals().size() >0;
116    }
117    
118    public boolean isApprovable(){
119       if(approveRequestData.getApproveActionDataVO().getStatus() == ApprovalDataVO.STATUS_WAITINGFORAPPROVAL){
120         return true;
121       }
122         
123       return false;
124    }
125    
126    public void setApprobalViews(List JavaDoc list){}
127    
128    public String JavaDoc approve(){
129        Approval approval = new Approval(comment);
130        try {
131            EjbcaJSFHelper.getBean().getApprovalSession().approve(EjbcaJSFHelper.getBean().getAdmin(), approveRequestData.getApprovalId(), approval);
132            updateApprovalRequestData(approveRequestData.getApproveActionDataVO().getId());
133        } catch (ApprovalRequestExpiredException e) {
134            addErrorMessage("APPROVALREQUESTEXPIRED");
135        } catch (ApprovalRequestExecutionException e) {
136            addErrorMessage("ERROREXECUTINGACTION");
137        } catch (AuthorizationDeniedException e) {
138            addErrorMessage("AUTHORIZATIONDENIED");
139        } catch (ApprovalException e) {
140            addErrorMessage("ERRORHAPPENDWHENAPPROVING");
141        } catch (AdminAlreadyApprovedRequestException e) {
142            addErrorMessage("ADMINALREADYPROCESSED");
143        }
144
145        return "approveaction";
146    }
147    
148    public String JavaDoc reject(){
149        Approval approval = new Approval(comment);
150
151         try {
152             EjbcaJSFHelper.getBean().getApprovalSession().reject(EjbcaJSFHelper.getBean().getAdmin(), approveRequestData.getApprovalId(), approval);
153             updateApprovalRequestData(approveRequestData.getApproveActionDataVO().getId());
154         } catch (ApprovalRequestExpiredException e) {
155             addErrorMessage("APPROVALREQUESTEXPIRED");
156         } catch (AuthorizationDeniedException e) {
157             addErrorMessage("AUTHORIZATIONDENIED");
158         } catch (ApprovalException e) {
159             addErrorMessage("ERRORHAPPENDWHENAPPROVING");
160         } catch (AdminAlreadyApprovedRequestException e) {
161             addErrorMessage("ADMINALREADYPROCESSED");
162         }
163
164        return "approveaction";
165    }
166
167 public void setUniqueId(int uniqueId) {
168     log.debug("ApproveActionSessionBean.setApprovalId setting uniqueId : " + uniqueId);
169     updateApprovalRequestData(uniqueId);
170 }
171
172 public void updateApprovalRequestData(int id){
173     Query query = new Query(Query.TYPE_APPROVALQUERY);
174     query.add(ApprovalMatch.MATCH_WITH_UNIQUEID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(id));
175     
176     List JavaDoc result;
177     try {
178         result = EjbcaJSFHelper.getBean().getApprovalSession().query( EjbcaJSFHelper.getBean().getAdmin(), query, 0, 1);
179         if(result.size() > 0){
180             this.approveRequestData = new ApprovalDataVOView((ApprovalDataVO) result.get(0));
181         }
182     } catch (IllegalQueryException e) {
183         addErrorMessage("INVALIDQUERY");
184     } catch (AuthorizationDeniedException e) {
185         addErrorMessage("AUTHORIZATIONDENIED");
186     }
187 }
188
189
190
191 public String JavaDoc getComment() {
192     return "";
193 }
194 public void setComment(String JavaDoc comment) {
195     this.comment = comment;
196 }
197
198
199
200 }
201
Popular Tags