@Transactional(readOnly = true)
public AddingSatisfactionResult addSatisfaction(ICriterionType<?> type,
CriterionSatisfaction original, CriterionSatisfaction edited) {
/* Check worker's version. */
Worker worker = getWorker();
resourceDAO.checkVersion(worker);
/* Add criterion satisfaction. */
edited.setResource(worker);
boolean previouslyContained = false;
if (previouslyContained = worker.contains(original)) {
worker.removeCriterionSatisfaction(original);
}
boolean canAdd = false;
try {
canAdd = worker.canAddSatisfaction(type, edited);
} catch (IllegalArgumentException e) {
if (previouslyContained) {
worker.addSatisfaction(type, original);
}
return AddingSatisfactionResult.SATISFACTION_WRONG;
}
if (!canAdd) {
if (previouslyContained) {
worker.addSatisfaction(type, original);
}
return AddingSatisfactionResult.DONT_COMPLY_OVERLAPPING_RESTRICTIONS;
}
worker.addSatisfaction(type, edited);
return AddingSatisfactionResult.OK;
}