|
|
|
@ -7,8 +7,6 @@ import java.io.FileInputStream;
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.nio.channels.FileChannel;
|
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
@ -25,11 +23,9 @@ import javax.websocket.server.ServerEndpoint;
|
|
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
|
|
|
|
import org.gcube.common.homelibrary.home.HomeLibrary;
|
|
|
|
|
import org.gcube.common.homelibrary.home.exceptions.InternalErrorException;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.Workspace;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceFolder;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.WorkspaceItem;
|
|
|
|
|
import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException;
|
|
|
|
|
import org.gcube.common.homelibrary.util.zip.ZipUtil;
|
|
|
|
|
import org.gcube.common.portal.PortalContext;
|
|
|
|
|
import org.gcube.common.scope.api.ScopeProvider;
|
|
|
|
@ -73,12 +69,12 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private final static String DEFAULT_ROLE = "OrganizationMember";
|
|
|
|
|
private static void setAuthorizationToken(String username) throws Exception {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String scope = "/"+PortalContext.getConfiguration().getInfrastructureName();
|
|
|
|
|
ScopeProvider.instance.set(scope);
|
|
|
|
|
_log.debug("calling service token on scope " + scope);
|
|
|
|
@ -88,7 +84,7 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
_log.debug("received token: "+token);
|
|
|
|
|
_log.info("Security token set in session for: "+username + " on " + scope);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String zipFolder(String itemId, Session peer, String username) {
|
|
|
|
|
|
|
|
|
|
_log.info("FOLDER DOWNLOAD REQUEST itemId="+itemId + " user=" + username);
|
|
|
|
@ -108,14 +104,8 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
item = wa.getItem(itemId);
|
|
|
|
|
try{
|
|
|
|
|
//ACCOUNTING
|
|
|
|
|
item.markAsRead(true);
|
|
|
|
|
} catch (InternalErrorException e) {
|
|
|
|
|
_log.error("Requested item "+itemId+" has thrown an internal error exception",e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (ItemNotFoundException e) {
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
_log.error("Requested item "+itemId+" not found",e);
|
|
|
|
|
peer.getAsyncRemote().sendText(ConstantsExplorer.DOWNLOAD_WORKSPACE_FOLDER_PROTOCOL_ERROR_NOT_FOUND);
|
|
|
|
|
return null;
|
|
|
|
@ -126,7 +116,7 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
case FOLDER:{
|
|
|
|
|
try {
|
|
|
|
|
File tmpZip = ZipUtil.zipFolder((WorkspaceFolder) item);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String tmpSys = System.getProperty("java.io.tmpdir");
|
|
|
|
|
String randomDirName = UUID.randomUUID().toString();
|
|
|
|
|
String toReturn = randomDirName + File.separator + item.getName();
|
|
|
|
@ -137,7 +127,7 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
File toCopy = new File(tmpSys + File.separator + toReturn);
|
|
|
|
|
if (!toCopy.exists())
|
|
|
|
|
toCopy.createNewFile();
|
|
|
|
|
copyFileUsingFileChannels(tmpZip, toCopy);
|
|
|
|
|
copyFileUsingFileChannels(tmpZip, toCopy);
|
|
|
|
|
_log.info("Zipped folder in="+toCopy.getAbsolutePath() + ", returning="+toReturn);
|
|
|
|
|
tmpZip.deleteOnExit();
|
|
|
|
|
return toReturn;
|
|
|
|
@ -167,6 +157,6 @@ public class DownloadFolderWebSocketServer {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|