void initialisePolicyHandlerIfNeeded() { if (!initialised) { synchronized (ClassifyDocumentApiDirectImpl.class) { if (!initialised) { PolicyType metadataPolicyType = policyApi.retrievePolicyTypeByName("MetadataPolicy"); //This is a singleton and so is PolicyEngine so this should only happen once! registerHandler(new MetadataPolicyHandler(metadataPolicyType.id)); //Add handlers from classpath ServiceLoader<PolicyHandler> loader = ServiceLoader.load(PolicyHandler.class); for (PolicyHandler d : loader) { registerHandler(d); } initialised = true; } } } }
private void setUpWorkerHandler(WorkerPolicyHandler workerPolicyHandler, String projectId) { String uniqueName = workerPolicyHandler.getPolicyType().shortName + projectId; if (registeredHandlers.contains(uniqueName)) { return; } workerPolicyHandler.setApplicationContext(corePolicyApplicationContext); ((ClassifyDocumentApiDirectImpl) classifyDocumentApi).registerHandler(workerPolicyHandler); //Register policy PolicyType policyTypeToRegister = workerPolicyHandler.getPolicyType(); PolicyType registeredPolicyType; try { registeredPolicyType = policyApi.retrievePolicyTypeByName(policyTypeToRegister.shortName); } catch (Exception e) { logger.trace("PolicyType for name " + policyTypeToRegister.shortName + " not found.", e); // workers for this type aren't found in the system this is fatal, and shouldn't happen. throw new RuntimeException("PolicyType for name " + policyTypeToRegister.shortName + " not found.", e); } workerPolicyHandler.setPolicyTypeId(registeredPolicyType.id); logger.info("Registered WorkerPolicyHandler - " + uniqueName); registeredHandlers.add(uniqueName); } }
registeredPolicyType = policyApi.retrievePolicyTypeByName(policyTypeToRegister.shortName); } catch (Exception e) { logger.trace("Base PolicyType for name " + policyTypeToRegister.shortName + " not found.", e);
public static Policy createPolicy(PolicyApi policyApi, String policyType, String policyNameBase, String policyDetails) throws IOException { Policy policy = new Policy(); policy.name = getUniqueString(policyNameBase); policy.details = mapper.readTree(policyDetails); policy.typeId = policyApi.retrievePolicyTypeByName(policyType).id; policy = policyApi.create(policy); return policy; }
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; }
private Policy createAdvancedPolicy(String policyName, String policyTypeName, String policyDefinition) throws IOException { Policy textExtractPolicy = new Policy(); textExtractPolicy.name = policyName; PolicyType policyType = getPolicyApi().retrievePolicyTypeByName(policyTypeName); Assert.assertNotNull("Policytype must exist:", policyType); textExtractPolicy.typeId = policyType.id; textExtractPolicy.details = mapper.readTree(policyDefinition); textExtractPolicy = getPolicyApi().create(textExtractPolicy); Assert.assertNotEquals(0L, (long) (textExtractPolicy.id)); return textExtractPolicy; } }
taggingPolicy.name = BaseTestsHelper.getUniqueString("Tag the document"); taggingPolicy.details = mapper.readTree(mapper.writeValueAsString(metadataPolicy)); taggingPolicy.typeId = policyApi.retrievePolicyTypeByName("MetadataPolicy").id; taggingPolicy = policyApi.create(taggingPolicy); externalPolicyId = taggingPolicy.id;
taggingPolicy.description = "\"{\\\"name\\\":\\\"Meeting Notifications\\\",\\\"description\\\":\\\"Documents that match this classification are Meeting Notifications.\\\"}\""; taggingPolicy.details = mapper.readTree(mapper.writeValueAsString(metadataPolicy)); taggingPolicy.typeId = policyApi.retrievePolicyTypeByName("MetadataPolicy").id; taggingPolicy = policyApi.create(taggingPolicy); externalPolicyId = taggingPolicy.id;
binaryHashPolicy.typeId = policyApi.retrievePolicyTypeByName("BinaryHashPolicyType").id; binaryHashPolicy.details = mapper.readTree(binaryHashPolicyTypeJson); binaryHashPolicy = policyApi.create(binaryHashPolicy);