Search in sources :

Example 6 with RelationshipRepositoryV2

use of io.crnk.core.repository.RelationshipRepositoryV2 in project crnk-framework by crnk-project.

the class RelationshipRepositoryAdapter method removeRelations.

@SuppressWarnings("rawtypes")
public JsonApiResponse removeRelations(T source, Iterable<J> targetIds, ResourceField field, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            Object source = request.getEntity();
            Iterable<?> targetIds = request.getIds();
            ResourceField field = request.getRelationshipField();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            if (isAnnotated) {
                ((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
            } else if (relationshipRepository instanceof RelationshipRepositoryV2) {
                ((RelationshipRepositoryV2) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
            } else {
                ((RelationshipRepository) relationshipRepository).removeRelations(source, targetIds, field.getUnderlyingName());
            }
            return new JsonApiResponse();
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.DELETE, source, queryAdapter, targetIds, field);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2) BulkRelationshipRepositoryV2(io.crnk.core.repository.BulkRelationshipRepositoryV2)

Example 7 with RelationshipRepositoryV2

use of io.crnk.core.repository.RelationshipRepositoryV2 in project crnk-framework by crnk-project.

the class RelationshipRepositoryAdapter method findOneTarget.

@SuppressWarnings("rawtypes")
public JsonApiResponse findOneTarget(I sourceId, ResourceField field, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            Serializable sourceId = request.getId();
            ResourceField field = request.getRelationshipField();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Object resource;
            if (isAnnotated) {
                resource = ((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).findOneTarget(sourceId, field.getUnderlyingName(), queryAdapter);
            } else if (relationshipRepository instanceof RelationshipRepositoryV2) {
                RelationshipRepositoryV2 querySpecRepository = (RelationshipRepositoryV2) relationshipRepository;
                ResourceInformation targetResourceInformation = moduleRegistry.getResourceRegistry().getEntry(field.getOppositeResourceType()).getResourceInformation();
                resource = querySpecRepository.findOneTarget(sourceId, field.getUnderlyingName(), request.getQuerySpec(targetResourceInformation));
            } else {
                resource = ((RelationshipRepository) relationshipRepository).findOneTarget(sourceId, field.getUnderlyingName(), request.getQueryParams());
            }
            return getResponse(relationshipRepository, resource, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindTarget(moduleRegistry, queryAdapter, Arrays.asList(sourceId), field);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Serializable(java.io.Serializable) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) RelationshipRepository(io.crnk.legacy.repository.RelationshipRepository) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2) BulkRelationshipRepositoryV2(io.crnk.core.repository.BulkRelationshipRepositoryV2)

Example 8 with RelationshipRepositoryV2

use of io.crnk.core.repository.RelationshipRepositoryV2 in project crnk-framework by crnk-project.

the class RelationshipRepositoryAdapter method findManyTargets.

@SuppressWarnings("rawtypes")
public JsonApiResponse findManyTargets(I sourceId, ResourceField field, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            Serializable sourceId = request.getId();
            ResourceField field = request.getRelationshipField();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            Object resources;
            if (isAnnotated) {
                resources = ((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).findManyTargets(sourceId, field.getUnderlyingName(), queryAdapter);
            } else if (relationshipRepository instanceof RelationshipRepositoryV2) {
                RelationshipRepositoryV2 querySpecRepository = (RelationshipRepositoryV2) relationshipRepository;
                ResourceInformation targetResourceInformation = moduleRegistry.getResourceRegistry().getEntry(field.getOppositeResourceType()).getResourceInformation();
                resources = querySpecRepository.findManyTargets(sourceId, field.getUnderlyingName(), request.getQuerySpec(targetResourceInformation));
            } else {
                resources = ((RelationshipRepository) relationshipRepository).findManyTargets(sourceId, field.getUnderlyingName(), request.getQueryParams());
            }
            return getResponse(relationshipRepository, resources, request);
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forFindTarget(moduleRegistry, queryAdapter, Arrays.asList(sourceId), field);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) Serializable(java.io.Serializable) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) RelationshipRepository(io.crnk.legacy.repository.RelationshipRepository) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2) BulkRelationshipRepositoryV2(io.crnk.core.repository.BulkRelationshipRepositoryV2)

Example 9 with RelationshipRepositoryV2

use of io.crnk.core.repository.RelationshipRepositoryV2 in project crnk-framework by crnk-project.

the class RelationshipRepositoryAdapter method setRelations.

@SuppressWarnings("rawtypes")
public JsonApiResponse setRelations(T source, Iterable<J> targetIds, ResourceField field, QueryAdapter queryAdapter) {
    RepositoryRequestFilterChainImpl chain = new RepositoryRequestFilterChainImpl() {

        @Override
        protected JsonApiResponse invoke(RepositoryFilterContext context) {
            RepositoryRequestSpec request = context.getRequest();
            Object source = request.getEntity();
            Iterable<?> targetIds = request.getIds();
            ResourceField field = request.getRelationshipField();
            QueryAdapter queryAdapter = request.getQueryAdapter();
            if (isAnnotated) {
                ((AnnotatedRelationshipRepositoryAdapter) relationshipRepository).setRelations(source, targetIds, field.getUnderlyingName(), queryAdapter);
            } else if (relationshipRepository instanceof RelationshipRepositoryV2) {
                ((RelationshipRepositoryV2) relationshipRepository).setRelations(source, targetIds, field.getUnderlyingName());
            } else {
                ((RelationshipRepository) relationshipRepository).setRelations(source, targetIds, field.getUnderlyingName());
            }
            return new JsonApiResponse();
        }
    };
    RepositoryRequestSpec requestSpec = RepositoryRequestSpecImpl.forRelation(moduleRegistry, HttpMethod.PATCH, source, queryAdapter, targetIds, field);
    return chain.doFilter(newRepositoryFilterContext(requestSpec));
}
Also used : ResourceField(io.crnk.core.engine.information.resource.ResourceField) RepositoryRequestSpec(io.crnk.core.engine.dispatcher.RepositoryRequestSpec) AnnotatedRelationshipRepositoryAdapter(io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) JsonApiResponse(io.crnk.core.repository.response.JsonApiResponse) RepositoryFilterContext(io.crnk.core.engine.filter.RepositoryFilterContext) RelationshipRepositoryV2(io.crnk.core.repository.RelationshipRepositoryV2) BulkRelationshipRepositoryV2(io.crnk.core.repository.BulkRelationshipRepositoryV2)

Aggregations

RelationshipRepositoryV2 (io.crnk.core.repository.RelationshipRepositoryV2)9 RepositoryRequestSpec (io.crnk.core.engine.dispatcher.RepositoryRequestSpec)6 RepositoryFilterContext (io.crnk.core.engine.filter.RepositoryFilterContext)6 ResourceField (io.crnk.core.engine.information.resource.ResourceField)6 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)6 BulkRelationshipRepositoryV2 (io.crnk.core.repository.BulkRelationshipRepositoryV2)6 JsonApiResponse (io.crnk.core.repository.response.JsonApiResponse)4 AnnotatedRelationshipRepositoryAdapter (io.crnk.legacy.internal.AnnotatedRelationshipRepositoryAdapter)4 Serializable (java.io.Serializable)3 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)2 RelationshipRepository (io.crnk.legacy.repository.RelationshipRepository)2 RepositoryMethodAccess (io.crnk.core.engine.information.repository.RepositoryMethodAccess)1 RelationshipRepositoryInformationImpl (io.crnk.core.engine.internal.information.repository.RelationshipRepositoryInformationImpl)1 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 Decorator (io.crnk.core.engine.internal.utils.Decorator)1 RelationshipMatcher (io.crnk.core.repository.RelationshipMatcher)1 ResourceRepositoryV2 (io.crnk.core.repository.ResourceRepositoryV2)1 RepositoryDecoratorFactory (io.crnk.core.repository.decorate.RepositoryDecoratorFactory)1