diff --git a/buildImageAndStart.sh b/buildImageAndStart.sh index b86b2c0..58d8153 100755 --- a/buildImageAndStart.sh +++ b/buildImageAndStart.sh @@ -10,6 +10,6 @@ compile=false mvn clean package -docker-compose -f docker-compose-standalone.yml build +docker compose -f docker-compose-standalone.yml build -docker-compose -f docker-compose-standalone.yml up +docker compose -f docker-compose-standalone.yml up diff --git a/src/main/java/org/gcube/data/access/storagehub/handlers/items/builders/FolderCreationParameters.java b/src/main/java/org/gcube/data/access/storagehub/handlers/items/builders/FolderCreationParameters.java index c6ae710..a9ee994 100644 --- a/src/main/java/org/gcube/data/access/storagehub/handlers/items/builders/FolderCreationParameters.java +++ b/src/main/java/org/gcube/data/access/storagehub/handlers/items/builders/FolderCreationParameters.java @@ -5,6 +5,7 @@ import java.util.Objects; import org.gcube.common.storagehub.model.Metadata; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; +import org.gcube.common.storagehub.model.plugins.PluginParameters; public class FolderCreationParameters extends CreateParameters { @@ -86,7 +87,7 @@ public class FolderCreationParameters extends CreateParameters { this.plugin = pluginName; } - public FolderCreationBuilder withParameters(Map params){ + public FolderCreationBuilder withParameters(Map params){ this.cb.parameters.backend = new PayloadBackend(plugin, new Metadata(params)); return this.cb; } diff --git a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java index d7d6590..c50be8b 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/ItemsCreator.java @@ -6,6 +6,9 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; import java.net.URLConnection; +import java.util.Iterator; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -15,6 +18,7 @@ import org.gcube.common.gxrest.response.outbound.GXOutboundErrorResponse; import org.gcube.common.storagehub.model.exceptions.BackendGenericError; import org.gcube.common.storagehub.model.exceptions.StorageHubException; import org.gcube.common.storagehub.model.items.GCubeItem; +import org.gcube.common.storagehub.model.plugins.PluginParameters; import org.gcube.data.access.storagehub.Constants; import org.gcube.data.access.storagehub.StorageHubApplicationManager; import org.gcube.data.access.storagehub.handlers.items.ItemHandler; @@ -37,6 +41,7 @@ import com.webcohesion.enunciate.metadata.rs.RequestHeaders; import jakarta.inject.Inject; import jakarta.servlet.ServletContext; +import jakarta.servlet.http.HttpServletRequest; import jakarta.ws.rs.Consumes; import jakarta.ws.rs.FormParam; import jakarta.ws.rs.POST; @@ -100,16 +105,25 @@ public class ItemsCreator extends Impersonable{ public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name, @FormParam("description") String description, @FormParam("hidden") boolean hidden, @FormParam("pluginName") String pluginName, - @FormParam("parameters") String pluginParameters) { + @Context HttpServletRequest request) { InnerMethodName.set("createItem(EXTERNALFOLDER)"); log.info("create folder item called"); Session ses = null; String toReturn = null; try{ - //TODO + Iterator paramIt = request.getParameterNames().asIterator(); + Iterable iterable = () -> paramIt; + Stream targetStream = StreamSupport.stream(iterable.spliterator(), false); + + PluginParameters pluginParams = new PluginParameters(); + + targetStream.filter(v -> v.startsWith("plugin.")) + .forEach(v -> pluginParams.add(v.replace("plugin.", ""), request.getParameter(v))); + + log.debug("parameters for external folder with plugin {} are {}",pluginName, pluginParams.toString()); ses = repository.getRepository().login(Constants.JCR_CREDENTIALS); ItemsParameterBuilder builder = FolderCreationParameters.builder().name(name) - .description(description).onRepository(pluginName).withParameters(null).hidden(hidden).on(id).with(ses).author(currentUser); + .description(description).onRepository(pluginName).withParameters(pluginParams.getParameters()).hidden(hidden).on(id).with(ses).author(currentUser); toReturn = itemHandler.create(builder.build()); }catch(StorageHubException she ){ log.error(she.getErrorMessage(), she); @@ -289,7 +303,7 @@ public class ItemsCreator extends Impersonable{ Session ses = null; String toReturn = null; try{ - + ses = repository.getRepository().login(Constants.JCR_CREDENTIALS); try(InputStream stream = new URI(url).toURL().openStream()){ ItemsParameterBuilder builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream) diff --git a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java index e34503e..96b855b 100644 --- a/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java +++ b/src/main/java/org/gcube/data/access/storagehub/services/WorkspaceManager.java @@ -155,11 +155,11 @@ public class WorkspaceManager extends Impersonable { } catch (StorageHubException she) { log.error(she.getErrorMessage(), she); GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus())); - } finally { + } + finally { if (ses != null) ses.logout(); } - return new ItemWrapper(toReturn); } diff --git a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GcubeMinIOStorageBackendFactory.java b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GcubeMinIOStorageBackendFactory.java index 7b54f57..2993015 100644 --- a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GcubeMinIOStorageBackendFactory.java +++ b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/GcubeMinIOStorageBackendFactory.java @@ -1,7 +1,9 @@ package org.gcube.data.access.storagehub.storage.backend.impl; +import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; import java.util.Properties; @@ -15,6 +17,8 @@ import org.gcube.common.storagehub.model.exceptions.InvalidCallParameters; import org.gcube.common.storagehub.model.items.nodes.PayloadBackend; import org.gcube.common.storagehub.model.storages.StorageBackend; import org.gcube.common.storagehub.model.storages.StorageBackendFactory; +import org.gcube.smartgears.ContextProvider; +import org.gcube.smartgears.context.application.ApplicationContext; @Singleton public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory { @@ -30,7 +34,7 @@ public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory { @Override public String getName() { - return "gcube-default-minio"; + return "gcube-minio"; } @Override @@ -48,12 +52,14 @@ public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory { Metadata metadata = new Metadata(new HashMap<>(baseParameters.getMap())); metadata.getMap().putAll(payloadConfiguration.getParameters()); - return new S3Backend(new PayloadBackend(getName(), metadata), (String) -> UUID.randomUUID().toString()); + + return new S3Backend(new PayloadBackend(getName(), metadata), (String) -> UUID.randomUUID().toString()); } private Metadata getParameters(){ - try (InputStream input = GcubeMinIOStorageBackendFactory.class.getClassLoader().getResourceAsStream("storage-settings.properties")) { - + ApplicationContext context = ContextProvider.get(); + String folderPath = context.appSpecificConfigurationFolder().toString(); + try (InputStream input = new FileInputStream(Paths.get(folderPath, "storage-settings.properties").toFile())) { Properties prop = new Properties(); prop.load(input); diff --git a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/S3Backend.java b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/S3Backend.java index 82c5e4c..680db25 100644 --- a/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/S3Backend.java +++ b/src/main/java/org/gcube/data/access/storagehub/storage/backend/impl/S3Backend.java @@ -1,6 +1,5 @@ package org.gcube.data.access.storagehub.storage.backend.impl; -import java.io.File; import java.io.InputStream; import java.util.HashMap; import java.util.Map; @@ -163,7 +162,9 @@ public class S3Backend extends StorageBackend{ upload.waitForCompletion(); } + long fileSize; + if (size != null && size>0) fileSize = size; else diff --git a/src/test/java/org/gcube/data/access/fs/external/CreateUsers.java b/src/test/java/org/gcube/data/access/fs/external/CreateUsers.java index c1c30e7..e07d674 100644 --- a/src/test/java/org/gcube/data/access/fs/external/CreateUsers.java +++ b/src/test/java/org/gcube/data/access/fs/external/CreateUsers.java @@ -171,6 +171,12 @@ public class CreateUsers { client.getVreFolderManager(vreWO).addUser("service-account-sg4-test-client"); } + @Test + public void getUserRootTest() throws Exception { + client.impersonate("lucio.lelii"); + client.getWSRoot().getId(); + } + public String getUserRootId() throws Exception { return client.getWSRoot().getId(); }