@JsonIgnore @Override public Optional<AttrTO> getDerAttr(final String schema) { return derAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore public Optional<AttrTO> getAttr(final String schema) { return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore @Override public Optional<AttrTO> getVirAttr(final String schema) { return virAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore @Override public Optional<AttrTO> getPlainAttr(final String schema) { return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
public static Map<String, AttrTO> buildAttrMap(final Collection<AttrTO> attrs) { Map<String, AttrTO> result = new HashMap<>(attrs.size()); attrs.forEach(attrTO -> result.put(attrTO.getSchema(), attrTO)); return Collections.unmodifiableMap(result); }
@JsonIgnore @Override public Optional<AttrTO> getPlainAttr(final String schema) { return plainAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore @Override public Optional<AttrTO> getDerAttr(final String schema) { return derAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore @Override public Optional<AttrTO> getVirAttr(final String schema) { return virAttrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore public Optional<AttrTO> getAttr(final String schema) { return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
@JsonIgnore public Optional<AttrTO> getAttr(final String schema) { return attrs.stream().filter(attr -> attr.getSchema().equals(schema)).findFirst(); }
private void completeAttrs(final Set<AttrTO> userTOAttrs, final Set<AttrTO> selfTOAttrs) { Map<String, AttrTO> userTOAttrsMap = EntityTOUtils.buildAttrMap(userTOAttrs); selfTOAttrs.stream(). filter(selfTOAttr -> (!userTOAttrsMap.containsKey(selfTOAttr.getSchema()))). forEachOrdered(selfTOAttr -> { userTOAttrs.add(selfTOAttr); }); }
public static void addAttrTOsToContext(final Collection<AttrTO> attrs, final JexlContext jexlContext) { attrs.stream().filter(attr -> attr.getSchema() != null).forEach(attr -> { String expressionValue = attr.getValues().isEmpty() ? StringUtils.EMPTY : attr.getValues().get(0); LOG.debug("Add attribute {} with value {}", attr.getSchema(), expressionValue); jexlContext.set(attr.getSchema(), expressionValue); }); }
private void customizeAttrTOs(final Set<AttrTO> attrs, final CustomAttributesInfo customAttributesInfo) { if (customAttributesInfo != null && !customAttributesInfo.getAttributes().isEmpty()) { attrs.removeAll(attrs.stream(). filter(attr -> !customAttributesInfo.getAttributes().containsKey(attr.getSchema())). collect(Collectors.toList())); attrs.clear(); } } }
private static Collection<AttrTO> patch(final Map<String, AttrTO> attrs, final Set<AttrPatch> attrPatches) { Map<String, AttrTO> rwattrs = new HashMap<>(attrs); attrPatches.forEach(patch -> { if (patch.getAttrTO() == null) { LOG.warn("Invalid {} specified: {}", AttrPatch.class.getName(), patch); } else { AttrTO removed = rwattrs.remove(patch.getAttrTO().getSchema()); if (patch.getOperation() == PatchOperation.ADD_REPLACE && !patch.getAttrTO().getValues().isEmpty()) { rwattrs.put(patch.getAttrTO().getSchema(), patch.getAttrTO()); } } }); return rwattrs.values(); }
protected void millisToDate(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws IllegalArgumentException { final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern()); attrs.stream(). filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))). forEachOrdered(attr -> { for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext();) { String value = itor.next(); try { itor.set(fmt.format(Long.valueOf(value))); } catch (NumberFormatException ex) { LOG.error("Invalid format value for {}", value); } } }); }
private static boolean validateAttributes(final Map<String, AttrTO> attrMap, final CustomAttributesInfo customAttrInfo, final boolean checkDefaultValues) { return customAttrInfo == null || customAttrInfo.getAttributes().isEmpty() || attrMap.entrySet().stream().allMatch(entry -> { String schemaKey = entry.getKey(); AttrTO attrTO = entry.getValue(); CustomAttribute customAttr = customAttrInfo.getAttributes().get(schemaKey); boolean compliant = customAttr != null && (!checkDefaultValues || isValid(attrTO, customAttr)); if (!compliant) { LOG.trace("Attribute [{}] or its values [{}] are not allowed by form customization rules", attrTO.getSchema(), attrTO.getValues()); } return compliant; }); }
protected void dateToMillis(final Set<AttrTO> attrs, final PlainSchemaTO plainSchema) throws ParseException { final FastDateFormat fmt = FastDateFormat.getInstance(plainSchema.getConversionPattern()); attrs.stream(). filter(attr -> (attr.getSchema().equals(plainSchema.getKey()))). forEachOrdered(attr -> { for (ListIterator<String> itor = attr.getValues().listIterator(); itor.hasNext();) { String value = itor.next(); try { itor.set(String.valueOf(fmt.parse(value).getTime())); } catch (ParseException ex) { LOG.error("Unable to parse date {}", value); } } }); }
private AttrTO evaluateAttr(final AttrTO template, final MapContext jexlContext) { AttrTO result = new AttrTO(); result.setSchema(template.getSchema()); if (template.getValues() != null && !template.getValues().isEmpty()) { template.getValues().forEach(value -> { String evaluated = JexlUtils.evaluate(value, jexlContext); if (StringUtils.isNotBlank(evaluated)) { result.getValues().add(evaluated); } }); } return result; }
/** * Add PLAIN attribute DELETE patch for those attributes of the input AnyTO without values or containing null value * * @param anyTO User, Group or Any Object to look for attributes with no value * @param patch patch to enrich with DELETE statements */ public static void cleanEmptyAttrs(final AnyTO anyTO, final AnyPatch patch) { patch.getPlainAttrs().addAll(anyTO.getPlainAttrs().stream(). filter(plainAttrTO -> isEmpty(plainAttrTO)). map(plainAttrTO -> new AttrPatch.Builder(). operation(PatchOperation.DELETE). attrTO(new AttrTO.Builder().schema(plainAttrTO.getSchema()).build()). build()).collect(Collectors.toSet())); }
@Override public Response update(final String key, final SchemaType schemaType, final AttrTO attrTO) { String actualKey = getActualKey(getAnyDAO(), key); addUpdateOrReplaceAttr(actualKey, schemaType, attrTO, PatchOperation.ADD_REPLACE); return modificationResponse(read(actualKey, schemaType, attrTO.getSchema())); }