volatile method added
This commit is contained in:
parent
7e6d6e2325
commit
fec3941a37
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.common.storagehub.client.dsl;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.net.URI;
|
||||
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
|
@ -97,4 +99,16 @@ public class StorageHubClient {
|
|||
return userClient.exists(user);
|
||||
}
|
||||
|
||||
public String uploadFileOnVolatile(File file) throws StorageHubException {
|
||||
return wsClient.uploadFileToVolatile(file);
|
||||
}
|
||||
|
||||
public String uploadFileOnVolatile(InputStream stream, String fileName) throws StorageHubException {
|
||||
return wsClient.uploadFileToVolatile(stream, fileName);
|
||||
}
|
||||
|
||||
public String uploadFileOnVolatile(InputStream stream, String fileName, long size) throws StorageHubException {
|
||||
return wsClient.uploadFileToVolatile(stream, fileName, size);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -23,6 +27,13 @@ import org.gcube.common.storagehub.model.items.Item;
|
|||
import org.gcube.common.storagehub.model.query.Query;
|
||||
import org.gcube.common.storagehub.model.service.ItemList;
|
||||
import org.gcube.common.storagehub.model.service.ItemWrapper;
|
||||
import org.glassfish.jersey.media.multipart.ContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
|
||||
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPart;
|
||||
import org.glassfish.jersey.media.multipart.MultiPartFeature;
|
||||
import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
|
||||
import org.glassfish.jersey.media.multipart.file.StreamDataBodyPart;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
|
@ -415,6 +426,65 @@ public class DefaultWorkspaceManager extends DefaultManagerClient implements Wor
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileToVolatile(InputStream stream, String fileName, long contentLength) throws StorageHubException{
|
||||
Call<GXWebTargetAdapterRequest, String> call = new Call<GXWebTargetAdapterRequest, String>() {
|
||||
@Override
|
||||
public String call(GXWebTargetAdapterRequest manager) throws Exception {
|
||||
Objects.requireNonNull(stream, "stream cannot be null");
|
||||
Objects.requireNonNull(fileName, "parentId cannot be null");
|
||||
|
||||
GXWebTargetAdapterRequest myManager = manager.register(MultiPartFeature.class)
|
||||
.path("volatile");
|
||||
|
||||
GXInboundResponse response =null;
|
||||
FormDataMultiPart multipart = new FormDataMultiPart();
|
||||
|
||||
StreamDataBodyPart filePart = new StreamDataBodyPart("file", stream);
|
||||
filePart.setContentDisposition(FormDataContentDisposition.name("file").fileName(fileName).size(contentLength).build());
|
||||
|
||||
MultiPart multipartEntity = new FormDataMultiPart().bodyPart(filePart);
|
||||
|
||||
response = myManager.queryParams(initQueryParameters()).post(Entity.entity(multipartEntity, multipartEntity.getMediaType()));
|
||||
|
||||
if (response.isErrorResponse()) {
|
||||
if (response.hasException()) {
|
||||
throw response.getException();
|
||||
}else
|
||||
throw new BackendGenericError("HTTP error code is "+response.getHTTPCode());
|
||||
}
|
||||
|
||||
return response.getSource().readEntity(String.class);
|
||||
}
|
||||
};
|
||||
try {
|
||||
return delegate.make(call);
|
||||
}catch(StorageHubException e) {
|
||||
throw e;
|
||||
}catch(Exception e1) {
|
||||
throw new RuntimeException(e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileToVolatile(InputStream stream, String fileName) throws StorageHubException {
|
||||
return this.uploadFileToVolatile(stream, fileName, -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String uploadFileToVolatile(File file) throws StorageHubException {
|
||||
if (!file.exists()) throw new BackendGenericError("file "+file.getAbsolutePath()+" doesn't exist");
|
||||
String fileName = file.getName();
|
||||
|
||||
long size = file.length();
|
||||
try (InputStream is = new FileInputStream(file)){
|
||||
return uploadFileToVolatile(is, fileName, size);
|
||||
}catch (IOException io) {
|
||||
throw new BackendGenericError("error closing stream", io);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package org.gcube.common.storagehub.client.proxies;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.storagehub.model.exceptions.BackendGenericError;
|
||||
|
@ -34,4 +36,10 @@ public interface WorkspaceManagerClient extends ManagerClient{
|
|||
|
||||
long getTotalVolume();
|
||||
|
||||
String uploadFileToVolatile(InputStream stream, String filename, long contentLength) throws StorageHubException;
|
||||
|
||||
String uploadFileToVolatile(InputStream stream, String filename) throws StorageHubException;
|
||||
|
||||
String uploadFileToVolatile(File file) throws StorageHubException;
|
||||
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import java.util.List;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.dsl.ContainerType;
|
||||
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
||||
|
@ -53,8 +55,8 @@ public class Items {
|
|||
String token = splitValue[1];
|
||||
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
||||
|
||||
/*SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(context);*/
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(splitValue[0]);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -91,6 +93,18 @@ public class Items {
|
|||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uploadTovolatile() throws StorageHubException {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
|
||||
String vresFile = "/home/lucio/Downloads/gardaland_prenotazione.pdf";
|
||||
|
||||
File file = new File(vresFile);
|
||||
|
||||
System.out.println(shc.uploadFileOnVolatile(file));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void search() {
|
||||
|
@ -236,7 +250,7 @@ public class Items {
|
|||
public void removeUser() throws Exception {
|
||||
StorageHubClient shc = new StorageHubClient();
|
||||
|
||||
shc.deleteUserAccount("_sergencovid19");
|
||||
shc.deleteUserAccount("");
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ import java.util.Properties;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
//code-repo.d4science.org/gCubeSystem/storagehub-client-library.git
|
||||
import org.gcube.common.storagehub.client.StreamDescriptor;
|
||||
import org.gcube.common.storagehub.client.plugins.AbstractPlugin;
|
||||
|
@ -44,7 +46,7 @@ public class TestCall {
|
|||
|
||||
private static Logger log = LoggerFactory.getLogger(TestCall.class);
|
||||
|
||||
private static final String propFile = "/home/lucio/secret.properties";
|
||||
private static final String propFile = "/home/lucio/tokens.properties";
|
||||
|
||||
private static final String tokens = "dev-root";
|
||||
|
||||
|
@ -57,8 +59,12 @@ public class TestCall {
|
|||
String value =(String)prop.get(tokens);
|
||||
String[] splitValue = value.split(",");
|
||||
String token = splitValue[1];
|
||||
String scope = splitValue[0];
|
||||
//SecretManagerProvider.instance.set(new GCubeSecret(token));
|
||||
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(scope);
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -69,7 +75,7 @@ public class TestCall {
|
|||
@Test
|
||||
public void sendMessagesWithAttachment() throws Exception {
|
||||
MessageManagerClient client = AbstractPlugin.messages().build();
|
||||
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", Arrays.asList("4827dd33-6eea-4bba-b78b-b98e2fd2ddfa"));
|
||||
client.sendMessage(Arrays.asList("massimiliano.assante"), "subject encodato ? è ", "è econdato ??", null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue