@Test public void deleteJudgmentsWithoutRawSourceJudgment() throws IOException { SupremeCourtJudgment scJudgment1 = rawJudgmentTestFactory.createScJudgment(true); SupremeCourtJudgment scJudgment2 = rawJudgmentTestFactory.createScJudgment(false); rawJudgmentTestFactory.createScJudgment(false); ConstitutionalTribunalJudgment ctJudgment1 = rawJudgmentTestFactory.createCtJudgment(true); ConstitutionalTribunalJudgment ctJudgment2 = rawJudgmentTestFactory.createCtJudgment(false); scJudgment1.getTextContent().setFilePath("scJudgment1File.txt"); File scJudgment1File = new File(judgmentContentDir, "scJudgment1File.txt"); scJudgment2.getTextContent().setFilePath("scJudgment2File.txt"); File scJudgment2File = new File(judgmentContentDir, "scJudgment2File.txt"); ctJudgment1.getTextContent().setFilePath("ctJudgment1File.txt"); File ctJudgment1File = new File(judgmentContentDir, "ctJudgment1File.txt"); scJudgment1File.createNewFile(); scJudgment2File.createNewFile(); ctJudgment1File.createNewFile(); judgmentRepository.save(Lists.newArrayList(scJudgment1, scJudgment2, ctJudgment1)); judgmentObjectDeleter.deleteJudgmentsWithoutRawSourceJudgment(SupremeCourtJudgment.class, RawSourceScJudgment.class); List<Judgment> dbJudgments = judgmentRepository.findAll(); assertThat(dbJudgments.stream().map(x -> x.getId()).collect(Collectors.toList()), containsInAnyOrder(scJudgment1.getId(), ctJudgment1.getId(), ctJudgment2.getId())); assertTrue(scJudgment1File.exists()); assertFalse(scJudgment2File.exists()); assertTrue(ctJudgment1File.exists()); }
@Transactional public void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass) { log.debug("Deleting judgments ({}) without corresponding rawSourceJudgments ({})", judgmentClass.getName(), rawJudgmentClass.getName()); String q = "select judgment.id, content.filePath from " + judgmentClass.getName() + " judgment " + " left join judgment.textContent content" + " where not exists (select rJudgment from "+ rawJudgmentClass.getName() + " rJudgment " + " where rJudgment.sourceId = judgment.sourceInfo.sourceJudgmentId)"; List<Object[]> judgmentIdsWithContentPath = entityManager.createQuery(q, Object[].class).getResultList(); if (!judgmentIdsWithContentPath.isEmpty()) { judgmentWithEnrichmentDeleter.delete(judgmentIdsWithContentPath.stream() .map(x -> (Long)x[0]) .collect(Collectors.toList())); judgmentContentFileDeleter.deleteContents(judgmentIdsWithContentPath.stream() .map(x -> (String)x[1]) .filter(path -> StringUtils.isNotEmpty(path)) .collect(Collectors.toList())); } }
JudgmentObjectDeleter { @Transactional public void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass) { log.debug("Deleting judgments ({}) without corresponding rawSourceJudgments ({})", judgmentClass.getName(), rawJudgmentClass.getName()); String q = "select judgment.id, content.filePath from " + judgmentClass.getName() + " judgment " + " left join judgment.textContent content" + " where not exists (select rJudgment from "+ rawJudgmentClass.getName() + " rJudgment " + " where rJudgment.sourceId = judgment.sourceInfo.sourceJudgmentId)"; List<Object[]> judgmentIdsWithContentPath = entityManager.createQuery(q, Object[].class).getResultList(); if (!judgmentIdsWithContentPath.isEmpty()) { judgmentWithEnrichmentDeleter.delete(judgmentIdsWithContentPath.stream() .map(x -> (Long)x[0]) .collect(Collectors.toList())); judgmentContentFileDeleter.deleteContents(judgmentIdsWithContentPath.stream() .map(x -> (String)x[1]) .filter(path -> StringUtils.isNotEmpty(path)) .collect(Collectors.toList())); } } }
JudgmentObjectDeleter { @Transactional public void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass) { log.debug("Deleting judgments ({}) without corresponding rawSourceJudgments ({})", judgmentClass.getName(), rawJudgmentClass.getName()); String q = "select judgment.id, content.filePath from " + judgmentClass.getName() + " judgment " + " left join judgment.textContent content" + " where not exists (select rJudgment from "+ rawJudgmentClass.getName() + " rJudgment " + " where rJudgment.sourceId = judgment.sourceInfo.sourceJudgmentId)"; List<Object[]> judgmentIdsWithContentPath = entityManager.createQuery(q, Object[].class).getResultList(); if (!judgmentIdsWithContentPath.isEmpty()) { judgmentWithEnrichmentDeleter.delete(judgmentIdsWithContentPath.stream() .map(x -> (Long)x[0]) .collect(Collectors.toList())); judgmentContentFileDeleter.deleteContents(judgmentIdsWithContentPath.stream() .map(x -> (String)x[1]) .filter(path -> StringUtils.isNotEmpty(path)) .collect(Collectors.toList())); } }  }
JudgmentObjectDeleter { @Transactional public void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass) { log.debug("Deleting judgments ({}) without corresponding rawSourceJudgments ({})", judgmentClass.getName(), rawJudgmentClass.getName()); String q = "select judgment.id, content.filePath from " + judgmentClass.getName() + " judgment " + " left join judgment.textContent content" + " where not exists (select rJudgment from "+ rawJudgmentClass.getName() + " rJudgment " + " where rJudgment.sourceId = judgment.sourceInfo.sourceJudgmentId)"; List<Object[]> judgmentIdsWithContentPath = entityManager.createQuery(q, Object[].class).getResultList(); if (!judgmentIdsWithContentPath.isEmpty()) { judgmentWithEnrichmentDeleter.delete(judgmentIdsWithContentPath.stream() .map(x -> (Long)x[0]) .collect(Collectors.toList())); judgmentContentFileDeleter.deleteContents(judgmentIdsWithContentPath.stream() .map(x -> (String)x[1]) .filter(path -> StringUtils.isNotEmpty(path)) .collect(Collectors.toList())); } }  @Transactional void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass); @Transactional void deleteMeansOfAppealWithoutJudgments(CourtType courtType); @Transactional void deleteJudgmentResultsWithoutJudgments(CourtType courtType); }
JudgmentObjectDeleter { @Transactional public void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass) { log.debug("Deleting judgments ({}) without corresponding rawSourceJudgments ({})", judgmentClass.getName(), rawJudgmentClass.getName()); String q = "select judgment.id, content.filePath from " + judgmentClass.getName() + " judgment " + " left join judgment.textContent content" + " where not exists (select rJudgment from "+ rawJudgmentClass.getName() + " rJudgment " + " where rJudgment.sourceId = judgment.sourceInfo.sourceJudgmentId)"; List<Object[]> judgmentIdsWithContentPath = entityManager.createQuery(q, Object[].class).getResultList(); if (!judgmentIdsWithContentPath.isEmpty()) { judgmentWithEnrichmentDeleter.delete(judgmentIdsWithContentPath.stream() .map(x -> (Long)x[0]) .collect(Collectors.toList())); judgmentContentFileDeleter.deleteContents(judgmentIdsWithContentPath.stream() .map(x -> (String)x[1]) .filter(path -> StringUtils.isNotEmpty(path)) .collect(Collectors.toList())); } }  @Transactional void deleteJudgmentsWithoutRawSourceJudgment(Class<? extends Judgment> judgmentClass, Class<? extends RawSourceJudgment> rawJudgmentClass); @Transactional void deleteMeansOfAppealWithoutJudgments(CourtType courtType); @Transactional void deleteJudgmentResultsWithoutJudgments(CourtType courtType);  }