@Nullable protected View findProcessedView(Collection<View> processedViews, Class<? extends Entity> aClass, String viewName) { for (View view : processedViews) { if (aClass.equals(view.getEntityClass()) && viewName.equals(view.getName())) { return view; } } return null; } }
public Collection<MetaClassRepViewProperty> getProperties() { Collection<MetaClassRepViewProperty> result = new ArrayList<>(); MetaClass meta = getMetaClass(view.getEntityClass()); for (ViewProperty property : view.getProperties()) { if (!MetaClassRepresentation.viewPropertyReadPermitted(meta, property)) continue; result.add(new MetaClassRepViewProperty(property)); } return result; } }
protected void dumpHtml(View view, StringBuilder content) { content.append("<br/>").append("\n"); String metaClassName = metadata.getSession().getClass(view.getEntityClass()).getName(); String viewHtmlId = metaClassName + "__" + view.getName(); content.append("+ <a href=\"#").append(viewHtmlId).append("\"><span id=\"").append(viewHtmlId).append("\">") .append(metaClassName).append("/").append(view.getName()) .append("</span></a>"); for (ViewProperty viewProperty : view.getProperties()) { dumpHtml(viewProperty, content, " "); } content.append("<br/>").append("\n"); }
private static boolean viewAccessPermitted(View view) { Class clazz = view.getEntityClass(); MetaClass meta = getMetaClass(clazz); return MetaClassRepresentation.readPermitted(meta); }
protected Set<Class> collectEntityClasses(View view, Set<View> visited) { if (visited.contains(view)) { return Collections.emptySet(); } else { visited.add(view); } HashSet<Class> classes = new HashSet<>(); classes.add(view.getEntityClass()); for (ViewProperty viewProperty : view.getProperties()) { if (viewProperty.getView() != null) { classes.addAll(collectEntityClasses(viewProperty.getView(), visited)); } } return classes; }
protected JsonObject serializeView(View view) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("name", view.getName()); MetaClass metaClass = metadata.getClassNN(view.getEntityClass()); jsonObject.addProperty("entity", metaClass.getName()); jsonObject.add("properties", createJsonArrayOfViewProperties(view)); return jsonObject; }
protected Set<Class> collectEntityClasses(View view, Set<View> visited) { if (visited.contains(view)) { return Collections.emptySet(); } else { visited.add(view); } HashSet<Class> classes = new HashSet<>(); classes.add(view.getEntityClass()); for (ViewProperty viewProperty : view.getProperties()) { if (viewProperty.getView() != null) { classes.addAll(collectEntityClasses(viewProperty.getView(), visited)); } } return classes; }
protected void dump(View view, StringBuilder content) { content.append("\n"); content.append("+ ") .append(metadata.getSession().getClass(view.getEntityClass()).getName()) .append("/") .append(view.getName()); for (ViewProperty viewProperty : view.getProperties()) { dump(viewProperty, content, " "); } content.append("\n"); }
protected Collection<? extends Entity> reloadEntities(Collection<? extends Entity> entities, View view) { List<Object> ids = entities.stream() .map(Entity::getId) .collect(Collectors.toList()); MetaClass metaClass = metadata.getClassNN(view.getEntityClass()); LoadContext.Query query = LoadContext.createQuery("select e from " + metaClass.getName() + " e where e.id in :ids") .setParameter("ids", ids); LoadContext<? extends Entity> ctx = LoadContext.create(view.getEntityClass()) .setQuery(query) .setView(view); return dataManager.loadList(ctx); }
protected void dumpHtml(ViewProperty viewProperty, StringBuilder content, String indent) { content.append("<br/>").append("\n"); content.append(indent); content.append("- ").append(viewProperty.getName()); View innerView = viewProperty.getView(); if (innerView != null) { if (StringUtils.isNotEmpty(innerView.getName())) { String metaClassName = metadata.getSession().getClass(innerView.getEntityClass()).getName(); content.append(" -> <a href=\"#").append(metaClassName).append("__").append(innerView.getName()).append("\">") .append(metaClassName) .append("/") .append(innerView.getName()) .append("</a>"); } else { for (ViewProperty innerProperty : innerView.getProperties()) { dumpHtml(innerProperty, content, " " + indent); } } } }
protected void dump(ViewProperty viewProperty, StringBuilder content, String indent) { content.append("\n"); content.append(indent); content.append("- ").append(viewProperty.getName()); View innerView = viewProperty.getView(); if (innerView != null) { if (StringUtils.isNotEmpty(innerView.getName())) { content.append(" -> ") .append(metadata.getSession().getClass(innerView.getEntityClass()).getName()) .append("/") .append(innerView.getName()); } else { for (ViewProperty innerProperty : innerView.getProperties()) { dump(innerProperty, content, " " + indent); } } } }
protected void replaceOverridden(View root, View replacementView, HashSet<View> checked) { checked.add(root); List<ViewProperty> replacements = null; for (ViewProperty property : root.getProperties()) { View propertyView = property.getView(); if (propertyView != null) { if (Objects.equals(propertyView.getName(), replacementView.getName()) && replacementView.getEntityClass() == propertyView.getEntityClass()) { if (replacements == null) { replacements = new LinkedList<>(); } replacements.add(new ViewProperty(property.getName(), replacementView, property.getFetchMode())); } else if (propertyView.getEntityClass() != null && !checked.contains(propertyView)) { replaceOverridden(propertyView, replacementView, checked); } } } if (replacements != null) { for (ViewProperty replacement : replacements) { root.addProperty(replacement.getName(), replacement.getView(), replacement.getFetchMode()); } } }
protected View getView(MetaClass metaClass) { View localView = viewRepository.getView(metaClass, View.LOCAL); View minimalView = viewRepository.getView(metaClass, View.MINIMAL); View view = new View(localView.getEntityClass(), "entitiesView", false); copyViewProperties(localView, view, metaClass); copyViewProperties(minimalView, view, metaClass); return view; }
protected void initView() { View localView = viewRepository.getView(metaClass, View.LOCAL); View minimalView = viewRepository.getView(metaClass, View.MINIMAL); view = new View(localView.getEntityClass(), "entitiesView", false); copyViewProperties(localView, view); copyViewProperties(minimalView, view); }
/** * Removes restricted attributes from a view. * * @param view source view * @return restricted view */ public View createRestrictedView(View view) { if (!config.getEntityAttributePermissionChecking()) { return view; } Preconditions.checkNotNullArgument(view, "view is null"); View restrictedView = new View(view.getEntityClass(), StringUtils.isEmpty(view.getName()) ? "" : view.getName() + "_restricted", false); // do not include system properties in constructor because they will be copied later if exist copyViewConsideringPermissions(view, restrictedView); return restrictedView; }
private void copyViewConsideringPermissions(View srcView, View dstView) { MetaClass metaClass = metadata.getClassNN(srcView.getEntityClass()); for (ViewProperty property : srcView.getProperties()) { if (security.isEntityAttrReadPermitted(metaClass, property.getName())) { View viewCopy = null; if (property.getView() != null) { viewCopy = new View(property.getView().getEntityClass(), property.getView().getName() + "(restricted)", false); copyViewConsideringPermissions(property.getView(), viewCopy); } dstView.addProperty(property.getName(), viewCopy, property.getFetchMode()); } } }
public static View copy(@Nullable View view) { if (view == null) { return null; } View.ViewParams viewParams = new View.ViewParams() .entityClass(view.getEntityClass()) .name(view.getName()); View copy = new View(viewParams); for (ViewProperty property : view.getProperties()) { copy.addProperty(property.getName(), copy(property.getView()), property.getFetchMode()); } return copy; }
protected View copyView(@Nullable View view) { if (view == null) { return null; } View.ViewParams viewParams = new View.ViewParams() .entityClass(view.getEntityClass()) .name(view.getName()); View copy = new View(viewParams); for (ViewProperty property : view.getProperties()) { copy.addProperty(property.getName(), copyView(property.getView()), property.getFetchMode()); } return copy; }
protected EntitySnapshot createEntitySnapshot(Entity entity, View view, Date snapshotDate, User author) { Preconditions.checkNotNullArgument(entity); Preconditions.checkNotNullArgument(view); Preconditions.checkNotNullArgument(snapshotDate); checkCompositePrimaryKey(entity); Class viewEntityClass = view.getEntityClass(); Class entityClass = entity.getClass(); if (!viewEntityClass.isAssignableFrom(entityClass)) { throw new IllegalStateException("View could not be used with this propertyValue"); } MetaClass metaClass = extendedEntities.getOriginalOrThisMetaClass(metadata.getClass(entity.getClass())); EntitySnapshot snapshot = metadata.create(EntitySnapshot.class); snapshot.setObjectEntityId(referenceToEntitySupport.getReferenceId(entity)); snapshot.setEntityMetaClass(metaClass.getName()); snapshot.setViewXml(viewSerializationAPI.toJson(view, ViewSerializationOption.COMPACT_FORMAT)); snapshot.setSnapshotXml(entitySerializationAPI.toJson(entity)); snapshot.setSnapshotDate(snapshotDate); snapshot.setAuthor(author); return snapshot; } }
public static View intersectViews(View first, View second) { if (first == null) throw new IllegalArgumentException("View is null"); if (second == null) throw new IllegalArgumentException("View is null"); View resultView = new View(first.getEntityClass()); Collection<ViewProperty> firstProps = first.getProperties(); for (ViewProperty firstProperty : firstProps) { if (second.containsProperty(firstProperty.getName())) { View resultPropView = null; ViewProperty secondProperty = second.getProperty(firstProperty.getName()); if ((firstProperty.getView() != null) && (secondProperty.getView() != null)) { resultPropView = intersectViews(firstProperty.getView(), secondProperty.getView()); } resultView.addProperty(firstProperty.getName(), resultPropView); } } return resultView; } }