Skip to content

Commit

Permalink
Add Distribution Preference
Browse files Browse the repository at this point in the history
- fixed a Hibernate error when a Departmental Schedule Manager is creating a Required/Prohibited distribution preference to be owned by an external department that does not allow for required distribution preferences
  - Error: There are delayed insert actions before operation as cascade level 0.
  • Loading branch information
tomas-muller committed Aug 21, 2024
1 parent 7c84a12 commit 0885742
Showing 1 changed file with 13 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -647,14 +647,16 @@ private void doAddOrUpdate() throws Exception {
dp.setDistributionObjects(s);
oldOwner = (Department)dp.getOwner();
}
} else dp = new DistributionPref();
} else {
dp = new DistributionPref();
}

dp.setDistributionType(DistributionTypeDAO.getInstance().get( Long.valueOf(form.getDistType()), hibSession));
dp.setStructure(form.getStructure());
dp.setPrefLevel(PreferenceLevel.getPreferenceLevel( Integer.parseInt(form.getPrefLevel()) ));

Department owningDept = null;

List<DistributionObject> distributionObjects = new ArrayList<DistributionObject>();
// Create distribution objects
for (int i=0; i<saList.size(); i++) {
String su = suList.get(i).toString();
Expand Down Expand Up @@ -697,58 +699,22 @@ else if (owningDept.getDistributionPrefPriority().intValue()==clazz.getManagingD
}

dObj.setSequenceNumber(Integer.valueOf(i+1));
dObj.setDistributionPref(dp);
dObj.getPrefGroup().getDistributionObjects().add(dObj);

dp.addToDistributionObjects(dObj);
if (dp.getUniqueId() != null)
hibSession.persist(dObj);
distributionObjects.add(dObj);
}

dp.setOwner(owningDept);

/*
if (dp.getOwner()==null)
throw new Exception("Creation of such constraint denied: no owner specified.");
if (sessionContext.hasPermission(Right.) && !dp.getDistributionType().isApplicable(owningDept)) {
throw new Exception("Creation of such constraint denied: distribution preference "+dp.getDistributionType().getLabel()+" not allowed for "+dp.getOwner()+".");
}
if (!sessionContext.hasPermission(dp.getOwner(), Right.DistributionPreferenceAdd))
throw new Exception("Creation of such constraint denied: unable to create constraint owned by "+dp.getOwner()+".");
if (!sessionContext.getUser().getCurrentAuthority().hasQualifier((Department)dp.getOwner()) && !((Department)dp.getOwner()).effectiveStatusType().canOwnerEdit())
throw new Exception("Creation of such constraint denied: unable to create constraint owned by "+dp.getOwner()+".");
if (dp.getUniqueId() == null) hibSession.persist(dp);

if (currentMgr.isExternalManager() && !sessionContext.getUser().getCurrentAuthority().hasQualifier((Department)dp.getOwner()))
throw new Exception("Creation of such constraint denied: unable to create constraint owned by "+dp.getOwner()+".");
Department dept = (Department)dp.getOwner();
if (dept.isExternalManager() && !dept.isAllowReqDistribution() && !sessionContext.getUser().getCurrentAuthority().hasQualifier((Department)dp.getOwner())) {
if (dp.getPrefLevel().getPrefProlog().equals(PreferenceLevel.sRequired)) {
if (dp.getDistributionType().getAllowedPref().indexOf(PreferenceLevel.sCharLevelStronglyPreferred)>=0)
dp.setPrefLevel(PreferenceLevel.getPreferenceLevel(PreferenceLevel.sStronglyPreferred));
else
throw new Exception("Creation of such constraint denied: unable to create "+dp.getPrefLevel().getPrefName()+" constraint owned by "+dp.getOwner()+".");
}
if (dp.getPrefLevel().getPrefProlog().equals(PreferenceLevel.sProhibited)) {
if (dp.getDistributionType().getAllowedPref().indexOf(PreferenceLevel.sCharLevelStronglyDiscouraged)>=0)
dp.setPrefLevel(PreferenceLevel.getPreferenceLevel(PreferenceLevel.sStronglyDiscouraged));
else
throw new Exception("Creation of such constraint denied: unable to create "+dp.getPrefLevel().getPrefName()+" constraint owned by "+dp.getOwner()+".");
}
}
}*/
for (DistributionObject dObj: distributionObjects) {
dObj.setDistributionPref(dp);
dp.addToDistributionObjects(dObj);
hibSession.persist(dObj);
}

sessionContext.checkPermission(dp, Right.DistributionPreferenceEdit);

// Save
if (dp.getUniqueId() == null)
hibSession.persist(dp);
else
hibSession.merge(dp);
hibSession.merge(dp);

Permission<InstructionalOffering> permissionOfferingLockNeeded = getPermission("permissionOfferingLockNeeded");

Expand Down

0 comments on commit 0885742

Please sign in to comment.