public EntityDictionary getDictionary() { return requestScope.getDictionary(); } }
Preconditions.checkNotNull(requestScope); DataStoreTransaction tx = requestScope.getTransaction(); EntityDictionary dictionary = requestScope.getDictionary(); Object obj = requestScope.getObjectById(dictionary.getJsonAliasFor(loadClass), id); if (obj == null) { PersistentResource<T> resource = new PersistentResource(obj, null, requestScope.getUUIDFor(obj), requestScope); if (!requestScope.getNewResources().contains(resource)) { resource.checkFieldAwarePermissions(ReadPermission.class);
/** * Mark this object as dirty. */ private void markDirty() { requestScope.getDirtyResources().add(this); }
/** * Construct a new resource from the ID provided. * * @param obj the obj * @param parent the parent * @param id the id * @param scope the request scope */ public PersistentResource(@NonNull T obj, PersistentResource parent, String id, @NonNull RequestScope scope) { this.obj = obj; this.uuid = Optional.ofNullable(id); this.lineage = parent != null ? new ResourceLineage(parent.lineage, parent) : new ResourceLineage(); this.dictionary = scope.getDictionary(); this.type = dictionary.getJsonAliasFor(obj.getClass()); this.transaction = scope.getTransaction(); this.requestScope = scope; dictionary.initializeEntity(obj); }
T obj = requestScope.getTransaction().createNewObject(entityClass); requestScope.getNewPersistentResources().add(newResource); checkPermission(CreatePermission.class, newResource); requestScope.publishLifecycleEvent(newResource, CRUDEvent.CRUDAction.CREATE); requestScope.setUUIDForObject(type, id, newResource.getObject()); requestScope.getDictionary().getRelationships(entityClass).stream() .filter(relationName -> newResource.getRelationshipType(relationName).isToMany() && newResource.getValueUnchecked(relationName) == null)
private PersistentResource createObject(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { JsonApiDocument doc = requestScope.getJsonApiDocument(); JsonApiMapper mapper = requestScope.getMapper(); Class<?> newObjectClass = requestScope.getDictionary().getEntityClass(resource.getType());
RequestScope requestScope) { EntityDictionary dictionary = requestScope.getDictionary(); FilterExpression filterExpression; DataStoreTransaction tx = requestScope.getTransaction(); newResources = requestScope.getNewPersistentResources().stream() .filter(resource -> typeAlias.equals(resource.getType()) && ids.contains(resource.getUUID().orElse("")))
Supplier<Expression> expressionSupplier = () -> { if (SharePermission.class == annotationClass) { if (requestScope.getDictionary().isShareable(resource.getResourceClass())) { return expressionBuilder.buildAnyFieldExpressions(resource, ReadPermission.class, changeSpec); } else { if (requestScope.getNewPersistentResources().contains(resource)) { return executeUserChecksDeferInline(annotationClass, expression);
@Override public void handle(StateContext state, SubCollectionReadCollectionContext ctx) { String subCollection = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass; String entityName; if (type.isToOne()) { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); collection = resource.getRelationCheckedFiltered(subCollection, filterExpression, Optional.empty(), Optional.empty());
@Override public PersistentResource<T> next() { T obj = iterator.next(); return new PersistentResource<>(obj, parent, requestScope.getUUIDFor(obj), requestScope); } };
if (requestScope.isMutatingMultipleEntities()) { val = transaction.getRelation(transaction, obj, relationName, Optional.empty(), sorting, Optional.empty(), requestScope); } else if (type.isToOne()) { resources = new SingleElementSet( new PersistentResource(val, this, requestScope.getUUIDFor(val), requestScope)); } else { resources.add(new PersistentResource(val, this, requestScope.getUUIDFor(val), requestScope));
/** * Handle DELETE. * * @param path the path * @param jsonApiDocument the json api document * @param opaqueUser the opaque user * @return Elide response object */ public ElideResponse delete(String path, String jsonApiDocument, Object opaqueUser) { return handleRequest(false, opaqueUser, dataStore::beginTransaction, (tx, user) -> { JsonApiDocument jsonApiDoc = StringUtils.isEmpty(jsonApiDocument) ? new JsonApiDocument() : mapper.readJsonApiDocument(jsonApiDocument); RequestScope requestScope = new RequestScope(path, jsonApiDoc, tx, user, null, elideSettings, false); BaseVisitor visitor = new DeleteVisitor(requestScope); return visit(path, requestScope, visitor); }); }
requestScope.publishLifecycleEvent(this, CRUDEvent.CRUDAction.DELETE); requestScope.getDeletedResources().add(this);
/** * Audit an action on an entity. * * @param action the action * @param changeSpec the change that occurred */ protected void auditClass(Audit.Action action, ChangeSpec changeSpec) { Audit[] annotations = getResourceClass().getAnnotationsByType(Audit.class); if (annotations == null) { return; } for (Audit annotation : annotations) { for (Audit.Action auditAction : annotation.action()) { if (auditAction == action) { // compare object reference LogMessage message = new LogMessage(annotation, this, Optional.ofNullable(changeSpec)); getRequestScope().getAuditLogger().log(message); } } } }
T obj = requestScope.getTransaction().createNewObject(entityClass); requestScope.getNewPersistentResources().add(newResource); checkPermission(CreatePermission.class, newResource); requestScope.publishLifecycleEvent(newResource, CRUDEvent.CRUDAction.CREATE); requestScope.setUUIDForObject(type, id, newResource.getObject()); requestScope.getDictionary().getRelationships(entityClass).stream() .filter(relationName -> newResource.getRelationshipType(relationName).isToMany() && newResource.getValueUnchecked(relationName) == null)
private PersistentResource createObject(RequestScope requestScope) throws ForbiddenAccessException, InvalidObjectIdentifierException { JsonApiDocument doc = requestScope.getJsonApiDocument(); JsonApiMapper mapper = requestScope.getMapper(); Class<?> newObjectClass = requestScope.getDictionary().getEntityClass(resource.getType());
RequestScope requestScope) { EntityDictionary dictionary = requestScope.getDictionary(); FilterExpression filterExpression; DataStoreTransaction tx = requestScope.getTransaction(); newResources = requestScope.getNewPersistentResources().stream() .filter(resource -> typeAlias.equals(resource.getType()) && ids.contains(resource.getUUID().orElse("")))
/** * Construct a new resource from the ID provided. * * @param obj the obj * @param parent the parent * @param id the id * @param scope the request scope */ public PersistentResource(@NonNull T obj, PersistentResource parent, String id, @NonNull RequestScope scope) { this.obj = obj; this.uuid = Optional.ofNullable(id); this.lineage = parent != null ? new ResourceLineage(parent.lineage, parent) : new ResourceLineage(); this.dictionary = scope.getDictionary(); this.type = dictionary.getJsonAliasFor(obj.getClass()); this.transaction = scope.getTransaction(); this.requestScope = scope; dictionary.initializeEntity(obj); }
Supplier<Expression> expressionSupplier = () -> { if (SharePermission.class == annotationClass) { if (requestScope.getDictionary().isShareable(resource.getResourceClass())) { return expressionBuilder.buildAnyFieldExpressions(resource, ReadPermission.class, changeSpec); } else { if (requestScope.getNewPersistentResources().contains(resource)) { return executeUserChecksDeferInline(annotationClass, expression);
@Override public void handle(StateContext state, SubCollectionReadCollectionContext ctx) { String subCollection = ctx.term().getText(); EntityDictionary dictionary = state.getRequestScope().getDictionary(); Class<?> entityClass; String entityName; if (type.isToOne()) { Optional<FilterExpression> filterExpression = state.getRequestScope().getExpressionForRelation(resource, subCollection); collection = resource.getRelationCheckedFiltered(subCollection, filterExpression, Optional.empty(), Optional.empty());