|
|
|
@ -5,17 +5,12 @@ import java.io.FileInputStream;
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
|
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.UmaJWTProvider;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FileContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.FolderContainer;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.OpenResolver;
|
|
|
|
|
import org.gcube.common.storagehub.client.dsl.StorageHubClient;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.InvalidItemException;
|
|
|
|
|
import org.gcube.common.storagehub.model.exceptions.StorageHubException;
|
|
|
|
|
import org.gcube.oidc.rest.JWTToken;
|
|
|
|
|
import org.gcube.portal.oidc.lr62.OIDCUmaUtil;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
@ -62,15 +57,10 @@ public class UploadToWorkspaceThread implements Runnable {
|
|
|
|
|
try {
|
|
|
|
|
String currContext = ScopeProvider.instance.get();
|
|
|
|
|
StorageHubClient shc = new StorageHubClient();
|
|
|
|
|
_log.info("Trying to get VRE folder for scope="+currContext);
|
|
|
|
|
String umaToken = UmaJWTProvider.instance.get();
|
|
|
|
|
System.out.println("\n\n\n UMA Token:");
|
|
|
|
|
System.out.println(umaToken);
|
|
|
|
|
System.out.println("\n\n\n END UMA Token");
|
|
|
|
|
|
|
|
|
|
_log.debug("Trying to get VRE folder for scope="+currContext);
|
|
|
|
|
FolderContainer vreFolder = shc.openVREFolder();
|
|
|
|
|
|
|
|
|
|
_log.info("File to upload="+fileabsolutePathOnServer);
|
|
|
|
|
_log.debug("File to upload="+fileabsolutePathOnServer);
|
|
|
|
|
File file = new File(fileabsolutePathOnServer);
|
|
|
|
|
InputStream fileData = new FileInputStream(file);
|
|
|
|
|
FolderContainer attachmentFolder = null;
|
|
|
|
@ -79,12 +69,12 @@ public class UploadToWorkspaceThread implements Runnable {
|
|
|
|
|
attachmentFolder = oRes.asFolder();
|
|
|
|
|
} catch (StorageHubException e) {
|
|
|
|
|
_log.info(ATTACHMENT_FOLDER + " in VRE Folder does not exists, creating it for "+currContext);
|
|
|
|
|
vreFolder.newFolder(ATTACHMENT_FOLDER,"Folder created automatically by the System");
|
|
|
|
|
attachmentFolder = vreFolder.newFolder(ATTACHMENT_FOLDER,"Folder created automatically by the System");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String itemName = getUniqueName(fileName);
|
|
|
|
|
FileContainer uploadedFile = attachmentFolder.uploadFile(fileData, itemName, "File shared by " + fullName + "("+username+")");
|
|
|
|
|
_log.debug("Uploaded " + uploadedFile.get().getName() + " - Returned Workspace id=" + uploadedFile.getId());
|
|
|
|
|
_log.info("Uploaded " + uploadedFile.get().getName() + " - Returned Workspace id=" + uploadedFile.getId());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|