Skip to content

Commit

Permalink
Merge pull request #4133 from matthias-ronge/issue-4131
Browse files Browse the repository at this point in the history
Issue 4131
  • Loading branch information
Kathrin-Huber authored Jan 8, 2021
2 parents 754f5d2 + 3c38870 commit b46f88f
Show file tree
Hide file tree
Showing 22 changed files with 99 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,19 @@

package org.kitodo.exceptions;

public class RulesetNotFoundException extends Exception {
import java.io.FileNotFoundException;
import java.util.Arrays;

import org.kitodo.production.helper.Helper;

public class RulesetNotFoundException extends FileNotFoundException {
/**
* Constructor with given exception message.
* Creates a new ruleset not found exception.
*
* @param exceptionMessage
* as String
* @param missingFile
* name of missing ruleset file
*/
public RulesetNotFoundException(String exceptionMessage) {
super(exceptionMessage);
public RulesetNotFoundException(String missingFile) {
super(Helper.getTranslation("rulesetNotFound", Arrays.asList(missingFile)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.RulesetNotFoundException;
import org.kitodo.export.ExportDms;
import org.kitodo.production.dto.ProcessDTO;
import org.kitodo.production.enums.ChartMode;
Expand Down Expand Up @@ -316,7 +315,7 @@ private void exportDMSForProcesses(List<Process> processes) {
public boolean createProcessesWithCalendar(ProcessDTO processDTO) {
try {
return ProcessService.canCreateProcessWithCalendar(processDTO);
} catch (IOException | DAOException | RulesetNotFoundException e) {
} catch (IOException | DAOException e) {
Helper.setErrorMessage(ERROR_READING, new Object[] {ObjectType.PROCESS.getTranslationSingular() }, logger,
e);
}
Expand All @@ -333,7 +332,7 @@ public boolean createProcessesWithCalendar(ProcessDTO processDTO) {
public boolean createProcessAsChildPossible(ProcessDTO processDTO) {
try {
return ProcessService.canCreateChildProcess(processDTO);
} catch (IOException | DAOException | RulesetNotFoundException e) {
} catch (IOException | DAOException e) {
Helper.setErrorMessage(ERROR_READING, new Object[] {ObjectType.PROCESS.getTranslationSingular() }, logger,
e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class CreateProcessForm extends BaseForm implements RulesetSetupInterface
private final SearchTab searchTab = new SearchTab(this);
private final TitleRecordLinkTab titleRecordLinkTab = new TitleRecordLinkTab(this);

private RulesetManagementInterface rulesetManagementInterface;
private RulesetManagementInterface rulesetManagement;
private List<Locale.LanguageRange> priorityList = ServiceManager.getUserService().getCurrentMetadataLanguage();
private String acquisitionStage = "create";
private Project project;
Expand All @@ -83,33 +83,28 @@ public class CreateProcessForm extends BaseForm implements RulesetSetupInterface
/**
* Returns the ruleset management to access the ruleset.
*
* @return the ruleset
* @return the ruleset management
*/
@Override
public RulesetManagementInterface getRuleset() {
return rulesetManagementInterface;
public RulesetManagementInterface getRulesetManagement() {
return rulesetManagement;
}

/**
* Update ruleset and docType.
* @param ruleset as Ruleset
* @throws RulesetNotFoundException thrown if ruleset could not be found
*
* @param ruleset
* as Ruleset
* @throws IOException
* thrown if ruleset could not be read
*/
public void updateRulesetAndDocType(Ruleset ruleset) throws RulesetNotFoundException {
setRulesetManagementInterface(ruleset);
public void updateRulesetAndDocType(Ruleset ruleset) throws IOException {
rulesetManagement = ServiceManager.getRulesetService().openRuleset(ruleset);
processDataTab.setAllDocTypes(getAllRulesetDivisions());
}

private void setRulesetManagementInterface(Ruleset ruleset) throws RulesetNotFoundException {
try {
this.rulesetManagementInterface = ServiceManager.getRulesetService().openRuleset(ruleset);
} catch (IOException e) {
logger.error(e.getLocalizedMessage());
}
}

private List<SelectItem> getAllRulesetDivisions() {
List<SelectItem> allDocTypes = rulesetManagementInterface
List<SelectItem> allDocTypes = rulesetManagement
.getStructuralElements(priorityList).entrySet()
.stream().map(entry -> new SelectItem(entry.getKey(), entry.getValue()))
.collect(Collectors.toList());
Expand Down Expand Up @@ -294,14 +289,14 @@ public String createNewProcess() {
} catch (DataException e) {
Helper.setErrorMessage("errorSaving", new Object[] {ObjectType.PROCESS.getTranslationSingular() },
logger, e);
} catch (IOException | ProcessGenerationException e) {
logger.error(e.getLocalizedMessage());
} catch (RulesetNotFoundException e) {
String rulesetFile = "Process list is empty";
if (!this.processes.isEmpty() && Objects.nonNull(getMainProcess().getRuleset())) {
rulesetFile = getMainProcess().getRuleset().getFile();
}
Helper.setErrorMessage("rulesetNotFound", new Object[] {rulesetFile }, logger, e);
} catch (IOException | ProcessGenerationException e) {
logger.error(e.getLocalizedMessage(), e);
}
return this.stayOnCurrentPage;
}
Expand Down Expand Up @@ -370,7 +365,7 @@ public void prepareProcess(int templateId, int projectId, String referringView,

}
}
} catch (ProcessGenerationException | RulesetNotFoundException | DataException | DAOException | IOException e) {
} catch (ProcessGenerationException | DataException | DAOException | IOException e) {
Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
}
}
Expand All @@ -379,7 +374,7 @@ public void prepareProcess(int templateId, int projectId, String referringView,
* Create process hierarchy.
*/
private void createProcessHierarchy()
throws DataException, ProcessGenerationException, IOException, RulesetNotFoundException {
throws DataException, ProcessGenerationException, IOException {
// discard all processes in hierarchy except the first if parent process in
// title record link tab is selected!
if (this.processes.size() > 1 && Objects.nonNull(this.titleRecordLinkTab.getTitleRecordProcess())
Expand Down Expand Up @@ -460,9 +455,9 @@ private void processChildren() {
// set parent relations between main process and its imported child processes!
try {
ImportService.processProcessChildren(getMainProcess(), this.childProcesses, template,
rulesetManagementInterface, acquisitionStage, priorityList);
rulesetManagement, acquisitionStage, priorityList);
} catch (DataException | InvalidMetadataValueException | NoSuchMetadataFieldException
| ProcessGenerationException | IOException | RulesetNotFoundException e) {
| ProcessGenerationException | IOException e) {
Helper.setErrorMessage("Unable to attach child documents to process: " + e.getMessage());
}
}
Expand All @@ -489,14 +484,15 @@ private void processAncestors() throws ProcessGenerationException {
ImportService.updateTasks(process);
} else if (Objects.nonNull(tempProcess.getMetadataNodes())) {
try {
ImportService.processTempProcess(tempProcess, template, rulesetManagementInterface,
ImportService.processTempProcess(tempProcess, template, rulesetManagement,
acquisitionStage, priorityList);
} catch (InvalidMetadataValueException | NoSuchMetadataFieldException e) {
throw new ProcessGenerationException("Error creating process hierarchy: invalid metadata found!");
} catch (RulesetNotFoundException e) {
throw new ProcessGenerationException(
"Ruleset not found:" + tempProcess.getProcess().getRuleset().getTitle());
} catch (IOException e) {
throw new ProcessGenerationException("Error reading Ruleset: " + tempProcess.getProcess().getRuleset().getTitle());
} catch (RulesetNotFoundException e) {
throw new ProcessGenerationException("Ruleset not found:" + tempProcess.getProcess().getRuleset().getTitle());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public void getRecordHierarchy() {
// import ancestors
LinkedList<TempProcess> processes = ServiceManager.getImportService().importProcessHierarchy(
this.currentRecordId, opac, projectId, templateId, this.importDepth,
this.createProcessForm.getRuleset().getFunctionalKeys(
this.createProcessForm.getRulesetManagement().getFunctionalKeys(
FunctionalMetadata.HIGHERLEVEL_IDENTIFIER));
this.createProcessForm.setProcesses(processes);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void generateProcessTitleAndTiffHeader() {
List<ProcessDetail> processDetails = this.createProcessForm.getProcessMetadataTab().getProcessDetailsElements();
Process process = this.createProcessForm.getMainProcess();
try {
StructuralElementViewInterface docTypeView = createProcessForm.getRuleset().getStructuralElementView(
StructuralElementViewInterface docTypeView = createProcessForm.getRulesetManagement().getStructuralElementView(
docType, createProcessForm.getAcquisitionStage(), createProcessForm.getPriorityList());
String processTitle = docTypeView.getProcessTitle().orElse("");
if (processTitle.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public ProcessMetadataTab(CreateProcessForm createProcessForm) {
* which its Metadata are wanted to be shown
*/
public ProcessFieldedMetadata initializeProcessDetails(IncludedStructuralElement structure) {
return ImportService.initializeProcessDetails(structure, this.createProcessForm.getRuleset(),
return ImportService.initializeProcessDetails(structure, this.createProcessForm.getRulesetManagement(),
this.createProcessForm.getAcquisitionStage(), this.createProcessForm.getPriorityList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.RulesetNotFoundException;
import org.kitodo.production.dto.ProcessDTO;
import org.kitodo.production.helper.Helper;
import org.kitodo.production.metadata.MetadataEditor;
Expand Down Expand Up @@ -126,7 +125,7 @@ public void chooseParentProcess() {
try {
titleRecordProcess = ServiceManager.getProcessService().getById(Integer.valueOf(chosenParentProcess));
createInsertionPositionSelectionTree();
} catch (DAOException | DataException | IOException | RulesetNotFoundException e) {
} catch (DAOException | DataException | IOException e) {
Helper.setErrorMessage("errorLoadingOne",
new Object[] {possibleParentProcesses.parallelStream()
.filter(selectItem -> selectItem.getValue().equals(chosenParentProcess)).findAny()
Expand All @@ -142,7 +141,7 @@ public void chooseParentProcess() {
* @throws IOException
* if the METS file cannot be read
*/
public void createInsertionPositionSelectionTree() throws DAOException, DataException, IOException, RulesetNotFoundException {
public void createInsertionPositionSelectionTree() throws DAOException, DataException, IOException {
if (Objects.isNull(titleRecordProcess)) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void prepareDocStructTypes() {

private void prepareDocStructAddTypeSelectionItemsForChildren() {
docStructAddTypeSelectionItemsForChildren = new ArrayList<>();
StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView(
StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView(
dataEditor.getSelectedStructure().orElseThrow(IllegalStateException::new).getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
for (Entry<String, String> entry : divisionView.getAllowedSubstructuralElements().entrySet()) {
Expand All @@ -448,11 +448,11 @@ private void prepareDocStructAddTypeSelectionItemsForChildren() {
private void prepareDocStructAddTypeSelectionItemsForParent() {
docStructAddTypeSelectionItemsForParent = new ArrayList<>();
if (!parents.isEmpty()) {
StructuralElementViewInterface parentDivisionView = dataEditor.getRuleset().getStructuralElementView(
StructuralElementViewInterface parentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView(
parents.getLast().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
for (Entry<String, String> entry : parentDivisionView.getAllowedSubstructuralElements().entrySet()) {
String newParent = entry.getKey();
StructuralElementViewInterface newParentDivisionView = dataEditor.getRuleset().getStructuralElementView(
StructuralElementViewInterface newParentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView(
newParent, dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
if (newParentDivisionView.getAllowedSubstructuralElements().containsKey(
dataEditor.getSelectedStructure().orElseThrow(IllegalStateException::new).getType())) {
Expand All @@ -465,7 +465,7 @@ private void prepareDocStructAddTypeSelectionItemsForParent() {
private void prepareDocStructAddTypeSelectionItemsForSiblings() {
docStructAddTypeSelectionItemsForSiblings = new ArrayList<>();
if (!parents.isEmpty()) {
StructuralElementViewInterface parentDivisionView = dataEditor.getRuleset().getStructuralElementView(
StructuralElementViewInterface parentDivisionView = dataEditor.getRulesetManagement().getStructuralElementView(
parents.getLast().getType(), dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
for (Entry<String, String> entry : parentDivisionView.getAllowedSubstructuralElements().entrySet()) {
docStructAddTypeSelectionItemsForSiblings.add(new SelectItem(entry.getKey(), entry.getValue()));
Expand Down Expand Up @@ -508,7 +508,7 @@ public void prepareSelectAddableMetadataTypesItems(boolean currentElement, List<
if (Objects.nonNull(selectedMetadataTreeNode)
&& Objects.nonNull(selectedMetadataTreeNode.getData())) {
existingMetadata = Metadata.mapToKey(((ProcessFieldedMetadata) selectedMetadataTreeNode.getData()).getMetadata());
ComplexMetadataViewInterface metadataView = dataEditor.getRuleset().getMetadataView(
ComplexMetadataViewInterface metadataView = dataEditor.getRulesetManagement().getMetadataView(
((ProcessFieldedMetadata) selectedMetadataTreeNode.getData()).getMetadataID(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
addableMetadata = metadataView.getAddableMetadata(existingMetadata, Collections.emptyList());
Expand All @@ -518,7 +518,7 @@ public void prepareSelectAddableMetadataTypesItems(boolean currentElement, List<
addableMetadata = structure.getAddableMetadata(existingMetadata,
Collections.emptyList());
} else {
structure = dataEditor.getRuleset()
structure = dataEditor.getRulesetManagement()
.getStructuralElementView(docStructAddTypeSelectionSelectedItem,
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
addableMetadata = structure.getAddableMetadata(existingMetadata,
Expand Down Expand Up @@ -575,7 +575,7 @@ private Map<Metadata, String> getExistingMetadataRows(List<TreeNode> metadataTre
private StructuralElementViewInterface getStructuralElementView() {
Optional<IncludedStructuralElement> selectedStructure = dataEditor.getSelectedStructure();
if (selectedStructure.isPresent()) {
return dataEditor.getRuleset()
return dataEditor.getRulesetManagement()
.getStructuralElementView(
selectedStructure.get().getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
Expand All @@ -587,7 +587,7 @@ private StructuralElementViewInterface getStructuralElementView() {
if (structureTreeNode.getDataObject() instanceof View) {
View view = (View) structureTreeNode.getDataObject();
if (Objects.nonNull(view.getMediaUnit())) {
return dataEditor.getRuleset().getStructuralElementView(view.getMediaUnit().getType(),
return dataEditor.getRulesetManagement().getStructuralElementView(view.getMediaUnit().getType(),
dataEditor.getAcquisitionStage(), dataEditor.getPriorityList());
}
}
Expand Down Expand Up @@ -770,7 +770,7 @@ public void addLinkButtonClick() {
*/
public String getCurrentStructureLabel() {
if (dataEditor.getSelectedStructure().isPresent()) {
StructuralElementViewInterface divisionView = dataEditor.getRuleset().getStructuralElementView(
StructuralElementViewInterface divisionView = dataEditor.getRulesetManagement().getStructuralElementView(
dataEditor.getSelectedStructure().get().getType(), dataEditor.getAcquisitionStage(),
dataEditor.getPriorityList());
return divisionView.getLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void preparePossibleTypes() {

if (InsertionPosition.FIRST_CHILD_OF_CURRENT_ELEMENT.equals(selectedPosition)
|| InsertionPosition.LAST_CHILD_OF_CURRENT_ELEMENT.equals(selectedPosition)) {
divisionView = dataEditor.getRuleset().getStructuralElementView(
divisionView = dataEditor.getRulesetManagement().getStructuralElementView(
selectedMediaUnit.orElseThrow(IllegalStateException::new).getType(),
dataEditor.getAcquisitionStage(),
dataEditor.getPriorityList()
Expand All @@ -116,7 +116,7 @@ public void preparePossibleTypes() {
selectedMediaUnit.get(),
dataEditor.getWorkpiece().getMediaUnit());
if (!parents.isEmpty()) {
divisionView = dataEditor.getRuleset().getStructuralElementView(
divisionView = dataEditor.getRulesetManagement().getStructuralElementView(
parents.getLast().getType(),
dataEditor.getAcquisitionStage(),
dataEditor.getPriorityList());
Expand Down
Loading

0 comments on commit b46f88f

Please sign in to comment.