Coverage Report - org.kuali.student.core.organization.ui.server.gwt.OrgRpcGwtServlet
 
Classes in this File Line Coverage Branch Coverage Complexity
OrgRpcGwtServlet
0%
0/214
0%
0/20
2.892
 
 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.core.organization.ui.server.gwt;
 17  
 
 18  
 import java.io.FileInputStream;
 19  
 import java.io.FileNotFoundException;
 20  
 import java.io.InputStream;
 21  
 import java.util.ArrayList;
 22  
 import java.util.HashMap;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import javax.xml.bind.JAXBContext;
 27  
 import javax.xml.bind.JAXBElement;
 28  
 import javax.xml.bind.JAXBException;
 29  
 import javax.xml.bind.Unmarshaller;
 30  
 
 31  
 import org.apache.log4j.Logger;
 32  
 import org.kuali.rice.kim.bo.entity.dto.KimEntityNamePrincipalNameInfo;
 33  
 import org.kuali.rice.kim.service.IdentityService;
 34  
 import org.kuali.student.common.ui.client.service.DataSaveResult;
 35  
 import org.kuali.student.common.ui.server.gwt.old.AbstractBaseDataOrchestrationRpcGwtServlet;
 36  
 import org.kuali.student.core.assembly.data.AssemblyException;
 37  
 import org.kuali.student.core.assembly.data.Data;
 38  
 import org.kuali.student.core.dto.StatusInfo;
 39  
 import org.kuali.student.core.organization.dto.OrgHierarchyInfo;
 40  
 import org.kuali.student.core.organization.dto.OrgInfo;
 41  
 import org.kuali.student.core.organization.dto.OrgOrgRelationInfo;
 42  
 import org.kuali.student.core.organization.dto.OrgOrgRelationTypeInfo;
 43  
 import org.kuali.student.core.organization.dto.OrgPersonRelationInfo;
 44  
 import org.kuali.student.core.organization.dto.OrgPersonRelationTypeInfo;
 45  
 import org.kuali.student.core.organization.dto.OrgPositionRestrictionInfo;
 46  
 import org.kuali.student.core.organization.dto.OrgTreeInfo;
 47  
 import org.kuali.student.core.organization.dto.OrgTypeInfo;
 48  
 import org.kuali.student.core.organization.dynamic.Field;
 49  
 import org.kuali.student.core.organization.dynamic.Fields;
 50  
 import org.kuali.student.core.organization.dynamic.MultipleField;
 51  
 import org.kuali.student.core.organization.dynamic.Section;
 52  
 import org.kuali.student.core.organization.dynamic.SectionConfig;
 53  
 import org.kuali.student.core.organization.dynamic.SectionView;
 54  
 import org.kuali.student.core.organization.service.OrganizationService;
 55  
 import org.kuali.student.core.organization.ui.client.mvc.model.FieldInfo;
 56  
 import org.kuali.student.core.organization.ui.client.mvc.model.FieldInfoImpl;
 57  
 import org.kuali.student.core.organization.ui.client.mvc.model.MembershipInfo;
 58  
 import org.kuali.student.core.organization.ui.client.mvc.model.MultipleFieldInfoImpl;
 59  
 import org.kuali.student.core.organization.ui.client.mvc.model.OrgPositionPersonRelationInfo;
 60  
 import org.kuali.student.core.organization.ui.client.mvc.model.SectionConfigInfo;
 61  
 import org.kuali.student.core.organization.ui.client.mvc.model.SectionViewInfo;
 62  
 import org.kuali.student.core.organization.ui.client.service.OrgRpcService;
 63  
 import org.kuali.student.core.validation.dto.ValidationResultInfo;
 64  
 
 65  0
 public class OrgRpcGwtServlet extends AbstractBaseDataOrchestrationRpcGwtServlet implements OrgRpcService{
 66  0
         final Logger LOG = Logger.getLogger(OrgRpcGwtServlet.class);
 67  
         private static final long serialVersionUID = 1L;
 68  
         public static final String CONFIGURE_XML_PATH = "C:/org_configure.xml";
 69  
         private IdentityService identityServiceNonCached;
 70  
         private OrganizationService service;
 71  
 
 72  
         public void setIdentityServiceNonCached(IdentityService identityServiceNonCached) {
 73  0
                 this.identityServiceNonCached = identityServiceNonCached;
 74  0
         }
 75  
         
 76  
         public void setService(OrganizationService service){
 77  0
             this.service=service;
 78  0
         }
 79  
         
 80  
     @Override
 81  
     public StatusInfo removePositionRestrictionFromOrg(String orgId, String orgPersonRelationTypeKey){
 82  
         try {
 83  0
             return service.removePositionRestrictionFromOrg(orgId, orgPersonRelationTypeKey);
 84  0
         } catch (Exception e) {
 85  0
                         LOG.error(e);
 86  
                 }
 87  0
         return null;
 88  
     }
 89  
     
 90  
     @Override
 91  
     public StatusInfo removeOrgOrgRelation(String orgOrgRelationId){
 92  
         try {
 93  0
             return service.removeOrgOrgRelation(orgOrgRelationId);
 94  0
         } catch (Exception e) {
 95  0
                 LOG.error(e);
 96  
                 }
 97  0
         return null;
 98  
     }
 99  
     
 100  
     @Override
 101  
     public List<OrgHierarchyInfo> getOrgHierarchies() {
 102  
         try {
 103  0
             return service.getOrgHierarchies();
 104  0
         } catch (Exception e) {
 105  0
                 LOG.error(e);
 106  
                 }
 107  0
         return null;    
 108  
     }
 109  
 
 110  
     @Override
 111  
     public List<OrgOrgRelationInfo> getOrgOrgRelationsByOrg(String orgId) {
 112  
         try {
 113  0
             return service.getOrgOrgRelationsByOrg(orgId);
 114  0
         } catch (Exception e) {
 115  0
                 LOG.error(e);
 116  
                 }
 117  0
         return null;
 118  
     }
 119  
     
 120  
     @Override
 121  
     public List<OrgOrgRelationInfo> getOrgOrgRelationsByRelatedOrg(String orgId) {
 122  
         
 123  
         try {
 124  0
             return service.getOrgOrgRelationsByRelatedOrg(orgId);
 125  0
         } catch (Exception e) {
 126  0
                 LOG.error(e);
 127  
                 }
 128  0
         return null;
 129  
     }
 130  
 
 131  
     @Override
 132  
     public List<OrgInfo> getOrganizationsByIdList(List<String> orgIdList) {
 133  
         try {
 134  0
             return service.getOrganizationsByIdList(orgIdList);
 135  0
         } catch (Exception e) {
 136  0
                 LOG.error(e);
 137  
                 }
 138  0
         return null;
 139  
     }
 140  
 
 141  
     @Override
 142  
     public List<String> getAllDescendants(String orgId, String orgHierarchy) {
 143  
         try {
 144  0
             return service.getAllDescendants(orgId, orgHierarchy);
 145  0
         } catch (Exception e) {
 146  0
                 LOG.error(e);
 147  
                 }
 148  0
         return null;
 149  
     }
 150  
 
 151  
     @Override
 152  
     public OrgPositionRestrictionInfo addPositionRestrictionToOrg(OrgPositionRestrictionInfo orgPositionRestrictionInfo) {
 153  
         try {
 154  0
             return service.addPositionRestrictionToOrg(orgPositionRestrictionInfo.getOrgId(), orgPositionRestrictionInfo.getOrgPersonRelationTypeKey(), orgPositionRestrictionInfo);
 155  0
         } catch (Exception e) {
 156  0
                 LOG.error(e);
 157  
                 }
 158  0
         return null;
 159  
     }
 160  
 
 161  
     @Override
 162  
     public OrgInfo createOrganization(OrgInfo orgInfo) {
 163  
         try {
 164  0
             return service.createOrganization(orgInfo.getType(), orgInfo);
 165  0
         } catch (Exception e) {
 166  0
                 LOG.error(e);
 167  
                 }
 168  0
         return null;
 169  
     }
 170  
 
 171  
     @Override
 172  
     public OrgOrgRelationInfo createOrgOrgRelation(OrgOrgRelationInfo orgOrgRelationInfo) {
 173  
         try {
 174  0
             return service.createOrgOrgRelation(orgOrgRelationInfo.getOrgId(), orgOrgRelationInfo.getRelatedOrgId(),
 175  
                     orgOrgRelationInfo.getType(), orgOrgRelationInfo);
 176  0
         } catch (Exception e) {
 177  0
                 LOG.error(e);
 178  
                 }
 179  0
         return null;
 180  
     }
 181  
 
 182  
 
 183  
     public List<OrgPersonRelationTypeInfo> getOrgPersonRelationTypes() {
 184  
         try {
 185  0
             return service.getOrgPersonRelationTypes();
 186  0
         } catch (Exception e) {
 187  0
                 LOG.error(e);
 188  
                 }
 189  0
         return null;
 190  
     }
 191  
 
 192  
     public List<OrgTypeInfo> getOrgTypes() {
 193  
         try {
 194  0
             return service.getOrgTypes();
 195  0
         } catch (Exception e) {
 196  0
                 LOG.error(e);
 197  
                 }
 198  0
         return null;
 199  
     }
 200  
 
 201  
 
 202  
     public List<OrgOrgRelationTypeInfo> getOrgOrgRelationTypes() {
 203  
         try {
 204  0
             return service.getOrgOrgRelationTypes();
 205  0
         } catch (Exception e) {
 206  0
                 LOG.error(e);
 207  
                 }
 208  0
         return null;
 209  
     }
 210  
     
 211  
     @Override
 212  
     public OrgOrgRelationTypeInfo getOrgOrgRelationType(String orgOrgRelationTypeKey) {
 213  
         try {
 214  0
             return service.getOrgOrgRelationType(orgOrgRelationTypeKey);
 215  0
         } catch (Exception e) {
 216  0
                 LOG.error(e);
 217  
                 }
 218  0
         return null;
 219  
     }
 220  
 
 221  
     public List<OrgTreeInfo> getOrgDisplayTree(String orgId, String orgHierarchy, int maxLevels) {
 222  
         try {
 223  0
             return service.getOrgTree(orgId, orgHierarchy, maxLevels);
 224  0
         } catch (Exception e) {
 225  0
                 LOG.error(e);
 226  
                 }
 227  0
         return null;
 228  
     }
 229  
 
 230  
     public OrgInfo getOrganization(String orgId) {
 231  
         try {
 232  0
             return service.getOrganization(orgId);
 233  0
         } catch (Exception e) {
 234  0
                 LOG.error(e);
 235  
                 }
 236  0
         return null;
 237  
     }
 238  
 
 239  
 
 240  
     public List<OrgPositionRestrictionInfo> getPositionRestrictionsByOrg(String orgId) {
 241  
         try {
 242  0
             return service.getPositionRestrictionsByOrg(orgId);
 243  0
         } catch (Exception e) {
 244  0
                 LOG.error(e);
 245  
                 }
 246  0
         return null;
 247  
     }
 248  
 
 249  
 
 250  
     public OrgInfo updateOrganization(OrgInfo orgInfo) {
 251  
         try {
 252  0
             return service.updateOrganization(orgInfo.getId(), orgInfo);
 253  0
         } catch (Exception e) {
 254  0
                 LOG.error(e);
 255  
                 }
 256  0
         return null;
 257  
     }
 258  
 
 259  
 
 260  
     public OrgPositionRestrictionInfo updatePositionRestrictionForOrg(OrgPositionRestrictionInfo orgPositionRestrictionInfo) {
 261  
         try {
 262  0
             return service.updatePositionRestrictionForOrg(orgPositionRestrictionInfo.getOrgId(), orgPositionRestrictionInfo.getOrgPersonRelationTypeKey(), orgPositionRestrictionInfo);
 263  0
         } catch (Exception e) {
 264  0
                 LOG.error(e);
 265  
                 }
 266  0
         return null;
 267  
     }
 268  
 
 269  
     @Override
 270  
     public OrgOrgRelationInfo updateOrgOrgRelation(OrgOrgRelationInfo orgOrgRelationInfo) {
 271  
         try {
 272  0
             return service.updateOrgOrgRelation(orgOrgRelationInfo.getId(), orgOrgRelationInfo);
 273  0
         } catch (Exception e) {
 274  0
                 LOG.error(e);
 275  
                 }
 276  0
         return null;
 277  
     }
 278  
 
 279  
     @Override
 280  
     public OrgPersonRelationInfo createOrgPersonRelation(String orgId,
 281  
             String personId, String orgPersonRelationTypeKey,
 282  
             OrgPersonRelationInfo orgPersonRelationInfo) {
 283  
 
 284  
         try {
 285  0
             return service.createOrgPersonRelation(orgId, personId, orgPersonRelationTypeKey, orgPersonRelationInfo);
 286  0
         } catch (Exception e) {
 287  0
                 LOG.error(e);
 288  
                 }
 289  0
         return null;
 290  
     }
 291  
 
 292  
     @Override
 293  
     public List<OrgPersonRelationTypeInfo> getOrgPersonRelationTypesForOrgType(
 294  
             String orgTypeKey) {
 295  
         try {
 296  0
             return service.getOrgPersonRelationTypesForOrgType(orgTypeKey);
 297  0
         } catch (Exception e) {
 298  0
                 LOG.error(e);
 299  
                 }
 300  0
         return null;
 301  
     }
 302  
 
 303  
     @Override
 304  
     public List<OrgPersonRelationInfo> getOrgPersonRelationsByOrg(String orgId) {
 305  
         try {
 306  0
             return service.getOrgPersonRelationsByOrg(orgId);
 307  0
         } catch (Exception e) {
 308  0
                 LOG.error(e);
 309  
                 }
 310  0
         return null;
 311  
     }
 312  
 
 313  
     @Override
 314  
     public StatusInfo removeOrgPersonRelation(String orgPersonRelationId) {
 315  
         try {
 316  0
             return service.removeOrgPersonRelation(orgPersonRelationId);
 317  0
         } catch (Exception e) {
 318  0
                 LOG.error(e);
 319  
                 }
 320  0
         return null;
 321  
     }
 322  
 
 323  
     @Override
 324  
     public OrgPersonRelationInfo updateOrgPersonRelation(
 325  
             String orgPersonRelationId,
 326  
             OrgPersonRelationInfo orgPersonRelationInfo) {
 327  
         try {
 328  0
             return service.updateOrgPersonRelation(orgPersonRelationId, orgPersonRelationInfo);
 329  0
         } catch (Exception e) {
 330  0
                 LOG.error(e);
 331  
                 }
 332  0
         return null;
 333  
     }        
 334  
     
 335  
     @Override
 336  
     public DataSaveResult saveOrgProposal(Data proposal) throws AssemblyException, org.kuali.student.common.ui.client.service.exceptions.OperationFailedException {
 337  
 
 338  
         try {
 339  0
             DataSaveResult s = this.saveData(proposal);
 340  0
             if (s == null) {
 341  0
                 return null;
 342  
             } else {
 343  
                 Data sampdata;
 344  0
                 sampdata = s.getValue();
 345  0
                 List<ValidationResultInfo> vsr =  new ArrayList<ValidationResultInfo>();
 346  0
                 DataSaveResult dsr = new DataSaveResult(vsr,sampdata);
 347  0
                 return dsr;
 348  
             }
 349  0
         } catch(Exception e){
 350  0
             throw new org.kuali.student.common.ui.client.service.exceptions.OperationFailedException("Unable to save");
 351  
             
 352  
         }
 353  
      
 354  
     }
 355  
 
 356  
     @Override
 357  
     public SectionConfigInfo getSectionConfig() throws org.kuali.student.common.ui.client.service.exceptions.OperationFailedException {
 358  
         // Move this into Common UI
 359  0
         SectionConfigInfo sectionConfigInfo = new SectionConfigInfo();
 360  0
         String packageName = SectionConfig.class.getPackage().getName();
 361  
         JAXBContext jc;
 362  
         try {
 363  0
             jc = JAXBContext.newInstance( packageName );
 364  0
             Unmarshaller u = jc.createUnmarshaller();
 365  0
             SectionConfig sectionConfig = null;
 366  
             try{
 367  0
                 sectionConfig = (SectionConfig)((JAXBElement)u.unmarshal(
 368  
                     new FileInputStream( CONFIGURE_XML_PATH ))).getValue();
 369  
             }
 370  0
             catch(FileNotFoundException e){
 371  0
                 InputStream in = OrgRpcGwtServlet.class.getResourceAsStream("/org_configure.xml");
 372  0
                 sectionConfig = (SectionConfig)((JAXBElement)u.unmarshal(in)).getValue();
 373  0
             }
 374  0
             List<SectionView> sectionViews = sectionConfig.getSectionView();
 375  0
             List<SectionViewInfo> sectionViewInfoList = new ArrayList<SectionViewInfo>();
 376  0
             for(SectionView sectionView:sectionViews){
 377  0
                 SectionViewInfo sectionViewInfo = new SectionViewInfo();
 378  0
                 sectionViewInfo.setViewName(sectionView.getViewName());
 379  0
                 sectionViewInfo.setTab(sectionView.getTab());
 380  0
                 sectionViewInfo.setMenu(sectionView.getMenu());
 381  0
                 Section section = sectionView.getSection();
 382  0
                 sectionViewInfo.setSectionName(section.getSectionName());
 383  0
                 sectionViewInfo.setSectionEnum(section.getEnum());
 384  0
                 Fields fields = sectionView.getFields();
 385  0
                 if (fields != null) {
 386  0
                     List<Field> fieldList = fields.getField();
 387  
 
 388  0
                     List<MultipleField> multipleFieldList = fields.getMultipleField();
 389  0
                     List<FieldInfo> fieldInfoList = new ArrayList<FieldInfo>();
 390  0
                     for (Field field : fieldList) {
 391  0
                         FieldInfo fieldInfo = new FieldInfoImpl();
 392  0
                         fieldInfo.setLabel(field.getLabel());
 393  0
                         fieldInfo.setKey(field.getKey());
 394  0
                         fieldInfo.setWidget(field.getWidget());
 395  0
                         fieldInfoList.add(fieldInfo);
 396  0
                     }
 397  0
                     for (MultipleField multipleField : multipleFieldList) {
 398  0
                         MultipleFieldInfoImpl fieldInfo = new MultipleFieldInfoImpl();
 399  0
                         fieldInfo.setKey(multipleField.getKey());
 400  0
                         fieldInfo.setLabel(multipleField.getItemLabel());
 401  0
                         fieldInfo.setAddItemLabel(multipleField.getAddItemLabel());
 402  0
                         List<Field> fieldMultiList = multipleField.getFields().getField();
 403  0
                         List<FieldInfo> fieldMultiInfoList = new ArrayList<FieldInfo>();
 404  0
                         for (Field field : fieldMultiList) {
 405  0
                             FieldInfo fieldMultiInfo = new FieldInfoImpl();
 406  0
                             fieldMultiInfo.setLabel(field.getLabel());
 407  0
                             fieldMultiInfo.setKey(field.getKey());
 408  0
                             fieldMultiInfo.setWidget(field.getWidget());
 409  0
                             fieldMultiInfoList.add(fieldMultiInfo);
 410  0
                         }
 411  0
                         fieldInfo.setFields(fieldMultiInfoList);
 412  0
                         fieldInfoList.add(fieldInfo);
 413  0
                     }
 414  
 
 415  0
                     sectionViewInfo.setfields(fieldInfoList);
 416  
                 }
 417  0
                 sectionViewInfoList.add(sectionViewInfo);
 418  
                 
 419  0
             }
 420  0
            sectionConfigInfo.setSectionViewInfoList(sectionViewInfoList);
 421  
             
 422  0
         } catch (JAXBException e) {
 423  0
                 LOG.error(e);
 424  0
             throw new org.kuali.student.common.ui.client.service.exceptions.OperationFailedException("Org Screen XML Cnfig file: recources/org_configure.xml parse exception");
 425  0
         } 
 426  
 
 427  0
         return sectionConfigInfo;
 428  
     }
 429  
 
 430  
     @Override
 431  
     public Data fetchOrg(String orgId) {
 432  
         try {
 433  0
             return (Data)this.getData(orgId);
 434  
         }
 435  0
         catch(Exception e){
 436  0
                 LOG.error(e);
 437  
         }
 438  0
         return null;
 439  
     }
 440  
 
 441  
     @Override
 442  
     public List<OrgPositionPersonRelationInfo> getOrgPositionPersonRelation(String orgId) {
 443  0
         ArrayList<OrgPositionPersonRelationInfo> relations = new ArrayList<OrgPositionPersonRelationInfo>();
 444  0
         OrgPositionPersonRelationInfo personRelationInfo = null;
 445  
         try{
 446  0
             List<OrgPersonRelationInfo> orgPersonRelations = service.getAllOrgPersonRelationsByOrg(orgId);
 447  0
             List<OrgPositionRestrictionInfo> orgPositionRestrictions = service.getPositionRestrictionsByOrg(orgId);
 448  
             
 449  0
             for(OrgPositionRestrictionInfo position:orgPositionRestrictions){
 450  0
                 personRelationInfo = new OrgPositionPersonRelationInfo();
 451  0
                 personRelationInfo.setOrgPersonRelationTypeKey(position.getOrgPersonRelationTypeKey());
 452  0
                 personRelationInfo.setTitle(position.getTitle());
 453  0
                 personRelationInfo.setDesc(position.getDesc());
 454  0
                 personRelationInfo.setMinNumRelations(position.getMinNumRelations().toString());
 455  0
                 personRelationInfo.setMaxNumRelations(position.getMaxNumRelations());
 456  0
                 ArrayList<String> names = new ArrayList<String>();
 457  0
                 for(OrgPersonRelationInfo relation: orgPersonRelations){
 458  0
                     if(position.getOrgPersonRelationTypeKey().equals(relation.getType())){
 459  0
                         names.add(relation.getPersonId());
 460  
                     }
 461  
                 }
 462  0
                 personRelationInfo.setPersonId(names);
 463  0
                 relations.add(personRelationInfo);
 464  0
             }
 465  
             
 466  
         }
 467  0
         catch(Exception e){
 468  0
                 LOG.error(e);
 469  0
         }
 470  0
         return relations;
 471  
     }
 472  
 
 473  
 
 474  
     @Override
 475  
     public Map<String, MembershipInfo> getNamesForPersonIds(List<String> personIds) {
 476  0
         Map<String, KimEntityNamePrincipalNameInfo> kimIdentities = identityServiceNonCached.getDefaultNamesForPrincipalIds(personIds);
 477  0
         Map<String, MembershipInfo> identities = new HashMap<String, MembershipInfo>();
 478  0
         for(String pId:personIds ){
 479  0
             KimEntityNamePrincipalNameInfo kimEntity = kimIdentities.get(pId);
 480  0
             MembershipInfo memeberEntity = new MembershipInfo();
 481  0
             memeberEntity.setFirstName(kimEntity.getDefaultEntityName().getFirstName());
 482  0
             memeberEntity.setLastName(kimEntity.getDefaultEntityName().getLastName());
 483  0
             identities.put(pId, memeberEntity);
 484  0
         }
 485  
         
 486  0
         return identities;
 487  
     }
 488  
 
 489  
     @Override
 490  
     protected String deriveAppIdFromData(Data data) {
 491  0
         return null;
 492  
     }
 493  
 
 494  
     @Override
 495  
     protected String deriveDocContentFromData(Data data) {
 496  0
         return null;
 497  
     }
 498  
 
 499  
     @Override
 500  
     protected String getDefaultMetaDataState() {
 501  0
         return null;
 502  
     }
 503  
 
 504  
     @Override
 505  
     protected String getDefaultMetaDataType() {
 506  0
         return null;
 507  
     }
 508  
 
 509  
     @Override
 510  
     protected String getDefaultWorkflowDocumentType() {
 511  0
         return null;
 512  
     }
 513  
     
 514  
 }