//МЕСТО РАБОТЫ И ДОЛЖНОСТЬ
if (!c.job.isEmpty()) {
Field f1[] = { new Field("client", client) };
List<Job> jobList = findEntityList(Job.class, f1);
Job job = null;
for (Job item : jobList) {
if (item.getEnterprise().getTitle().equals(c.job)) {
job = item;
break;
}
}
if (job == null) {
//Создание новой работы, возможно с созданием нового предприятия
Field f2[] = { new Field("title", c.job) };
List<Enterprise> entList = findEntityList(Enterprise.class, f2);
Enterprise enterprise;
if (entList.size() > 0) {
//хотябы одно предприятие с совпадающим тайтлом
enterprise = entList.get(0);
} else {
enterprise = new Enterprise();
enterprise.setTitle(c.job);
manager.persist(enterprise);
manager.flush();
manager.refresh(enterprise);
enterprise.setTreePath(enterprise.getId() + ".");
manager.persist(enterprise);
}
job = new Job();
job.setClient(client);
job.setEnterprise(enterprise);
job.setBegin(DateTimeUtils.getDateOnly());
manager.persist(job);
manager.flush();
manager.refresh(job);
}
if (c.appointmentID == 0) {
job.setAppointment(null);
} else {
job.setAppointment(findEntity(Appointment.class, c.appointmentID));
}
manager.persist(job);
manager.flush();
}