| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 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 | 0 | List<OrgHierarchyInfo> orgHierarchyInfos = new ArrayList<OrgHierarchyInfo>(orgHierarchys.size()); |
| 55 | 0 | for(OrgHierarchy orgHierarchy:orgHierarchys){ |
| 56 | 0 | orgHierarchyInfos.add(toOrgHierarchyInfo(orgHierarchy)); |
| 57 | |
} |
| 58 | 0 | return orgHierarchyInfos; |
| 59 | |
} |
| 60 | |
|
| 61 | |
public static OrgHierarchyInfo toOrgHierarchyInfo(OrgHierarchy orgHierarchy) { |
| 62 | 0 | if (orgHierarchy == null) { |
| 63 | 0 | return null; |
| 64 | |
} |
| 65 | |
|
| 66 | 0 | OrgHierarchyInfo orgHierarchyInfo = new OrgHierarchyInfo(); |
| 67 | |
|
| 68 | 0 | BeanUtils.copyProperties(orgHierarchy, orgHierarchyInfo, new String[] { "rootOrgId", |
| 69 | |
"attributes" }); |
| 70 | |
|
| 71 | |
|
| 72 | 0 | orgHierarchyInfo.setAttributes(toAttributeMap(orgHierarchy.getAttributes())); |
| 73 | 0 | orgHierarchyInfo.setRootOrgId(orgHierarchy.getRootOrg().getId()); |
| 74 | 0 | orgHierarchyInfo.setDescr(orgHierarchy.getDescr()); |
| 75 | 0 | 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 | 0 | if (org == null) { |
| 88 | 0 | return null; |
| 89 | |
} |
| 90 | |
|
| 91 | 0 | OrgInfo orgInfo = new OrgInfo(); |
| 92 | |
|
| 93 | 0 | BeanUtils.copyProperties(org, orgInfo, new String[] { "type", |
| 94 | |
"attributes", "metaInfo" }); |
| 95 | |
|
| 96 | |
|
| 97 | 0 | orgInfo.setAttributes(toAttributeMap(org.getAttributes())); |
| 98 | 0 | orgInfo.setMetaInfo(toMetaInfo(org.getMeta(), org.getVersionNumber())); |
| 99 | 0 | orgInfo.setType(org.getType().getId()); |
| 100 | |
|
| 101 | 0 | return orgInfo; |
| 102 | |
} |
| 103 | |
|
| 104 | |
public static List<OrgPersonRelationInfo> toOrgPersonRelationInfos(List<OrgPersonRelation> relations) { |
| 105 | 0 | List<OrgPersonRelationInfo> relationInfos = new ArrayList<OrgPersonRelationInfo>(relations.size()); |
| 106 | 0 | for (OrgPersonRelation relation : relations) { |
| 107 | 0 | relationInfos.add(toOrgPersonRelationInfo(relation)); |
| 108 | |
} |
| 109 | 0 | return relationInfos; |
| 110 | |
} |
| 111 | |
|
| 112 | |
public static OrgPersonRelationInfo toOrgPersonRelationInfo(OrgPersonRelation relation) { |
| 113 | 0 | OrgPersonRelationInfo relationInfo = new OrgPersonRelationInfo(); |
| 114 | |
|
| 115 | 0 | BeanUtils.copyProperties(relation, relationInfo, new String[] { "type", |
| 116 | |
"attributes", "metaInfo", "orgId"}); |
| 117 | |
|
| 118 | 0 | relationInfo.setOrgId(relation.getOrg().getId()); |
| 119 | 0 | relationInfo.setAttributes(toAttributeMap(relation.getAttributes())); |
| 120 | 0 | relationInfo.setMetaInfo(toMetaInfo(relation.getMeta(), relation.getVersionNumber())); |
| 121 | 0 | relationInfo.setType(relation.getType().getId()); |
| 122 | |
|
| 123 | 0 | return relationInfo; |
| 124 | |
} |
| 125 | |
|
| 126 | |
public static List<OrgOrgRelationInfo> toOrgOrgRelationInfos( |
| 127 | |
List<OrgOrgRelation> orgOrgRelations) { |
| 128 | 0 | List<OrgOrgRelationInfo> orgOrgRelationInfo = new ArrayList<OrgOrgRelationInfo>(); |
| 129 | 0 | for(OrgOrgRelation orgOrgRelation:orgOrgRelations){ |
| 130 | 0 | orgOrgRelationInfo.add(toOrgOrgRelationInfo(orgOrgRelation)); |
| 131 | |
} |
| 132 | 0 | return orgOrgRelationInfo; |
| 133 | |
} |
| 134 | |
|
| 135 | |
public static OrgOrgRelationInfo toOrgOrgRelationInfo( |
| 136 | |
OrgOrgRelation orgOrgRelation) { |
| 137 | 0 | if (orgOrgRelation == null) { |
| 138 | 0 | return null; |
| 139 | |
} |
| 140 | 0 | OrgOrgRelationInfo orgOrgRelationInfo = new OrgOrgRelationInfo(); |
| 141 | |
|
| 142 | 0 | BeanUtils.copyProperties(orgOrgRelation, orgOrgRelationInfo, new String[] { "type", |
| 143 | |
"attributes", "metaInfo","orgId","relatedOrgId" }); |
| 144 | |
|
| 145 | |
|
| 146 | 0 | orgOrgRelationInfo.setAttributes(toAttributeMap(orgOrgRelation.getAttributes())); |
| 147 | 0 | orgOrgRelationInfo.setMetaInfo(toMetaInfo(orgOrgRelation.getMeta(), orgOrgRelation.getVersionNumber())); |
| 148 | 0 | orgOrgRelationInfo.setType(orgOrgRelation.getType().getId()); |
| 149 | 0 | orgOrgRelationInfo.setOrgId(orgOrgRelation.getOrg().getId()); |
| 150 | 0 | orgOrgRelationInfo.setRelatedOrgId(orgOrgRelation.getRelatedOrg().getId()); |
| 151 | |
|
| 152 | 0 | return orgOrgRelationInfo; |
| 153 | |
} |
| 154 | |
|
| 155 | |
public static OrgPositionRestrictionInfo toOrgPositionRestrictionInfo(OrgPositionRestriction restriction) { |
| 156 | 0 | OrgPositionRestrictionInfo restrictionInfo = new OrgPositionRestrictionInfo(); |
| 157 | |
|
| 158 | 0 | BeanUtils.copyProperties(restriction, restrictionInfo, new String[] { "attributes", "metaInfo","orgId","personRelationType","stdDuration" }); |
| 159 | |
|
| 160 | 0 | if(restriction.getStdDuration()!=null){ |
| 161 | 0 | restrictionInfo.setStdDuration(new TimeAmountInfo()); |
| 162 | 0 | BeanUtils.copyProperties(restriction.getStdDuration(), restrictionInfo.getStdDuration()); |
| 163 | |
} |
| 164 | |
|
| 165 | 0 | restrictionInfo.setOrgId(restriction.getOrg().getId()); |
| 166 | 0 | restrictionInfo.setAttributes(toAttributeMap(restriction.getAttributes())); |
| 167 | 0 | restrictionInfo.setMetaInfo(toMetaInfo(restriction.getMeta(), restriction.getVersionNumber())); |
| 168 | 0 | restrictionInfo.setOrgPersonRelationTypeKey(restriction.getPersonRelationType().getId()); |
| 169 | 0 | restrictionInfo.setDesc(restriction.getDescr()); |
| 170 | 0 | return restrictionInfo; |
| 171 | |
|
| 172 | |
} |
| 173 | |
public static List<OrgPositionRestrictionInfo> toOrgPositionRestrictionInfos(List<OrgPositionRestriction> restrictions) { |
| 174 | 0 | List<OrgPositionRestrictionInfo> restrictionInfos = new ArrayList<OrgPositionRestrictionInfo>(restrictions.size()); |
| 175 | 0 | for (OrgPositionRestriction restriction : restrictions) { |
| 176 | 0 | restrictionInfos.add(toOrgPositionRestrictionInfo(restriction)); |
| 177 | |
} |
| 178 | 0 | return restrictionInfos; |
| 179 | |
} |
| 180 | |
|
| 181 | |
public static OrgTypeInfo toOrgTypeInfo(OrgType orgType) { |
| 182 | 0 | return toGenericTypeInfo(OrgTypeInfo.class, orgType); |
| 183 | |
} |
| 184 | |
|
| 185 | |
public static List<OrgTypeInfo> toOrgTypeInfos(List<OrgType> orgTypes) { |
| 186 | 0 | List<OrgTypeInfo> orgTypeInfos = new ArrayList<OrgTypeInfo>(orgTypes.size()); |
| 187 | 0 | for (OrgType orgType : orgTypes) { |
| 188 | 0 | orgTypeInfos.add(toOrgTypeInfo(orgType)); |
| 189 | |
} |
| 190 | 0 | return orgTypeInfos; |
| 191 | |
} |
| 192 | |
|
| 193 | |
public static OrgPersonRelationTypeInfo toOrgPersonRelationTypeInfo(OrgPersonRelationType orgPersonRelationType) { |
| 194 | 0 | OrgPersonRelationTypeInfo orgPersonRelationTypeInfo = new OrgPersonRelationTypeInfo(); |
| 195 | 0 | BeanUtils.copyProperties(orgPersonRelationType, orgPersonRelationTypeInfo, new String[] { "attributes", "orgHierarchy"}); |
| 196 | |
|
| 197 | 0 | orgPersonRelationTypeInfo.setAttributes(toAttributeMap(orgPersonRelationType.getAttributes())); |
| 198 | 0 | return orgPersonRelationTypeInfo; |
| 199 | |
} |
| 200 | |
|
| 201 | |
public static List<OrgPersonRelationTypeInfo> toOrgPersonRelationTypeInfos(List<OrgPersonRelationType> orgPersonRelationTypes) { |
| 202 | 0 | List<OrgPersonRelationTypeInfo> oprtys = new ArrayList<OrgPersonRelationTypeInfo>(orgPersonRelationTypes.size()); |
| 203 | 0 | for (OrgPersonRelationType type : orgPersonRelationTypes) { |
| 204 | 0 | oprtys.add(toOrgPersonRelationTypeInfo(type)); |
| 205 | |
} |
| 206 | 0 | return oprtys; |
| 207 | |
} |
| 208 | |
|
| 209 | |
public static OrgOrgRelationTypeInfo toOrgOrgRelationTypeInfo(OrgOrgRelationType orgOrgRelationType) { |
| 210 | 0 | if (orgOrgRelationType == null) { |
| 211 | 0 | return null; |
| 212 | |
} |
| 213 | |
|
| 214 | 0 | OrgOrgRelationTypeInfo orgOrgRelationTypeInfo = new OrgOrgRelationTypeInfo(); |
| 215 | 0 | BeanUtils.copyProperties(orgOrgRelationType, orgOrgRelationTypeInfo, new String[] { "attributes", "orgHierarchy"}); |
| 216 | |
|
| 217 | 0 | orgOrgRelationTypeInfo.setAttributes(toAttributeMap(orgOrgRelationType.getAttributes())); |
| 218 | 0 | orgOrgRelationTypeInfo.setOrgHierarchyKey(orgOrgRelationType.getOrgHierarchy().getId()); |
| 219 | 0 | return orgOrgRelationTypeInfo; |
| 220 | |
} |
| 221 | |
|
| 222 | |
public static List<OrgOrgRelationTypeInfo> toOrgOrgRelationTypeInfos(List<OrgOrgRelationType> orgOrgRelationTypes) { |
| 223 | 0 | List<OrgOrgRelationTypeInfo> orgOrgRelationTypeInfos = new ArrayList<OrgOrgRelationTypeInfo>(orgOrgRelationTypes.size()); |
| 224 | 0 | for (OrgOrgRelationType orgOrgRelationType : orgOrgRelationTypes) { |
| 225 | 0 | orgOrgRelationTypeInfos.add(toOrgOrgRelationTypeInfo(orgOrgRelationType)); |
| 226 | |
} |
| 227 | |
|
| 228 | 0 | return orgOrgRelationTypeInfos; |
| 229 | |
} |
| 230 | |
|
| 231 | |
public static Org toOrg(boolean isUpdate, OrgInfo orgInfo, OrganizationDao dao) |
| 232 | |
throws InvalidParameterException, DoesNotExistException, VersionMismatchException { |
| 233 | |
Org org; |
| 234 | 0 | if (isUpdate) { |
| 235 | 0 | org = dao.fetch(Org.class, orgInfo.getId()); |
| 236 | 0 | if (org == null) { |
| 237 | 0 | throw new DoesNotExistException("Org does not exist for id: " + orgInfo.getId()); |
| 238 | |
} |
| 239 | 0 | if (!String.valueOf(org.getVersionNumber()).equals(orgInfo.getMetaInfo().getVersionInd())){ |
| 240 | 0 | throw new VersionMismatchException("Org to be updated is not the current version"); |
| 241 | |
} |
| 242 | |
} else { |
| 243 | 0 | org = new Org(); |
| 244 | |
} |
| 245 | |
|
| 246 | |
|
| 247 | 0 | BeanUtils.copyProperties(orgInfo, org, new String[] { "type", |
| 248 | |
"attributes", "metaInfo", "orgPersonRelationTypes" }); |
| 249 | |
|
| 250 | |
|
| 251 | 0 | org.setAttributes(toGenericAttributes(OrgAttribute.class, orgInfo.getAttributes(), org, dao)); |
| 252 | |
|
| 253 | |
|
| 254 | 0 | OrgType orgType = dao.fetch(OrgType.class, orgInfo.getType()); |
| 255 | 0 | if (orgType == null) { |
| 256 | 0 | throw new InvalidParameterException( |
| 257 | |
"OrgType does not exist for id: " + orgInfo.getType()); |
| 258 | |
} |
| 259 | 0 | org.setType(orgType); |
| 260 | |
|
| 261 | 0 | 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 | 0 | 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 | 0 | orgOrgRelation = new OrgOrgRelation(); |
| 278 | |
} |
| 279 | |
|
| 280 | |
|
| 281 | 0 | BeanUtils.copyProperties(orgOrgRelationInfo, orgOrgRelation, new String[] { "type", |
| 282 | |
"attributes", "metaInfo", "org", "relatedOrg" }); |
| 283 | |
|
| 284 | |
|
| 285 | 0 | orgOrgRelation.setAttributes(toGenericAttributes(OrgOrgRelationAttribute.class, orgOrgRelationInfo.getAttributes(), orgOrgRelation, dao)); |
| 286 | |
|
| 287 | |
|
| 288 | 0 | Org org = dao.fetch(Org.class, orgOrgRelationInfo.getOrgId()); |
| 289 | 0 | if (org == null) { |
| 290 | 0 | throw new InvalidParameterException( |
| 291 | |
"Org does not exist for id: " + orgOrgRelationInfo.getOrgId()); |
| 292 | |
} |
| 293 | 0 | orgOrgRelation.setOrg(org); |
| 294 | |
|
| 295 | |
|
| 296 | 0 | Org relatedOrg = dao.fetch(Org.class, orgOrgRelationInfo.getRelatedOrgId()); |
| 297 | 0 | if (relatedOrg == null) { |
| 298 | 0 | throw new InvalidParameterException( |
| 299 | |
"RelatedOrg does not exist for id: " + orgOrgRelationInfo.getRelatedOrgId()); |
| 300 | |
} |
| 301 | 0 | orgOrgRelation.setRelatedOrg(relatedOrg); |
| 302 | |
|
| 303 | |
|
| 304 | 0 | OrgOrgRelationType orgOrgRelationType = dao.fetch(OrgOrgRelationType.class, orgOrgRelationInfo.getType()); |
| 305 | 0 | if (orgOrgRelationType == null) { |
| 306 | 0 | throw new InvalidParameterException( |
| 307 | |
"OrgOrgRelationType does not exist for id: " + orgOrgRelationInfo.getType()); |
| 308 | |
} |
| 309 | 0 | orgOrgRelation.setType(orgOrgRelationType); |
| 310 | |
|
| 311 | 0 | 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 | 0 | 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 | 0 | orgPersonRelation = new OrgPersonRelation(); |
| 328 | |
} |
| 329 | |
|
| 330 | |
|
| 331 | 0 | BeanUtils.copyProperties(orgPersonRelationInfo, orgPersonRelation, new String[] { "type", |
| 332 | |
"attributes", "metaInfo", "org", "personId" }); |
| 333 | |
|
| 334 | |
|
| 335 | 0 | orgPersonRelation.setAttributes(toGenericAttributes(OrgPersonRelationAttribute.class, orgPersonRelationInfo.getAttributes(), orgPersonRelation, dao)); |
| 336 | |
|
| 337 | |
|
| 338 | 0 | Org org = dao.fetch(Org.class, orgPersonRelationInfo.getOrgId()); |
| 339 | 0 | if (org == null) { |
| 340 | 0 | throw new InvalidParameterException( |
| 341 | |
"Org does not exist for id: " + orgPersonRelationInfo.getOrgId()); |
| 342 | |
} |
| 343 | 0 | orgPersonRelation.setOrg(org); |
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | 0 | orgPersonRelation.setPersonId(orgPersonRelationInfo.getPersonId()); |
| 354 | |
|
| 355 | |
|
| 356 | 0 | OrgPersonRelationType orgPersonRelationType = dao.fetch(OrgPersonRelationType.class, orgPersonRelationInfo.getType()); |
| 357 | 0 | if (orgPersonRelationType == null) { |
| 358 | 0 | throw new InvalidParameterException( |
| 359 | |
"OrgPersonRelationType does not exist for id: " + orgPersonRelationInfo.getType()); |
| 360 | |
} |
| 361 | 0 | orgPersonRelation.setType(orgPersonRelationType); |
| 362 | |
|
| 363 | 0 | 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 | 0 | 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 | 0 | orgPositionRestriction = new OrgPositionRestriction(); |
| 380 | |
} |
| 381 | |
|
| 382 | |
|
| 383 | 0 | BeanUtils.copyProperties(orgPositionRestrictionInfo, orgPositionRestriction, new String[] { "personRelationType", |
| 384 | |
"attributes", "metaInfo", "org", "stdDuration" }); |
| 385 | 0 | if(orgPositionRestrictionInfo.getStdDuration()!=null){ |
| 386 | 0 | orgPositionRestriction.setStdDuration(new TimeAmount()); |
| 387 | 0 | BeanUtils.copyProperties(orgPositionRestrictionInfo.getStdDuration(), orgPositionRestriction.getStdDuration()); |
| 388 | |
} |
| 389 | |
|
| 390 | 0 | orgPositionRestriction.setAttributes(toGenericAttributes(OrgPositionRestrictionAttribute.class, orgPositionRestrictionInfo.getAttributes(), orgPositionRestriction, dao)); |
| 391 | |
|
| 392 | |
|
| 393 | 0 | Org org = dao.fetch(Org.class, orgPositionRestrictionInfo.getOrgId()); |
| 394 | 0 | if (org == null) { |
| 395 | 0 | throw new InvalidParameterException( |
| 396 | |
"Org does not exist for id: " + orgPositionRestrictionInfo.getOrgId()); |
| 397 | |
} |
| 398 | 0 | orgPositionRestriction.setOrg(org); |
| 399 | |
|
| 400 | |
|
| 401 | 0 | OrgPersonRelationType orgPersonRelationType = dao.fetch(OrgPersonRelationType.class, orgPositionRestrictionInfo.getOrgPersonRelationTypeKey()); |
| 402 | 0 | if (orgPersonRelationType == null) { |
| 403 | 0 | throw new InvalidParameterException( |
| 404 | |
"OrgPersonRelationType does not exist for id: " + orgPositionRestrictionInfo.getOrgPersonRelationTypeKey()); |
| 405 | |
} |
| 406 | 0 | orgPositionRestriction.setPersonRelationType(orgPersonRelationType); |
| 407 | |
|
| 408 | 0 | orgPositionRestriction.setDescr(orgPositionRestrictionInfo.getDesc()); |
| 409 | |
|
| 410 | 0 | return orgPositionRestriction; |
| 411 | |
} |
| 412 | |
} |