creation of folder with different backend fixed
This commit is contained in:
parent
50b2c80a1a
commit
a9cc80f424
|
@ -10,6 +10,6 @@ compile=false
|
||||||
|
|
||||||
mvn clean package
|
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
|
||||||
|
|
|
@ -5,6 +5,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
import org.gcube.common.storagehub.model.Metadata;
|
import org.gcube.common.storagehub.model.Metadata;
|
||||||
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
|
import org.gcube.common.storagehub.model.items.nodes.PayloadBackend;
|
||||||
|
import org.gcube.common.storagehub.model.plugins.PluginParameters;
|
||||||
|
|
||||||
public class FolderCreationParameters extends CreateParameters {
|
public class FolderCreationParameters extends CreateParameters {
|
||||||
|
|
||||||
|
@ -86,7 +87,7 @@ public class FolderCreationParameters extends CreateParameters {
|
||||||
this.plugin = pluginName;
|
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));
|
this.cb.parameters.backend = new PayloadBackend(plugin, new Metadata(params));
|
||||||
return this.cb;
|
return this.cb;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@ import java.io.InputStream;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
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.RepositoryException;
|
||||||
import javax.jcr.Session;
|
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.BackendGenericError;
|
||||||
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
||||||
import org.gcube.common.storagehub.model.items.GCubeItem;
|
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.Constants;
|
||||||
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
import org.gcube.data.access.storagehub.StorageHubApplicationManager;
|
||||||
import org.gcube.data.access.storagehub.handlers.items.ItemHandler;
|
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.inject.Inject;
|
||||||
import jakarta.servlet.ServletContext;
|
import jakarta.servlet.ServletContext;
|
||||||
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.ws.rs.Consumes;
|
import jakarta.ws.rs.Consumes;
|
||||||
import jakarta.ws.rs.FormParam;
|
import jakarta.ws.rs.FormParam;
|
||||||
import jakarta.ws.rs.POST;
|
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,
|
public Response createExternalFolder(@PathParam("id") String id, @FormParam("name") String name,
|
||||||
@FormParam("description") String description, @FormParam("hidden") boolean hidden,
|
@FormParam("description") String description, @FormParam("hidden") boolean hidden,
|
||||||
@FormParam("pluginName") String pluginName,
|
@FormParam("pluginName") String pluginName,
|
||||||
@FormParam("parameters") String pluginParameters) {
|
@Context HttpServletRequest request) {
|
||||||
InnerMethodName.set("createItem(EXTERNALFOLDER)");
|
InnerMethodName.set("createItem(EXTERNALFOLDER)");
|
||||||
log.info("create folder item called");
|
log.info("create folder item called");
|
||||||
Session ses = null;
|
Session ses = null;
|
||||||
String toReturn = null;
|
String toReturn = null;
|
||||||
try{
|
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);
|
ses = repository.getRepository().login(Constants.JCR_CREDENTIALS);
|
||||||
ItemsParameterBuilder<FolderCreationParameters> builder = FolderCreationParameters.builder().name(name)
|
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());
|
toReturn = itemHandler.create(builder.build());
|
||||||
}catch(StorageHubException she ){
|
}catch(StorageHubException she ){
|
||||||
log.error(she.getErrorMessage(), she);
|
log.error(she.getErrorMessage(), she);
|
||||||
|
|
|
@ -155,11 +155,11 @@ public class WorkspaceManager extends Impersonable {
|
||||||
} catch (StorageHubException she) {
|
} catch (StorageHubException she) {
|
||||||
log.error(she.getErrorMessage(), she);
|
log.error(she.getErrorMessage(), she);
|
||||||
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
GXOutboundErrorResponse.throwException(she, Response.Status.fromStatusCode(she.getStatus()));
|
||||||
} finally {
|
}
|
||||||
|
finally {
|
||||||
if (ses != null)
|
if (ses != null)
|
||||||
ses.logout();
|
ses.logout();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ItemWrapper<Item>(toReturn);
|
return new ItemWrapper<Item>(toReturn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package org.gcube.data.access.storagehub.storage.backend.impl;
|
package org.gcube.data.access.storagehub.storage.backend.impl;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
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.items.nodes.PayloadBackend;
|
||||||
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
import org.gcube.common.storagehub.model.storages.StorageBackend;
|
||||||
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
import org.gcube.common.storagehub.model.storages.StorageBackendFactory;
|
||||||
|
import org.gcube.smartgears.ContextProvider;
|
||||||
|
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory {
|
public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory {
|
||||||
|
@ -30,7 +34,7 @@ public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "gcube-default-minio";
|
return "gcube-minio";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,12 +52,14 @@ public class GcubeMinIOStorageBackendFactory implements StorageBackendFactory {
|
||||||
|
|
||||||
Metadata metadata = new Metadata(new HashMap<>(baseParameters.getMap()));
|
Metadata metadata = new Metadata(new HashMap<>(baseParameters.getMap()));
|
||||||
metadata.getMap().putAll(payloadConfiguration.getParameters());
|
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(){
|
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();
|
Properties prop = new Properties();
|
||||||
|
|
||||||
prop.load(input);
|
prop.load(input);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package org.gcube.data.access.storagehub.storage.backend.impl;
|
package org.gcube.data.access.storagehub.storage.backend.impl;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -163,7 +162,9 @@ public class S3Backend extends StorageBackend{
|
||||||
upload.waitForCompletion();
|
upload.waitForCompletion();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
long fileSize;
|
long fileSize;
|
||||||
|
|
||||||
if (size != null && size>0)
|
if (size != null && size>0)
|
||||||
fileSize = size;
|
fileSize = size;
|
||||||
else
|
else
|
||||||
|
|
|
@ -171,6 +171,12 @@ public class CreateUsers {
|
||||||
client.getVreFolderManager(vreWO).addUser("service-account-sg4-test-client");
|
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 {
|
public String getUserRootId() throws Exception {
|
||||||
return client.getWSRoot().getId();
|
return client.getWSRoot().getId();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue