Clover Coverage Report - Kuali Student 1.1.1-SNAPSHOT (Aggregated)
Coverage timestamp: Wed Apr 20 2011 04:04:00 EST
../../../../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
52   197   28   3.25
14   141   0.54   16
16     1.75  
1    
 
  AbstractBaseDataOrchestrationRpcGwtServlet       Line # 47 52 0% 28 82 0% 0.0
 
No Tests
 
1    /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10    * software distributed under the License is distributed on an "AS IS"
11    * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12    * or implied. See the License for the specific language governing
13    * permissions and limitations under the License.
14    */
15   
16    package org.kuali.student.common.ui.server.gwt.old;
17   
18    import java.util.Map;
19   
20    import org.apache.commons.lang.StringUtils;
21    import org.apache.log4j.Logger;
22    import org.kuali.rice.kew.service.WorkflowUtility;
23    import org.kuali.rice.kew.webservice.SimpleDocumentActionsWebService;
24    import org.kuali.rice.kim.bo.types.dto.AttributeSet;
25    import org.kuali.rice.kim.service.IdentityManagementService;
26    import org.kuali.rice.kim.service.IdentityManagementService;
27    import org.kuali.student.common.ui.client.service.BaseDataOrchestrationRpcService;
28    import org.kuali.student.common.ui.client.service.DataSaveResult;
29    import org.kuali.student.common.ui.client.service.exceptions.OperationFailedException;
30    import org.kuali.student.common.ui.shared.IdAttributes;
31    import org.kuali.student.common.util.security.SecurityUtils;
32    import org.kuali.student.core.assembly.data.AssemblyException;
33    import org.kuali.student.core.assembly.data.Data;
34    import org.kuali.student.core.assembly.data.Metadata;
35    import org.kuali.student.core.assembly.old.Assembler;
36    import org.kuali.student.core.assembly.old.data.SaveResult;
37    import org.kuali.student.core.rice.StudentIdentityConstants;
38    import org.kuali.student.core.rice.authorization.PermissionType;
39   
40    import com.google.gwt.user.server.rpc.RemoteServiceServlet;
41   
42    /**
43    * Generic implementation of data orchestration calls and workflow calls
44    *
45    */
46    @Deprecated
 
