public static void cleanJobObjects(Job job, ModelService model, IndexService index) {
if (RodaCoreFactory.getNodeType() == NodeType.MASTER) {
Filter filter = new Filter();
filter.add(new SimpleFilterParameter(RodaConstants.INGEST_JOB_ID, job.getId()));
filter.add(new OneOfManyFilterParameter(RodaConstants.AIP_STATE,
Arrays.asList(AIPState.CREATED.toString(), AIPState.INGEST_PROCESSING.toString())));
try (IterableIndexResult<IndexedAIP> result = index.findAll(IndexedAIP.class, filter, false,
Arrays.asList(RodaConstants.INDEX_UUID))) {
for (IndexedAIP aip : result) {
String aipId = aip.getUUID();
try {
LOGGER.info("Deleting AIP {} during job {} cleanup", aipId, job.getId());
model.deleteAIP(aipId);
} catch (RequestNotValidException | NotFoundException | GenericException | AuthorizationDeniedException e) {
LOGGER.error("Error deleting AIP {} during job {} cleanup", aipId, job.getId(), e);
}
}
} catch (IOException | GenericException | RequestNotValidException e) {
LOGGER.error("Error getting AIP iterator when cleaning job objects", e);
}
}
}