@Test public void whenFormHasSoftDeletedInstances_deletesForm() { formsRepository.save(new Form.Builder() .id(1L) .jrFormId("id") .jrVersion("version") .build()); instancesRepository.save(new Instance.Builder() .jrFormId("id") .jrVersion("version") .deletedDate(0L) .build()); formDeleter.delete(1L); assertThat(formsRepository.getAll().size(), is(0)); }
public void delete(Long id) { Form form = formsRepository.get(id); List<Instance> instancesForVersion = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (instancesForVersion.isEmpty()) { formsRepository.delete(id); } else { formsRepository.softDelete(form.getId()); } }
FormDeleter { public void delete(Long id) { Form form = formsRepository.get(id); List<Instance> instancesForVersion = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (instancesForVersion.isEmpty()) { formsRepository.delete(id); } else { formsRepository.softDelete(form.getId()); } } }
FormDeleter { public void delete(Long id) { Form form = formsRepository.get(id); List<Instance> instancesForVersion = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (instancesForVersion.isEmpty()) { formsRepository.delete(id); } else { formsRepository.softDelete(form.getId()); } } FormDeleter(FormsRepository formsRepository, InstancesRepository instancesRepository); }
FormDeleter { public void delete(Long id) { Form form = formsRepository.get(id); List<Instance> instancesForVersion = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (instancesForVersion.isEmpty()) { formsRepository.delete(id); } else { formsRepository.softDelete(form.getId()); } } FormDeleter(FormsRepository formsRepository, InstancesRepository instancesRepository); void delete(Long id); }
FormDeleter { public void delete(Long id) { Form form = formsRepository.get(id); List<Instance> instancesForVersion = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (instancesForVersion.isEmpty()) { formsRepository.delete(id); } else { formsRepository.softDelete(form.getId()); } } FormDeleter(FormsRepository formsRepository, InstancesRepository instancesRepository); void delete(Long id);  }