| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.lum.kim.role.type; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.kuali.rice.kew.api.KewApiServiceLocator; |
| 20 | |
import org.kuali.rice.kew.api.action.WorkflowDocumentActionsService; |
| 21 | |
import org.kuali.rice.kew.api.document.WorkflowDocumentService; |
| 22 | |
import org.kuali.rice.kew.api.exception.WorkflowException; |
| 23 | |
import org.kuali.rice.kim.api.KimConstants; |
| 24 | |
import org.kuali.rice.kim.api.role.RoleMembership; |
| 25 | |
import org.kuali.rice.kns.kim.role.DerivedRoleTypeServiceBase; |
| 26 | |
import org.kuali.student.common.rice.StudentIdentityConstants; |
| 27 | |
import org.kuali.student.lum.kim.KimQualificationHelper; |
| 28 | |
|
| 29 | |
import java.util.*; |
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | 0 | public class KSRouteLogDerivedRoleTypeServiceImpl extends DerivedRoleTypeServiceBase { |
| 35 | 0 | private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KSRouteLogDerivedRoleTypeServiceImpl.class); |
| 36 | |
|
| 37 | |
public static final String INITIATOR_ROLE_NAME = "Initiator"; |
| 38 | |
public static final String INITIATOR_OR_REVIEWER_ROLE_NAME = "Initiator or Reviewer"; |
| 39 | |
public static final String ROUTER_ROLE_NAME = "Router"; |
| 40 | |
|
| 41 | 0 | private boolean checkFutureRequests = false; |
| 42 | 0 | protected Set<List<String>> newRequiredAttributes = new HashSet<List<String>>(); |
| 43 | |
|
| 44 | |
{ |
| 45 | |
|
| 46 | 0 | List<String> listOne = new ArrayList<String>(); |
| 47 | 0 | listOne.add( KimConstants.AttributeConstants.DOCUMENT_NUMBER ); |
| 48 | 0 | newRequiredAttributes.add(listOne); |
| 49 | |
|
| 50 | 0 | List<String> listTwo = new ArrayList<String>(); |
| 51 | 0 | listTwo.add( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME ); |
| 52 | 0 | listTwo.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
| 53 | 0 | newRequiredAttributes.add(listTwo); |
| 54 | |
|
| 55 | 0 | List<String> listThree = new ArrayList<String>(); |
| 56 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID ); |
| 57 | 0 | listThree.add( StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_TYPE ); |
| 58 | 0 | newRequiredAttributes.add(listThree); |
| 59 | |
|
| 60 | 0 | for (String proposalReferenceType : StudentIdentityConstants.QUALIFICATION_PROPOSAL_ID_REF_TYPES) { |
| 61 | 0 | List<String> tempList = new ArrayList<String>(); |
| 62 | 0 | tempList.add( proposalReferenceType ); |
| 63 | 0 | newRequiredAttributes.add(tempList); |
| 64 | 0 | } |
| 65 | 0 | } |
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
@Override |
| 73 | |
protected void validateRequiredAttributesAgainstReceived(Map<String,String> receivedAttributes){ |
| 74 | 0 | KimQualificationHelper.validateRequiredAttributesAgainstReceived(newRequiredAttributes, receivedAttributes, isCheckFutureRequests(), COMMA_SEPARATOR); |
| 75 | 0 | super.validateRequiredAttributesAgainstReceived(receivedAttributes); |
| 76 | 0 | } |
| 77 | |
|
| 78 | |
@Override |
| 79 | |
public Map<String,String> translateInputAttributes(Map<String,String> qualification) { |
| 80 | 0 | return KimQualificationHelper.translateInputAttributeSet(super.translateInputAttributes(qualification)); |
| 81 | |
} |
| 82 | |
|
| 83 | |
protected String getDocumentNumber(Map<String,String> qualification) throws WorkflowException { |
| 84 | |
|
| 85 | 0 | String documentId = qualification.get( KimConstants.AttributeConstants.DOCUMENT_NUMBER ); |
| 86 | 0 | if (StringUtils.isNotEmpty(documentId)) { |
| 87 | 0 | return documentId; |
| 88 | |
} else { |
| 89 | 0 | LOG.warn("Could not find workflow document id in qualification list:"); |
| 90 | 0 | LOG.warn(qualification); |
| 91 | 0 | return null; |
| 92 | |
} |
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
} |
| 112 | |
|
| 113 | |
public boolean isCheckFutureRequests() { |
| 114 | 0 | return checkFutureRequests; |
| 115 | |
} |
| 116 | |
|
| 117 | |
public void setCheckFutureRequests(boolean checkFutureRequests) { |
| 118 | 0 | this.checkFutureRequests = checkFutureRequests; |
| 119 | 0 | } |
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
|
| 132 | |
@Override |
| 133 | |
public List<RoleMembership> getRoleMembersFromDerivedRole(String namespaceCode, String roleName, Map<String,String> paramQualification) { |
| 134 | 0 | List<RoleMembership> members = new ArrayList<RoleMembership>(); |
| 135 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
| 136 | 0 | Map<String,String> qualification = translateInputAttributes(paramQualification); |
| 137 | 0 | String documentNumber = null; |
| 138 | |
try { |
| 139 | 0 | documentNumber = getDocumentNumber(qualification); |
| 140 | 0 | if (documentNumber != null) { |
| 141 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)) { |
| 142 | 0 | String principalId = getWorkflowDocumentService().getDocumentInitiatorPrincipalId(documentNumber); |
| 143 | 0 | members.add(RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, null).build()); |
| 144 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)) { |
| 145 | 0 | List<String> ids = getWorkflowDocumentActionsService().getPrincipalIdsInRouteLog(documentNumber, isCheckFutureRequests()); |
| 146 | 0 | if (ids != null) { |
| 147 | 0 | for ( String id : ids ) { |
| 148 | 0 | if ( StringUtils.isNotBlank(id) ) { |
| 149 | 0 | members.add(RoleMembership.Builder.create(null, null, id, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, null).build()); |
| 150 | |
} |
| 151 | |
} |
| 152 | |
} |
| 153 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)) { |
| 154 | 0 | String principalId = getWorkflowDocumentService().getRoutedByPrincipalIdByDocumentId(documentNumber); |
| 155 | 0 | members.add(RoleMembership.Builder.create(null, null, principalId, KimConstants.KimGroupMemberTypes.PRINCIPAL_MEMBER_TYPE, null).build() ); |
| 156 | |
} |
| 157 | |
} |
| 158 | 0 | } catch (WorkflowException wex) { |
| 159 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
| 160 | 0 | throw new RuntimeException("Error in getting principal Ids in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
| 161 | 0 | } |
| 162 | 0 | return members; |
| 163 | |
} |
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
@Override |
| 169 | |
public boolean hasDerivedRole( |
| 170 | |
String principalId, List<String> groupIds, String namespaceCode, String roleName, Map<String,String> paramQualification){ |
| 171 | 0 | validateRequiredAttributesAgainstReceived(paramQualification); |
| 172 | 0 | Map<String,String> qualification = translateInputAttributes(paramQualification); |
| 173 | 0 | boolean isUserInRouteLog = false; |
| 174 | 0 | String documentNumber = null; |
| 175 | |
try { |
| 176 | 0 | documentNumber = getDocumentNumber(qualification); |
| 177 | 0 | if (documentNumber != null) { |
| 178 | 0 | if (INITIATOR_ROLE_NAME.equals(roleName)){ |
| 179 | 0 | isUserInRouteLog = principalId.equals(getWorkflowDocumentService().getDocumentInitiatorPrincipalId(documentNumber)); |
| 180 | 0 | } else if(INITIATOR_OR_REVIEWER_ROLE_NAME.equals(roleName)){ |
| 181 | 0 | isUserInRouteLog = getWorkflowDocumentActionsService().isUserInRouteLog(documentNumber, principalId, isCheckFutureRequests()); |
| 182 | 0 | } else if(ROUTER_ROLE_NAME.equals(roleName)){ |
| 183 | 0 | isUserInRouteLog = principalId.equals(getWorkflowDocumentService().getRoutedByPrincipalIdByDocumentId(documentNumber)); |
| 184 | |
} |
| 185 | |
} |
| 186 | 0 | } catch (WorkflowException wex) { |
| 187 | 0 | LOG.error("Workflow Error: " + wex.getLocalizedMessage(),wex); |
| 188 | 0 | throw new RuntimeException("Error in determining whether the principal Id: "+principalId+" is in route log for document number: "+documentNumber+" :"+wex.getLocalizedMessage(),wex); |
| 189 | 0 | } |
| 190 | 0 | return isUserInRouteLog; |
| 191 | |
} |
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
public boolean shouldCacheRoleMembershipResults(String namespaceCode, String roleName) { |
| 200 | 0 | return false; |
| 201 | |
} |
| 202 | |
|
| 203 | |
|
| 204 | |
protected WorkflowDocumentService getWorkflowDocumentService() { |
| 205 | 0 | return KewApiServiceLocator.getWorkflowDocumentService(); |
| 206 | |
} |
| 207 | |
|
| 208 | |
public WorkflowDocumentActionsService getWorkflowDocumentActionsService() { |
| 209 | 0 | return KewApiServiceLocator.getWorkflowDocumentActionsService(); |
| 210 | |
} |
| 211 | |
|
| 212 | |
} |