creation of folder with different backend fixed

This commit is contained in:
lucio 2024-08-16 13:02:55 +02:00
parent 50b2c80a1a
commit a9cc80f424
7 changed files with 42 additions and 14 deletions

View File

@ -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

View File

@ -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<String,Object> params){
public FolderCreationBuilder withParameters(Map<String, Object> params){
this.cb.parameters.backend = new PayloadBackend(plugin, new Metadata(params));
return this.cb;
}

View File

@ -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<String> paramIt = request.getParameterNames().asIterator();
Iterable<String> iterable = () -> paramIt;
Stream<String> 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<FolderCreationParameters> 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<ArchiveStructureCreationParameter> builder = ArchiveStructureCreationParameter.builder().parentName(parentFolderName).stream(stream)

View File

@ -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<Item>(toReturn);
}

View File

@ -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);

View File

@ -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

View File

@ -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();
}