/** * 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()); }
public boolean onDelete(final DataDefinition operationalTaskDD, final Entity operationalTask) { boolean isDeleted = true; Entity techOperCompOperationalTask = operationalTask .getBelongsToField(OperationalTaskFieldsOTFO.TECH_OPER_COMP_OPERATIONAL_TASK); if (techOperCompOperationalTask != null) { isDeleted = techOperCompOperationalTask.getDataDefinition().delete(techOperCompOperationalTask.getId()) .isSuccessfull(); } return isDeleted; }
public boolean onDelete(final DataDefinition technologyOperationComponentDD, final Entity technologyOperationComponent) { boolean isDeleted = true; Entity techOperCompTimeCalculation = technologyOperationComponent .getBelongsToField(TechnologyOperationComponentFieldsTNFO.TECH_OPER_COMP_TIME_CALCULATION); if (techOperCompTimeCalculation != null) { isDeleted = techOperCompTimeCalculation.getDataDefinition().delete(techOperCompTimeCalculation.getId()) .isSuccessfull(); } return isDeleted; }
EntityOpResult result = productionCountingQuantity.getDataDefinition() .delete(productionCountingQuantity.getId()); if (!result.isSuccessfull()) { deleteSuccessful = false; errors.addAll(result.getMessagesHolder().getGlobalErrors());
@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()); } }
@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()); } }
private boolean deleteBasicProductionCounting(final Entity productionCountingQuantity) { boolean isDeleted = true; Entity basicProductionCounting = productionCountingQuantity .getBelongsToField(ProductionCountingQuantityFields.BASIC_PRODUCTION_COUNTING); if ((basicProductionCounting != null) && checkIfItIsLastProductionCountingQuantity(basicProductionCounting)) { productionCountingQuantity.setField(ProductionCountingQuantityFields.BASIC_PRODUCTION_COUNTING, null); productionCountingQuantity.getDataDefinition().save(productionCountingQuantity); isDeleted = basicProductionCounting.getDataDefinition().delete(basicProductionCounting.getId()).isSuccessfull(); } return isDeleted; }
@Transactional public void clearAndLoadPatternTechnology(final ViewDefinitionState view, final ComponentState state, final String[] args) { final FormComponent technologyForm = (FormComponent) state; Entity technology = technologyForm.getPersistedEntityWithIncludedFormValues(); Entity order = getOrderWithTechnology(view); Entity orderTechnologyPrototype = order.getBelongsToField(OrderFields.TECHNOLOGY_PROTOTYPE); if (orderTechnologyPrototype != null && technology.getId().equals(orderTechnologyPrototype.getId())) { Entity copyOfTechnology = copyTechnology(orderTechnologyPrototype, order); if (copyOfTechnology.isValid()) { order.setField(OrderFields.TECHNOLOGY, copyOfTechnology); order.getDataDefinition().save(order); state.setFieldValue(copyOfTechnology.getId()); technologyForm.setEntity(copyOfTechnology); } else { technologyForm.addMessage("orders.copyOfTechnology.reloadFromPattern.failure.validationError", ComponentState.MessageType.FAILURE); return; } EntityOpResult deleteResult = deleteTechnology(technology); if (!deleteResult.isSuccessfull()) { technologyForm.addMessage("orders.copyOfTechnology.reloadFromPattern.failure.deletePrevented", ComponentState.MessageType.FAILURE); } } }