PolicyHandlerSetup(CorePolicyApplicationContext applicationContext) { this.corePolicyApplicationContext = applicationContext; this.classifyDocumentApi = corePolicyApplicationContext.getBean(ClassifyDocumentApi.class); this.policyApi = corePolicyApplicationContext.getBean(PolicyApi.class); this.adminApi = corePolicyApplicationContext.getBean(AdminApi.class); this.register = new PolicyTypeRegister(this.corePolicyApplicationContext,this.policyApi,this.adminApi); }
protected CollectionSequence SetupCollectionSequence(DocumentCollection collection) { ClassificationApi classificationApi = genericApplicationContext.getBean(ClassificationApi.class); return SetupCollectionSequence(classificationApi, collection.id, true); }
private boolean shouldContinueProcessing() { WorkerResponseHolder bean = corePolicyApplicationContext.getBean(WorkerResponseHolder.class); return !bean.isShouldStop(); }
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); } } }
@Override public HealthResult healthCheck() { HealthStatus status; if (applicationContext.getBean(ElasticsearchProperties.class).isElasticsearchDisabled()) { status = HealthStatus.HEALTHY; } else { BooleanAgentServices booleanAgentServices = applicationContext.getBean(BooleanAgentServices.class); if (booleanAgentServices.canConnect()) { status = HealthStatus.HEALTHY; } else { status = HealthStatus.UNHEALTHY; } } return new HealthResult(status); }
/** * 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); } } }
@Override protected Connection getConnectionToClearDown() { RepositoryConnectionProvider repositoryConnectionProvider = getGenericApplicationContext().getBean(RepositoryConnectionProvider.class); return repositoryConnectionProvider.getConnection(RepositoryType.CONDITION_ENGINE); }
private Connection getPolicyConnectionToClearDown() { RepositoryConnectionProvider repositoryConnectionProvider = getGenericApplicationContext().getBean(RepositoryConnectionProvider.class); return repositoryConnectionProvider.getConnection(RepositoryType.POLICY); }
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); }
protected DocumentCollection SetupCollection(Collection<Long> overridePolicyIds) { ClassificationApi classificationApi = genericApplicationContext.getBean(ClassificationApi.class); NumberCondition numberCondition = new NumberCondition(); numberCondition.name = "afield condition 1"; numberCondition.field = "afield"; numberCondition.operator = NumberOperatorType.EQ; numberCondition.value = 1L; DocumentCollection collection1 = new DocumentCollection(); collection1.name = "Collection 1"; collection1.policyIds = new HashSet<>(); if (overridePolicyIds != null) { collection1.policyIds.addAll(overridePolicyIds); } collection1.condition = numberCondition; collection1 = classificationApi.create(collection1); return collection1; }
protected CollectionSequence SetupCollectionSequenceWithPolicies(final Collection<Long> defaultPolicyIds, final Collection<Long> overridePolicyIds) { ClassificationApi classificationApi = genericApplicationContext.getBean(ClassificationApi.class); NumberCondition numberCondition = new NumberCondition(); numberCondition.name = "afield condition 1"; numberCondition.field = "afield"; numberCondition.operator = NumberOperatorType.EQ; numberCondition.value = 1L; DocumentCollection collection1 = new DocumentCollection(); collection1.name = "Collection 1"; collection1.policyIds = new HashSet<>(); if (overridePolicyIds == null) { collection1.policyIds.addAll(defaultPolicyIds); } else { collection1.policyIds.addAll(overridePolicyIds); } collection1.condition = numberCondition; collection1 = classificationApi.create(collection1); return SetupCollectionSequence(classificationApi, collection1.id, true); }
/** * @param executedDocument A Corepolicy document that has been executed * @return True if should stop processing */ private boolean updateTaskDataAndCheckIfShouldCreateChainedWorkerResponse(com.github.cafdataprocessing.corepolicy.common.Document executedDocument){ WorkerResponseHolder workerResponseHolder = corePolicyApplicationContext.getBean(WorkerResponseHolder.class); Objects.requireNonNull(workerResponseHolder); TaskData taskData = workerResponseHolder.getTaskData(); Objects.requireNonNull(taskData); //update taskData with current document taskData = WorkerPolicyHandler.updateTaskDataDocument(taskData, executedDocument); if (!shouldContinueProcessing()) { createChainedWorkerResponse(taskData, workerResponseHolder); return true; } return false; }
/*** * Create our policy handler response, to a normal classify or execution. * For more advanced executions which use chaining, we will have already created a WorkerResponse earlier which * consisted of a newtask to be sent on to another queue. * * @param classifyDocumentResults * @return * @throws WorkerException */ private WorkerResponse getOrCreateResponse(Collection<ClassifyDocumentResult> classifyDocumentResults) { WorkerResponseHolder workerResponseHolder; workerResponseHolder = corePolicyApplicationContext.getBean(WorkerResponseHolder.class); if (workerResponseHolder.getWorkerResponse() != null) { return workerResponseHolder.getWorkerResponse(); } return policyWorker.createSuccessResultCallback(PolicyWorker.createResultObject(classifyDocumentResults)); }
protected LinkedList<Long> SetupPolicies() throws IOException { PolicyApi policyApi = genericApplicationContext.getBean(PolicyApi.class); MetadataPolicy metadataPolicy = new MetadataPolicy(); metadataPolicy.setFieldActions(new ArrayList<>()); FieldAction fieldAction = new FieldAction(); fieldAction.setAction(FieldAction.Action.ADD_FIELD_VALUE); fieldAction.setFieldName("EXTERNAL_TEST"); fieldAction.setFieldValue("1"); metadataPolicy.getFieldActions().add(fieldAction); PolicyType policyType = policyApi.retrievePolicyTypeByName("MetadataPolicy"); Policy policy = new Policy(); policy.name = "Policy"; policy.details = mapper.valueToTree(metadataPolicy); policy.typeId = policyType.id; policy.priority = 100; policy = policyApi.create(policy); LinkedList<Long> policyIds = new LinkedList<>(); policyIds.add(policy.id); return policyIds; }
protected Collection<Long> SetupPoliciesWithNoHandlersAvailable() throws IOException { PolicyApi policyApi = genericApplicationContext.getBean(PolicyApi.class); //register new policy type that will have no handlers associated MetadataPolicy metadataPolicy = new MetadataPolicy(); metadataPolicy.setFieldActions(new ArrayList<>()); FieldAction fieldAction = new FieldAction(); fieldAction.setAction(FieldAction.Action.ADD_FIELD_VALUE); fieldAction.setFieldName("EXTERNAL_TEST"); fieldAction.setFieldValue("1"); metadataPolicy.getFieldActions().add(fieldAction); PolicyType policyType = createCustomPolicyType(policyApi, getUniqueString("NoHandler"), null); Policy policy = new Policy(); policy.name = "Policy"; policy.details = mapper.valueToTree(metadataPolicy); policy.typeId = policyType.id; policy.priority = 100; policy = policyApi.create(policy); ArrayList<Long> noHandlers = new ArrayList<>(); noHandlers.add(policy.id); return noHandlers; }
public PolicyWorkerFactory(Codec codec, DataStore dataStore, PolicyWorkerConfiguration config) { this.codec = codec; this.dataStore = dataStore; this.resultQueue = config.getResultQueue(); this.workerIdentifier = config.getWorkerIdentifier(); this.workerThreads = config.getWorkerThreads(); this.configuration = config; applicationContext = new CorePolicyApplicationContext(); createBeanDefinition(WorkerResponseHolder.class, "WorkerResponseHolder", "thread"); createBeanDefinition(WorkerRequestHolder.class, "WorkerRequestHolder", "thread"); applicationContext.refresh(); taskDataConverter = new TaskDataConverter(); apiProvider = new ApiProvider(applicationContext); EngineProperties engineProperties = applicationContext.getBean(EngineProperties.class); Period period = new Period(engineProperties.getEnvironmentCacheVerifyPeriod()); workflowCache = CacheBuilder.newBuilder().expireAfterWrite(period.toStandardDuration().getMillis(), TimeUnit.MILLISECONDS) .build(new CacheLoader<Long, SequenceWorkflow>() { @Override public SequenceWorkflow load(Long key) throws Exception { logger.warn("Loading workflow from database, id: {}", key); return getWorkflow(key, apiProvider.getWorkflowApi()); } }); if (config.getRegisterHandlers()) { new PolicyHandlerSetup(applicationContext).checkBasePolicies(); } }
condition.value = "true"; ClassificationApi classificationApi = genericApplicationContext.getBean(ClassificationApi.class);
private Long createBinaryHashWorkflow(String binaryHashPolicyTypeJson) throws IOException PolicyApi policyApi = genericApplicationContext.getBean(PolicyApi.class); ClassificationApi classificationApi = getClassificationApi();