/** * 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); }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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 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); }
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));