Skip to content

Commit

Permalink
Cache folder configuration state instead of repeatly re-evaluating it
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Sep 21, 2021
1 parent 28a18b6 commit 6da4337
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.kitodo.config.ConfigCore;
import org.kitodo.data.database.beans.DataEditorSetting;
import org.kitodo.data.database.beans.Process;
import org.kitodo.data.database.beans.Project;
import org.kitodo.data.database.beans.User;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.exceptions.InvalidImagesException;
Expand Down Expand Up @@ -184,6 +185,8 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable {

private List<PhysicalDivision> unsavedUploadedMedia = new ArrayList<>();

private boolean folderConfigurationComplete = false;

/**
* Public constructor.
*/
Expand Down Expand Up @@ -232,17 +235,8 @@ public String open(String processID, String referringView) {
this.process = ServiceManager.getProcessService().getById(Integer.parseInt(processID));
this.currentChildren.addAll(process.getChildren());
this.user = ServiceManager.getUserService().getCurrentUser();

if (templateTaskId > 0) {
dataEditorSetting = ServiceManager.getDataEditorSettingService().loadDataEditorSetting(user.getId(), templateTaskId);
if (Objects.isNull(dataEditorSetting)) {
dataEditorSetting = new DataEditorSetting();
dataEditorSetting.setUserId(user.getId());
dataEditorSetting.setTaskId(templateTaskId);
}
} else {
dataEditorSetting = null;
}
this.checkProjectFolderConfiguration();
this.loadDataEditorSettings();

User blockedUser = MetadataLock.getLockUser(process.getId());
if (Objects.nonNull(blockedUser) && !blockedUser.equals(this.user)) {
Expand All @@ -269,6 +263,34 @@ public String open(String processID, String referringView) {
return "/pages/metadataEditor?faces-redirect=true";
}

private void checkProjectFolderConfiguration() {
if (Objects.nonNull(this.process)) {
Project project = this.process.getProject();
if (Objects.nonNull(project)) {
this.folderConfigurationComplete = Objects.nonNull(project.getGeneratorSource())
&& Objects.nonNull(project.getMediaView()) && Objects.nonNull(project.getPreview());
} else {
this.folderConfigurationComplete = false;
}
} else {
this.folderConfigurationComplete = false;
}
}

private void loadDataEditorSettings() {
if (templateTaskId > 0) {
dataEditorSetting = ServiceManager.getDataEditorSettingService().loadDataEditorSetting(user.getId(),
templateTaskId);
if (Objects.isNull(dataEditorSetting)) {
dataEditorSetting = new DataEditorSetting();
dataEditorSetting.setUserId(user.getId());
dataEditorSetting.setTaskId(templateTaskId);
}
} else {
dataEditorSetting = null;
}
}

/**
* Opens the METS file.
*
Expand Down Expand Up @@ -890,4 +912,13 @@ public void saveDataEditorSetting() {
public UploadFileDialog getUploadFileDialog() {
return uploadFileDialog;
}

/**
* Get folderConfigurationComplete.
*
* @return value of folderConfigurationComplete
*/
public boolean isFolderConfigurationComplete() {
return folderConfigurationComplete;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -443,18 +443,4 @@ public void refresh() throws NoSuchMetadataFieldException {
uploadFileUri = null;
}
}

/**
* Check and return whether folder configuration of current process' project is
* complete, e.g. allows upload and conversion of media files. This means folders for thumbnails,
* detail views and generator source have to be configured in the project configuration.
*
* @return whether project folder configuration is complete or not
*/
public boolean isFolderConfigurationComplete() {
return Objects.nonNull(dataEditor.getProcess().getProject().getGeneratorSource())
&& Objects.nonNull(dataEditor.getProcess().getProject().getMediaView())
&& Objects.nonNull(dataEditor.getProcess().getProject().getPreview());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
imagePreviewForm:mediaContextMenu"/>
<p:menuitem value="#{msgs.uploadMedia}"
action="#{DataEditorForm.uploadFileDialog.prepare}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.uploadFileDialog.isFolderConfigurationComplete()}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.isFolderConfigurationComplete()}"
icon="fa fa-download fa-sm"
styleClass="plain"
update = "uploadFileDialog"
Expand Down Expand Up @@ -418,7 +418,7 @@
update="dialogEditDocStrucTypeDialog"/>
<p:menuitem value="#{msgs.uploadMedia}"
action="#{DataEditorForm.uploadFileDialog.prepare}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.uploadFileDialog.isFolderConfigurationComplete()}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.isFolderConfigurationComplete()}"
icon="fa fa-download fa-sm"
styleClass="plain"
update = "uploadFileDialog"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@
imagePreviewForm:mediaContextMenu"/>
<p:menuitem value="#{msgs.uploadMedia}"
action="#{DataEditorForm.uploadFileDialog.prepare}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.uploadFileDialog.isFolderConfigurationComplete()}"
rendered="#{SecurityAccessController.hasAuthorityToUploadMedia() and DataEditorForm.isFolderConfigurationComplete()}"
icon="fa fa-download fa-sm"
styleClass="plain"
update = "uploadFileDialog"
Expand Down

0 comments on commit 6da4337

Please sign in to comment.