/** * Deletes technology generator context entities that weren't used since given date and time. * * By 'weren't used' we mean contexts having update date (or create date if update date is not defined) earlier than given * one. * * @param threshold * date time threshold used to decide which contexts need to be deleted * @return either the messages holder if operation didn't finish successfully or list of deleted context ids. */ public Either<EntityMessagesHolder, List<ContextId>> deleteContextsNotUsedSince(final DateTime threshold) { List<Long> contextIdsToBeDeleted = findContextsOlderThan(threshold); if (contextIdsToBeDeleted.isEmpty()) { return Either.right(Lists.newArrayList()); } EntityOpResult result = getContextDD().delete(contextIdsToBeDeleted.toArray(new Long[contextIdsToBeDeleted.size()])); if (result.isSuccessfull()) { return Either.right(contextIdsToBeDeleted.stream().map(ContextId::new).collect(Collectors.toList())); } return Either.left(result.getMessagesHolder()); }
if (!result.isSuccessfull()) { deleteSuccessful = false; errors.addAll(result.getMessagesHolder().getGlobalErrors());
@RunIfEnabled(ProductionBalancePerShiftConstants.PLUGIN_IDENTIFIER) public void cleanUp() { info("Starting clean up."); Collection<Long> ids = getContextIds(); if (ids.isEmpty()) { info("There is no entities to be cleaned up. Aborting."); return; } int idsSize = ids.size(); info("Found %s entities to delete.", idsSize); // FIXME maku - we need to introduce some kind of batch deletion.. EntityOpResult deleteResult = getDataDefinition().delete(ids.toArray(new Long[idsSize])); if (deleteResult.isSuccessfull()) { info("Successfully deleted %s entities.", idsSize); } else { logFailure(deleteResult.getMessagesHolder()); } }
@RunIfEnabled(TimeGapsPreviewConstants.PLUGIN_IDENTIFIER) public void cleanUp() { info("Starting clean up."); Collection<Long> ids = getContextIds(); if (ids.isEmpty()) { info("There is no entities to be cleaned up. Aborting."); return; } int idsSize = ids.size(); info("Found %s entities to delete.", idsSize); EntityOpResult deleteResult = getDataDefinition().delete(ids.toArray(new Long[idsSize])); if (deleteResult.isSuccessfull()) { info("Successfully deleted %s time gaps context entities.", idsSize); } else { logFailure(deleteResult.getMessagesHolder()); } }