Search in sources :

Example 1 with FancyProject

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);
}
Also used : Project(io.crnk.core.mock.models.Project) FancyProject(io.crnk.core.mock.models.FancyProject) ResourceField(io.crnk.core.engine.information.resource.ResourceField) Task(io.crnk.core.mock.models.Task) ResourceInformation(io.crnk.core.engine.information.resource.ResourceInformation) ResourceRepositoryAdapter(io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter) QueryAdapter(io.crnk.core.engine.query.QueryAdapter) FancyProject(io.crnk.core.mock.models.FancyProject) QuerySpecAdapter(io.crnk.core.queryspec.internal.QuerySpecAdapter) QuerySpec(io.crnk.core.queryspec.QuerySpec) RelationshipRepositoryAdapter(io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter) Before(org.junit.Before)

Example 2 with FancyProject

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;
}
Also used : FancyProject(io.crnk.core.mock.models.FancyProject) Project(io.crnk.core.mock.models.Project) Task(io.crnk.core.mock.models.Task) FancyProject(io.crnk.core.mock.models.FancyProject) LinkedList(java.util.LinkedList)

Example 3 with FancyProject

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;
}
Also used : FancyProject(io.crnk.core.mock.models.FancyProject) Project(io.crnk.core.mock.models.Project) Relation(io.crnk.core.mock.repository.util.Relation) Task(io.crnk.core.mock.models.Task) FancyProject(io.crnk.core.mock.models.FancyProject)

Aggregations

FancyProject (io.crnk.core.mock.models.FancyProject)3 Project (io.crnk.core.mock.models.Project)3 Task (io.crnk.core.mock.models.Task)3 ResourceField (io.crnk.core.engine.information.resource.ResourceField)1 ResourceInformation (io.crnk.core.engine.information.resource.ResourceInformation)1 RelationshipRepositoryAdapter (io.crnk.core.engine.internal.repository.RelationshipRepositoryAdapter)1 ResourceRepositoryAdapter (io.crnk.core.engine.internal.repository.ResourceRepositoryAdapter)1 QueryAdapter (io.crnk.core.engine.query.QueryAdapter)1 Relation (io.crnk.core.mock.repository.util.Relation)1 QuerySpec (io.crnk.core.queryspec.QuerySpec)1 QuerySpecAdapter (io.crnk.core.queryspec.internal.QuerySpecAdapter)1 LinkedList (java.util.LinkedList)1 Before (org.junit.Before)1