/** * Writes a projection to include the given set of fields */ public static Projection writeProjection(Collection<Path> fields) { List<Projection> list = new ArrayList<>(fields.size()); for (Path p : fields) { list.add(new FieldProjection(p, true, false)); } return list.size() == 1 ? list.get(0) : new ProjectionList(list); }
public FieldProjector(FieldProjection p, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); field = new Path(ctxPath, p.getField()); include = p.isInclude(); recursive = p.isRecursive(); }
@Override public JsonNode toJson() { return getFactory().objectNode(). put("field", field.toString()). put("include", include). put("recursive", recursive); } }
/** * Writes a projection to include the given set of fields */ public static Projection writeProjection(Collection<Path> fields) { List<Projection> list = new ArrayList<>(fields.size()); for (Path p : fields) { list.add(new FieldProjection(p, true, false)); } return list.size() == 1 ? list.get(0) : new ProjectionList(list); }
public FieldProjector(FieldProjection p, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); field = new Path(ctxPath, p.getField()); include = p.isInclude(); recursive = p.isRecursive(); }
@Override public JsonNode toJson() { return getFactory().objectNode(). put("field", field.toString()). put("include", include). put("recursive", recursive); } }
/** * Returns a projection that excludes the fields the caller does not have * access to based on the operation */ public Projection getExcludedFields(Operation op) { Set<Path> inaccessibleFields = getInaccessibleFields(op); Projection ret; if (inaccessibleFields.isEmpty()) { ret = null; } else if (inaccessibleFields.size() == 1) { ret = new FieldProjection(inaccessibleFields.iterator().next(), false, true); } else { List<Projection> list = new ArrayList<>(inaccessibleFields.size()); for (Path x : inaccessibleFields) { list.add(new FieldProjection(x, false, true)); } ret = new ProjectionList(list); } return ret; }
public FieldProjector(FieldProjection p, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); field = new Path(ctxPath, p.getField()); include = p.isInclude(); recursive = p.isRecursive(); }
/** * Returns a projection that excludes the fields the caller does not have * access to based on the operation */ public Projection getExcludedFields(Operation op) { Set<Path> inaccessibleFields = getInaccessibleFields(op); Projection ret; if (inaccessibleFields.isEmpty()) { ret = null; } else if (inaccessibleFields.size() == 1) { ret = new FieldProjection(inaccessibleFields.iterator().next(), false, true); } else { List<Projection> list = new ArrayList<>(inaccessibleFields.size()); for (Path x : inaccessibleFields) { list.add(new FieldProjection(x, false, true)); } ret = new ProjectionList(list); } return ret; }
private Inclusion getFieldInclusion(Path field, FieldProjection p, Path context) { Path projectionField = new Path(context, toMask(p.getField())); LOGGER.debug("Checking if field projection on {} projects {}", projectionField, field); Inclusion inc = isFieldIncluded(field, projectionField, p.isInclude(), p.isRecursive()); LOGGER.debug("Field projection on {} projects {}: {}", projectionField, field, inc); return inc; }
/** * Returns a projection that excludes the fields the caller does not have * access to based on the operation */ public Projection getExcludedFields(Operation op) { Set<Path> inaccessibleFields = getInaccessibleFields(op); Projection ret; if (inaccessibleFields.isEmpty()) { ret = null; } else { if (inaccessibleFields.size() == 1) { ret = new FieldProjection(inaccessibleFields.iterator().next(), false, true); } else { List<Projection> list = new ArrayList<>(inaccessibleFields.size()); for (Path x : inaccessibleFields) { list.add(new FieldProjection(x, false, true)); } ret = new ProjectionList(list); } } return ret; }
private Inclusion getFieldInclusion(Path field, FieldProjection p, Path context) { Path projectionField = new Path(context, toMask(p.getField())); LOGGER.debug("Checking if field projection on {} projects {}", projectionField, field); Inclusion inc = isFieldIncluded(field, projectionField, p.isInclude(), p.isRecursive()); LOGGER.debug("Field projection on {} projects {}: {}", projectionField, field, inc); return inc; }
/** * Returns a projection containing the requested projection, all identity * fields, and the objectType field */ private Projection getProjectionFields(Projection requestedProjection, EntityMetadata md) { Field[] identityFields = md.getEntitySchema().getIdentityFields(); List<Projection> projectFields = new ArrayList<>(identityFields == null ? 1 : identityFields.length + 1); if (requestedProjection instanceof ProjectionList) { projectFields.addAll(((ProjectionList) requestedProjection).getItems()); } else if (requestedProjection != null) { projectFields.add(requestedProjection); } if (identityFields != null) { for (Field x : identityFields) { projectFields.add(new FieldProjection(x.getFullPath(), true, false)); } } projectFields.add(new FieldProjection(DocTranslator.OBJECT_TYPE, true, false)); return new ProjectionList(projectFields); }
/** * Returns a projection containing the requested projection, all identity * fields, and the objectType field */ private Projection getProjectionFields(Projection requestedProjection, EntityMetadata md) { Field[] identityFields = md.getEntitySchema().getIdentityFields(); List<Projection> projectFields = new ArrayList<>(identityFields == null ? 1 : identityFields.length + 1); if (requestedProjection instanceof ProjectionList) { projectFields.addAll(((ProjectionList) requestedProjection).getItems()); } else if (requestedProjection != null) { projectFields.add(requestedProjection); } if (identityFields != null) { for (Field x : identityFields) { projectFields.add(new FieldProjection(x.getFullPath(), true, false)); } } projectFields.add(new FieldProjection(Translator.OBJECT_TYPE, true, false)); return new ProjectionList(projectFields); }
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; }
return new FieldProjection(path, include, x == null ? false : x.asBoolean());
return new FieldProjection(path, include, x == null ? false : x.asBoolean());
pl.add(new FieldProjection(field, true, false));
pl.add(new FieldProjection(field, true, false));