Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Kitodo/src/main/java/org/kitodo/production/forms/ProjectForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ public Project getProject() {
}

/**
* Set my project.
* Set my project and check for assigned processes.
*
* @param project
* Project object
Expand All @@ -484,7 +484,17 @@ public void setProject(Project project) {
// has to be called if a page back move was done
cancel();
this.project = project;
hasProcesses = !project.getProcesses().isEmpty();
try {
hasProcesses = ServiceManager.getProjectService().hasProcesses(project.getId());
} catch (DAOException e) {
Helper.setErrorMessage(
ERROR_DATABASE_READING,
new Object[] { ObjectType.PROJECT.getTranslationSingular(), project.getId() },
logger,
e
);
hasProcesses = false; // fallback to safe default
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,20 @@ public String getProjectTitles(List<Project> projects) throws DAOException {
}
}

/**
* Checks whether the given project has any processes assigned to it.
*
* @param projectId
* the ID of the project to check
* @return return true if at least one process belongs to the project,
* false otherwise
*/
public boolean hasProcesses(int projectId) throws DAOException {
return dao.has("FROM Process AS process WHERE process.project.id = :project_id",
Collections.singletonMap("project_id", projectId)
);
}

/**
* Delete project with ID 'projectID'.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,28 @@ public void findByIds() throws Exception {
List<Project> byQuery = ServiceManager.getUserService().getCurrentUser().getProjects();
assertEquals(2, byQuery.size(), "Wrong amount of projects found");
}

@Test
public void shouldReturnFalseWhenProjectHasNoProcesses() throws Exception {
Project project = new Project();
project.setTitle("Empty Project");
Integer id = null;
try {
projectService.save(project);
id = project.getId();
boolean result = projectService.hasProcesses(id);
assertFalse(result, "Project without processes incorrectly reported as having processes!");
} finally {
if (id != null) {
projectService.remove(project);
}
}
}

@Test
public void shouldReturnTrueWhenProjectHasProcesses() throws Exception {
Project project = projectService.getById(1);
boolean result = projectService.hasProcesses(project.getId());
assertTrue(result, "Project with processes incorrectly reported as empty!");
}
}
Loading