public static void addPlainAttrsToContext( final Collection<? extends PlainAttr<?>> attrs, final JexlContext jexlContext) { attrs.stream().filter(attr -> attr.getSchema() != null).forEach(attr -> { List<String> attrValues = attr.getValuesAsStrings(); String expressionValue = attrValues.isEmpty() ? StringUtils.EMPTY : attrValues.get(0); LOG.debug("Add attribute {} with value {}", attr.getSchema().getKey(), expressionValue); jexlContext.set(attr.getSchema().getKey(), expressionValue); }); }
@Override public String getValueAsString() { PlainSchema schema = getAttr() == null || getAttr().getSchema() == null ? null : getAttr().getSchema(); AttrSchemaType type = schema == null || schema.getType() == null ? AttrSchemaType.String : getAttr().getSchema().getType(); return getValueAsString(type, schema); }
@Override protected void doValidate(final PlainAttrValue attrValue) { // check Binary schemas MIME Type mismatches if (attrValue.getBinaryValue() != null) { byte[] binaryValue = attrValue.getBinaryValue(); String mimeType = TIKA.detect(binaryValue); boolean valid = true; if (!mimeType.equals(attrValue.getAttr().getSchema().getMimeType())) { if (MediaType.TEXT_PLAIN.equals(mimeType) && MediaType.APPLICATION_JSON.equals(attrValue.getAttr().getSchema().getMimeType())) { String decoded = new String(binaryValue).trim(); valid = (decoded.startsWith("{") && decoded.endsWith("}")) || (decoded.startsWith("[") && decoded.endsWith("]")) && isValidJSON(decoded); } else { valid = false; } } if (!valid) { throw new InvalidPlainAttrValueException( "Found MIME type: '" + mimeType + "', expecting: '" + attrValue.getAttr().getSchema().getMimeType() + "'"); } } }
protected void fillTO( final AnyTO anyTO, final String realmFullPath, final Collection<? extends AnyTypeClass> auxClasses, final Collection<? extends PlainAttr<?>> plainAttrs, final Map<DerSchema, String> derAttrs, final Map<VirSchema, List<String>> virAttrs, final Collection<? extends ExternalResource> resources, final boolean details) { anyTO.setRealm(realmFullPath); anyTO.getAuxClasses().addAll(auxClasses.stream().map(Entity::getKey).collect(Collectors.toList())); plainAttrs.forEach(plainAttr -> { anyTO.getPlainAttrs().add(new AttrTO.Builder(). schema(plainAttr.getSchema().getKey()). values(plainAttr.getValuesAsStrings()).build()); }); derAttrs.forEach((schema, value) -> { anyTO.getDerAttrs().add(new AttrTO.Builder().schema(schema.getKey()).value(value).build()); }); virAttrs.forEach((schema, values) -> { anyTO.getVirAttrs().add(new AttrTO.Builder().schema(schema.getKey()).values(values).build()); }); anyTO.getResources().addAll(resources.stream().map(Entity::getKey).collect(Collectors.toSet())); }
isValid = true; } else { if (attr.getSchema().isUniqueConstraint()) { isValid = attr.getValues().isEmpty() && attr.getUniqueValue() != null; } else { isValid = !attr.getValues().isEmpty() && attr.getUniqueValue() == null; if (!attr.getSchema().isMultivalue()) { isValid &= attr.getValues().size() == 1; + "schema=" + attr.getSchema().getKey() + ", values={}", attr.getValuesAsStrings()); addPropertyNode(attr.getSchema().getKey()).addConstraintViolation();
if (attr != null && !allowedPlainSchemas.forSelfContains(attr.getSchema().getKey())) { return raiseNotAllowedViolation(context, attr.getSchema().getKey(), null); for (PlainAttr<?> attr : ((GroupableRelatable<?, ?, ?, ?, ?>) any).getPlainAttrs(membership)) { if (attr != null && !allowedPlainSchemas.forMembershipsContains( membership.getRightEnd(), attr.getSchema().getKey())) { context, attr.getSchema().getKey(), membership.getRightEnd());
case ADD_REPLACE: if (attr.getSchema().isUniqueConstraint()) { if (attr.getUniqueValue() != null && !patch.getAttrTO().getValues().isEmpty()
PlainSchema attrSchema = value.getAttr().getSchema();
protected MembershipTO getMembershipTO( final Collection<? extends PlainAttr<?>> plainAttrs, final Map<DerSchema, String> derAttrs, final Map<VirSchema, List<String>> virAttrs, final Membership<? extends Any<?>> membership) { MembershipTO membershipTO = new MembershipTO.Builder(). group(membership.getRightEnd().getKey(), membership.getRightEnd().getName()). build(); plainAttrs.forEach(plainAttr -> { membershipTO.getPlainAttrs().add(new AttrTO.Builder(). schema(plainAttr.getSchema().getKey()). values(plainAttr.getValuesAsStrings()). build()); }); derAttrs.forEach((schema, value) -> { membershipTO.getDerAttrs().add(new AttrTO.Builder(). schema(schema.getKey()). value(value). build()); }); virAttrs.forEach((schema, values) -> { membershipTO.getVirAttrs().add(new AttrTO.Builder(). schema(schema.getKey()). values(values). build()); }); return membershipTO; }