@Override public Projection parseProjection(JsonNode object) { return object == null ? null : Projection.fromJson(object); }
@Override public void putProjection(JsonNode object,String name,Projection p) { if(p!=null) ((ObjectNode)object).put(name,p.toJson()); }
private boolean isProjected(Path field,Projection p) { switch(p.getFieldInclusion(field)) { case explicit_inclusion: case implicit_inclusion:return true; default: return false; } }
/** * Determine if the field is explicitly included/excluded, implicitly * included, or the projection does not decide on the field. */ public Inclusion getFieldInclusion(Path field, Path ctx) { Path mfield = toMask(field); ctx = toMask(ctx); if (this instanceof FieldProjection) { return getFieldInclusion(mfield, (FieldProjection) this, ctx); } else if (this instanceof ArrayProjection) { return getFieldInclusion(mfield, (ArrayProjection) this, ctx); } else if (this instanceof ProjectionList) { return getFieldInclusion(mfield, (ProjectionList) this, ctx); } return Inclusion.undecided; }
Path mfield = toMask(field); ctx = toMask(ctx); if (this instanceof FieldProjection) { switch (getFieldInclusion(mfield, (FieldProjection) this, ctx)) { case implicit_inclusion: case explicit_inclusion: if (getFieldInclusion(mfield, (ArrayProjection) this, ctx) == Inclusion.undecided) { LOGGER.debug("whether to include {} is Undecided, checking projection query", mfield); Path absField = new Path(ctx, toMask(((ArrayQueryMatchProjection) this).getField())); Path nestedCtx = new Path(absField, Path.ANYPATH); boolean ret = ((ArrayQueryMatchProjection) this).getMatch().isRequired(field, nestedCtx); ret = ((ArrayProjection) this).getProject().isFieldRequiredToEvaluateProjection(field, nestedCtx); return getFieldInclusion(mfield, (ArrayProjection) this, ctx) != Inclusion.undecided; } else if (this instanceof ProjectionList) { for (Projection x : ((ProjectionList) this).getItems()) { if (x.isFieldRequiredToEvaluateProjection(field, ctx)) { return true;
/** * Returns true if the field is needed to evaluate the projection */ public boolean isFieldRequiredToEvaluateProjection(Path field) { LOGGER.debug("Checking if {} is referenced in projection", field); return isFieldRequiredToEvaluateProjection(field, Path.EMPTY); }
private Inclusion getFieldInclusion(Path field, ArrayProjection p, Path context) { Path absField = new Path(context, toMask(p.getField())); LOGGER.debug("Checking if array projection on {} projects {}", absField, field); Inclusion inc = isFieldIncluded(field, absField, p.isInclude(), false); Inclusion inc2 = p.getProject().getFieldInclusion(field, new Path(absField, Path.ANYPATH)); Inclusion ret; if (inc == Inclusion.explicit_inclusion || inc2 == Inclusion.explicit_inclusion) { ret = Inclusion.explicit_inclusion; } else if (inc == Inclusion.implicit_inclusion || inc2 == Inclusion.implicit_inclusion) { ret = Inclusion.implicit_inclusion; } else if (inc == Inclusion.explicit_exclusion || inc2 == Inclusion.explicit_exclusion) { ret = Inclusion.explicit_exclusion; } else if (inc == Inclusion.implicit_exclusion || inc2 == Inclusion.implicit_exclusion) { ret = Inclusion.implicit_exclusion; } else { ret = Inclusion.undecided; } LOGGER.debug("array projection on {} projects {}: {}", absField, field, ret); return ret; }
private Projection addArrayIdentities(Projection p,EntityMetadata md) { // If an array is included in the projection, make sure its identity is also included Map<Path,List<Path>> arrayIdentities=md.getEntitySchema().getArrayIdentities(); List<Projection> addFields=new ArrayList<>(); for(Map.Entry<Path,List<Path>> entry:arrayIdentities.entrySet()) { Path array=entry.getKey(); List<Path> identities=new ArrayList<>(); for(Path x:entry.getValue()) identities.add(new Path(array,new Path(Path.ANYPATH,x))); if(isProjected(array,p)) { for(Path id:identities) { if(!isProjected(id,p)) { addFields.add(new FieldProjection(id,true,true)); } } } } if(!addFields.isEmpty()) { LOGGER.debug("Excluded array identities are added to projection:{}",addFields); // Need to first add the original projection, then the included fields. // This is order sensitive return Projection.add(p,new ProjectionList(addFields)); } else return p; }
public JsonNodeBuilder add(String key, Projection value) { if (include(value)) { getRoot().put(key, value.toString()); } return this; }
Path mfield = toMask(field); ctx = toMask(ctx); if (this instanceof FieldProjection) { switch (getFieldInclusion(mfield, (FieldProjection) this, ctx)) { case implicit_inclusion: case explicit_inclusion: if (getFieldInclusion(mfield, (ArrayProjection) this, ctx) == Inclusion.undecided) { LOGGER.debug("whether to include {} is Undecided, checking projection query", mfield); Path absField = new Path(ctx, toMask(((ArrayQueryMatchProjection) this).getField())); Path nestedCtx = new Path(absField, Path.ANYPATH); boolean ret = ((ArrayQueryMatchProjection) this).getMatch().isRequired(field, nestedCtx); ret = ((ArrayProjection) this).getProject().isFieldRequiredToEvaluateProjection(field, nestedCtx); return getFieldInclusion(mfield, (ArrayProjection) this, ctx) != Inclusion.undecided; } else if (this instanceof ProjectionList) { for (Projection x : ((ProjectionList) this).getItems()) { if (x.isFieldRequiredToEvaluateProjection(field, ctx)) { return true;
/** * Returns true if the field is needed to evaluate the projection */ public boolean isFieldRequiredToEvaluateProjection(Path field) { LOGGER.debug("Checking if {} is referenced in projection", field); return isFieldRequiredToEvaluateProjection(field, Path.EMPTY); }
private Inclusion getFieldInclusion(Path field, ArrayProjection p, Path context) { Path absField = new Path(context, toMask(p.getField())); LOGGER.debug("Checking if array projection on {} projects {}", absField, field); Inclusion inc = isFieldIncluded(field, absField, p.isInclude(), false); Inclusion inc2 = p.getProject().getFieldInclusion(field, new Path(absField, Path.ANYPATH)); Inclusion ret; if (inc == Inclusion.explicit_inclusion || inc2 == Inclusion.explicit_inclusion) { ret = Inclusion.explicit_inclusion; } else if (inc == Inclusion.implicit_inclusion || inc2 == Inclusion.implicit_inclusion) { ret = Inclusion.implicit_inclusion; } else if (inc == Inclusion.explicit_exclusion || inc2 == Inclusion.explicit_exclusion) { ret = Inclusion.explicit_exclusion; } else if (inc == Inclusion.implicit_exclusion || inc2 == Inclusion.implicit_exclusion) { ret = Inclusion.implicit_exclusion; } else { ret = Inclusion.undecided; } LOGGER.debug("array projection on {} projects {}: {}", absField, field, ret); return ret; }
DBCollection collection = db.getCollection(store.getCollectionName()); Projection combinedProjection = Projection.add(projection, roleEval.getExcludedFields(FieldAccessRoleEvaluator.Operation.find));
/** * Determine if the field is explicitly included/excluded, implicitly * included, or the projection does not decide on the field. */ public Inclusion getFieldInclusion(Path field, Path ctx) { Path mfield = toMask(field); ctx = toMask(ctx); if (this instanceof FieldProjection) { return getFieldInclusion(mfield, (FieldProjection) this, ctx); } else if (this instanceof ArrayProjection) { return getFieldInclusion(mfield, (ArrayProjection) this, ctx); } else if (this instanceof ProjectionList) { return getFieldInclusion(mfield, (ProjectionList) this, ctx); } return Inclusion.undecided; }
public JsonNodeBuilder add(String key, Projection value) { if (include(value)) { getRoot().put(key, value.toString()); } return this; }
@Override public void putProjection(JsonNode object, String name, Projection p) { if (p != null) { ((ObjectNode) object).set(name, p.toJson()); } }
@Override public Projection getProjection(JsonNode object, String name) { JsonNode node = object.get(name); return node == null ? null : Projection.fromJson(node); }
/** * Returns true if field inclusion is explicit. * * @param field the path to check * @return */ private boolean isProjected(Path field) { LOGGER.debug("Checking if {} is explicitly projected", field); for (Projection p : projections) { Projection.Inclusion inc=p.getFieldInclusion(field); if(inc==Projection.Inclusion.explicit_inclusion) return true; } return false; }
(node instanceof ArrayElement)) { } else if( (p!=null && p.isFieldRequiredToEvaluateProjection(field)) || (q!=null && q.isRequired(field)) || (s!=null && s.isRequired(field)) ) {
DBCollection collection = db.getCollection(store.getCollectionName()); Projection combinedProjection = Projection.add(projection, roleEval.getExcludedFields(FieldAccessRoleEvaluator.Operation.find));