Skip to content

Commit

Permalink
Show multiple potential parent processes in titleRecordLinkTab
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Mar 5, 2024
1 parent e360c2c commit a3b3b50
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -311,26 +312,27 @@ public void searchForParentProcesses() {
}
try {
List<ProcessDTO> processes = ServiceManager.getProcessService().findLinkableParentProcesses(searchQuery,
createProcessForm.getProject().getId(), createProcessForm.getTemplate().getRuleset().getId());
createProcessForm.getTemplate().getRuleset().getId());
if (processes.isEmpty()) {
Helper.setMessage("createProcessForm.titleRecordLinkTab.searchButtonClick.noHits");
}
indicationOfMoreHitsVisible = processes.size() > MAXIMUM_NUMBER_OF_HITS;
possibleParentProcesses = ServiceManager.getImportService()
.getPotentialParentProcesses(processes, MAXIMUM_NUMBER_OF_HITS);
} catch (DataException | DAOException e) {
} catch (DataException | DAOException | IOException e) {
Helper.setErrorMessage("createProcessForm.titleRecordLinkTab.searchButtonClick.error", e.getMessage(),
logger, e);
indicationOfMoreHitsVisible = false;
possibleParentProcesses = Collections.emptyList();
}
possibleParentProcesses.sort(Comparator.comparing(SelectItem::getLabel));
for (SelectItem selectItem : possibleParentProcesses) {
if (!selectItem.isDisabled()) {
int processId = Integer.parseInt(selectItem.getValue().toString());
try {
int processId = Integer.parseInt(selectItem.getValue().toString());
setParentAsTitleRecord(ServiceManager.getProcessService().getById(processId));
break;
} catch (DAOException e) {
} catch (DAOException | NumberFormatException e) {
logger.error(e);
}
}
Expand Down Expand Up @@ -447,16 +449,12 @@ public void setTitleRecordProcess(Process titleRecordProcess) {
public void setParentAsTitleRecord(Process parentProcess) {
createProcessForm.setEditActiveTabIndex(CreateProcessForm.TITLE_RECORD_LINK_TAB_INDEX);
try {
ProcessDTO parentProcessDto = ServiceManager.getProcessService().findById(parentProcess.getId());
possibleParentProcesses = ServiceManager.getImportService()
.getPotentialParentProcesses(Collections.singletonList(parentProcessDto), MAXIMUM_NUMBER_OF_HITS);

if (ImportService.userMayLinkToParent(parentProcess.getId())) {
setChosenParentProcess(String.valueOf(parentProcess.getId()));
} else {
setChosenParentProcess(null);
}
} catch (DAOException | DataException e) {
} catch (DAOException e) {
Helper.setErrorMessage(e);
}
chooseParentProcess();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1428,19 +1428,23 @@ public Collection<RecordIdentifierMissingDetail> getDetailsOfRecordIdentifierMis
* @param maxNumber limit
* @return list of "SelectItem" objects corresponding to given "ProcessDTO" objects.
* @throws DAOException when checking whether user can link to given "ProcessDTO"s fails
* @throws IOException when opening ruleset file fails
*/
public ArrayList<SelectItem> getPotentialParentProcesses(List<ProcessDTO> parentCandidates, int maxNumber)
throws DAOException {
throws DAOException, IOException {
ArrayList<SelectItem> possibleParentProcesses = new ArrayList<>();
for (ProcessDTO process : parentCandidates.subList(0, Math.min(parentCandidates.size(), maxNumber))) {
SelectItem selectItem = new SelectItem(process.getId().toString(), process.getTitle());
selectItem.setDisabled(!userMayLinkToParent(process.getId()));
if (!processInAssignedProject(process.getId())) {
String problem = Helper.getTranslation("projectNotAssignedToCurrentUser", process.getProject().getTitle());
selectItem.setDescription(problem);
selectItem.setLabel(selectItem.getLabel() + " (" + problem + ")");
if (ProcessService.canCreateChildProcess(process) || ProcessService.canCreateProcessWithCalendar(process)) {
SelectItem selectItem = new SelectItem(process.getId().toString(), process.getTitle());
selectItem.setDisabled(!userMayLinkToParent(process.getId()));
if (!processInAssignedProject(process.getId())) {
String problem = Helper.getTranslation("projectNotAssignedToCurrentUser", process.getProject()
.getTitle());
selectItem.setDescription(problem);
selectItem.setLabel(selectItem.getLabel() + " (" + problem + ")");
}
possibleParentProcesses.add(selectItem);
}
possibleParentProcesses.add(selectItem);
}
return possibleParentProcesses;
}
Expand All @@ -1452,7 +1456,7 @@ public ArrayList<SelectItem> getPotentialParentProcesses(List<ProcessDTO> parent
* @return whether the process with the provided ID belongs to a project assigned to the current user or not
* @throws DAOException when retrieving the process with the ID "processId" from the database fails
*/
public static Boolean processInAssignedProject(int processId) throws DAOException {
public static boolean processInAssignedProject(int processId) throws DAOException {
Process process = ServiceManager.getProcessService().getById(processId);
if (Objects.nonNull(process)) {
return ServiceManager.getUserService().getCurrentUser().getProjects().contains(process.getProject());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -815,15 +815,13 @@ public List<ProcessDTO> findLinkableChildProcesses(String searchInput, int rules
*
* @param searchInput
* user input
* @param projectId
* the id of the allowed project
* @param rulesetId
* the id of the allowed ruleset
* @return found processes
* @throws DataException
* if the search engine fails
*/
public List<ProcessDTO> findLinkableParentProcesses(String searchInput, int projectId, int rulesetId)
public List<ProcessDTO> findLinkableParentProcesses(String searchInput, int rulesetId)
throws DataException {

BoolQueryBuilder processQuery = new BoolQueryBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public void shouldNotFindByTokenizedPropertyTitleAndWrongValue() throws DataExce
@Test
public void shouldFindLinkableParentProcesses() throws DataException {
assertEquals("Processes were not found in index!", 1,
processService.findLinkableParentProcesses("HierarchyParent", 1, 1).size());
processService.findLinkableParentProcesses("HierarchyParent", 1).size());
}

@Ignore("for second process is attached task which is processed by blocked user")
Expand Down

0 comments on commit a3b3b50

Please sign in to comment.