当前位置: 首页>>代码示例>>Java>>正文


Java SpringUtils类代码示例

本文整理汇总了Java中org.ligoj.bootstrap.core.SpringUtils的典型用法代码示例。如果您正苦于以下问题:Java SpringUtils类的具体用法?Java SpringUtils怎么用?Java SpringUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpringUtils类属于org.ligoj.bootstrap.core包,在下文中一共展示了SpringUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: executeInternal

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@Override
protected void executeInternal(final JobExecutionContext arg0) throws JobExecutionException {
	// 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(VmResource.class).execute(entity.getSubscription(), entity.getOperation());
	log.info("Succeed {} for schedule {}, subscription {}", entity.getOperation(), entity.getId(), entity.getSubscription().getId());
}
 
开发者ID:ligoj,项目名称:plugin-vm,代码行数:17,代码来源:VmJob.java

示例2: mockApplicationContext

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
	final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
	SpringUtils.setSharedApplicationContext(applicationContext);
	mockLdapResource = Mockito.mock(GroupResource.class);
	final GroupFullLdapTask mockTask = new GroupFullLdapTask();
	mockTask.resource = mockLdapResource;
	mockTask.securityHelper = securityHelper;
	mockTask.containerScopeResource = Mockito.mock(ContainerScopeResource.class);
	Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
	Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
		final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
		if (requiredType == GroupFullLdapTask.class) {
			return mockTask;
		}
		return GroupBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
	});

	final ContainerScope container = new ContainerScope();
	container.setId(1);
	container.setName("Fonction");
	container.setType(ContainerType.GROUP);
	Mockito.when(mockTask.containerScopeResource.findByName("Fonction")).thenReturn(container);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:26,代码来源:GroupBatchLdapResourceTest.java

