public void checkBasePolicies() { if (classifyDocumentApi instanceof ClassifyDocumentApiDirectImpl) { logger.debug("Registering Handlers"); UserContext userContext = corePolicyApplicationContext.getBean(UserContext.class); // Dont run under a particular user for this! Its about system base data. userContext.setProjectId(null); ServiceLoader<WorkerPolicyHandler> loader = ServiceLoader.load(WorkerPolicyHandler.class); // This is per user registration of policy handlers per policy type. // not to be confused with the base data creation on startup. for (WorkerPolicyHandler handler : loader) { register.checkAndRegisterHandlerPolicyTypes(handler); } } }
/** * Get the handlers for a given user context. This will internally register either * a user specific type or a base data type implicitally. * * @param projectId */ private void registerHandlers(String projectId) { if (classifyDocumentApi instanceof ClassifyDocumentApiDirectImpl) { UserContext userContext = corePolicyApplicationContext.getBean(UserContext.class); userContext.setProjectId(projectId); if (!registeredUsers.contains(projectId)) { ServiceLoader<WorkerPolicyHandler> loader = ServiceLoader.load(WorkerPolicyHandler.class); for (WorkerPolicyHandler handler : loader) { setUpWorkerHandler(handler, projectId); } registeredUsers.add(projectId); } } }
public IntegrationTestBase() { // in certain cases we now have to shutdown the main ApiApplicationInstance as once a profile has been activated // it doesn't remove itself, it has to be rebuilt. As such a quick request here will ensure we have a new context. // if it has been removed. if (genericApplicationContext == null) { genericApplicationContext = new CorePolicyApplicationContext(); genericApplicationContext.refresh(); } apiProperties = genericApplicationContext.getBean(ApiProperties.class); try { // let our deployment type setup the usercontext correctly. depending on iod/web switch (apiProperties.getMode()) { case "direct": case "web": { // set the real user context now! userContext = genericApplicationContext.getBean(UserContext.class); userContext.setProjectId(UUID.randomUUID().toString()); break; } } } catch (Exception ex) { getLogger().trace("Exception in IntegrationTestBase... ", ex); throw new RuntimeException(ex); } classificationApi = genericApplicationContext.getBean(ClassificationApi.class); }
userContext.setProjectId(taskData.getProjectId());