public static Constraints constraints() { return new Constraints(); }
PropertyConstraint pc= Constraints. propertyConstraint(uri("property")). withLabel("property-constraint"). withComment("A property constraint"). InversePropertyConstraint ipc= Constraints. inversePropertyConstraint(uri("inverseProperty")). withLabel("inverse-property-constraint"). withComment("An inverse property constraint"). Shape nodeShape= Constraints. shape(). withLabel("node-constraint"). withComment("A constraint for an specific value"). Shape typeShape= Constraints. shape(). withLabel("type-constraint"). withComment("A constraint for a type"). return Constraints. constraints(). withNodeShape(managedIndividual(dataSet, "individual", "template"), nodeShape). withTypeShape(uri("constrainedType"), typeShape);
private void validate(DataSet dataSet, DataSet metadata) throws InvalidContentException { ManagedIndividualId id = individualId(); Individual<?,?> individual=metadata.individualOfId(id); ValidatorBuilder builder=Validator.builder(); configureValidationConstraints(builder,individual,metadata); Validator validator=builder.build(); ValidationReport report = validator.validate(dataSet); if(!report.isValid()) { // TODO: Add validation constraints Constraints constraints = Constraints.constraints(); throw new InconsistentContentException("Protocol/framework managed metadata validation failed: "+report.validationFailures(),constraints); } }
PropertyConstraint pc= Constraints. propertyConstraint(uri("property")). withLabel("property-constraint"). withComment("A property constraint"). InversePropertyConstraint ipc= Constraints. inversePropertyConstraint(uri("inverseProperty")). withLabel("inverse-property-constraint"). withComment("An inverse property constraint"). Shape nodeShape= Constraints. shape(). withLabel("node-constraint"). withComment("A constraint for an specific value"). Shape typeShape= Constraints. shape(). withLabel("type-constraint"). withComment("A constraint for a type"). return Constraints. constraints(). withNodeShape(managedIndividual(dataSet, "individual", "template"), nodeShape). withTypeShape(uri("constrainedType"), typeShape);
protected void enforceConsistency(ResourceSnapshot resource, DataSet content, DataSet dataSet) throws InconsistentContentException { ManagedIndividualId id = ManagedIndividualId.createId(resource.name(),PersonHandler.ID); ManagedIndividual stateIndividual = dataSet. individual( id, ManagedIndividual.class); Property stateProperty= stateIndividual.property(PersonHandler.READ_ONLY_PROPERTY); ValidationConstraint<Property> constraint=null; if(stateProperty!=null) { constraint=ValidationConstraintFactory.readOnlyProperty(stateProperty); } else { constraint=ValidationConstraintFactory.readOnlyProperty(id,PersonHandler.READ_ONLY_PROPERTY); } Validator helper = Validator. builder(). withPropertyConstraint(constraint). build(); ValidationReport report = helper.validate(content); if(!report.isValid()) { InconsistentContentException error = new InconsistentContentException("Validation failed: "+report.validationFailures(), Constraints.constraints()); logError(resource,error,"Something went wrong when validating %n%s",content); throw error; } }