use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class IncludeLookupSetterInheritanceTest method setup.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Before
public void setup() {
super.setup();
// get repositories
ResourceRepositoryAdapter taskRepository = resourceRegistry.getEntry(Task.class).getResourceRepository(null);
RelationshipRepositoryAdapter relRepositoryTaskToProject = resourceRegistry.getEntry(Task.class).getRelationshipRepository("projects", null);
ResourceRepositoryAdapter projectRepository = resourceRegistry.getEntry(Project.class).getResourceRepository(null);
// setup test data
ResourceInformation taskInfo = resourceRegistry.getEntry(Task.class).getResourceInformation();
ResourceField includedProjectsField = taskInfo.findRelationshipFieldByName("includedProjects");
QueryAdapter emptyProjectQuery = new QuerySpecAdapter(new QuerySpec(Project.class), resourceRegistry);
QueryAdapter emptyTaskQuery = new QuerySpecAdapter(new QuerySpec(Task.class), resourceRegistry);
Project project1 = new Project();
project1.setId(3L);
projectRepository.create(project1, emptyProjectQuery);
FancyProject project2 = new FancyProject();
project2.setId(ProjectRepository.FANCY_PROJECT_ID);
projectRepository.create(project2, emptyProjectQuery);
Task task = new Task();
task.setId(1L);
taskRepository.create(task, emptyTaskQuery);
relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project1.getId()), includedProjectsField, emptyProjectQuery);
relRepositoryTaskToProject.addRelations(task, Collections.singletonList(project2.getId()), includedProjectsField, emptyProjectQuery);
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class TestResourceInformationProvider method build.
@Override
public ResourceInformation build(Class<?> resourceClass) {
ResourceField idField = new ResourceFieldImpl("testId", "id", ResourceFieldType.ID, Integer.class, null, null);
List<ResourceField> fields = Arrays.asList(idField);
TypeParser typeParser = context.getTypeParser();
ResourceInformation info = new ResourceInformation(typeParser, resourceClass, resourceClass.getSimpleName(), null, fields, new OffsetLimitPagingBehavior());
return info;
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method contributeFields.
private void contributeFields(ResourceInformation resourceInformation) {
// TODO make service discovery the primary target to resolve all objects => wrapped it with module
List<ResourceFieldContributor> contributors = new ArrayList<>();
contributors.addAll(moduleRegistry.getServiceDiscovery().getInstancesByType(ResourceFieldContributor.class));
for (Object repo : moduleRegistry.getRepositories()) {
if (repo instanceof ResourceFieldContributor && !contributors.contains(repo)) {
contributors.add((ResourceFieldContributor) repo);
}
}
for (ResourceFieldContributor contributor : contributors) {
List<ResourceField> contributedFields = contributor.getResourceFields(new ResourceFieldContributorContext() {
@Override
public ResourceInformation getResourceInformation() {
return resourceInformation;
}
@Override
public InformationBuilder getInformationBuilder() {
return new DefaultInformationBuilder(moduleRegistry.getTypeParser());
}
});
List<ResourceField> fields = new ArrayList<>();
fields.addAll(resourceInformation.getFields());
fields.addAll(contributedFields);
resourceInformation.setFields(fields);
}
}
use of io.crnk.core.engine.information.resource.ResourceField in project crnk-framework by crnk-project.
the class DefaultRegistryEntryBuilder method build.
@Override
public RegistryEntry build() {
ResourceInformation resourceInformation = buildResource();
ResourceEntry resourceEntry = buildResourceRepository(resourceInformation);
Map<ResourceField, ResponseRelationshipEntry> relationshipEntries = buildRelationships(resourceInformation);
RegistryEntry entry = new RegistryEntry(resourceEntry, relationshipEntries);
entry.initialize(moduleRegistry);
return entry;
}
use of io.crnk.core.engine.information.resource.ResourceField 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));
}
Aggregations