query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_WAITINGFORAPPROVAL, Query.CONNECTOR_AND);
Date now = new Date();
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, -1);
query.add(cal.getTime(), now);
RAAuthorization raAuthorization = new RAAuthorization(admin, globalConfigurationSession, authorizationSession, caSession, endEntityProfileSession);
List<ApprovalDataVO> approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
// If there is an request waiting for approval we don't have to go on and try to add the user
if (approvals.size() > 0) {
log.debug("Found at least one waiting approval request for approvalid: "+approvalid);
throw new ApprovalException("There is already an existing approval request pending for approvalid: "+approvalid);
}
// If there is no waiting request which should be the most common, we check If there is an existing reject withing the last 30 minutes
// If there is a reject, we will cancel this request. A new request will then probably not be possible to create until 30 minutes have passed
query = new Query(Query.TYPE_APPROVALQUERY);
query.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalid), Query.CONNECTOR_AND);
query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_EXECUTIONDENIED, Query.CONNECTOR_AND);
cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, APPROVAL_REJECT_TIMEOUT);
query.add(cal.getTime(), now);
approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
// If there is an request waiting for approval we don't have to go on and try to add the user
if (approvals.size() > 0) {
log.debug("Found at least one rejected approval request for approvalid: "+approvalid);
throw new Exception("Approval request was rejected for approvalid: "+approvalid);
}
// Check if it failed as well...
query = new Query(Query.TYPE_APPROVALQUERY);
query.add(ApprovalMatch.MATCH_WITH_APPROVALID, BasicMatch.MATCH_TYPE_EQUALS, Integer.toString(approvalid), Query.CONNECTOR_AND);
query.add(ApprovalMatch.MATCH_WITH_STATUS, BasicMatch.MATCH_TYPE_EQUALS, "" + ApprovalDataVO.STATUS_EXECUTIONFAILED, Query.CONNECTOR_AND);
cal = Calendar.getInstance();
cal.add(Calendar.MINUTE, -30);
query.add(cal.getTime(), now);
approvals = approvalSession.query(admin, query, 0, 25, raAuthorization.getCAAuthorizationString(), raAuthorization.getEndEntityProfileAuthorizationString());
// If there is an request waiting for approval we don't have to go on and try to add the user
if (approvals.size() > 0) {
log.debug("Found at least one failed approval request for approvalid: "+approvalid);
throw new Exception("Approval request execution failed for approvalid: "+approvalid);
}