1 13 14 package org.ejbca.ui.web.admin.approval; 15 16 import java.util.ArrayList ; 17 import java.util.HashMap ; 18 import java.util.Iterator ; 19 import java.util.List ; 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 45 public class ApproveActionSessionBean extends BaseManagedBean { 46 private static final Logger log = Logger.getLogger(ApproveActionSessionBean.class); 47 48 private String comment = ""; 49 50 public ApproveActionSessionBean() { 51 super(); 52 53 approveRequestData = new ApprovalDataVOView(); 54 } 55 56 57 private HashMap statustext = null; 58 59 public HashMap getStatusText(){ 60 if(statustext == null){ 61 EjbcaWebBean ejbcawebbean = EjbcaJSFHelper.getBean().getEjbcaWebBean(); 62 statustext = new HashMap (); 63 statustext.put(new Integer (ApprovalDataVO.STATUS_WAITINGFORAPPROVAL), ejbcawebbean.getText("WAITING", true)); 64 statustext.put(new Integer (ApprovalDataVO.STATUS_EXPIRED), ejbcawebbean.getText("EXPIRED", true)); 65 statustext.put(new Integer (ApprovalDataVO.STATUS_EXPIREDANDNOTIFIED), ejbcawebbean.getText("EXPIREDANDNOTIFIED", true)); 66 statustext.put(new Integer (ApprovalDataVO.STATUS_EXECUTED), ejbcawebbean.getText("EXECUTED", true)); 67 statustext.put(new Integer (ApprovalDataVO.STATUS_APPROVED), ejbcawebbean.getText("APPROVED", true)); 68 statustext.put(new Integer (ApprovalDataVO.STATUS_REJECTED), ejbcawebbean.getText("REJECTED", true)); 69 statustext.put(new Integer (ApprovalDataVO.STATUS_EXECUTIONFAILED), ejbcawebbean.getText("EXECUTIONFAILED", true)); 70 statustext.put(new Integer (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 getWindowWidth(){ 92 if(isApprovalRequestComparable()){ 93 return "1000"; 94 } 95 96 return "600"; 97 } 98 99 100 public List getApprovalViews(){ 101 List approvalViews = new ArrayList (); 102 103 if(approveRequestData != null && 104 approveRequestData.getApproveActionDataVO().getApprovals() != null){ 105 Iterator 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 list){} 127 128 public String 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 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 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 getComment() { 192 return ""; 193 } 194 public void setComment(String comment) { 195 this.comment = comment; 196 } 197 198 199 200 } 201 | Popular Tags |