47    public abstract class AbstractBaseDataOrchestrationRpcGwtServlet extends RemoteServiceServlet implements BaseDataOrchestrationRpcService {
48    //FIXME issues:
49    // -The Type/state config is hardcoded here which will cause troubles with different types and states
50    // -Workflow filter should be combined with this for save
51    // -The exception handling here needs standardization. Should RPC errors throw operation failed with just the message and log the message and exception?
52    // also should calls that return Boolean ever throw exceptions?
53   
54    private static final long serialVersionUID = 1L;
55   
56    final Logger LOG = Logger.getLogger(AbstractBaseDataOrchestrationRpcGwtServlet.class);
57   
58    private Assembler<Data, Void> assembler;
59   
60    private SimpleDocumentActionsWebService simpleDocService;
61    private WorkflowUtility workflowUtilityService;
62    private IdentityManagementService permissionService;
63    private IdentityManagementService identityService;
64   
 
65  0 toggle @Override
66    public Data getData(String dataId) {
67  0 try {
68  0 return assembler.get(dataId);
69    } catch (AssemblyException e) {
70  0 LOG.error("Error getting Data.",e);
71    }
72  0 return null;
73    }
74   
 
75  0 toggle @Override
76    public Metadata getMetadata(String id, Map<String,String> idAttributes) {
77   
78  0 try {
79    //FIXME: should not pass empty id. What to do here?
80  0 String idType = "";
81  0 if (idAttributes != null){
82  0 idType = idAttributes.get(IdAttributes.ID_TYPE);
83    }
84  0 return assembler.getMetadata(idType, id, getDefaultMetaDataType(), getDefaultMetaDataState());
85    } catch (AssemblyException e) {
86  0 LOG.error("Error getting Metadata.",e);
87    }
88  0 return null;
89    }
90   
 
91  0 toggle @Override
92    public DataSaveResult saveData(Data data) throws OperationFailedException {
93  0 try {
94  0 SaveResult<Data> saveResult = assembler.save(data);
95  0 if (saveResult != null) {
96  0 return new DataSaveResult(saveResult.getValidationResults(), saveResult.getValue());
97    }
98    } catch (Exception e) {
99  0 LOG.error("Unable to save", e);
100  0 throw new OperationFailedException("Unable to save");
101    }
102  0 return null;
103    }
104   
105   
 
106  0 toggle protected String getCurrentUser() {
107  0 String username = SecurityUtils.getCurrentUserId();
108    //backdoorId is only for convenience
109  0 if(username==null&&this.getThreadLocalRequest().getSession().getAttribute("backdoorId")!=null){
110  0 username=(String)this.getThreadLocalRequest().getSession().getAttribute("backdoorId");
111    }
112  0 return username;
113    }
114   
 
115  0 toggle protected boolean checkDocumentLevelPermissions() {
116  0 return false;
117    }
118   
 
119  0 toggle public Boolean isAuthorized(PermissionType type, Map<String,String> attributes) {
120  0 String user = getCurrentUser();
121  0 boolean result = false;
122  0 if (checkDocumentLevelPermissions()) {
123  0 if (type == null) {
124  0 return null;
125    }
126  0 String namespaceCode = type.getPermissionNamespace();
127  0 String permissionTemplateName = type.getPermissionTemplateName();
128  0 AttributeSet roleQuals = new AttributeSet(StudentIdentityConstants.DOCUMENT_TYPE_NAME, getDefaultWorkflowDocumentType());
129  0 if (attributes != null) {
130  0 roleQuals.putAll(attributes);
131    }
132  0 if (StringUtils.isNotBlank(namespaceCode) && StringUtils.isNotBlank(permissionTemplateName)) {
133  0 LOG.info("Checking Permission '" + namespaceCode + "/" + permissionTemplateName + "' for user '" + user + "'");
134  0 result = getPermissionService().isAuthorizedByTemplateName(user, namespaceCode, permissionTemplateName, null, roleQuals);
135    }
136    else {
137  0 LOG.info("Can not check Permission with namespace '" + namespaceCode + "' and template name '" + permissionTemplateName + "' for user '" + user + "'");
138  0 return Boolean.TRUE;
139    }
140    }
141    else {
142  0 LOG.info("Will not check for document level permissions. Defaulting authorization to true.");
143  0 result = true;
144    }
145  0 LOG.info("Result of authorization check for user '" + user + "': " + result);
146  0 return Boolean.valueOf(result);
147    }
148   
149    protected abstract String deriveAppIdFromData(Data data);
150    protected abstract String deriveDocContentFromData(Data data);
151    protected abstract String getDefaultWorkflowDocumentType();
152    protected abstract String getDefaultMetaDataState();
153    protected abstract String getDefaultMetaDataType();
154   
155    //POJO methods
 
156  0 toggle public void setAssembler(Assembler<Data, Void> assembler) {
157  0 this.assembler = assembler;
158    }
159   
 
160  0 toggle public IdentityManagementService getPermissionService() {
161  0 return permissionService;
162    }
163   
 
164  0 toggle public void setPermissionService(IdentityManagementService permissionService) {
165  0 this.permissionService = permissionService;
166    }
167   
 
168  0 toggle public IdentityManagementService getIdentityService() {
169  0 return identityService;
170    }
171   
 
172  0 toggle public void setIdentityService(IdentityManagementService identityService) {
173  0 this.identityService = identityService;
174    }
175   
 
176  0 toggle public void setSimpleDocService(SimpleDocumentActionsWebService simpleDocService) {
177  0 this.simpleDocService = simpleDocService;
178    }
179   
 
180  0 toggle public void setWorkflowUtilityService(WorkflowUtility workflowUtilityService) {
181  0 this.workflowUtilityService = workflowUtilityService;
182    }
183   
 
184  0 toggle protected Assembler<Data, Void> getAssembler() {
185  0 return assembler;
186    }
187   
 
188  0 toggle protected SimpleDocumentActionsWebService getSimpleDocService() {
189  0 return simpleDocService;
190    }
191   
 
192  0 toggle protected WorkflowUtility getWorkflowUtilityService() {
193  0 return workflowUtilityService;
194    }
195   
196   
197    }