/** * Special copy constructor for use by PatchRequestScope. * * @param jsonApiDocument the json api document * @param outerRequestScope the outer request scope */ protected RequestScope( String path, JsonApiDocument jsonApiDocument, RequestScope outerRequestScope) { this.jsonApiDocument = jsonApiDocument; this.path = path; this.transaction = outerRequestScope.transaction; this.user = outerRequestScope.user; this.dictionary = outerRequestScope.dictionary; this.mapper = outerRequestScope.mapper; this.auditLogger = outerRequestScope.auditLogger; this.queryParams = Optional.empty(); this.sparseFields = Collections.emptyMap(); this.sorting = Sorting.getDefaultEmptyInstance(); this.pagination = Pagination.getDefaultPagination(); this.objectEntityCache = outerRequestScope.objectEntityCache; this.securityMode = outerRequestScope.securityMode; this.newPersistentResources = outerRequestScope.newPersistentResources; this.commitTriggers = outerRequestScope.commitTriggers; this.permissionExecutor = outerRequestScope.getPermissionExecutor(); this.dirtyResources = outerRequestScope.dirtyResources; this.filterDialect = outerRequestScope.filterDialect; this.expressionsByType = outerRequestScope.expressionsByType; this.useFilterExpressions = outerRequestScope.useFilterExpressions; }
/** * Create a new RequestScope. * * @param path the URL path * @param jsonApiDocument the document for this request * @param transaction the transaction for this request * @param user the user making this request * @param dictionary the entity dictionary * @param mapper converts JsonApiDocuments to raw JSON * @param auditLogger logger for this request * @param queryParams the query parameters * @param securityMode the current security mode * @param permissionExecutorGenerator the user-provided function that will generate a * permissionExecutor */ public RequestScope( String path, JsonApiDocument jsonApiDocument, DataStoreTransaction transaction, User user, EntityDictionary dictionary, JsonApiMapper mapper, AuditLogger auditLogger, MultivaluedMap<String, String> queryParams, SecurityMode securityMode, Function<RequestScope, PermissionExecutor> permissionExecutorGenerator, MultipleFilterDialect filterDialect, boolean useFilterExpressions) { this.path = path; this.jsonApiDocument = jsonApiDocument; this.transaction = transaction; this.user = user; this.dictionary = dictionary; this.mapper = mapper; this.auditLogger = auditLogger; this.securityMode = securityMode; this.filterDialect = filterDialect; this.expressionsByType = new HashMap<>(); this.globalFilterExpression = null; this.objectEntityCache = new ObjectEntityCache(); this.newPersistentResources = new LinkedHashSet<>(); this.dirtyResources = new LinkedHashSet<>(); this.commitTriggers = new LinkedHashSet<>(); this.useFilterExpressions = useFilterExpressions; this.permissionExecutor = (permissionExecutorGenerator == null) ? new ActivePermissionExecutor(this) : permissionExecutorGenerator.apply(this); this.queryParams = (queryParams == null || queryParams.size() == 0) ? Optional.empty() : Optional.of(queryParams); if (this.queryParams.isPresent()) { /* Extract any query param that starts with 'filter' */ MultivaluedMap filterParams = getFilterParams(queryParams); String errorMessage = ""; if (!filterParams.isEmpty()) { /* First check to see if there is a global, cross-type filter */ try { globalFilterExpression = filterDialect.parseGlobalExpression(path, filterParams); } catch (ParseException e) { errorMessage = e.getMessage(); } /* Next check to see if there is are type specific filters */ try { expressionsByType.putAll(filterDialect.parseTypedExpression(path, filterParams)); } catch (ParseException e) { /* If neither dialect parsed, report the last error found */ if (globalFilterExpression == null) { if (errorMessage.isEmpty()) { errorMessage = e.getMessage(); } else if (!errorMessage.equals(e.getMessage())) { /* Combine the two different messages together */ errorMessage = errorMessage + "\n" + e.getMessage(); } throw new InvalidPredicateException(errorMessage); } } } this.sparseFields = parseSparseFields(queryParams); this.sorting = Sorting.parseQueryParams(queryParams); this.pagination = Pagination.parseQueryParams(queryParams); } else { this.sparseFields = Collections.emptyMap(); this.sorting = Sorting.getDefaultEmptyInstance(); this.pagination = Pagination.getDefaultPagination(); } if (transaction instanceof RequestScopedTransaction) { ((RequestScopedTransaction) transaction).setRequestScope(this); } }