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