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; }
private Collection<Policy> getPolicies(Collection<Long> policyIds) { return policyApi.retrievePolicies(policyIds); }
@Override public void validate(Policy policy) throws Exception { if (this.policyType == null) { // Policy type is either setup by Id or by using our Internal name. // In the case of the MetadataPolicyConvertor its name must be what is // in front of the JSON property- x_Convertor prefix. e.g. MetadataPolicy_Converter this.policyType = this.policyApi.retrievePolicyType(policy.typeId); } // Validate the json in this policy against the schema held for the given policyType. policyApi.validate(policy, policyType); }
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; } } } }
protected Policy createCustomExternalClassificationPolicy(PolicyApi policyApi, PolicyType policyType, CollectionSequence colSeq, String polName, Integer polPriority, String queueName) throws IOException { String policyDef = "{\"classificationSequenceId\":" + colSeq.id + ",\"queueName\":\"" + queueName + "\"}"; ObjectMapper mapper = new ObjectMapper(); Policy policy = new Policy(); policy.name = polName; policy.details = mapper.readTree(policyDef); policy.typeId = policyType.id; policy.priority = polPriority; return policyApi.create(policy); }
private void addPolicyType(EnvironmentSnapshotImpl environmentSnapshot, Long policyTypeId){ if(environmentSnapshot.getPolicyTypes().containsKey(policyTypeId)) { return; } PolicyType policyType = policyApi.retrievePolicyType(policyTypeId); environmentSnapshot.getPolicyTypes().put(policyTypeId, policyType); }
private void addPolicy(EnvironmentSnapshotImpl environmentSnapshot, Long policyId){ if(environmentSnapshot.getPolicies().containsKey(policyId)) { return; } Policy policy = policyApi.retrievePolicy(policyId); addPolicyType(environmentSnapshot, policy.typeId); environmentSnapshot.getPolicies().put(policyId, policy); }
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); } }
protected PolicyType createCustomPolicyType(PolicyApi policyApi, final String uniqueName, final String uniqueShortName) { PolicyType policyType = new PolicyType(); policyType.conflictResolutionMode = ConflictResolutionMode.PRIORITY; policyType.name = uniqueName; policyType.shortName = Strings.isNullOrEmpty(uniqueShortName) ? getUniqueString("") : uniqueShortName; JsonNodeFactory nodeFactory = new JsonNodeFactory(false); policyType.definition = nodeFactory.objectNode(); policyType = policyApi.create(policyType); return policyType; }
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; } }
registeredPolicyType = policyApi.retrievePolicyTypeByName(policyTypeToRegister.shortName); } catch (Exception e) { logger.trace("Base PolicyType for name " + policyTypeToRegister.shortName + " not found.", e);
protected PolicyType createCustomExternalClassificationPolicyType(PolicyApi policyApi, String ptName, String ptShortName, String ptDesc, String ptJsonDefinition) throws IOException { PolicyType policyType = new PolicyType(); policyType.name = getUniqueString(ptName); policyType.shortName = ptShortName; policyType.description = ptDesc; policyType.definition = mapper.readTree(ptJsonDefinition); return policyApi.create(policyType); }
@Override public void validate(Policy policy) throws Exception { if(this.policyType==null){ // Policy type is either setup by Id or by using our Internal name. // In the case of the MetadataPolicyConvertor its name must be what is // in front of the JSON property- x_Convertor prefix. e.g. MetadataPolicy_Converter this.policyType = this.policyApi.retrievePolicyType( policy.typeId ); } // Validate the json in this policy against the schema held for the given policyType. policyApi.validate( policy, policyType ); }
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 createCustomPolicyType(PolicyApi policyApi, String ptName, String ptShortName, String ptDesc, String ptJsonDefinition, String polName, String fieldName, String fieldValue, Integer polPriority) throws IOException { PolicyType policyType = new PolicyType(); policyType.name = getUniqueString(ptName); policyType.shortName = ptShortName; policyType.description = ptDesc; TagPolicy examplePolicy = new TagPolicy(); ObjectMapper mapper = new ObjectMapper(); policyType.definition = mapper.readTree(ptJsonDefinition); policyType = policyApi.create(policyType); Policy policy = new Policy(); policy.name = polName; if (!Strings.isNullOrEmpty(fieldName)) { FieldAction fieldAction = new FieldAction(); fieldAction.setFieldName(fieldName); fieldAction.setAction(FieldAction.Action.ADD_FIELD_VALUE); fieldAction.setFieldValue(fieldValue); examplePolicy.setFieldActions(Arrays.asList(fieldAction)); } policy.details = mapper.valueToTree(examplePolicy); policy.typeId = policyType.id; policy.priority = polPriority; return policyApi.create(policy); }
@Override public void validate(Policy policy) throws Exception { if (this.policyType == null) { // as the custom policies can have any internal_name we need to use ID, instead of internal_name this.policyType = this.policyApi.retrievePolicyType(policy.typeId); } // Validate the json in this policy against the schema held for the given policyType. policyApi.validate(policy, policyType); }
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; externalPolicyName = taggingPolicy.name;
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; }
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; externalPolicyName = "Meeting Notifications";
binaryHashPolicy.typeId = policyApi.retrievePolicyTypeByName("BinaryHashPolicyType").id; binaryHashPolicy.details = mapper.readTree(binaryHashPolicyTypeJson); binaryHashPolicy = policyApi.create(binaryHashPolicy);