use of io.crnk.core.mock.models.FancyProject 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.mock.models.FancyProject in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findManyTargets.
@Override
public Iterable<Project> findManyTargets(Long sourceId, String fieldName, QueryParams queryParams) {
List<Project> projects = new LinkedList<>();
for (Relation<Task> relation : getRepo().keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
if (relation.getTargetId().equals(ProjectRepository.FANCY_PROJECT_ID)) {
project = new FancyProject();
}
project.setId((Long) relation.getTargetId());
projects.add(project);
}
}
return projects;
}
use of io.crnk.core.mock.models.FancyProject in project crnk-framework by crnk-project.
the class TaskToProjectRepository method findOneTarget.
@Override
public Project findOneTarget(Long sourceId, String fieldName, QueryParams queryParams) {
Map<Relation<Task>, Integer> repo = getRepo();
for (Relation<Task> relation : repo.keySet()) {
if (relation.getSource().getId().equals(sourceId) && relation.getFieldName().equals(fieldName)) {
Project project = new Project();
if (relation.getTargetId().equals(ProjectRepository.FANCY_PROJECT_ID)) {
project = new FancyProject();
}
project.setId((Long) relation.getTargetId());
return project;
}
}
return null;
}
Aggregations