Coverage Report - org.kuali.student.core.organization.service.impl.OrganizationAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
OrganizationAssembler
80%
133/166
52%
36/68
3.7
 
 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.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import org.kuali.student.common.dto.TimeAmountInfo;
 22  
 import org.kuali.student.common.entity.TimeAmount;
 23  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 24  
 import org.kuali.student.common.exceptions.InvalidParameterException;
 25  
 import org.kuali.student.common.exceptions.VersionMismatchException;
 26  
 import org.kuali.student.common.service.impl.BaseAssembler;
 27  
 import org.kuali.student.core.organization.dao.OrganizationDao;
 28  
 import org.kuali.student.core.organization.dto.OrgHierarchyInfo;
 29  
 import org.kuali.student.core.organization.dto.OrgInfo;
 30  
 import org.kuali.student.core.organization.dto.OrgOrgRelationInfo;
 31  
 import org.kuali.student.core.organization.dto.OrgOrgRelationTypeInfo;
 32  
 import org.kuali.student.core.organization.dto.OrgPersonRelationInfo;
 33  
 import org.kuali.student.core.organization.dto.OrgPersonRelationTypeInfo;
 34  
 import org.kuali.student.core.organization.dto.OrgPositionRestrictionInfo;
 35  
 import org.kuali.student.core.organization.dto.OrgTypeInfo;
 36  
 import org.kuali.student.core.organization.entity.Org;
 37  
 import org.kuali.student.core.organization.entity.OrgAttribute;
 38  
 import org.kuali.student.core.organization.entity.OrgHierarchy;
 39  
 import org.kuali.student.core.organization.entity.OrgOrgRelation;
 40  
 import org.kuali.student.core.organization.entity.OrgOrgRelationAttribute;
 41  
 import org.kuali.student.core.organization.entity.OrgOrgRelationType;
 42  
 import org.kuali.student.core.organization.entity.OrgPersonRelation;
 43  
 import org.kuali.student.core.organization.entity.OrgPersonRelationAttribute;
 44  
 import org.kuali.student.core.organization.entity.OrgPersonRelationType;
 45  
 import org.kuali.student.core.organization.entity.OrgPositionRestriction;
 46  
 import org.kuali.student.core.organization.entity.OrgPositionRestrictionAttribute;
 47  
 import org.kuali.student.core.organization.entity.OrgType;
 48  
 import org.springframework.beans.BeanUtils;
 49  
 
 50  0
 public class OrganizationAssembler extends BaseAssembler{
 51  
 
 52  
         public static List<OrgHierarchyInfo> toOrgHierarchyInfos(
 53  
                         List<OrgHierarchy> orgHierarchys) {
 54  1
                 List<OrgHierarchyInfo> orgHierarchyInfos = new ArrayList<OrgHierarchyInfo>(orgHierarchys.size());
 55  1
                 for(OrgHierarchy orgHierarchy:orgHierarchys){
 56  2
                         orgHierarchyInfos.add(toOrgHierarchyInfo(orgHierarchy));
 57  
                 }
 58  1
                 return orgHierarchyInfos;
 59  
         }
 60  
 
 61  
         public static OrgHierarchyInfo toOrgHierarchyInfo(OrgHierarchy orgHierarchy) {
 62  3
                 if (orgHierarchy == null) {
 63  0
                         return null;
 64  
                 }
 65  
                 
 66  3
                 OrgHierarchyInfo orgHierarchyInfo = new OrgHierarchyInfo();
 67  
 
 68  3
                 BeanUtils.copyProperties(orgHierarchy, orgHierarchyInfo, new String[] { "rootOrgId",
 69  
                                 "attributes" });
 70  
 
 71  
                 // copy attributes and RootOrg
 72  3
                 orgHierarchyInfo.setAttributes(toAttributeMap(orgHierarchy.getAttributes()));
 73  3
                 orgHierarchyInfo.setRootOrgId(orgHierarchy.getRootOrg().getId());
 74  3
                 orgHierarchyInfo.setDescr(orgHierarchy.getDescr());
 75  3
                 return orgHierarchyInfo;
 76  
         }
 77  
 
 78  
         public static List<OrgInfo> toOrgInfos(List<Org> orgs) {
 79  0
                 List<OrgInfo> orgInfos = new ArrayList<OrgInfo>(orgs.size());
 80  0
                 for(Org org:orgs){
 81  0
                         orgInfos.add(toOrgInfo(org));
 82  
                 }
 83  0
                 return orgInfos;
 84  
         }
 85  
 
 86  
         public static OrgInfo toOrgInfo(Org org) {
 87  5
                 if (org == null) {
 88  0
                         return null;
 89  
                 }
 90  
                 
 91  5
                 OrgInfo orgInfo = new OrgInfo();
 92  
 
 93  5
                 BeanUtils.copyProperties(org, orgInfo, new String[] { "type",
 94  
                                 "attributes", "metaInfo" });
 95  
 
 96  
                 // copy attributes, metadata, and Type
 97  5
                 orgInfo.setAttributes(toAttributeMap(org.getAttributes()));
 98  5
                 orgInfo.setMetaInfo(toMetaInfo(org.getMeta(), org.getVersionNumber()));
 99  5
                 orgInfo.setType(org.getType().getId());
 100  
 
 101  5
                 return orgInfo;
 102  
         }
 103  
 
 104  
         public static List<OrgPersonRelationInfo> toOrgPersonRelationInfos(List<OrgPersonRelation> relations) {
 105  11
                 List<OrgPersonRelationInfo> relationInfos = new ArrayList<OrgPersonRelationInfo>(relations.size());
 106  11
                 for (OrgPersonRelation relation : relations) {
 107  12
                         relationInfos.add(toOrgPersonRelationInfo(relation));
 108  
                 }
 109  11
                 return relationInfos;
 110  
         }
 111  
 
 112  
         public static OrgPersonRelationInfo toOrgPersonRelationInfo(OrgPersonRelation relation) {
 113  13
                 OrgPersonRelationInfo relationInfo = new OrgPersonRelationInfo();
 114  
 
 115  13
                 BeanUtils.copyProperties(relation, relationInfo, new String[] { "type",
 116  
                                 "attributes", "metaInfo", "orgId"});
 117  
 
 118  13
                 relationInfo.setOrgId(relation.getOrg().getId());
 119  13
                 relationInfo.setAttributes(toAttributeMap(relation.getAttributes()));
 120  13
                 relationInfo.setMetaInfo(toMetaInfo(relation.getMeta(), relation.getVersionNumber()));
 121  13
                 relationInfo.setType(relation.getType().getId());
 122  
                 //relationInfo.setId(relation.getId());
 123  13
                 return relationInfo;
 124  
         }
 125  
 
 126  
         public static List<OrgOrgRelationInfo> toOrgOrgRelationInfos(
 127  
                         List<OrgOrgRelation> orgOrgRelations) {
 128  7
                 List<OrgOrgRelationInfo> orgOrgRelationInfo = new ArrayList<OrgOrgRelationInfo>();
 129  7
                 for(OrgOrgRelation orgOrgRelation:orgOrgRelations){
 130  13
                         orgOrgRelationInfo.add(toOrgOrgRelationInfo(orgOrgRelation));
 131  
                 }
 132  7
                 return orgOrgRelationInfo;
 133  
         }
 134  
 
 135  
         public static OrgOrgRelationInfo toOrgOrgRelationInfo(
 136  
                         OrgOrgRelation orgOrgRelation) {
 137  15
                 if (orgOrgRelation == null) {
 138  0
                         return null;
 139  
                 }
 140  15
                 OrgOrgRelationInfo orgOrgRelationInfo = new OrgOrgRelationInfo();
 141  
 
 142  15
                 BeanUtils.copyProperties(orgOrgRelation, orgOrgRelationInfo, new String[] { "type",
 143  
                                 "attributes", "metaInfo","orgId","relatedOrgId" });
 144  
 
 145  
                 // copy attributes, metadata, Type, and related orgs
 146  15
                 orgOrgRelationInfo.setAttributes(toAttributeMap(orgOrgRelation.getAttributes()));
 147  15
                 orgOrgRelationInfo.setMetaInfo(toMetaInfo(orgOrgRelation.getMeta(), orgOrgRelation.getVersionNumber()));
 148  15
                 orgOrgRelationInfo.setType(orgOrgRelation.getType().getId());
 149  15
                 orgOrgRelationInfo.setOrgId(orgOrgRelation.getOrg().getId());
 150  15
                 orgOrgRelationInfo.setRelatedOrgId(orgOrgRelation.getRelatedOrg().getId());
 151  
 
 152  15
                 return orgOrgRelationInfo;
 153  
         }
 154  
 
 155  
         public static OrgPositionRestrictionInfo toOrgPositionRestrictionInfo(OrgPositionRestriction restriction) {
 156  4
                 OrgPositionRestrictionInfo restrictionInfo = new OrgPositionRestrictionInfo();
 157  
 
 158  4
                 BeanUtils.copyProperties(restriction, restrictionInfo, new String[] { "attributes", "metaInfo","orgId","personRelationType","stdDuration" });
 159  
                 
 160  4
                 if(restriction.getStdDuration()!=null){
 161  4
                         restrictionInfo.setStdDuration(new TimeAmountInfo());
 162  4
                         BeanUtils.copyProperties(restriction.getStdDuration(), restrictionInfo.getStdDuration());
 163  
                 }
 164  
                 
 165  4
                 restrictionInfo.setOrgId(restriction.getOrg().getId());
 166  4
                 restrictionInfo.setAttributes(toAttributeMap(restriction.getAttributes()));
 167  4
                 restrictionInfo.setMetaInfo(toMetaInfo(restriction.getMeta(), restriction.getVersionNumber()));
 168  4
                 restrictionInfo.setOrgPersonRelationTypeKey(restriction.getPersonRelationType().getId());
 169  4
                 restrictionInfo.setDesc(restriction.getDescr());
 170  4
                 return restrictionInfo;
 171  
 
 172  
         }
 173  
         public static List<OrgPositionRestrictionInfo> toOrgPositionRestrictionInfos(List<OrgPositionRestriction> restrictions) {
 174  2
                 List<OrgPositionRestrictionInfo> restrictionInfos = new ArrayList<OrgPositionRestrictionInfo>(restrictions.size());
 175  2
                 for (OrgPositionRestriction restriction : restrictions) {
 176  2
                         restrictionInfos.add(toOrgPositionRestrictionInfo(restriction));
 177  
                 }
 178  2
                 return restrictionInfos;
 179  
         }
 180  
 
 181  
         public static OrgTypeInfo toOrgTypeInfo(OrgType orgType) {
 182  18
                 return toGenericTypeInfo(OrgTypeInfo.class, orgType);
 183  
         }
 184  
 
 185  
         public static List<OrgTypeInfo> toOrgTypeInfos(List<OrgType> orgTypes) {
 186  1
                 List<OrgTypeInfo> orgTypeInfos = new ArrayList<OrgTypeInfo>(orgTypes.size());
 187  1
                 for (OrgType orgType : orgTypes) {
 188  17
                         orgTypeInfos.add(toOrgTypeInfo(orgType));
 189  
                 }
 190  1
                 return orgTypeInfos;
 191  
         }
 192  
 
 193  
         public static OrgPersonRelationTypeInfo toOrgPersonRelationTypeInfo(OrgPersonRelationType orgPersonRelationType) {
 194  2
                 OrgPersonRelationTypeInfo orgPersonRelationTypeInfo = new OrgPersonRelationTypeInfo();
 195  2
                 BeanUtils.copyProperties(orgPersonRelationType, orgPersonRelationTypeInfo, new String[] { "attributes", "orgHierarchy"});
 196  
 
 197  2
                 orgPersonRelationTypeInfo.setAttributes(toAttributeMap(orgPersonRelationType.getAttributes()));
 198  2
                 return orgPersonRelationTypeInfo;
 199  
         }
 200  
 
 201  
         public static List<OrgPersonRelationTypeInfo> toOrgPersonRelationTypeInfos(List<OrgPersonRelationType> orgPersonRelationTypes) {
 202  2
                 List<OrgPersonRelationTypeInfo> oprtys = new ArrayList<OrgPersonRelationTypeInfo>(orgPersonRelationTypes.size());
 203  2
                 for (OrgPersonRelationType type : orgPersonRelationTypes) {
 204  2
                         oprtys.add(toOrgPersonRelationTypeInfo(type));
 205  
                 }
 206  2
                 return oprtys;
 207  
         }
 208  
 
 209  
         public static OrgOrgRelationTypeInfo toOrgOrgRelationTypeInfo(OrgOrgRelationType orgOrgRelationType) {
 210  30
                 if (orgOrgRelationType == null) {
 211  0
                         return null;
 212  
                 }
 213  
                 
 214  30
                 OrgOrgRelationTypeInfo orgOrgRelationTypeInfo = new OrgOrgRelationTypeInfo();
 215  30
                 BeanUtils.copyProperties(orgOrgRelationType, orgOrgRelationTypeInfo, new String[] { "attributes", "orgHierarchy"});
 216  
 
 217  30
                 orgOrgRelationTypeInfo.setAttributes(toAttributeMap(orgOrgRelationType.getAttributes()));
 218  30
                 orgOrgRelationTypeInfo.setOrgHierarchyKey(orgOrgRelationType.getOrgHierarchy().getId());
 219  30
                 return orgOrgRelationTypeInfo;
 220  
         }
 221  
 
 222  
         public static List<OrgOrgRelationTypeInfo> toOrgOrgRelationTypeInfos(List<OrgOrgRelationType> orgOrgRelationTypes) {
 223  5
                 List<OrgOrgRelationTypeInfo> orgOrgRelationTypeInfos = new ArrayList<OrgOrgRelationTypeInfo>(orgOrgRelationTypes.size());
 224  5
                 for (OrgOrgRelationType orgOrgRelationType : orgOrgRelationTypes) {
 225  29
                         orgOrgRelationTypeInfos.add(toOrgOrgRelationTypeInfo(orgOrgRelationType));
 226  
                 }
 227  
 
 228  5
                 return orgOrgRelationTypeInfos;
 229  
         }
 230  
 
 231  
         public static Org toOrg(boolean isUpdate, OrgInfo orgInfo, OrganizationDao dao)
 232  
                         throws InvalidParameterException, DoesNotExistException, VersionMismatchException {
 233  
                 Org org;
 234  3
                 if (isUpdate) {
 235  2
                         org = dao.fetch(Org.class, orgInfo.getId());
 236  2
                         if (org == null) {
 237  0
                                 throw new DoesNotExistException("Org does not exist for id: " + orgInfo.getId());
 238  
                         }
 239  2
                         if (!String.valueOf(org.getVersionNumber()).equals(orgInfo.getMetaInfo().getVersionInd())){
 240  1
                                 throw new VersionMismatchException("Org to be updated is not the current version");
 241  
                         }
 242  
                 } else {
 243  1
                         org = new Org();
 244  
                 }
 245  
 
 246  
                 // Copy all basic properties
 247  2
                 BeanUtils.copyProperties(orgInfo, org, new String[] { "type",
 248  
                                 "attributes", "metaInfo", "orgPersonRelationTypes" });
 249  
 
 250  
                 // Copy Attributes
 251  2
                 org.setAttributes(toGenericAttributes(OrgAttribute.class, orgInfo.getAttributes(), org, dao));
 252  
 
 253  
                 // Search for and copy the type
 254  2
                 OrgType orgType = dao.fetch(OrgType.class, orgInfo.getType());
 255  2
                 if (orgType == null) {
 256  0
                         throw new InvalidParameterException(
 257  
                                         "OrgType does not exist for id: " + orgInfo.getType());
 258  
                 }
 259  2
                 org.setType(orgType);
 260  
 
 261  2
                 return org;
 262  
         }
 263  
 
 264  
         public static OrgOrgRelation toOrgOrgRelation(boolean isUpdate,
 265  
                         OrgOrgRelationInfo orgOrgRelationInfo,
 266  
                         OrganizationDao dao) throws DoesNotExistException, VersionMismatchException, InvalidParameterException {
 267  
                 OrgOrgRelation orgOrgRelation;
 268  1
                 if (isUpdate) {
 269  0
                         orgOrgRelation = dao.fetch(OrgOrgRelation.class, orgOrgRelationInfo.getId());
 270  0
                         if (orgOrgRelation == null) {
 271  0
                                 throw new DoesNotExistException("OrgOrgRelation does not exist for id: " + orgOrgRelationInfo.getId());
 272  
                         }
 273  0
                         if (!String.valueOf(orgOrgRelation.getVersionNumber()).equals(orgOrgRelationInfo.getMetaInfo().getVersionInd())){
 274  0
                                 throw new VersionMismatchException("OrgOrgRelation to be updated is not the current version");
 275  
                         }
 276  
                 } else {
 277  1
                         orgOrgRelation = new OrgOrgRelation();
 278  
                 }
 279  
 
 280  
                 // Copy all basic properties
 281  1
                 BeanUtils.copyProperties(orgOrgRelationInfo, orgOrgRelation, new String[] { "type",
 282  
                                 "attributes", "metaInfo", "org", "relatedOrg" });
 283  
 
 284  
                 // Copy Attributes
 285  1
                 orgOrgRelation.setAttributes(toGenericAttributes(OrgOrgRelationAttribute.class, orgOrgRelationInfo.getAttributes(), orgOrgRelation, dao));
 286  
 
 287  
                 // Search for and copy the org
 288  1
                 Org org = dao.fetch(Org.class, orgOrgRelationInfo.getOrgId());
 289  1
                 if (org == null) {
 290  0
                         throw new InvalidParameterException(
 291  
                                         "Org does not exist for id: " + orgOrgRelationInfo.getOrgId());
 292  
                 }
 293  1
                 orgOrgRelation.setOrg(org);
 294  
 
 295  
                 // Search for and copy the related org
 296  1
                 Org relatedOrg = dao.fetch(Org.class, orgOrgRelationInfo.getRelatedOrgId());
 297  1
                 if (relatedOrg == null) {
 298  0
                         throw new InvalidParameterException(
 299  
                                         "RelatedOrg does not exist for id: " + orgOrgRelationInfo.getRelatedOrgId());
 300  
                 }
 301  1
                 orgOrgRelation.setRelatedOrg(relatedOrg);
 302  
                 
 303  
                 // Search for and copy the type
 304  1
                 OrgOrgRelationType orgOrgRelationType = dao.fetch(OrgOrgRelationType.class, orgOrgRelationInfo.getType());
 305  1
                 if (orgOrgRelationType == null) {
 306  0
                         throw new InvalidParameterException(
 307  
                                         "OrgOrgRelationType does not exist for id: " + orgOrgRelationInfo.getType());
 308  
                 }
 309  1
                 orgOrgRelation.setType(orgOrgRelationType);
 310  
 
 311  1
                 return orgOrgRelation;
 312  
         }
 313  
 
 314  
         public static OrgPersonRelation toOrgPersonRelation(boolean isUpdate,
 315  
                         OrgPersonRelationInfo orgPersonRelationInfo,
 316  
                         OrganizationDao dao) throws InvalidParameterException, VersionMismatchException, DoesNotExistException {
 317  
                 OrgPersonRelation orgPersonRelation;
 318  1
                 if (isUpdate) {
 319  0
                         orgPersonRelation = dao.fetch(OrgPersonRelation.class, orgPersonRelationInfo.getId());
 320  0
                         if (orgPersonRelation == null) {
 321  0
                                 throw new DoesNotExistException("OrgOrgRelation does not exist for id: " + orgPersonRelationInfo.getId());
 322  
                         }
 323  0
                         if (!String.valueOf(orgPersonRelation.getVersionNumber()).equals(orgPersonRelationInfo.getMetaInfo().getVersionInd())){
 324  0
                                 throw new VersionMismatchException("OrgOrgRelation to be updated is not the current version");
 325  
                         }
 326  
                 } else {
 327  1
                         orgPersonRelation = new OrgPersonRelation();
 328  
                 }
 329  
 
 330  
                 // Copy all basic properties
 331  1
                 BeanUtils.copyProperties(orgPersonRelationInfo, orgPersonRelation, new String[] { "type",
 332  
                                 "attributes", "metaInfo", "org", "personId" });
 333  
 
 334  
                 // Copy Attributes
 335  1
                 orgPersonRelation.setAttributes(toGenericAttributes(OrgPersonRelationAttribute.class, orgPersonRelationInfo.getAttributes(), orgPersonRelation, dao));
 336  
 
 337  
                 // Search for and copy the org
 338  1
                 Org org = dao.fetch(Org.class, orgPersonRelationInfo.getOrgId());
 339  1
                 if (org == null) {
 340  0
                         throw new InvalidParameterException(
 341  
                                         "Org does not exist for id: " + orgPersonRelationInfo.getOrgId());
 342  
                 }
 343  1
                 orgPersonRelation.setOrg(org);
 344  
 
 345  
                 // Search for and copy the related org
 346  
                 //TODO Use the person Service here
 347  
 //                Person person = personService.findPerson(orgPersonRelationInfo.getPersonId());
 348  
 //                if (person == null) {
 349  
 //                        throw new InvalidParameterException(
 350  
 //                                        "Person does not exist for id: " + orgPersonRelationInfo.getPersonId());
 351  
 //                }
 352  
 //                orgPersonRelation.setPersonId(person.getId());
 353  1
                 orgPersonRelation.setPersonId(orgPersonRelationInfo.getPersonId());
 354  
                 
 355  
                 // Search for and copy the type
 356  1
                 OrgPersonRelationType orgPersonRelationType = dao.fetch(OrgPersonRelationType.class, orgPersonRelationInfo.getType());
 357  1
                 if (orgPersonRelationType == null) {
 358  0
                         throw new InvalidParameterException(
 359  
                                         "OrgPersonRelationType does not exist for id: " + orgPersonRelationInfo.getType());
 360  
                 }
 361  1
                 orgPersonRelation.setType(orgPersonRelationType);
 362  
 
 363  1
                 return orgPersonRelation;
 364  
         }
 365  
 
 366  
         public static OrgPositionRestriction toOrgPositionRestriction(boolean isUpdate,
 367  
                         OrgPositionRestrictionInfo orgPositionRestrictionInfo,
 368  
                         OrganizationDao dao) throws DoesNotExistException, VersionMismatchException, InvalidParameterException {
 369  
                 OrgPositionRestriction orgPositionRestriction;
 370  2
                 if (isUpdate) {
 371  0
                         orgPositionRestriction = dao.fetch(OrgPositionRestriction.class, orgPositionRestrictionInfo.getId());
 372  0
                         if (orgPositionRestriction == null) {
 373  0
                                 throw new DoesNotExistException("OrgPositionRestriction does not exist for id: " + orgPositionRestrictionInfo.getId());
 374  
                         }
 375  0
                         if (!String.valueOf(orgPositionRestriction.getVersionNumber()).equals(orgPositionRestrictionInfo.getMetaInfo().getVersionInd())){
 376  0
                                 throw new VersionMismatchException("OrgPositionRestriction to be updated is not the current version");
 377  
                         }
 378  
                 } else {
 379  2
                         orgPositionRestriction = new OrgPositionRestriction();
 380  
                 }
 381  
 
 382  
                 // Copy all basic properties
 383  2
                 BeanUtils.copyProperties(orgPositionRestrictionInfo, orgPositionRestriction, new String[] { "personRelationType",
 384  
                                 "attributes", "metaInfo", "org", "stdDuration" });
 385  2
                 if(orgPositionRestrictionInfo.getStdDuration()!=null){
 386  2
                         orgPositionRestriction.setStdDuration(new TimeAmount());
 387  2
                         BeanUtils.copyProperties(orgPositionRestrictionInfo.getStdDuration(), orgPositionRestriction.getStdDuration());
 388  
                 }
 389  
                 // Copy Attributes
 390  2
                 orgPositionRestriction.setAttributes(toGenericAttributes(OrgPositionRestrictionAttribute.class, orgPositionRestrictionInfo.getAttributes(), orgPositionRestriction, dao));
 391  
 
 392  
                 // Search for and copy the org
 393  2
                 Org org = dao.fetch(Org.class, orgPositionRestrictionInfo.getOrgId());
 394  2
                 if (org == null) {
 395  0
                         throw new InvalidParameterException(
 396  
                                         "Org does not exist for id: " + orgPositionRestrictionInfo.getOrgId());
 397  
                 }
 398  2
                 orgPositionRestriction.setOrg(org);
 399  
 
 400  
                 // Search for and copy the type
 401  2
                 OrgPersonRelationType orgPersonRelationType = dao.fetch(OrgPersonRelationType.class, orgPositionRestrictionInfo.getOrgPersonRelationTypeKey());
 402  2
                 if (orgPersonRelationType == null) {
 403  0
                         throw new InvalidParameterException(
 404  
                                         "OrgPersonRelationType does not exist for id: " + orgPositionRestrictionInfo.getOrgPersonRelationTypeKey());
 405  
                 }
 406  2
                 orgPositionRestriction.setPersonRelationType(orgPersonRelationType);
 407  
 
 408  2
                 orgPositionRestriction.setDescr(orgPositionRestrictionInfo.getDesc());
 409  
                 
 410  2
                 return orgPositionRestriction;
 411  
         }
 412  
 }