public void saveCarePlans(CarePlanForCopyCarePlansVoCollection collCarePlansToSave) throws StaleObjectException { if (collCarePlansToSave == null || collCarePlansToSave.size() == 0) { throw new CodingRuntimeException("Cannot copy Care Plans"); } DomainFactory factory = getDomainFactory(); for (int i = 0; i < collCarePlansToSave.size(); i++) { CarePlan domainCarePlan = CarePlanForCopyCarePlansVoAssembler.extractCarePlan(factory, collCarePlansToSave.get(i)); factory.save(domainCarePlan); } }
private boolean save() { CarePlanForCopyCarePlansVoCollection collCarePlansToSave = new CarePlanForCopyCarePlansVoCollection(); for (int i = 0; i < form.grdCarePlans().getRows().size(); i++) { if (form.grdCarePlans().getRows().get(i).getcolSelect()) { collCarePlansToSave.add(populateCarePlanDataFromScreen(form.grdCarePlans().getRows().get(i).getValue())); } } if (collCarePlansToSave == null || collCarePlansToSave.size() == 0) { engine.showMessage("At least one Care Plan should be selected to be able to copy!"); return false; } for (int i = 0; i < collCarePlansToSave.size(); i++) { String[] errors = collCarePlansToSave.get(i).validate(); if (errors != null && errors.length > 0) { engine.showErrors(errors); return false; } } if (currentEpisodeHaveCarePlans()) { engine.showMessage(ConfigFlag.UI.STALE_OBJECT_MESSAGE.getValue()); engine.close(DialogResult.ABORT); return false; } try { domain.saveCarePlans(collCarePlansToSave); } catch (StaleObjectException e) { engine.showMessage(ConfigFlag.UI.STALE_OBJECT_MESSAGE.getValue()); engine.close(DialogResult.ABORT); return false; } return true; }