Source:
private void createProcessHierarchy() throws DataException, ProcessGenerationException, IOException { if (this.processes.size() > 1 && Objects.nonNull(this.titleRecordLinkTab.getTitleRecordProcess()) && Objects.nonNull(this.titleRecordLinkTab.getSelectedInsertionPosition()) && !this.titleRecordLinkTab.getSelectedInsertionPosition().isEmpty()) { this.processes = new LinkedList<>(Collections.singletonList(this.processes.get(0))); } processAncestors(); processChildren(); ServiceManager.getProcessService().save(getMainProcess()); if (!createProcessesLocation(this.processes)) { throw new IOException("Unable to create directories for process hierarchy!"); } if (this.importTab.isImportChildren() && !createProcessesLocation(this.childProcesses)) { throw new IOException("Unable to create directories for child processes!"); } saveProcessHierarchyMetadata(); if (ImportService.ensureNonEmptyTitles(this.processes)) { ServiceManager.getProcessService().save(getMainProcess()); } for (int i = 0; i < childProcesses.size(); i++) { Process childProcess = childProcesses.get(i).getProcess(); MetadataEditor.addLink(getMainProcess(), String.valueOf(i), childProcess.getId()); ServiceManager.getProcessService().save(childProcess); } if (this.processes.size() > 0 && Objects.nonNull(titleRecordLinkTab.getTitleRecordProcess())) { MetadataEditor.addLink(titleRecordLinkTab.getTitleRecordProcess(), titleRecordLinkTab.getSelectedInsertionPosition(), this.processes.get(0).getProcess().getId()); ProcessService.setParentRelations(titleRecordLinkTab.getTitleRecordProcess(), processes.get(0).getProcess()); String summary = Helper.getTranslation("newProcess.catalogueSearch.linkedToExistingProcessSummary"); String detail = Helper.getTranslation("newProcess.catalogueSearch.linkedToExistingProcessDetail", Collections.singletonList(titleRecordLinkTab.getTitleRecordProcess().getTitle())); importTab.showGrowlMessage(summary, detail); } else { for (int i = 0; i < this.processes.size() - 1; i++) { TempProcess tempProcess = this.processes.get(i); MetadataEditor.addLink(this.processes.get(i + 1).getProcess(), "0", tempProcess.getProcess().getId()); } } }

Target:
private void createProcessHierarchy() throws DataException, ProcessGenerationException, IOException { if (this.processes.size() > 1 && Objects.nonNull(this.titleRecordLinkTab.getTitleRecordProcess()) && Objects.nonNull(this.titleRecordLinkTab.getSelectedInsertionPosition()) && !this.titleRecordLinkTab.getSelectedInsertionPosition().isEmpty()) { this.processes = new LinkedList<>(Collections.singletonList(this.processes.get(0))); } processAncestors(); processChildren(); ServiceManager.getProcessService().save(getMainProcess()); if (!createProcessesLocation(this.processes)) { throw new IOException("Unable to create directories for process hierarchy!"); } if (this.importTab.isImportChildren() && !createProcessesLocation(this.childProcesses)) { throw new IOException("Unable to create directories for child processes!"); } saveProcessHierarchyMetadata(); if (ImportService.ensureNonEmptyTitles(this.processes)) { ServiceManager.getProcessService().save(getMainProcess()); } this.saveChildProcessLinks(); if (this.processes.size() > 0 && Objects.nonNull(titleRecordLinkTab.getTitleRecordProcess())) { MetadataEditor.addLink(titleRecordLinkTab.getTitleRecordProcess(), titleRecordLinkTab.getSelectedInsertionPosition(), this.processes.get(0).getProcess().getId()); ProcessService.setParentRelations(titleRecordLinkTab.getTitleRecordProcess(), processes.get(0).getProcess()); String summary = Helper.getTranslation("newProcess.catalogueSearch.linkedToExistingProcessSummary"); String detail = Helper.getTranslation("newProcess.catalogueSearch.linkedToExistingProcessDetail", Collections.singletonList(titleRecordLinkTab.getTitleRecordProcess().getTitle())); importTab.showGrowlMessage(summary, detail); } else { for (int i = 0; i < this.processes.size() - 1; i++) { TempProcess tempProcess = this.processes.get(i); MetadataEditor.addLink(this.processes.get(i + 1).getProcess(), "0", tempProcess.getProcess().getId()); } } ServiceManager.getProcessService().save(getMainProcess()); }