@SuppressWarnings("unchecked") private List<EntityBaseBean> allowedMany( Step step, Map<Field, Method> getters, GateKeeper gateKeeper, String userId, EntityManager manager) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IcatException { Field field = step.getRelationship().getField(); List<EntityBaseBean> beans = (List<EntityBaseBean>) getters.get(field).invoke(this); if (step.isAllowed()) { return beans; } else { return gateKeeper.getReadable(userId, beans, manager); } }
/** * Clone a pruned copy of tree * * @param one true if INCLUDE 1 specified * @param hereVarNum current idVarNum. If steps is null this value is irrelevant. * @param steps list of steps to consider. This may be null. Steps starting with hereVarNum will * be followed. Steps hold the starting idVarNum, the field to navigate and the destination * idVarNum. * @param manager * @param userId * @return * @throws IcatException */ public EntityBaseBean pruned( boolean one, int hereVarNum, List<Step> steps, GateKeeper gateKeeper, String userId, EntityManager manager) throws IcatException { Class<? extends EntityBaseBean> klass = this.getClass(); if (logger.isDebugEnabled()) { if (one) { logger.debug("Pruning " + klass.getSimpleName() + " INCLUDE 1"); } else if (steps != null) { logger.debug("Pruning " + klass.getSimpleName() + " INCLUDE from " + hereVarNum); } else { logger.debug("Pruning " + klass.getSimpleName()); } } try { Constructor<? extends EntityBaseBean> con = eiHandler.getConstructor(klass); EntityBaseBean clone = con.newInstance(); clone.id = this.id; clone.createTime = this.createTime; clone.createId = this.createId; clone.modTime = this.modTime; clone.modId = this.modId; Set<Field> atts = eiHandler.getAttributes(klass); Map<Field, Method> getters = eiHandler.getGetters(klass); Map<Field, Method> setters = eiHandler.getSettersForUpdate(klass); for (Field att : atts) { Object value = getters.get(att).invoke(this); if (value != null) { setters.get(att).invoke(clone, new Object[] {value}); } } if (one) { for (Relationship r : eiHandler.getOnes(klass)) { Field att = r.getField(); EntityBaseBean value = allowedOne(r, getters.get(att), gateKeeper, userId, manager); if (value != null) { value = value.pruned(false, 0, null, gateKeeper, userId, manager); setters.get(att).invoke(clone, new Object[] {value}); } } } else if (steps != null) { for (Step step : steps) { if (step.getHereVarNum() == hereVarNum) { Relationship r = step.getRelationship(); Field field = r.getField(); if (r.isCollection()) { List<EntityBaseBean> values = allowedMany(step, getters, gateKeeper, userId, manager); @SuppressWarnings("unchecked") List<EntityBaseBean> cloneList = (List<EntityBaseBean>) getters.get(field).invoke(clone); for (EntityBaseBean value : values) { value = value.pruned(false, step.getThereVarNum(), steps, gateKeeper, userId, manager); cloneList.add(value); } } else { EntityBaseBean value = allowedOne(r, getters.get(field), gateKeeper, userId, manager); if (value != null) { value = value.pruned(false, step.getThereVarNum(), steps, gateKeeper, userId, manager); setters.get(field).invoke(clone, new Object[] {value}); } } } } } return clone; } catch (Exception e) { reportUnexpected(e); throw new IcatException(IcatException.IcatExceptionType.INTERNAL, "" + e); } }