Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload files #4625

Merged
merged 16 commits into from
Sep 29, 2021
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
--
-- (c) Kitodo. Key to digital objects e. V. <[email protected]>
--
-- This file is part of the Kitodo project.
--
-- It is licensed under GNU General Public License version 3 or later.
--
-- For the full copyright and license information, please read the
-- GPL3-License.txt file that was distributed with this source code.
--

-- Insert authorities for upload and delete media in metadata editor.

INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_globalAssignable');
INSERT IGNORE INTO authority (title) VALUES ('uploadMedia_clientAssignable');

INSERT IGNORE INTO authority (title) VALUES ('deleteMedia_globalAssignable');
INSERT IGNORE INTO authority (title) VALUES ('deleteMedia_clientAssignable');

INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_globalAssignable';
INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'uploadMedia_clientAssignable';

INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'deleteMedia_globalAssignable';
INSERT IGNORE INTO role_x_authority (role_id, authority_id)
SELECT (SELECT id FROM role WHERE title = 'Administration'), id FROM authority WHERE title = 'deleteMedia_clientAssignable';
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,11 @@ public enum ParameterCore implements ParameterInterface {
*/
METS_EDITOR_DISPLAY_FILE_MANIPULATION(new Parameter<UndefinedParameter>("metsEditor.displayFileManipulation")),

/**
* Maximum number of media that can be uploaded at the same time in mets editor.
*/
METS_EDITOR_MAX_UPLOADED_MEDIA(new Parameter<UndefinedParameter>("metsEditor.maxUploadedMedia")),

/**
* Comma-separated list of Strings which may be enclosed in double quotes.
* Separators available for double page pagination modes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,16 @@ public boolean hasAuthorityToUnassignTasks() {
return securityAccessService.hasAuthorityToUnassignTasks();
}


/**
* Check if the current user has the authority to upload media in metadataeditor.
*
* @return true if the current user has the authority to to upload media in metadataeditor
*/
public boolean hasAuthorityToUploadMedia() {
return securityAccessService.hasAuthorityToUploadMedia();
}

/**
* Check if the current user has the authority to edit the role.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.OutputStream;
import java.io.Serializable;
import java.net.URI;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -43,8 +44,10 @@
import org.kitodo.api.dataformat.Workpiece;
import org.kitodo.api.validation.State;
import org.kitodo.api.validation.ValidationResult;
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 @@ -96,6 +99,7 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable {
*/
private final EditPagesDialog editPagesDialog;

private final UploadFileDialog uploadFileDialog ;
/**
* Backing bean for the gallery panel.
*/
Expand Down Expand Up @@ -179,6 +183,10 @@ public class DataEditorForm implements RulesetSetupInterface, Serializable {

private static final String DESKTOP_LINK = "/pages/desktop.jsf";

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

private boolean folderConfigurationComplete = false;

/**
* Public constructor.
*/
Expand All @@ -192,6 +200,7 @@ public DataEditorForm() {
this.addPhysicalDivisionDialog = new AddPhysicalDivisionDialog(this);
this.changeDocStrucTypeDialog = new ChangeDocStrucTypeDialog(this);
this.editPagesDialog = new EditPagesDialog(this);
this.uploadFileDialog = new UploadFileDialog(this);
acquisitionStage = "edit";
}

Expand Down Expand Up @@ -226,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 @@ -253,6 +253,7 @@ public String open(String processID, String referringView) {
return referringView;
}
selectedMedia = new LinkedList<>();
unsavedUploadedMedia = new ArrayList<>();
init();
MetadataLock.setLocked(process.getId(), user);
} catch (IOException | DAOException | InvalidImagesException | NoSuchElementException e) {
Expand All @@ -262,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 @@ -308,6 +337,7 @@ private void init() {
* @return the referring view, to return there
*/
public String close() {
deleteNotSavedUploadedMedia();
metadataPanel.clear();
structurePanel.clear();
workpiece = null;
Expand All @@ -326,6 +356,21 @@ public String close() {
}
}

private void deleteNotSavedUploadedMedia() {
URI uri = Paths.get(ConfigCore.getKitodoDataDirectory(),
ServiceManager.getProcessService().getProcessDataDirectory(this.process).getPath()).toUri();
for (PhysicalDivision mediaUnit : this.unsavedUploadedMedia) {
for (URI fileURI : mediaUnit.getMediaFiles().values()) {
try {
ServiceManager.getFileService().delete(uri.resolve(fileURI));
} catch (IOException e) {
logger.error(e.getMessage());
}
}
}
this.unsavedUploadedMedia.clear();
}

/**
* Validate the structure and metadata.
*
Expand Down Expand Up @@ -377,6 +422,7 @@ private String save(boolean close) {
try (OutputStream out = ServiceManager.getFileService().write(mainFileUri)) {
ServiceManager.getMetsService().save(workpiece, out);
ServiceManager.getProcessService().saveToIndex(process,false);
unsavedUploadedMedia.clear();
if (close) {
return close();
} else {
Expand Down Expand Up @@ -437,6 +483,15 @@ public String getAcquisitionStage() {
return acquisitionStage;
}

/**
* Get unsavedUploadedMedia.
*
* @return value of unsavedUploadedMedia
*/
public List<PhysicalDivision> getUnsavedUploadedMedia() {
return unsavedUploadedMedia;
}

/**
* Returns the backing bean for the add doc struc type dialog. This function
* is used by PrimeFaces to access the elements of the add doc struc type
Expand Down Expand Up @@ -848,4 +903,22 @@ public void saveDataEditorSetting() {
templateTaskId);
}
}

/**
* Get uploadFileDialog.
*
* @return value of uploadFileDialog
*/
public UploadFileDialog getUploadFileDialog() {
return uploadFileDialog;
}

/**
* Get folderConfigurationComplete.
*
* @return value of folderConfigurationComplete
*/
public boolean isFolderConfigurationComplete() {
return folderConfigurationComplete;
}
}
Loading