if(pserviceId == 0) {
throw new EDataIntegrity("Попытка назначить связанную услугу услуге с ID=0");
}
ServiceToService serviceToService = null;
if(details.pserviceId != 0) {
Field f[] = {
new Field("key.pservice", pserviceId),
new Field("key.cservice", details.cserviceId)
};
List list = findEntityList(ServiceToService.class, f);
if (!list.isEmpty()){
serviceToService = (ServiceToService) list.get(0);//Должна быть одна
serviceToService.setDescription(details.description);
serviceToService.setObligatory(details.obligatory);
}
else {
serviceToService = new ServiceToService();
serviceToService.setKey(new ServiceToServicePK(pserviceId, details.cserviceId));
serviceToService.setDescription(details.description);
serviceToService.setObligatory(details.obligatory);
serviceToService.setParentService(findEntity(Service.class, details.pserviceId));
serviceToService.setChildService(findEntity(Service.class, details.cserviceId));
}
}
return saveEntity(serviceToService);
}