示例3: mockApplicationContext

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void mockApplicationContext() {
	final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
	SpringUtils.setSharedApplicationContext(applicationContext);
	mockLdapResource = Mockito.mock(UserOrgResource.class);
	final UserFullLdapTask mockTask = new UserFullLdapTask();
	mockTask.resource = mockLdapResource;
	mockTask.securityHelper = securityHelper;
	final UserAtomicLdapTask mockTaskUpdate = new UserAtomicLdapTask();
	mockTaskUpdate.resource = mockLdapResource;
	mockTaskUpdate.securityHelper = securityHelper;
	Mockito.when(applicationContext.getBean(SessionSettings.class)).thenReturn(new SessionSettings());
	Mockito.when(applicationContext.getBean((Class<?>) ArgumentMatchers.any(Class.class))).thenAnswer((Answer<Object>) invocation -> {
		final Class<?> requiredType = (Class<Object>) invocation.getArguments()[0];
		if (requiredType == UserFullLdapTask.class) {
			return mockTask;
		}
		if (requiredType == UserAtomicLdapTask.class) {
			return mockTaskUpdate;
		}
		return UserBatchLdapResourceTest.super.applicationContext.getBean(requiredType);
	});

	mockTaskUpdate.jaxrsFactory = ServerProviderFactory.createInstance(null);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:27,代码来源:UserBatchLdapResourceTest.java

示例4: getUserLdapRepository

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * Build a user LDAP repository from the given node.
 * 
 * @param node
 *            The node, also used as cache key.
 * @return The {@link UserLdapRepository} instance. Cache is involved.
 */
@CacheResult(cacheName = "ldap-user-repository")
public UserLdapRepository getUserLdapRepository(@CacheKey final String node) {
	log.info("Build ldap template for node {}", node);
	final Map<String, String> parameters = pvResource.getNodeParameters(node);
	final LdapContextSource contextSource = new LdapContextSource();
	contextSource.setReferral(parameters.get(PARAMETER_REFERRAL));
	contextSource.setPassword(parameters.get(PARAMETER_PASSWORD));
	contextSource.setUrl(parameters.get(PARAMETER_URL));
	contextSource.setUserDn(parameters.get(PARAMETER_USER));
	contextSource.setBase(parameters.get(PARAMETER_BASE_BN));
	contextSource.afterPropertiesSet();
	final LdapTemplate template = new LdapTemplate();
	template.setContextSource(contextSource);
	template.setIgnorePartialResultException(true);

	// A new repository instance
	final UserLdapRepository repository = new UserLdapRepository();
	repository.setTemplate(template);
	repository.setPeopleBaseDn(StringUtils.trimToEmpty(parameters.get(PARAMETER_PEOPLE_DN)));
	repository.setPeopleInternalBaseDn(parameters.get(PARAMETER_PEOPLE_INTERNAL_DN));
	repository.setQuarantineBaseDn(StringUtils.trimToEmpty(parameters.get(PARAMETER_QUARANTINE_DN)));
	repository.setDepartmentAttribute(parameters.get(PARAMETER_DEPARTMENT_ATTRIBUTE));
	repository.setLocalIdAttribute(parameters.get(PARAMETER_LOCAL_ID_ATTRIBUTE));
	repository.setUidAttribute(parameters.get(PARAMETER_UID_ATTRIBUTE));
	repository.setLockedAttribute(parameters.get(PARAMETER_LOCKED_ATTRIBUTE));
	repository.setLockedValue(parameters.get(PARAMETER_LOCKED_VALUE));
	repository.setPeopleClass(parameters.get(PARAMETER_PEOPLE_CLASS));
	repository.setCompanyPattern(StringUtils.trimToEmpty(parameters.get(PARAMETER_COMPANY_PATTERN)));

	// Complete the bean
	SpringUtils.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(repository);

	return repository;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:42,代码来源:LdapPluginResource.java

示例5: newGroupLdapRepository

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:22,代码来源:LdapPluginResource.java

示例6: newCompanyLdapRepository

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:23,代码来源:LdapPluginResource.java

示例7: cleanRecoveries

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * Daily, clean old recovery requests.
 */
@Scheduled(cron = "0 0 1 1/1 * ?")
public void cleanRecoveries() {
	// @Modifying + @Scheduled + @Transactional [+protected] --> No TX, wait
	// for next release & TU
	SpringUtils.getBean(PasswordResource.class).cleanRecoveriesInternal();
}
 
开发者ID:ligoj,项目名称:plugin-password,代码行数:10,代码来源:PasswordResource.java

示例8: updateForbiddenAccess

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * Update response for a forbidden access.
 */
private void updateForbiddenAccess(final HttpServletResponse response) throws IOException {
	final Response response2 = SpringUtils.getBean(AccessDeniedExceptionMapper.class).toResponse(new AccessDeniedException(""));
	response.setStatus(response2.getStatus());
	response.setContentType(response2.getMediaType().toString());
	response.getOutputStream().write(((String) response2.getEntity()).getBytes(StandardCharsets.UTF_8));
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:10,代码来源:AuthorizingFilter.java

示例9: findOne

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * 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();
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:18,代码来源:RestRepositoryImpl.java

示例10: prepareSecurityContext

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * Create a role and one authorization for user DEFAULT_USER. Only run once.
 */
@Before
public void prepareSecurityContext() {
	if (setUpIsDone) {
		return;
	}

	final RoleResource resource = SpringUtils.getBean(RoleResource.class);
	final UserResource userResource = SpringUtils.getBean(UserResource.class);

	// Create the authorization
	final AuthorizationEditionVo authorization = new AuthorizationEditionVo();
	authorization.setPattern(SESSION_RESOURCE);
	authorization.setType(AuthorizationType.API);
	final List<AuthorizationEditionVo> authorizations = new ArrayList<>();
	authorizations.add(authorization);

	// Create the role
	final SystemRoleVo role = new SystemRoleVo();
	role.setName("test");
	role.setAuthorizations(authorizations);
	final int roleId = resource.create(role);

	final SystemUserEditionVo user = new SystemUserEditionVo();
	user.setLogin(DEFAULT_USER);
	final List<Integer> roles = new ArrayList<>();
	roles.add(roleId);
	user.setRoles(roles);
	userResource.create(user);

	setUpIsDone = true;
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:35,代码来源:SessionResourceRestIT.java

示例11: restoreApplicationContext

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
/**
 * Restore original Spring application context
 */
@After
@Before
public void restoreApplicationContext() {
	if (applicationContext != null) {
		// This test was running in a Spring context, restore the shared context
		SpringUtils.setSharedApplicationContext(applicationContext);
	}
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:12,代码来源:AbstractDataGeneratorTest.java

示例12: init

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@Before
public void init() {
	companyRepository = Mockito.mock(CompanyLdapRepository.class);
	groupRepository = Mockito.mock(GroupLdapRepository.class);
	userRepository = Mockito.mock(UserLdapRepository.class);
	iamProvider = Mockito.mock(IamProvider.class);
	final ApplicationContext applicationContext = Mockito.mock(ApplicationContext.class);
	SpringUtils.setSharedApplicationContext(applicationContext);
	final IamConfiguration iamConfiguration = new IamConfiguration();
	iamConfiguration.setCompanyRepository(companyRepository);
	iamConfiguration.setGroupRepository(groupRepository);
	iamConfiguration.setUserRepository(userRepository);
	Mockito.when(iamProvider.getConfiguration()).thenReturn(iamConfiguration);

	companies = new HashMap<>();
	companies.put("company", new CompanyOrg("dnc", "Company"));
	groups = new HashMap<>();
	final Set<String> members = new HashSet<>();
	members.add("u");
	groupLdap = new GroupOrg("dn", "Group", members);
	groups.put("group", groupLdap);
	groupLdap2 = new GroupOrg("dn2", "Group2", new HashSet<>());
	groups.put("group2", groupLdap2);
	user = new UserOrg();
	user.setId("u");
	user.setFirstName("f");
	user.setLastName("l");
	user.setCompany("company");
	final List<String> userGroups = new ArrayList<>();
	userGroups.add("group");
	user.setGroups(userGroups);
	user.setMails(Collections.singletonList("mail"));
	user2 = new UserOrg();
	user2.setId("u2");
	user2.setFirstName("f");
	user2.setLastName("l");
	user2.setCompany("company");
	user2.setGroups(new ArrayList<>());
	users = new HashMap<>();
	users.put("u", user);
	users.put("u2", user2);
	Mockito.when(companyRepository.findAllNoCache()).thenReturn(companies);
	Mockito.when(groupRepository.findAllNoCache()).thenReturn(groups);
	Mockito.when(userRepository.findAllNoCache(groups)).thenReturn(users);
	Mockito.when(companyRepository.findAll()).thenReturn(companies);
	Mockito.when(groupRepository.findAll()).thenReturn(groups);
	Mockito.when(userRepository.findAll()).thenReturn(users);
	CacheManager.getInstance().getCache("ldap").removeAll();
	
	repository = new LdapCacheRepository();
	repository.iamProvider = new IamProvider[] { iamProvider };
	repository.ldapCacheDao = Mockito.mock(LdapCacheDao.class);
}
 
开发者ID:ligoj,项目名称:plugin-id-ldap,代码行数:54,代码来源:LdapCacheRepositoryTest.java

示例13: batch

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
protected <B extends BatchElement, T extends AbstractLdapBatchTask<B>> long batch(final InputStream uploadedFile, final String[] columns,
		final String encoding, final String[] defaultColumns, final Class<B> batchType, final Class<T> taskType) throws IOException {

	// Public identifier is based on system date
	final long id = System.currentTimeMillis();

	// Check column's name validity
	final String[] sanitizeColumns = ArrayUtils.isEmpty(columns) ? defaultColumns : columns;
	checkHeaders(defaultColumns, sanitizeColumns);

	// Build CSV header from array
	final String csvHeaders = StringUtils.chop(ArrayUtils.toString(sanitizeColumns)).substring(1).replace(',', ';') + "\n";

	// Build entries
	final List<B> entries = csvForBean.toBean(batchType,
			new InputStreamReader(new SequenceInputStream(
					new ByteArrayInputStream(csvHeaders.getBytes(ObjectUtils.defaultIfNull(encoding, StandardCharsets.UTF_8.name()))),
					uploadedFile), ObjectUtils.defaultIfNull(encoding, StandardCharsets.UTF_8.name())));
	entries.removeIf(Objects::isNull);

	// Validate them
	validator.validateCheck(entries);

	// Clone the context for the asynchronous import
	final BatchTaskVo<B> importTask = new BatchTaskVo<>();
	importTask.setEntries(entries);
	importTask.setPrincipal(SecurityContextHolder.getContext().getAuthentication().getName());
	importTask.setId(id);

	// Schedule the import
	final T task = SpringUtils.getBean(taskType);
	task.configure(importTask);
	executor.execute(task);

	// Also cleanup the previous tasks
	cleanup();

	// Expose the task with internal identifier, based on current user PLUS the public identifier
	imports.put(importTask.getPrincipal() + "-" + importTask.getId(), importTask);

	// Return private task identifier
	return id;
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:44,代码来源:AbstractBatchResource.java

示例14: unmockApplicationContext

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@After
public void unmockApplicationContext() {
	SpringUtils.setSharedApplicationContext(super.applicationContext);
}
 
开发者ID:ligoj,项目名称:plugin-id,代码行数:5,代码来源:GroupBatchLdapResourceTest.java

示例15: throwJSonMapping

import org.ligoj.bootstrap.core.SpringUtils; //导入依赖的package包/类
@DELETE
@Path("json-mapping")
public void throwJSonMapping() throws IOException {
	SpringUtils.getApplicationContext().getBean("jacksonProvider", com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider.class);
	new ObjectMapperTrim().readValue("{\"dialDouble\":\"A\"}", SystemDialect.class);
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:7,代码来源:ExceptionMapperResource.java


注:本文中的org.ligoj.bootstrap.core.SpringUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。