| 1 |
|
package org.kuali.student.common.ui.server.gwt; |
| 2 |
|
|
| 3 |
|
import java.util.HashMap; |
| 4 |
|
import java.util.Map; |
| 5 |
|
|
| 6 |
|
import org.apache.commons.lang.StringUtils; |
| 7 |
|
import org.apache.log4j.Logger; |
| 8 |
|
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
| 9 |
|
import org.kuali.rice.kim.service.IdentityManagementService; |
| 10 |
|
import org.kuali.student.common.ui.client.service.DataSaveResult; |
| 11 |
|
import org.kuali.student.common.ui.shared.IdAttributes; |
| 12 |
|
import org.kuali.student.common.util.security.SecurityUtils; |
| 13 |
|
import org.kuali.student.core.assembly.data.Data; |
| 14 |
|
import org.kuali.student.core.assembly.data.Metadata; |
| 15 |
|
import org.kuali.student.core.assembly.transform.AuthorizationFilter; |
| 16 |
|
import org.kuali.student.core.assembly.transform.MetadataFilter; |
| 17 |
|
import org.kuali.student.core.assembly.transform.ProposalWorkflowFilter; |
| 18 |
|
import org.kuali.student.core.assembly.transform.TransformFilter; |
| 19 |
|
import org.kuali.student.core.assembly.transform.TransformFilter.TransformFilterAction; |
| 20 |
|
import org.kuali.student.core.assembly.transform.TransformationManager; |
| 21 |
|
import org.kuali.student.core.dto.DtoConstants; |
| 22 |
|
import org.kuali.student.core.exceptions.DataValidationErrorException; |
| 23 |
|
import org.kuali.student.core.exceptions.DoesNotExistException; |
| 24 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
| 25 |
|
import org.kuali.student.core.proposal.dto.ProposalInfo; |
| 26 |
|
import org.kuali.student.core.proposal.service.ProposalService; |
| 27 |
|
import org.kuali.student.core.rice.StudentIdentityConstants; |
| 28 |
|
import org.kuali.student.core.rice.authorization.PermissionType; |
| 29 |
|
import org.springframework.transaction.annotation.Transactional; |
| 30 |
|
|
| 31 |
|
@Transactional(readOnly=true,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class}) |
|
|
|
| 0% |
Uncovered Elements: 146 (146) |
Complexity: 40 |
Complexity Density: 0.42 |
|
| 32 |
|
public abstract class AbstractDataService implements DataService{ |
| 33 |
|
|
| 34 |
|
private static final long serialVersionUID = 1L; |
| 35 |
|
|
| 36 |
|
final Logger LOG = Logger.getLogger(AbstractDataService.class); |
| 37 |
|
|
| 38 |
|
private TransformationManager transformationManager; |
| 39 |
|
|
| 40 |
|
private IdentityManagementService permissionService; |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
private ProposalService proposalService; |
| 44 |
|
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 5 |
Complexity Density: 0.33 |
|
| 45 |
0
|
@Override... |
| 46 |
|
public Data getData(String id) throws OperationFailedException { |
| 47 |
0
|
Map<String, Object> filterProperties = getDefaultFilterProperties(); |
| 48 |
0
|
filterProperties.put(TransformFilter.FILTER_ACTION, TransformFilterAction.GET); |
| 49 |
0
|
filterProperties.put(MetadataFilter.METADATA_ID_VALUE, id); |
| 50 |
|
|
| 51 |
0
|
String dtoId = id; |
| 52 |
|
|
| 53 |
|
|
| 54 |
0
|
try{ |
| 55 |
0
|
if (proposalService != null){ |
| 56 |
0
|
ProposalInfo proposalInfo = proposalService.getProposal(dtoId); |
| 57 |
0
|
filterProperties.put(ProposalWorkflowFilter.PROPOSAL_INFO, proposalInfo); |
| 58 |
0
|
dtoId = proposalInfo.getProposalReference().get(0); |
| 59 |
|
} |
| 60 |
|
|
| 61 |
0
|
Object dto = get(dtoId); |
| 62 |
0
|
if (dto != null){ |
| 63 |
0
|
return transformationManager.transform(dto, filterProperties); |
| 64 |
|
} |
| 65 |
|
} catch(DoesNotExistException e){ |
| 66 |
0
|
return null; |
| 67 |
|
} catch (Exception e) { |
| 68 |
0
|
throw new OperationFailedException("Error getting data",e); |
| 69 |
|
} |
| 70 |
0
|
return null; |
| 71 |
|
} |
| 72 |
|
|
|
|
|
| 0% |
Uncovered Elements: 38 (38) |
Complexity: 10 |
Complexity Density: 0.5 |
|
| 73 |
0
|
@Override... |
| 74 |
|
public Metadata getMetadata(String id, Map<String, String> attributes) { |
| 75 |
0
|
Map<String, Object> filterProperties = getDefaultFilterProperties(); |
| 76 |
0
|
filterProperties.put(MetadataFilter.METADATA_ID_VALUE, id); |
| 77 |
|
|
| 78 |
|
|
| 79 |
0
|
String idType = (attributes != null? attributes.get(IdAttributes.ID_TYPE):null); |
| 80 |
0
|
String docType = (attributes != null ? attributes.get(StudentIdentityConstants.DOCUMENT_TYPE_NAME):null); |
| 81 |
0
|
String dtoState = (attributes != null ? attributes.get(DtoConstants.DTO_STATE):null); |
| 82 |
0
|
String dtoNextState = (attributes != null ? attributes.get(DtoConstants.DTO_NEXT_STATE):null); |
| 83 |
|
|
| 84 |
0
|
if (idType == null){ |
| 85 |
0
|
filterProperties.remove(MetadataFilter.METADATA_ID_TYPE); |
| 86 |
|
} else { |
| 87 |
0
|
filterProperties.put(MetadataFilter.METADATA_ID_TYPE, idType); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
0
|
if (docType == null){ |
| 91 |
0
|
filterProperties.put(ProposalWorkflowFilter.WORKFLOW_DOC_TYPE, getDefaultWorkflowDocumentType()); |
| 92 |
|
} else { |
| 93 |
0
|
filterProperties.put(ProposalWorkflowFilter.WORKFLOW_DOC_TYPE, docType); |
| 94 |
|
} |
| 95 |
|
|
| 96 |
0
|
if (dtoState != null){ |
| 97 |
0
|
filterProperties.put(DtoConstants.DTO_STATE, dtoState); |
| 98 |
|
} |
| 99 |
|
|
| 100 |
0
|
if (dtoNextState != null){ |
| 101 |
0
|
filterProperties.put(DtoConstants.DTO_NEXT_STATE, dtoNextState); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
0
|
if (checkDocumentLevelPermissions()){ |
| 105 |
0
|
filterProperties.put(AuthorizationFilter.DOC_LEVEL_PERM_CHECK, Boolean.TRUE.toString()); |
| 106 |
|
} |
| 107 |
|
|
| 108 |
0
|
Metadata metadata = transformationManager.getMetadata(getDtoClass().getName(), filterProperties); |
| 109 |
0
|
return metadata; |
| 110 |
|
} |
| 111 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 112 |
0
|
@Override... |
| 113 |
|
@Transactional(readOnly=false) |
| 114 |
|
public DataSaveResult saveData(Data data) throws OperationFailedException, DataValidationErrorException { |
| 115 |
0
|
Map<String, Object> filterProperties = getDefaultFilterProperties(); |
| 116 |
0
|
filterProperties.put(TransformFilter.FILTER_ACTION, TransformFilterAction.SAVE); |
| 117 |
0
|
try { |
| 118 |
0
|
Object dto = transformationManager.transform(data, getDtoClass(), filterProperties); |
| 119 |
0
|
dto = save(dto, filterProperties); |
| 120 |
|
|
| 121 |
0
|
Data persistedData = transformationManager.transform(dto, filterProperties); |
| 122 |
0
|
return new DataSaveResult(null, persistedData); |
| 123 |
|
}catch (DataValidationErrorException e){ |
| 124 |
0
|
throw e; |
| 125 |
|
}catch (Exception e) { |
| 126 |
0
|
throw new OperationFailedException("Unable to save",e); |
| 127 |
|
} |
| 128 |
|
} |
| 129 |
|
|
|
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 11 |
Complexity Density: 0.35 |
|
| 130 |
0
|
@Override... |
| 131 |
|
public Boolean isAuthorized(PermissionType type, Map<String,String> attributes) { |
| 132 |
0
|
String user = SecurityUtils.getCurrentUserId(); |
| 133 |
0
|
boolean result = false; |
| 134 |
0
|
if (checkDocumentLevelPermissions()) { |
| 135 |
0
|
if (type == null) { |
| 136 |
0
|
return null; |
| 137 |
|
} |
| 138 |
0
|
String namespaceCode = type.getPermissionNamespace(); |
| 139 |
0
|
String permissionTemplateName = type.getPermissionTemplateName(); |
| 140 |
|
|
| 141 |
0
|
AttributeSet roleQuals = new AttributeSet(); |
| 142 |
0
|
if (attributes != null) { |
| 143 |
0
|
if (proposalService != null){ |
| 144 |
0
|
ProposalInfo proposalInfo = null; |
| 145 |
0
|
try { |
| 146 |
0
|
if (attributes.containsKey(IdAttributes.IdType.KS_KEW_OBJECT_ID.toString())){ |
| 147 |
0
|
proposalInfo = proposalService.getProposal(attributes.get(IdAttributes.IdType.KS_KEW_OBJECT_ID.toString())); |
| 148 |
0
|
} else if (attributes.containsKey(IdAttributes.IdType.DOCUMENT_ID.toString())){ |
| 149 |
0
|
proposalInfo = proposalService.getProposalByWorkflowId(attributes.get(IdAttributes.IdType.DOCUMENT_ID.toString())); |
| 150 |
|
} |
| 151 |
0
|
if (proposalInfo != null){ |
| 152 |
0
|
attributes.put(IdAttributes.IdType.KS_KEW_OBJECT_ID.toString(), proposalInfo.getId()); |
| 153 |
0
|
attributes.put(IdAttributes.IdType.DOCUMENT_ID.toString(), proposalInfo.getWorkflowId()); |
| 154 |
0
|
attributes.put(StudentIdentityConstants.DOCUMENT_TYPE_NAME, proposalInfo.getType()); |
| 155 |
|
} |
| 156 |
|
} catch (Exception e){ |
| 157 |
0
|
LOG.error("Could not retrieve proposal to determine permission qualifiers."); |
| 158 |
|
} |
| 159 |
|
} |
| 160 |
0
|
roleQuals.putAll(attributes); |
| 161 |
|
} |
| 162 |
0
|
if (StringUtils.isNotBlank(namespaceCode) && StringUtils.isNotBlank(permissionTemplateName)) { |
| 163 |
0
|
LOG.info("Checking Permission '" + namespaceCode + "/" + permissionTemplateName + "' for user '" + user + "'"); |
| 164 |
0
|
result = getPermissionService().isAuthorizedByTemplateName(user, namespaceCode, permissionTemplateName, null, roleQuals); |
| 165 |
|
} |
| 166 |
|
else { |
| 167 |
0
|
LOG.info("Can not check Permission with namespace '" + namespaceCode + "' and template name '" + permissionTemplateName + "' for user '" + user + "'"); |
| 168 |
0
|
return Boolean.TRUE; |
| 169 |
|
} |
| 170 |
|
} |
| 171 |
|
else { |
| 172 |
0
|
LOG.info("Will not check for document level permissions. Defaulting authorization to true."); |
| 173 |
0
|
result = true; |
| 174 |
|
} |
| 175 |
0
|
LOG.info("Result of authorization check for user '" + user + "': " + result); |
| 176 |
0
|
return Boolean.valueOf(result); |
| 177 |
|
} |
| 178 |
|
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 179 |
0
|
public Map<String, Object> getDefaultFilterProperties(){... |
| 180 |
0
|
Map<String, Object> filterProperties = new HashMap<String,Object>(); |
| 181 |
0
|
filterProperties.put(MetadataFilter.METADATA_ID_TYPE, StudentIdentityConstants.QUALIFICATION_KEW_OBJECT_ID); |
| 182 |
0
|
filterProperties.put(ProposalWorkflowFilter.WORKFLOW_USER, SecurityUtils.getCurrentUserId()); |
| 183 |
|
|
| 184 |
0
|
return filterProperties; |
| 185 |
|
} |
| 186 |
|
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 3 |
Complexity Density: 0.33 |
|
| 187 |
0
|
protected DataSaveResult _saveData(Data data, Map<String, Object> filterProperties) throws OperationFailedException{... |
| 188 |
0
|
try { |
| 189 |
0
|
filterProperties.put(MetadataFilter.METADATA_ID_VALUE, (String)data.query("id")); |
| 190 |
|
|
| 191 |
0
|
Object dto = transformationManager.transform(data, getDtoClass(),filterProperties); |
| 192 |
0
|
dto = save(dto, filterProperties); |
| 193 |
|
|
| 194 |
0
|
Data persistedData = transformationManager.transform(dto,filterProperties); |
| 195 |
0
|
return new DataSaveResult(null, persistedData); |
| 196 |
|
} catch (DataValidationErrorException dvee){ |
| 197 |
0
|
return new DataSaveResult(dvee.getValidationResults(), null); |
| 198 |
|
} catch (Exception e) { |
| 199 |
0
|
LOG.error("Unable to save", e); |
| 200 |
0
|
throw new OperationFailedException("Unable to save"); |
| 201 |
|
} |
| 202 |
|
} |
| 203 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 204 |
0
|
protected boolean checkDocumentLevelPermissions() {... |
| 205 |
0
|
return false; |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 210 |
0
|
public TransformationManager getTransformationManager() {... |
| 211 |
0
|
return transformationManager; |
| 212 |
|
} |
| 213 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 214 |
0
|
public void setTransformationManager(TransformationManager transformationManager) {... |
| 215 |
0
|
this.transformationManager = transformationManager; |
| 216 |
|
} |
| 217 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 218 |
0
|
public IdentityManagementService getPermissionService() {... |
| 219 |
0
|
return permissionService; |
| 220 |
|
} |
| 221 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 222 |
0
|
public void setPermissionService(IdentityManagementService permissionService) {... |
| 223 |
0
|
this.permissionService = permissionService; |
| 224 |
|
} |
| 225 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 226 |
0
|
public ProposalService getProposalService() {... |
| 227 |
0
|
return proposalService; |
| 228 |
|
} |
| 229 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 230 |
0
|
public void setProposalService(ProposalService proposalService) {... |
| 231 |
0
|
this.proposalService = proposalService; |
| 232 |
|
} |
| 233 |
|
|
| 234 |
|
protected abstract String getDefaultWorkflowDocumentType(); |
| 235 |
|
|
| 236 |
|
protected abstract String getDefaultMetaDataState(); |
| 237 |
|
|
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
@param |
| 243 |
|
@return |
| 244 |
|
@throws |
| 245 |
|
|
| 246 |
|
protected abstract Object get(String id) throws Exception; |
| 247 |
|
|
| 248 |
|
|
| 249 |
|
|
| 250 |
|
|
| 251 |
|
|
| 252 |
|
@param |
| 253 |
|
@return |
| 254 |
|
@throws |
| 255 |
|
|
| 256 |
|
protected abstract Object save(Object dto, Map<String, Object> properties) throws Exception; |
| 257 |
|
|
| 258 |
|
|
| 259 |
|
|
| 260 |
|
|
| 261 |
|
@return |
| 262 |
|
|
| 263 |
|
protected abstract Class<?> getDtoClass(); |
| 264 |
|
} |