if(details.dangerId == 0) {
throw new EDataIntegrity("Попытка назначить услуги опасному фактору с ID=0");
}
DangerService dangerService = null;
Field f[] = {
new Field("danger.id", details.dangerId),
new Field("service.id", details.serviceId),
new Field("speciality.id", details.specialityID)
};
Field fNull[] = {
new Field("danger.id", details.dangerId),
new Field("service.id", details.serviceId),
new Field("speciality", null, Field.OPERATOR_IS_NULL)
};
List list;
if (details.specialityID == 0) {
list = findEntityList(DangerService.class, fNull);
} else {
list = findEntityList(DangerService.class, f);
}
if (!list.isEmpty()){
dangerService = (DangerService) list.get(0);//Должна быть одна и ниибёт
dangerService.setDescription(details.description);
Speciality spec = null;
if (details.specialityID != 0) {
spec = findEntity(Speciality.class, details.specialityID);
}
dangerService.setSpeciality(spec);
}
else {
dangerService = new DangerService();
dangerService.setDescription(details.description);
dangerService.setDanger(findEntity(Danger.class, details.dangerId));
dangerService.setService(findEntity(Service.class, details.serviceId));
Speciality spec = null;
if (details.specialityID != 0) {
spec = findEntity(Speciality.class, details.specialityID);
}
dangerService.setSpeciality(spec);
}
return saveEntity(dangerService);
}