private void setAssignedDistributionSetAndTargetUpdateStatus(final AbstractDsAssignmentStrategy assignmentStrategy, final JpaDistributionSet set, final List<List<Long>> targetIdsChunks) { final String currentUser = auditorProvider.getCurrentAuditor().orElse(null); assignmentStrategy.updateTargetStatus(set, targetIdsChunks, currentUser); }
/** * Sets modifying and creating auditor. Creating auditor is only set on new auditables. * * @param auditable * @return */ private Optional<Object> touchAuditor(AuditableBeanWrapper<?> wrapper, boolean isNew) { Assert.notNull(wrapper, "AuditableBeanWrapper must not be null!"); return auditorAware.map(it -> { Optional<?> auditor = it.getCurrentAuditor(); Assert.notNull(auditor, () -> String.format("Auditor must not be null! Returned by: %s!", AopUtils.getTargetClass(it))); auditor.filter(__ -> isNew).ifPresent(foo -> wrapper.setCreatedBy(foo)); auditor.filter(__ -> !isNew || modifyOnCreation).ifPresent(foo -> wrapper.setLastModifiedBy(foo)); return auditor; }); }
/** * Sets modifying and creating auditor. Creating auditor is only set on new * auditables. * @return */ private Optional<Object> touchAuditor(AuditableBeanWrapper<?> wrapper, boolean isNew) { Assert.notNull(wrapper, "AuditableBeanWrapper must not be null!"); return auditorAware.map(it -> { Optional<?> auditor = it.getCurrentAuditor(); Assert.notNull(auditor, () -> String.format("Auditor must not be null! Returned by: %s!", AopUtils.getTargetClass(it))); auditor.filter(__ -> isNew).ifPresent(foo -> wrapper.setCreatedBy(foo)); auditor.filter(__ -> !isNew || modifyOnCreation) .ifPresent(foo -> wrapper.setLastModifiedBy(foo)); return auditor; }); }
@Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void delete(final Collection<Long> ids) { final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids); if (swModulesToDelete.size() < ids.size()) { throw new EntityNotFoundException(SoftwareModule.class, ids, swModulesToDelete.stream().map(SoftwareModule::getId).collect(Collectors.toList())); } final Set<Long> assignedModuleIds = new HashSet<>(); swModulesToDelete.forEach(swModule -> { // delete binary data of artifacts deleteGridFsArtifacts(swModule); if (isUnassigned(swModule.getId())) { softwareModuleRepository.delete(swModule.getId()); } else { assignedModuleIds.add(swModule.getId()); } }); if (!assignedModuleIds.isEmpty()) { String currentUser = null; if (auditorProvider != null) { currentUser = auditorProvider.getCurrentAuditor(); } softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser, assignedModuleIds.toArray(new Long[0])); } }
@Override @Transactional @Retryable(include = { ConcurrencyFailureException.class }, maxAttempts = Constants.TX_RT_MAX, backoff = @Backoff(delay = Constants.TX_RT_DELAY)) public void delete(final Collection<Long> ids) { final List<JpaSoftwareModule> swModulesToDelete = softwareModuleRepository.findByIdIn(ids); if (swModulesToDelete.size() < ids.size()) { throw new EntityNotFoundException(SoftwareModule.class, ids, swModulesToDelete.stream().map(SoftwareModule::getId).collect(Collectors.toList())); } final Set<Long> assignedModuleIds = new HashSet<>(); swModulesToDelete.forEach(swModule -> { // delete binary data of artifacts deleteGridFsArtifacts(swModule); if (isUnassigned(swModule.getId())) { softwareModuleRepository.deleteById(swModule.getId()); } else { assignedModuleIds.add(swModule.getId()); } }); if (!assignedModuleIds.isEmpty()) { String currentUser = null; if (auditorProvider != null) { currentUser = auditorProvider.getCurrentAuditor().orElse(null); } softwareModuleRepository.deleteSoftwareModule(System.currentTimeMillis(), currentUser, assignedModuleIds.toArray(new Long[0])); } }
@SuppressWarnings("unchecked") @Override public void onEvent(DataStoreEvent event) { if (event instanceof BeforeInsertDataStoreEvent) { final Object entity = ((BeforeInsertDataStoreEvent) event).getEntity(); final Auditable wrapper = getAuditable(entity, event.getRepositoryMetadata()); wrapper.setCreatedBy(auditorAware == null ? null : auditorAware.getCurrentAuditor()); wrapper.setCreatedDate(DateTime.now()); } else if (event instanceof BeforeUpdateDataStoreEvent) { final Object entity = ((BeforeUpdateDataStoreEvent) event).getEntity(); final Auditable wrapper = getAuditable(entity, event.getRepositoryMetadata()); wrapper.setLastModifiedBy(auditorAware == null ? null : auditorAware.getCurrentAuditor()); wrapper.setLastModifiedDate(DateTime.now()); } }
@SuppressWarnings("unchecked") @Override public void onEvent(DataStoreEvent event) { if (event instanceof BeforeInsertDataStoreEvent) { final Object entity = ((BeforeInsertDataStoreEvent) event).getEntity(); final Auditable wrapper = getAuditable(entity, event.getRepositoryMetadata()); wrapper.setCreatedBy(auditorAware == null ? null : auditorAware.getCurrentAuditor()); wrapper.setCreatedDate(DateTime.now()); } else if (event instanceof BeforeUpdateDataStoreEvent) { final Object entity = ((BeforeUpdateDataStoreEvent) event).getEntity(); final Auditable wrapper = getAuditable(entity, event.getRepositoryMetadata()); wrapper.setLastModifiedBy(auditorAware == null ? null : auditorAware.getCurrentAuditor()); wrapper.setLastModifiedDate(DateTime.now()); } }
currentUser = auditorProvider.getCurrentAuditor(); } else { currentUser = null;