/** * Adds two projections and returns a new projection containing both. Any * projection can be null. If the resulting projection is empty, returns * null. */ public static Projection add(Projection p1, Projection p2) { List<Projection> list = new ArrayList<>(); if (p1 instanceof ProjectionList) { list.addAll(((ProjectionList) p1).getItems()); } else if (p1 != null) { list.add(p1); } if (p2 instanceof ProjectionList) { list.addAll(((ProjectionList) p2).getItems()); } else if (p2 != null) { list.add(p2); } return list.isEmpty() ? null : new ProjectionList(list); }
public static Projection fromJson(JsonNode node) { if (node instanceof ArrayNode) { return ProjectionList.fromJson((ArrayNode) node); } else { return BasicProjection.fromJson((ObjectNode) node); } }
@Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (Projection x : items) { arr.add(x.toJson()); } return arr; }
/** * 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 ListProjector(ProjectionList l, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); List<Projection> projections = l.getItems(); items = new ArrayList<>(projections.size()); for (Projection x : projections) { items.add(Projector.getInstance(x, ctxPath, ctx)); } }
/** * 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 ListProjector(ProjectionList l, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); List<Projection> projections = l.getItems(); items = new ArrayList<>(projections.size()); for (Projection x : projections) { items.add(Projector.getInstance(x, ctxPath, ctx)); } }
/** * Adds two projections and returns a new projection containing both. Any * projection can be null. If the resulting projection is empty, returns * null. */ public static Projection add(Projection p1, Projection p2) { List<Projection> list = new ArrayList<>(); if (p1 instanceof ProjectionList) { list.addAll(((ProjectionList) p1).getItems()); } else if (p1 != null) { list.add(p1); } if (p2 instanceof ProjectionList) { list.addAll(((ProjectionList) p2).getItems()); } else if (p2 != null) { list.add(p2); } return list.isEmpty() ? null : new ProjectionList(list); }
public static ProjectionList fromJson(ArrayNode node) { ArrayList<Projection> list = new ArrayList<>(node.size()); for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) { list.add(BasicProjection.fromJson((ObjectNode) itr.next())); } return new ProjectionList(list); } }
public ListProjector(ProjectionList l, Path ctxPath, FieldTreeNode ctx) { super(ctxPath, ctx); List<Projection> projections = l.getItems(); items = new ArrayList<>(projections.size()); for (Projection x : projections) { items.add(Projector.getInstance(x, ctxPath, ctx)); } }
public static Projection fromJson(JsonNode node) { if (node instanceof ArrayNode) { return ProjectionList.fromJson((ArrayNode) node); } else { return BasicProjection.fromJson((ObjectNode) node); } }
@Override public JsonNode toJson() { ArrayNode arr = getFactory().arrayNode(); for (Projection x : items) { arr.add(x.toJson()); } return arr; }
/** * 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); }
public static ProjectionList fromJson(ArrayNode node) { ArrayList<Projection> list = new ArrayList<>(node.size()); for (Iterator<JsonNode> itr = node.elements(); itr.hasNext();) { list.add(BasicProjection.fromJson((ObjectNode) itr.next())); } return new ProjectionList(list); } }
private Inclusion getFieldInclusion(Path field, ProjectionList p, Path context) { LOGGER.debug("Checking if a projection list projects {}", field); Inclusion lastResult = Inclusion.undecided; List<Projection> items = p.getItems();
/** * 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); }
/** * 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, ProjectionList p, Path context) { LOGGER.debug("Checking if a projection list projects {}", field); Inclusion lastResult = Inclusion.undecided; List<Projection> items = p.getItems();
/** * 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; }
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;