-
Notifications
You must be signed in to change notification settings - Fork 536
12141 - Storage Driver API #12182
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
base: develop
Are you sure you want to change the base?
12141 - Storage Driver API #12182
Changes from all commits
d4e7f3d
73853c8
e26fdd1
f301c72
39f6a73
555adff
827f878
b40bd12
1f254a0
c4ec41e
7f069ca
3634db6
26cc48b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| ### Breaking Changes | ||
|
|
||
| All the endpoints related to Storage Drivers have been moved out of the Admin API. | ||
|
|
||
| - The endpoints GET, PUT AND DELETE for `/api/admin/dataverse/{alias}/storageDriver` has been moved to `/api/dataverses/{alias}/storageDriver`. | ||
| - The endpoint `/api/admin/dataverse/storageDrivers` has been moved and renamed to `/api/dataverses/{alias}/allowedStorageDrivers`. Regarding the change of the name, this endpoint will in the future only display the storageDrivers that are allowed on the specified collection, as of now, it will display the entire list of available Drivers on the installation. | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -52,29 +52,29 @@ Configure a Dataverse Collection to Store All New Files in a Specific File Store | |||||
|
|
||||||
| To direct new files (uploaded when datasets are created or edited) for all datasets in a given Dataverse collection, the store can be specified via the API as shown below, or by editing the 'General Information' for a Dataverse collection on the Dataverse collection page. Only accessible to superusers. :: | ||||||
|
||||||
| To direct new files (uploaded when datasets are created or edited) for all datasets in a given Dataverse collection, the store can be specified via the API as shown below, or by editing the 'General Information' for a Dataverse collection on the Dataverse collection page. Only accessible to superusers. :: | |
| To direct new files (uploaded when datasets are created or edited) for all datasets in a given Dataverse collection, the store can be specified via the API as shown below, or by editing the 'General Information' for a Dataverse collection on the Dataverse collection page. Requires permission to edit the Dataverse collection (for example, the ``EditDataverse`` permission). :: |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,28 +3,24 @@ | |||||
| import com.google.common.collect.Lists; | ||||||
| import com.google.api.client.util.ArrayMap; | ||||||
| import edu.harvard.iq.dataverse.*; | ||||||
| import static edu.harvard.iq.dataverse.api.AbstractApiBean.error; | ||||||
| import edu.harvard.iq.dataverse.api.auth.AuthRequired; | ||||||
| import edu.harvard.iq.dataverse.api.datadeposit.SwordServiceBean; | ||||||
| import edu.harvard.iq.dataverse.api.dto.*; | ||||||
| import edu.harvard.iq.dataverse.authorization.DataverseRole; | ||||||
|
|
||||||
| import edu.harvard.iq.dataverse.api.imports.ImportException; | ||||||
| import edu.harvard.iq.dataverse.api.imports.ImportServiceBean; | ||||||
| import edu.harvard.iq.dataverse.authorization.Permission; | ||||||
| import edu.harvard.iq.dataverse.authorization.RoleAssignee; | ||||||
| import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup; | ||||||
| import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider; | ||||||
| import edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean; | ||||||
| import edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.ip.IpAddress; | ||||||
| import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser; | ||||||
| import edu.harvard.iq.dataverse.authorization.users.User; | ||||||
| import edu.harvard.iq.dataverse.dataset.DatasetType; | ||||||
| import edu.harvard.iq.dataverse.dataverse.DataverseUtil; | ||||||
| import edu.harvard.iq.dataverse.dataverse.featured.DataverseFeaturedItem; | ||||||
| import edu.harvard.iq.dataverse.dataverse.featured.DataverseFeaturedItemServiceBean; | ||||||
| import edu.harvard.iq.dataverse.engine.command.DataverseRequest; | ||||||
| import edu.harvard.iq.dataverse.engine.command.exception.CommandException; | ||||||
| import edu.harvard.iq.dataverse.engine.command.impl.*; | ||||||
| import edu.harvard.iq.dataverse.pidproviders.PidProvider; | ||||||
| import edu.harvard.iq.dataverse.pidproviders.PidUtil; | ||||||
|
|
@@ -73,6 +69,7 @@ | |||||
| import jakarta.ws.rs.core.Context; | ||||||
| import jakarta.ws.rs.core.HttpHeaders; | ||||||
| import jakarta.ws.rs.core.StreamingOutput; | ||||||
|
|
||||||
| import org.glassfish.jersey.media.multipart.FormDataBodyPart; | ||||||
| import org.glassfish.jersey.media.multipart.FormDataContentDisposition; | ||||||
| import org.glassfish.jersey.media.multipart.FormDataParam; | ||||||
|
|
@@ -89,7 +86,6 @@ | |||||
| public class Dataverses extends AbstractApiBean { | ||||||
|
|
||||||
| private static final Logger logger = Logger.getLogger(Dataverses.class.getCanonicalName()); | ||||||
| private static final SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH-mm-ss"); | ||||||
|
|
||||||
jp-tosca marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| @EJB | ||||||
| ExplicitGroupServiceBean explicitGroupSvc; | ||||||
|
|
@@ -1330,97 +1326,6 @@ public Response listAssignments(@Context ContainerRequestContext crc, @PathParam | |||||
| ), getRequestUser(crc)); | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * This code for setting a dataverse logo via API was started when initially | ||||||
| * investigating https://github.com/IQSS/dataverse/issues/3559 but it isn't | ||||||
| * finished so it's commented out. See also * "No functionality should be | ||||||
| * GUI-only. Make all functionality reachable via the API" at | ||||||
| * https://github.com/IQSS/dataverse/issues/3440 | ||||||
| */ | ||||||
| // File tempDir; | ||||||
| // | ||||||
| // TODO: Code duplicate in ThemeWidgetFragment. Maybe extract, make static and put some place else? | ||||||
| // Important: at least use JvmSettings.DOCROOT_DIRECTORY and not the hardcoded location! | ||||||
| // private void createTempDir(Dataverse editDv) { | ||||||
| // try { | ||||||
| // File tempRoot = java.nio.file.Files.createDirectories(Paths.get("../docroot/logos/temp")).toFile(); | ||||||
| // tempDir = java.nio.file.Files.createTempDirectory(tempRoot.toPath(), editDv.getId().toString()).toFile(); | ||||||
| // } catch (IOException e) { | ||||||
| // throw new RuntimeException("Error creating temp directory", e); // improve error handling | ||||||
| // } | ||||||
| // } | ||||||
| // | ||||||
| // private DataverseTheme initDataverseTheme(Dataverse editDv) { | ||||||
| // DataverseTheme dvt = new DataverseTheme(); | ||||||
| // dvt.setLinkColor(DEFAULT_LINK_COLOR); | ||||||
| // dvt.setLogoBackgroundColor(DEFAULT_LOGO_BACKGROUND_COLOR); | ||||||
| // dvt.setBackgroundColor(DEFAULT_BACKGROUND_COLOR); | ||||||
| // dvt.setTextColor(DEFAULT_TEXT_COLOR); | ||||||
| // dvt.setDataverse(editDv); | ||||||
| // return dvt; | ||||||
| // } | ||||||
| // | ||||||
| // @PUT | ||||||
| // @Path("{identifier}/logo") | ||||||
| // @Consumes(MediaType.MULTIPART_FORM_DATA) | ||||||
| // public Response setDataverseLogo(@PathParam("identifier") String dvIdtf, | ||||||
| // @FormDataParam("file") InputStream fileInputStream, | ||||||
| // @FormDataParam("file") FormDataContentDisposition contentDispositionHeader, | ||||||
| // @QueryParam("key") String apiKey) { | ||||||
| // boolean disabled = true; | ||||||
| // if (disabled) { | ||||||
| // return error(Status.FORBIDDEN, "Setting the dataverse logo via API needs more work."); | ||||||
| // } | ||||||
| // try { | ||||||
| // final DataverseRequest req = createDataverseRequest(findUserOrDie()); | ||||||
| // final Dataverse editDv = findDataverseOrDie(dvIdtf); | ||||||
| // | ||||||
| // logger.finer("entering fileUpload"); | ||||||
| // if (tempDir == null) { | ||||||
| // createTempDir(editDv); | ||||||
| // logger.finer("created tempDir"); | ||||||
| // } | ||||||
| // File uploadedFile; | ||||||
| // try { | ||||||
| // String fileName = contentDispositionHeader.getFileName(); | ||||||
| // | ||||||
| // uploadedFile = new File(tempDir, fileName); | ||||||
| // if (!uploadedFile.exists()) { | ||||||
| // uploadedFile.createNewFile(); | ||||||
| // } | ||||||
| // logger.finer("created file"); | ||||||
| // File file = null; | ||||||
| // file = FileUtil.inputStreamToFile(fileInputStream); | ||||||
| // if (file.length() > systemConfig.getUploadLogoSizeLimit()) { | ||||||
| // return error(Response.Status.BAD_REQUEST, "File is larger than maximum size: " + systemConfig.getUploadLogoSizeLimit() + "."); | ||||||
| // } | ||||||
| // java.nio.file.Files.copy(fileInputStream, uploadedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); | ||||||
| // logger.finer("copied inputstream to file"); | ||||||
| // editDv.setDataverseTheme(initDataverseTheme(editDv)); | ||||||
| // editDv.getDataverseTheme().setLogo(fileName); | ||||||
| // | ||||||
| // } catch (IOException e) { | ||||||
| // logger.finer("caught IOException"); | ||||||
| // logger.throwing("ThemeWidgetFragment", "handleImageFileUpload", e); | ||||||
| // throw new RuntimeException("Error uploading logo file", e); // improve error handling | ||||||
| // } | ||||||
| // // If needed, set the default values for the logo | ||||||
| // if (editDv.getDataverseTheme().getLogoFormat() == null) { | ||||||
| // editDv.getDataverseTheme().setLogoFormat(DataverseTheme.ImageFormat.SQUARE); | ||||||
| // } | ||||||
| // logger.finer("end handelImageFileUpload"); | ||||||
| // UpdateDataverseThemeCommand cmd = new UpdateDataverseThemeCommand(editDv, uploadedFile, req); | ||||||
| // Dataverse saved = execCommand(cmd); | ||||||
| // | ||||||
| // /** | ||||||
| // * @todo delete the temp file: | ||||||
| // * docroot/logos/temp/1148114212463761832421/cc0.png | ||||||
| // */ | ||||||
| // return ok("logo uploaded: " + saved.getDataverseTheme().getLogo()); | ||||||
| // } catch (WrappedResponse ex) { | ||||||
| // return error(Status.BAD_REQUEST, "problem uploading logo: " + ex); | ||||||
| // } | ||||||
| // } | ||||||
| @POST | ||||||
| @AuthRequired | ||||||
| @Path("{identifier}/assignments") | ||||||
|
|
@@ -2140,4 +2045,91 @@ public Response getRoleAssignmentHistory(@Context ContainerRequestContext crc, | |||||
| return getRoleAssignmentHistoryResponse(dataverse, authenticatedUser, false, headers); | ||||||
| }, getRequestUser(crc)); | ||||||
| } | ||||||
|
|
||||||
| @GET | ||||||
| @AuthRequired | ||||||
| @Path("{identifier}/storageDriver") | ||||||
| public Response getStorageDriver(@Context ContainerRequestContext crc, @PathParam("identifier") String id, | ||||||
| @QueryParam("getEffective") Boolean getEffective) throws WrappedResponse { | ||||||
|
|
||||||
jp-tosca marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| Dataverse dataverse = findDataverseOrDie(id); | ||||||
|
|
||||||
| if (dataverse == null) { | ||||||
| return error(Response.Status.NOT_FOUND, "Could not find dataverse based on the identifier supplied: " + id + "."); | ||||||
| } | ||||||
jp-tosca marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
|
||||||
| return response(req -> { | ||||||
| String storageDriver = execCommand(new GetDataverseStorageDriverCommand(req, findDataverseOrDie(id), getEffective)); | ||||||
|
||||||
| String storageDriver = execCommand(new GetDataverseStorageDriverCommand(req, findDataverseOrDie(id), getEffective)); | |
| String storageDriver = execCommand(new GetDataverseStorageDriverCommand(req, dataverse, getEffective)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see where this was resolved. 'findDataverseOrDie(id)' should be replaced with 'dataverse'.
Also where is the EditDataverse permission check?
I only see Permission.ViewUnpublishedDataverse in GetDataverseStorageDriverCommand
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All breaking changes need to be documented in changelog.rst