@Override protected List<Attr> getAttrsFromTO() { return anyTO.getPlainAttrs().stream().sorted(attrComparator).collect(Collectors.toList()); }
@Override protected void setAttrs() { List<Attr> attrs = new ArrayList<>(); Map<String, Attr> attrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs()); attrs.addAll(schemas.values().stream().map(schema -> { Attr attrTO = new Attr(); attrTO.setSchema(schema.getKey()); if (attrMap.get(schema.getKey()) == null || attrMap.get(schema.getKey()).getValues().isEmpty()) { attrTO.getValues().add(""); } else { attrTO = attrMap.get(schema.getKey()); } return attrTO; }).collect(Collectors.toList())); anyTO.getPlainAttrs().clear(); anyTO.getPlainAttrs().addAll(attrs); }
/** * 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 anyUR update req to enrich with DELETE statements */ public static void cleanEmptyAttrs(final AnyTO anyTO, final AnyUR anyUR) { anyUR.getPlainAttrs().addAll(anyTO.getPlainAttrs().stream(). filter(plainAttr -> isEmpty(plainAttr)). map(plainAttr -> new AttrPatch.Builder(new Attr.Builder(plainAttr.getSchema()).build()). operation(PatchOperation.DELETE). build()).collect(Collectors.toSet())); }
Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());
/** * 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())); }
Map<String, AttrTO> attrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs());
@Override public Set<AttrTO> read(final String key, final SchemaType schemaType) { TO any = read(key); Set<AttrTO> result; switch (schemaType) { case DERIVED: result = any.getDerAttrs(); break; case VIRTUAL: result = any.getVirAttrs(); break; case PLAIN: default: result = any.getPlainAttrs(); } return result; }
protected void fixPlainAndVirAttrs(final AnyTO updated, final AnyTO original) { for (Attr plainAttr : original.getPlainAttrs()) { if (!updated.getPlainAttr(plainAttr.getSchema()).isPresent()) { updated.getPlainAttrs().add(plainAttr); updated.getPlainAttrs().removeIf(attr -> attr.getValues().isEmpty()); updated.getVirAttrs().removeIf(attr -> attr.getValues().isEmpty()); if (updated instanceof GroupableRelatableTO) {
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())); }
value.getPlainAttrs().stream(). filter(attrTO -> !attrTO.getValues().isEmpty() && !JexlUtils.isExpressionValid(attrTO.getValues().get(0))).
result.getPlainAttrs().clear(); result.getPlainAttrs().addAll(patch(EntityTOUtils.buildAttrMap(to.getPlainAttrs()), patch.getPlainAttrs()));
result.getPlainAttrs().clear(); result.getPlainAttrs().addAll(patch(EntityTOUtils.buildAttrMap(to.getPlainAttrs()), req.getPlainAttrs()));
@Override public List<Object> beforePull( final Item item, final EntityTO entityTO, final List<Object> values) { if (StringUtils.isNotBlank(pullJEXL) && values != null) { List<Object> newValues = new ArrayList<>(values.size()); values.forEach(value -> { JexlContext jexlContext = new MapContext(); jexlContext.set("value", value); if (entityTO instanceof AnyTO) { JexlUtils.addFieldsToContext((AnyTO) entityTO, jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getPlainAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getDerAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext); } else if (entityTO instanceof RealmTO) { JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext); } newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext)); }); return newValues; } return JEXLItemTransformer.super.beforePull(item, entityTO, values); } }
private void fill(final AnyTO anyTO, final AnyTO template) { MapContext jexlContext = new MapContext(); JexlUtils.addFieldsToContext(anyTO, jexlContext); JexlUtils.addAttrTOsToContext(anyTO.getPlainAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(anyTO.getDerAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(anyTO.getVirAttrs(), jexlContext); Map<String, AttrTO> currentAttrMap = EntityTOUtils.buildAttrMap(anyTO.getPlainAttrs()); for (AttrTO templatePlainAttr : template.getPlainAttrs()) { if (!templatePlainAttr.getValues().isEmpty() && (!currentAttrMap.containsKey(templatePlainAttr.getSchema()) anyTO.getPlainAttrs().add(evaluated); jexlContext.set(evaluated.getSchema(), evaluated.getValues().get(0));
Map<String, Attr> updatedAttrs = EntityTOUtils.buildAttrMap(updated.getPlainAttrs()); Map<String, Attr> originalAttrs = EntityTOUtils.buildAttrMap(original.getPlainAttrs());
Map<String, AttrTO> updatedAttrs = EntityTOUtils.buildAttrMap(updated.getPlainAttrs()); Map<String, AttrTO> originalAttrs = EntityTOUtils.buildAttrMap(original.getPlainAttrs());
anyTO.getPlainAttrs().stream(). filter(attrTO -> !attrTO.getValues().isEmpty()). forEach(attrTO -> {
public static <C extends AnyCR, A extends AnyTO> void toAnyTO(final C anyCR, final A anyTO) { anyTO.setRealm(anyCR.getRealm()); anyTO.getAuxClasses().addAll(anyCR.getAuxClasses()); anyTO.getPlainAttrs().addAll(anyCR.getPlainAttrs()); anyTO.getVirAttrs().addAll(anyCR.getVirAttrs()); anyTO.getResources().addAll(anyCR.getResources());
public static <A extends AnyTO, C extends AnyCR> void toAnyCR(final A anyTO, final C anyCR) { anyCR.setRealm(anyTO.getRealm()); anyCR.getAuxClasses().addAll(anyTO.getAuxClasses()); anyCR.getPlainAttrs().addAll(anyTO.getPlainAttrs()); anyCR.getVirAttrs().addAll(anyTO.getVirAttrs()); anyCR.getResources().addAll(anyTO.getResources());
JexlUtils.addAttrTOsToContext(anyTO.getPlainAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(anyTO.getDerAttrs(), jexlContext); JexlUtils.addAttrTOsToContext(anyTO.getVirAttrs(), jexlContext);