/** * Find one with fetched associations. */ private T findOne(final K id, final Map<String, JoinType> fetchedAssociations) { final CriteriaBuilder builder = em.getCriteriaBuilder(); final CriteriaQuery<T> query = builder.createQuery(getDomainClass()); // Apply fetch final Root<T> root = query.from(getDomainClass()); SpringUtils.getBean(FetchHelper.class).applyFetchedAssociations(fetchedAssociations, root); // Apply specification final Specification<T> specification = (r, q, cb) -> cb.equal(r.get("id"), id); query.where(specification.toPredicate(root, query, builder)); query.select(root); return em.createQuery(query).getSingleResult(); }
@Override @Autowired public void setApplicationContext(final ApplicationContext applicationContext) { setSharedApplicationContext(applicationContext); }
/** * Build a group LDAP repository from the given node. * * @param node * The node, also used as cache key. * @param template * The {@link LdapTemplate} used to query the repository. * @return The {@link UserLdapRepository} instance. Cache is involved. */ public GroupLdapRepository newGroupLdapRepository(final String node, final LdapTemplate template) { final Map<String, String> parameters = pvResource.getNodeParameters(node); // A new repository instance final GroupLdapRepository repository = new GroupLdapRepository(); repository.setTemplate(template); repository.setGroupsBaseDn(StringUtils.trimToEmpty(parameters.get(PARAMETER_GROUPS_DN))); // Complete the bean SpringUtils.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(repository); return repository; }
/** * Build a group LDAP repository from the given node. * * @param node * The node, also used as cache key. * @param template * The {@link LdapTemplate} used to query the repository. * @return The {@link UserLdapRepository} instance. Cache is involved. */ public CompanyLdapRepository newCompanyLdapRepository(final String node, final LdapTemplate template) { final Map<String, String> parameters = pvResource.getNodeParameters(node); // A new repository instance final CompanyLdapRepository repository = new CompanyLdapRepository(); repository.setTemplate(template); repository.setCompanyBaseDn(parameters.get(PARAMETER_COMPANIES_DN)); repository.setQuarantineBaseDn(parameters.get(PARAMETER_QUARANTINE_DN)); // Complete the bean SpringUtils.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(repository); return repository; }
final T task = SpringUtils.getBean(taskType); task.configure(importTask); executor.execute(task);
SpringUtils.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(repository);
/** * Get or create a new task associated to given subscription. * * @param lockedId * The locked entity's identifier. The related entity will be locked. * @return The task, never <code>null</code>. */ default T createAsNeeded(final I lockedId) { final T task = Optional.ofNullable(getTaskInternal(lockedId)).map(t -> { // Additional remote check (optional) if (!isFinished(t)) { // On this service, there is already a running remote task throw new BusinessException("concurrent-task-remote", t.getAuthor(), t.getStart(), lockedId); } return t; }).orElseGet(() -> { final T newTask = newTask().get(); newTask.setLocked(getLockedRepository().findOneExpected(lockedId)); return newTask; }); // Reset internal fields task.setAuthor(SpringUtils.getBean(SecurityHelper.class).getLogin()); task.setStart(DateUtils.newCalendar().getTime()); task.setEnd(null); task.setFailed(false); return task; }
@Override protected void executeInternal(final JobExecutionContext arg0) { // Extract the job data to execute the operation final int schedule = arg0.getMergedJobDataMap().getInt("schedule"); final ApplicationContext context = ObjectUtils.defaultIfNull((ApplicationContext) arg0.getMergedJobDataMap().get("context"), SpringUtils.getApplicationContext()); final VmSchedule entity = context.getBean(VmScheduleRepository.class).findOneExpected(schedule); log.info("Executing {} for schedule {}, subscription {}", entity.getOperation(), entity.getId(), entity.getSubscription().getId()); // Set the user context.getBean(SecurityHelper.class).setUserName(SecurityHelper.SYSTEM_USERNAME); // Execute the operation context.getBean(VmExecutionResource.class).execute(entity.getSubscription(), entity.getOperation()); log.info("Succeed {} for schedule {}, subscription {}", entity.getOperation(), entity.getId(), entity.getSubscription().getId()); }