@Test public void whenFormForInstanceIsSoftDeleted_andThereIsAnotherSoftDeletedInstance_deletesForm() { formsRepository.save(new Form.Builder() .id(1L) .jrFormId("1") .jrVersion("version") .deleted(true) .build() ); instancesRepository.save(new Instance.Builder() .id(1L) .jrFormId("1") .deletedDate(0L) .jrVersion("version") .build() ); instancesRepository.save(new Instance.Builder() .id(2L) .jrFormId("1") .jrVersion("version") .build() ); instanceDeleter.delete(2L); assertThat(formsRepository.getAll().size(), is(0)); }
public void delete(Long id) { Instance instance = instancesRepository.get(id); instancesRepository.delete(id); Form form = formsRepository.get(instance.getJrFormId(), instance.getJrVersion()); if (form != null && form.isDeleted()) { List<Instance> otherInstances = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (otherInstances.isEmpty()) { formsRepository.delete(form.getId()); } } }
InstanceDeleter { public void delete(Long id) { Instance instance = instancesRepository.get(id); instancesRepository.delete(id); Form form = formsRepository.get(instance.getJrFormId(), instance.getJrVersion()); if (form != null && form.isDeleted()) { List<Instance> otherInstances = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (otherInstances.isEmpty()) { formsRepository.delete(form.getId()); } } } }
InstanceDeleter { public void delete(Long id) { Instance instance = instancesRepository.get(id); instancesRepository.delete(id); Form form = formsRepository.get(instance.getJrFormId(), instance.getJrVersion()); if (form != null && form.isDeleted()) { List<Instance> otherInstances = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (otherInstances.isEmpty()) { formsRepository.delete(form.getId()); } } } InstanceDeleter(InstancesRepository instancesRepository, FormsRepository formsRepository); }
InstanceDeleter { public void delete(Long id) { Instance instance = instancesRepository.get(id); instancesRepository.delete(id); Form form = formsRepository.get(instance.getJrFormId(), instance.getJrVersion()); if (form != null && form.isDeleted()) { List<Instance> otherInstances = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (otherInstances.isEmpty()) { formsRepository.delete(form.getId()); } } } InstanceDeleter(InstancesRepository instancesRepository, FormsRepository formsRepository); void delete(Long id); }
InstanceDeleter { public void delete(Long id) { Instance instance = instancesRepository.get(id); instancesRepository.delete(id); Form form = formsRepository.get(instance.getJrFormId(), instance.getJrVersion()); if (form != null && form.isDeleted()) { List<Instance> otherInstances = instancesRepository.getAllByJrFormIdAndJrVersionNotDeleted(form.getJrFormId(), form.getJrVersion()); if (otherInstances.isEmpty()) { formsRepository.delete(form.getId()); } } } InstanceDeleter(InstancesRepository instancesRepository, FormsRepository formsRepository); void delete(Long id);  }