@Override
public ModificationInfo addFunctions(CollaboratorFunctionsDetails cfd) throws ClipsServerException {
Collaborator collaborator = getExistentEntity();
if (collaborator.getId() != cfd.collaboratorID){
throw new EDataIntegrity("Попытка добавить исполняемые обязанности другому сотруднику");
}
int count = getEntityCount(CollaboratorFunctions.class,
new Field[]{new Field("collaborator", collaborator),
new Field("dvr.id", cfd.dvrID),
new Field("firstMedicalAid.id", cfd.firstMedicalAidID),
new Field("receptionType.id", cfd.receptionTypeID),
new Field("speciality.id", cfd.specialityID),
new Field("trash", false)});
if (count > 0){
throw new EDataIntegrity("У данного сотрудника уже есть исполняемые обязанности с указанными параметрами");
}
CollaboratorFunctions functions;
if (cfd.id == 0){
functions = new CollaboratorFunctions(collaborator,
cfd.dvrID != 0 ? findEntity(Dvr.class, cfd.dvrID) : null,
cfd.firstMedicalAidID != 0 ? findEntity(MedicalAidType.class, cfd.firstMedicalAidID) : null,
findEntity(ReceptionType.class, cfd.receptionTypeID),
findEntity(Speciality.class, cfd.specialityID),
cfd.external_key);
collaborator.addFunction(functions);
}else{
throw new EDataIntegrity("Данные не могут быть изменены");
}
manager.flush();
AuditDoc<CollaboratorFunctions> auditDoc = new AuditDoc<CollaboratorFunctions>(null, getCollaborator());
auditDoc.check(functions);