updated tests
git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@124381 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
1c0f14b386
commit
2fe12b9bbe
|
@ -166,16 +166,16 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
public static final GWTWorkspaceServiceAsync rpcWorkspaceService = (GWTWorkspaceServiceAsync) GWT.create(GWTWorkspaceService.class);
|
public static final GWTWorkspaceServiceAsync rpcWorkspaceService = (GWTWorkspaceServiceAsync) GWT.create(GWTWorkspaceService.class);
|
||||||
private ExplorerPanel explorerPanel;
|
private ExplorerPanel explorerPanel;
|
||||||
|
|
||||||
private final static HandlerManager eventBus = new HandlerManager(null);
|
private final static HandlerManager eventBus = new HandlerManager(null);
|
||||||
private HashMap<EventsTypeEnum, ArrayList<SubscriberInterface>> subscribers = null;
|
private HashMap<EventsTypeEnum, ArrayList<SubscriberInterface>> subscribers = null;
|
||||||
|
|
||||||
|
|
||||||
private boolean selectRootItem;
|
private boolean selectRootItem;
|
||||||
// private FileUploader fileUploader;
|
// private FileUploader fileUploader;
|
||||||
public static String myLogin;
|
public static String myLogin;
|
||||||
public static String myLoginFirstName;
|
public static String myLoginFirstName;
|
||||||
|
|
||||||
private static AppControllerExplorer singleton;
|
private static AppControllerExplorer singleton;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,11 +183,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
*/
|
*/
|
||||||
public AppControllerExplorer() {
|
public AppControllerExplorer() {
|
||||||
Registry.register(ConstantsExplorer.RPC_WORKSPACE_SERVICE, rpcWorkspaceService);
|
Registry.register(ConstantsExplorer.RPC_WORKSPACE_SERVICE, rpcWorkspaceService);
|
||||||
subscribers = new HashMap<EventsTypeEnum, ArrayList<SubscriberInterface>>();
|
subscribers = new HashMap<EventsTypeEnum, ArrayList<SubscriberInterface>>();
|
||||||
bind();
|
bind();
|
||||||
singleton = this;
|
singleton = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the single instance of AppControllerExplorer.
|
* Gets the single instance of AppControllerExplorer.
|
||||||
|
@ -223,7 +223,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
private void bind() {
|
private void bind() {
|
||||||
|
|
||||||
eventBus.addHandler(UpdateWorkspaceSizeEvent.TYPE, new UpdateWorkspaceSizeEventHandler() {
|
eventBus.addHandler(UpdateWorkspaceSizeEvent.TYPE, new UpdateWorkspaceSizeEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateWorkspaceSize(UpdateWorkspaceSizeEvent updateWorkspaceSizeEvent) {
|
public void onUpdateWorkspaceSize(UpdateWorkspaceSizeEvent updateWorkspaceSizeEvent) {
|
||||||
doUpdateWorkspaceSize(updateWorkspaceSizeEvent);
|
doUpdateWorkspaceSize(updateWorkspaceSizeEvent);
|
||||||
|
@ -233,9 +233,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
eventBus.addHandler(RenderForm.TYPE, new RenderFormEventHandler() {
|
eventBus.addHandler(RenderForm.TYPE, new RenderFormEventHandler() {
|
||||||
@Override
|
@Override
|
||||||
public void onRenderForm(RenderForm event) {
|
public void onRenderForm(RenderForm event) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
eventBus.addHandler(SendMessageEvent.TYPE, new SendMessageEventHandler() {
|
eventBus.addHandler(SendMessageEvent.TYPE, new SendMessageEventHandler() {
|
||||||
|
@ -245,7 +245,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
notifySubscriber(sendMessageEvent);
|
notifySubscriber(sendMessageEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(UnShareFolderEvent.TYPE,new UnShareFolderEventHandler() {
|
eventBus.addHandler(UnShareFolderEvent.TYPE,new UnShareFolderEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -296,7 +296,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -310,22 +310,22 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
notifySubscriber(trashEvent);
|
notifySubscriber(trashEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(AddAdministratorEvent.TYPE, new AddAdministratorEventHandler() {
|
eventBus.addHandler(AddAdministratorEvent.TYPE, new AddAdministratorEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAddAdministrator(AddAdministratorEvent addAdministratorEvent) {
|
public void onAddAdministrator(AddAdministratorEvent addAdministratorEvent) {
|
||||||
|
|
||||||
final FileModel file = addAdministratorEvent.getSelectedFolder();
|
final FileModel file = addAdministratorEvent.getSelectedFolder();
|
||||||
|
|
||||||
if(file==null || file.getIdentifier()==null)
|
if(file==null || file.getIdentifier()==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if(caught instanceof SessionExpiredException){
|
||||||
GWT.log("Session expired");
|
GWT.log("Session expired");
|
||||||
eventBus.fireEvent(new SessionExpiredEvent());
|
eventBus.fireEvent(new SessionExpiredEvent());
|
||||||
|
@ -344,28 +344,28 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
showAddAdministratorsDialog(file);
|
showAddAdministratorsDialog(file);
|
||||||
else
|
else
|
||||||
new MessageBoxAlert("Permission denied", "You have no permissions to manage administrators. You are not manager of \""+file.getName()+"\"", null);
|
new MessageBoxAlert("Permission denied", "You have no permissions to manage administrators. You are not manager of \""+file.getName()+"\"", null);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
eventBus.addHandler(EditUserPermissionEvent.TYPE, new EditUserPermissionEventHandler() {
|
eventBus.addHandler(EditUserPermissionEvent.TYPE, new EditUserPermissionEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEditUserPermission(EditUserPermissionEvent editUserPermissionEvent) {
|
public void onEditUserPermission(EditUserPermissionEvent editUserPermissionEvent) {
|
||||||
|
|
||||||
final FileModel file = editUserPermissionEvent.getSourceFolder();
|
final FileModel file = editUserPermissionEvent.getSourceFolder();
|
||||||
|
|
||||||
if(file==null || file.getIdentifier()==null)
|
if(file==null || file.getIdentifier()==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
rpcWorkspaceService.getOwnerByItemId(file.getIdentifier(), new AsyncCallback<InfoContactModel>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
|
||||||
if(caught instanceof SessionExpiredException){
|
if(caught instanceof SessionExpiredException){
|
||||||
GWT.log("Session expired");
|
GWT.log("Session expired");
|
||||||
eventBus.fireEvent(new SessionExpiredEvent());
|
eventBus.fireEvent(new SessionExpiredEvent());
|
||||||
|
@ -385,14 +385,14 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
ediPermissions(file);
|
ediPermissions(file);
|
||||||
else
|
else
|
||||||
new MessageBoxAlert("Permission denied", "You have no authority to manage user permissions. You are not manager of \""+file.getName()+"\"", null);
|
new MessageBoxAlert("Permission denied", "You have no authority to manage user permissions. You are not manager of \""+file.getName()+"\"", null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(GetInfoEvent.TYPE, new GetInfoEventHandler() {
|
eventBus.addHandler(GetInfoEvent.TYPE, new GetInfoEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -415,7 +415,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
//DEBUG
|
//DEBUG
|
||||||
System.out.println("create shared folderEvent - sourceFileModel id "+sourceFileModel.getIdentifier());
|
System.out.println("create shared folderEvent - sourceFileModel id "+sourceFileModel.getIdentifier());
|
||||||
|
|
||||||
final FileModel parentFileModel= createSharedFolderEvent.getParentFileModel();
|
final FileModel parentFileModel= createSharedFolderEvent.getParentFileModel();
|
||||||
final boolean isNewFolder = createSharedFolderEvent.isNewFolder();
|
final boolean isNewFolder = createSharedFolderEvent.isNewFolder();
|
||||||
DialogShareFolder dialogSharedFolder = null;
|
DialogShareFolder dialogSharedFolder = null;
|
||||||
String parentDirectoryName = null;
|
String parentDirectoryName = null;
|
||||||
|
@ -461,7 +461,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
fileModel = finalDialog.getParentFolder(); //add user for share
|
fileModel = finalDialog.getParentFolder(); //add user for share
|
||||||
|
|
||||||
//create a lowest object to send to server
|
//create a lowest object to send to server
|
||||||
fileModel = new FileModel(fileModel.getIdentifier(), fileModel.getName(), fileModel.getParentFileModel(), fileModel.isDirectory(), fileModel.isShared());
|
fileModel = new FileModel(fileModel.getIdentifier(), fileModel.getName(), fileModel.getParentFileModel(), fileModel.isDirectory(), fileModel.isShared());
|
||||||
|
@ -474,15 +474,15 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
System.out.println("FileModel id "+fileModel.getIdentifier() + " name: "+fileModel.getName() + " parent " + fileModel.getParentFileModel());
|
System.out.println("FileModel id "+fileModel.getIdentifier() + " name: "+fileModel.getName() + " parent " + fileModel.getParentFileModel());
|
||||||
for(InfoContactModel contact:finalDialog.getSharedListUsers() ){
|
for(InfoContactModel contact:finalDialog.getSharedListUsers() ){
|
||||||
System.out.println("Share with Contact "+contact) ;
|
System.out.println("Share with Contact "+contact) ;
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
System.out.println("ACL is "+finalDialog.getSelectedACL());
|
System.out.println("ACL is "+finalDialog.getSelectedACL());
|
||||||
|
|
||||||
|
|
||||||
Info.display("Info", "An operation of sharing was submitted");
|
Info.display("Info", "An operation of sharing was submitted");
|
||||||
explorerPanel.mask("Setting permissions", ConstantsExplorer.LOADINGSTYLE);
|
explorerPanel.mask("Setting permissions", ConstantsExplorer.LOADINGSTYLE);
|
||||||
|
|
||||||
rpcWorkspaceService.shareFolder(fileModel, finalDialog.getSharedListUsers(), isNewFolder, finalDialog.getSelectedACL(), new AsyncCallback<Boolean>() {
|
rpcWorkspaceService.shareFolder(fileModel, finalDialog.getSharedListUsers(), isNewFolder, finalDialog.getSelectedACL(), new AsyncCallback<Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -510,9 +510,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
parentToRefresh = parentFileModel;
|
parentToRefresh = parentFileModel;
|
||||||
|
|
||||||
GWT.log("share completed throwing refresh folder : "+parentToRefresh.getName() +" get id: "+parentToRefresh.getIdentifier());
|
GWT.log("share completed throwing refresh folder : "+parentToRefresh.getName() +" get id: "+parentToRefresh.getIdentifier());
|
||||||
|
|
||||||
// eventBus.fireEvent(new RefreshFolderEvent(parentToRefresh, true, false, false));
|
// eventBus.fireEvent(new RefreshFolderEvent(parentToRefresh, true, false, false));
|
||||||
|
|
||||||
//TODO UPDATED ID
|
//TODO UPDATED ID
|
||||||
RefreshFolderEvent refEvent = new RefreshFolderEvent(parentToRefresh, true, true, false);
|
RefreshFolderEvent refEvent = new RefreshFolderEvent(parentToRefresh, true, true, false);
|
||||||
refEvent.setForceReloadBreadCrumb(true);
|
refEvent.setForceReloadBreadCrumb(true);
|
||||||
|
@ -524,7 +524,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else{//ITEM IS NOT SHAREABLE
|
else{//ITEM IS NOT SHAREABLE
|
||||||
|
@ -628,7 +628,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshItem(RefreshFolderEvent refreshItemEvent) {
|
public void onRefreshItem(RefreshFolderEvent refreshItemEvent) {
|
||||||
|
|
||||||
GWT.log("RefreshFolderEvent: "+refreshItemEvent);
|
GWT.log("RefreshFolderEvent: "+refreshItemEvent);
|
||||||
|
|
||||||
if(refreshItemEvent.getFolderTarget()!=null){
|
if(refreshItemEvent.getFolderTarget()!=null){
|
||||||
|
@ -691,17 +691,17 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
if(pasteItemEvent.getIds()==null)
|
if(pasteItemEvent.getIds()==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Info.display("Info", "Paste working...");
|
Info.display("Info", "Paste working...");
|
||||||
|
|
||||||
switch(pasteItemEvent.getOperationType()){
|
switch(pasteItemEvent.getOperationType()){
|
||||||
|
|
||||||
case CUT:
|
case CUT:
|
||||||
|
|
||||||
//TODO remove this comments
|
//TODO remove this comments
|
||||||
// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty())
|
// if(pasteItemEvent.getFolderSourceId()==null || pasteItemEvent.getFolderSourceId().isEmpty())
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
rpcWorkspaceService.moveItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
|
rpcWorkspaceService.moveItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
|
||||||
|
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
|
@ -720,27 +720,27 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean result) {
|
public void onSuccess(Boolean result) {
|
||||||
|
|
||||||
FileModel fileInTree = explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId());
|
FileModel fileInTree = explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId());
|
||||||
|
|
||||||
if(result){
|
if(result){
|
||||||
eventBus.fireEvent(new RefreshFolderEvent(fileInTree, false, false, false));
|
eventBus.fireEvent(new RefreshFolderEvent(fileInTree, false, false, false));
|
||||||
//explorerPanel.getAsycTreePanel().setExpandTreeLevel(event.getTargetParentFileModel(), true); //Expand level drop
|
//explorerPanel.getAsycTreePanel().setExpandTreeLevel(event.getTargetParentFileModel(), true); //Expand level drop
|
||||||
}
|
}
|
||||||
|
|
||||||
if(fileInTree!=null)
|
if(fileInTree!=null)
|
||||||
pasteItemEvent.setTreeRefreshable(true);
|
pasteItemEvent.setTreeRefreshable(true);
|
||||||
else
|
else
|
||||||
pasteItemEvent.setTreeRefreshable(false);
|
pasteItemEvent.setTreeRefreshable(false);
|
||||||
|
|
||||||
notifySubscriber(pasteItemEvent);
|
notifySubscriber(pasteItemEvent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case COPY:
|
case COPY:
|
||||||
|
|
||||||
rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
|
rpcWorkspaceService.copyItems(pasteItemEvent.getIds(), pasteItemEvent.getFolderDestinationId(), new AsyncCallback<Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -753,9 +753,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
|
|
||||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||||
|
|
||||||
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
|
eventBus.fireEvent(new RefreshFolderEvent(explorerPanel.getAsycTreePanel().getFileModelByIdentifier(pasteItemEvent.getFolderDestinationId()), false, true, false));
|
||||||
|
|
||||||
notifySubscriber(pasteItemEvent);
|
notifySubscriber(pasteItemEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -770,16 +770,16 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
pasteItemEvent.setTreeRefreshable(true);
|
pasteItemEvent.setTreeRefreshable(true);
|
||||||
else
|
else
|
||||||
pasteItemEvent.setTreeRefreshable(false);
|
pasteItemEvent.setTreeRefreshable(false);
|
||||||
|
|
||||||
notifySubscriber(pasteItemEvent);
|
notifySubscriber(pasteItemEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -896,7 +896,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
// }
|
// }
|
||||||
// else
|
// else
|
||||||
// com.google.gwt.user.client.Window.open(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+"?id="+fileDownloadEvent.getItemIdentifier(), "_self", "");
|
// com.google.gwt.user.client.Window.open(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+"?id="+fileDownloadEvent.getItemIdentifier(), "_self", "");
|
||||||
//
|
//
|
||||||
|
|
||||||
if(fileDownloadEvent.getDownloadType().equals(DownloadType.SHOW)){
|
if(fileDownloadEvent.getDownloadType().equals(DownloadType.SHOW)){
|
||||||
if(fileDownloadEvent.getItemName()!= null){
|
if(fileDownloadEvent.getItemName()!= null){
|
||||||
|
@ -953,26 +953,26 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
caption+= "File/s";
|
caption+= "File/s";
|
||||||
upType = UPLOAD_TYPE.File;
|
upType = UPLOAD_TYPE.File;
|
||||||
}
|
}
|
||||||
|
|
||||||
caption+= " in: "+folder.getName();
|
caption+= " in: "+folder.getName();
|
||||||
|
|
||||||
MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(caption, folder.getIdentifier(), upType);
|
MultipleDilaogUpload uploadStream = new MultipleDilaogUpload(caption, folder.getIdentifier(), upType);
|
||||||
WorskpaceUploadNotificationListener listener = new WorskpaceUploadNotificationListener() {
|
WorskpaceUploadNotificationListener listener = new WorskpaceUploadNotificationListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadCompleted(String parentId, String itemId) {
|
public void onUploadCompleted(String parentId, String itemId) {
|
||||||
GWT.log("Upload completed: [parentID: "+parentId+", itemId: "+itemId+", uploadType: "+fileUploadEvent.getUploadType()+"]");
|
GWT.log("Upload completed: [parentID: "+parentId+", itemId: "+itemId+", uploadType: "+fileUploadEvent.getUploadType()+"]");
|
||||||
eventBus.fireEvent(new CompletedFileUploadEvent(parentId, itemId, fileUploadEvent.getUploadType(), false));
|
eventBus.fireEvent(new CompletedFileUploadEvent(parentId, itemId, fileUploadEvent.getUploadType(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUploadAborted(String parentId, String itemId) {
|
public void onUploadAborted(String parentId, String itemId) {
|
||||||
GWT.log("Upload Aborted: [parentID: "+parentId+", itemId: "+itemId+"]");
|
GWT.log("Upload Aborted: [parentID: "+parentId+", itemId: "+itemId+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(String parentId, String itemId, Throwable throwable) {
|
public void onError(String parentId, String itemId, Throwable throwable) {
|
||||||
GWT.log("Upload Error: [parentID: "+parentId+", itemId: "+itemId+"]");
|
GWT.log("Upload Error: [parentID: "+parentId+", itemId: "+itemId+"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -981,7 +981,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
eventBus.fireEvent(new CompletedFileUploadEvent(parentId, itemId, fileUploadEvent.getUploadType(), true));
|
eventBus.fireEvent(new CompletedFileUploadEvent(parentId, itemId, fileUploadEvent.getUploadType(), true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
uploadStream.addWorkspaceUploadNotificationListener(listener);
|
uploadStream.addWorkspaceUploadNotificationListener(listener);
|
||||||
uploadStream.center();
|
uploadStream.center();
|
||||||
}
|
}
|
||||||
|
@ -991,7 +991,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCompletedFileUploadEvent(CompletedFileUploadEvent completedFileUploadEvent) {
|
public void onCompletedFileUploadEvent(CompletedFileUploadEvent completedFileUploadEvent) {
|
||||||
doCompletedFileUploadEvent(completedFileUploadEvent);
|
doCompletedFileUploadEvent(completedFileUploadEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doCompletedFileUploadEvent(CompletedFileUploadEvent completedFileUploadEvent) {
|
private void doCompletedFileUploadEvent(CompletedFileUploadEvent completedFileUploadEvent) {
|
||||||
|
@ -1038,7 +1038,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(Boolean result) {
|
public void onSuccess(Boolean result) {
|
||||||
if(result)
|
if(result)
|
||||||
explorerPanel.getSmartFolderPanel().removeSmartFolder(smartIdentifier);
|
explorerPanel.getSmartFolderPanel().removeSmartFolder(smartIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1052,7 +1052,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1071,7 +1071,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
final String query = saveSmartFolderEvent.getSearchText();
|
final String query = saveSmartFolderEvent.getSearchText();
|
||||||
final String parentId = saveSmartFolderEvent.getParentId();
|
final String parentId = saveSmartFolderEvent.getParentId();
|
||||||
|
|
||||||
final DialogAddFolderAndSmart dialogAddSmartFolder = new DialogAddFolderAndSmart("", AddType.SMARTFOLDER);
|
final DialogAddFolderAndSmart dialogAddSmartFolder = new DialogAddFolderAndSmart("", AddType.SMARTFOLDER);
|
||||||
|
|
||||||
dialogAddSmartFolder.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
dialogAddSmartFolder.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
||||||
|
@ -1100,7 +1100,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1129,7 +1129,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
private void doRenameItem(final RenameItemEvent event) {
|
private void doRenameItem(final RenameItemEvent event) {
|
||||||
|
|
||||||
final FileModel target = event.getFileTarget();
|
final FileModel target = event.getFileTarget();
|
||||||
final DialogText dgt = new DialogText(ConstantsExplorer.MESSAGE_RENAME, ConstantsExplorer.MESSAGE_ITEM_NAME, event.getFileTarget().getName());
|
final DialogText dgt = new DialogText(ConstantsExplorer.MESSAGE_RENAME, ConstantsExplorer.MESSAGE_ITEM_NAME, event.getFileTarget().getName());
|
||||||
|
|
||||||
dgt.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
dgt.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
||||||
|
|
||||||
|
@ -1198,11 +1198,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
mbc.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
mbc.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||||
|
|
||||||
public void handleEvent(MessageBoxEvent be) {
|
public void handleEvent(MessageBoxEvent be) {
|
||||||
|
|
||||||
//IF NOT CANCELLED
|
//IF NOT CANCELLED
|
||||||
String clickedButton = be.getButtonClicked().getItemId();
|
String clickedButton = be.getButtonClicked().getItemId();
|
||||||
if(clickedButton.equals(Dialog.YES)){
|
if(clickedButton.equals(Dialog.YES)){
|
||||||
|
|
||||||
explorerPanel.getAsycTreePanel().mask("Deleting", ConstantsExplorer.LOADINGSTYLE);
|
explorerPanel.getAsycTreePanel().mask("Deleting", ConstantsExplorer.LOADINGSTYLE);
|
||||||
rpcWorkspaceService.removeItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
|
rpcWorkspaceService.removeItem(event.getFileTarget().getIdentifier(), new AsyncCallback<Boolean>(){
|
||||||
|
|
||||||
|
@ -1240,7 +1240,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1255,7 +1255,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
private void doSelectedItem(SelectedItemEvent event) {
|
private void doSelectedItem(SelectedItemEvent event) {
|
||||||
|
|
||||||
notifySubscriber(event);
|
notifySubscriber(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -1280,13 +1280,13 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAddItem(AddFolderEvent event) {
|
public void onAddItem(AddFolderEvent event) {
|
||||||
doAddItem(event);
|
doAddItem(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doAddItem(final AddFolderEvent event) {
|
private void doAddItem(final AddFolderEvent event) {
|
||||||
|
|
||||||
final FileModel sourceFileModel = event.getFileSourceModel();
|
final FileModel sourceFileModel = event.getFileSourceModel();
|
||||||
final FileModel parentFileModel= event.getParentFileModel();
|
final FileModel parentFileModel= event.getParentFileModel();
|
||||||
|
|
||||||
String directory = null;
|
String directory = null;
|
||||||
|
|
||||||
|
@ -1307,7 +1307,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
if(dialogAddFolder.isValidForm()){
|
if(dialogAddFolder.isValidForm()){
|
||||||
|
|
||||||
if(sourceFileModel.isDirectory()){
|
if(sourceFileModel.isDirectory()){
|
||||||
//
|
//
|
||||||
|
|
||||||
//TODO REMOVE
|
//TODO REMOVE
|
||||||
// System.out.println("description folder: "+dialogAddFolder.getDescription());
|
// System.out.println("description folder: "+dialogAddFolder.getDescription());
|
||||||
|
@ -1323,7 +1323,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(FolderModel child) {
|
public void onSuccess(FolderModel child) {
|
||||||
|
|
||||||
explorerPanel.getAsycTreePanel().addItem(sourceFileModel.getIdentifier(), child, false);
|
explorerPanel.getAsycTreePanel().addItem(sourceFileModel.getIdentifier(), child, false);
|
||||||
event.setNewFolder(child);
|
event.setNewFolder(child);
|
||||||
notifySubscriber(event);
|
notifySubscriber(event);
|
||||||
}
|
}
|
||||||
|
@ -1344,7 +1344,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(FolderModel child) {
|
public void onSuccess(FolderModel child) {
|
||||||
|
|
||||||
explorerPanel.getAsycTreePanel().addItem(parentFileModel.getIdentifier(), child, false);
|
explorerPanel.getAsycTreePanel().addItem(parentFileModel.getIdentifier(), child, false);
|
||||||
event.setNewFolder(child);
|
event.setNewFolder(child);
|
||||||
notifySubscriber(event);
|
notifySubscriber(event);
|
||||||
}
|
}
|
||||||
|
@ -1355,7 +1355,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1451,7 +1451,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
public void onClickUrl(OpenUrlEvent openUrlEvent) {
|
public void onClickUrl(OpenUrlEvent openUrlEvent) {
|
||||||
doClickUrl(openUrlEvent);
|
doClickUrl(openUrlEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -1491,7 +1491,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(FileModel child) {
|
public void onSuccess(FileModel child) {
|
||||||
|
|
||||||
explorerPanel.getAsycTreePanel().addItem(parent.getIdentifier(), child, false);
|
explorerPanel.getAsycTreePanel().addItem(parent.getIdentifier(), child, false);
|
||||||
explorerPanel.getAsycTreePanel().unmask();
|
explorerPanel.getAsycTreePanel().unmask();
|
||||||
notifySubscriber(createUrlEvent);
|
notifySubscriber(createUrlEvent);
|
||||||
}
|
}
|
||||||
|
@ -1501,12 +1501,12 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(VRESettingPermissionEvent.TYPE, new VRESettingPermissionEventHandler() {
|
eventBus.addHandler(VRESettingPermissionEvent.TYPE, new VRESettingPermissionEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPermissionSetting(VRESettingPermissionEvent settingPermissionEvent) {
|
public void onPermissionSetting(VRESettingPermissionEvent settingPermissionEvent) {
|
||||||
|
|
||||||
if(settingPermissionEvent.getSourceFile()!=null){
|
if(settingPermissionEvent.getSourceFile()!=null){
|
||||||
DialogPermission dialog = new DialogPermission(settingPermissionEvent.getSourceFile());
|
DialogPermission dialog = new DialogPermission(settingPermissionEvent.getSourceFile());
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
@ -1514,13 +1514,13 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
Info.display("Attention", "Select a VRE Folder to change permissions!");
|
Info.display("Attention", "Select a VRE Folder to change permissions!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
eventBus.addHandler(UpdatedVREPermissionEvent.TYPE, new UpdatedVREPermissionEventHandler() {
|
eventBus.addHandler(UpdatedVREPermissionEvent.TYPE, new UpdatedVREPermissionEventHandler() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onUpdateVREPermissions(UpdatedVREPermissionEvent updatedVREPermissionEvent) {
|
public void onUpdateVREPermissions(UpdatedVREPermissionEvent updatedVREPermissionEvent) {
|
||||||
notifySubscriber(updatedVREPermissionEvent);
|
notifySubscriber(updatedVREPermissionEvent);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1540,9 +1540,9 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
|
|
||||||
public void doClickOpenReport(OpenReportsEvent openReportsEvent) {
|
public void doClickOpenReport(OpenReportsEvent openReportsEvent) {
|
||||||
|
|
||||||
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_self", "");
|
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_self", "");
|
||||||
|
|
||||||
rpcWorkspaceService.getURLFromApplicationProfile(openReportsEvent.getSourceFileModel().getIdentifier(), new AsyncCallback<String>() {
|
rpcWorkspaceService.getURLFromApplicationProfile(openReportsEvent.getSourceFileModel().getIdentifier(), new AsyncCallback<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1574,7 +1574,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
private void doClickOpenReportTemplate(OpenReportsEvent openReportTemplateEvent) {
|
private void doClickOpenReportTemplate(OpenReportsEvent openReportTemplateEvent) {
|
||||||
|
|
||||||
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_self", "");
|
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_self", "");
|
||||||
|
|
||||||
rpcWorkspaceService.getURLFromApplicationProfile(openReportTemplateEvent.getSourceFileModel().getIdentifier(), new AsyncCallback<String>() {
|
rpcWorkspaceService.getURLFromApplicationProfile(openReportTemplateEvent.getSourceFileModel().getIdentifier(), new AsyncCallback<String>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1681,7 +1681,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
sub.addedFolder(addItemEvent.getNewFolder().getIdentifier(), addItemEvent.getFileSourceModel());
|
sub.addedFolder(addItemEvent.getNewFolder().getIdentifier(), addItemEvent.getFileSourceModel());
|
||||||
else
|
else
|
||||||
sub.addedFolder(addItemEvent.getNewFolder().getIdentifier(), addItemEvent.getParentFileModel());
|
sub.addedFolder(addItemEvent.getNewFolder().getIdentifier(), addItemEvent.getParentFileModel());
|
||||||
|
|
||||||
}else if(event instanceof SubTreeLoadedEvent){
|
}else if(event instanceof SubTreeLoadedEvent){
|
||||||
|
|
||||||
|
@ -1701,7 +1701,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}else if(event instanceof FileUploadEvent){
|
}else if(event instanceof FileUploadEvent){
|
||||||
|
|
||||||
// FileUploadEvent fileUpEvent = (FileUploadEvent) event;
|
// FileUploadEvent fileUpEvent = (FileUploadEvent) event;
|
||||||
// sub.addedFile(fileUpEvent.getParentFileModel(), "");
|
// sub.addedFile(fileUpEvent.getParentFileModel(), "");
|
||||||
|
|
||||||
} else if(event instanceof CompletedFileUploadEvent){
|
} else if(event instanceof CompletedFileUploadEvent){
|
||||||
|
@ -1746,7 +1746,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sub.createNewMessage(hashFiles);
|
sub.createNewMessage(hashFiles);
|
||||||
}else if(event instanceof FileDownloadEvent){
|
}else if(event instanceof FileDownloadEvent){
|
||||||
|
|
||||||
FileDownloadEvent messageEvent = (FileDownloadEvent) event;
|
FileDownloadEvent messageEvent = (FileDownloadEvent) event;
|
||||||
|
@ -1759,7 +1759,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}else if(event instanceof PasteItemEvent){
|
}else if(event instanceof PasteItemEvent){
|
||||||
|
|
||||||
PasteItemEvent pasteEvent = (PasteItemEvent) event;
|
PasteItemEvent pasteEvent = (PasteItemEvent) event;
|
||||||
sub.pasteEventIsCompleted(pasteEvent.isTreeRefreshable(), pasteEvent.getFolderDestinationId());
|
sub.pasteEventIsCompleted(pasteEvent.isTreeRefreshable(), pasteEvent.getFolderDestinationId());
|
||||||
|
|
||||||
}else if(event instanceof CopytemEvent){
|
}else if(event instanceof CopytemEvent){
|
||||||
|
@ -1769,11 +1769,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}else if(event instanceof TrashEvent){
|
}else if(event instanceof TrashEvent){
|
||||||
TrashEvent trashEvent = (TrashEvent) event;
|
TrashEvent trashEvent = (TrashEvent) event;
|
||||||
sub.trashEvent(trashEvent.getTrashOperation(), trashEvent.getTargetFileModels());
|
sub.trashEvent(trashEvent.getTrashOperation(), trashEvent.getTargetFileModels());
|
||||||
|
|
||||||
}else if(event instanceof UpdatedVREPermissionEvent){
|
}else if(event instanceof UpdatedVREPermissionEvent){
|
||||||
UpdatedVREPermissionEvent vreEvent = (UpdatedVREPermissionEvent) event;
|
UpdatedVREPermissionEvent vreEvent = (UpdatedVREPermissionEvent) event;
|
||||||
sub.updatedVREPermissions(vreEvent.getVreFolderId());
|
sub.updatedVREPermissions(vreEvent.getVreFolderId());
|
||||||
|
|
||||||
}else if(event instanceof UpdateWorkspaceSizeEvent){
|
}else if(event instanceof UpdateWorkspaceSizeEvent){
|
||||||
sub.updateWorksapaceSize(true);
|
sub.updateWorksapaceSize(true);
|
||||||
}
|
}
|
||||||
|
@ -1825,7 +1825,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
listParents.add(item.getParentFileModel());
|
listParents.add(item.getParentFileModel());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
listParents.add(item.getParentFileModel());
|
listParents.add(item.getParentFileModel());
|
||||||
getParents(listParents, item.getParentFileModel());
|
getParents(listParents, item.getParentFileModel());
|
||||||
}
|
}
|
||||||
|
@ -1890,7 +1890,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
this.explorerPanel.setSize(400, 600);
|
this.explorerPanel.setSize(400, 600);
|
||||||
this.explorerPanel.getAsycTreePanel().setSizeTreePanel(350, 550);
|
this.explorerPanel.getAsycTreePanel().setSizeTreePanel(350, 550);
|
||||||
|
|
||||||
// rootPanel.add(new BasicDNDExample()); //it's example of drag&drop
|
// rootPanel.add(new BasicDNDExample()); //it's example of drag&drop
|
||||||
}else
|
}else
|
||||||
this.explorerPanel = new ExplorerPanel(instancingSmartFolder,instancingMessages);
|
this.explorerPanel = new ExplorerPanel(instancingSmartFolder,instancingMessages);
|
||||||
|
|
||||||
|
@ -1902,7 +1902,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
* Use method getPanel.
|
* Use method getPanel.
|
||||||
*
|
*
|
||||||
* @return ExplorerPanel
|
* @return ExplorerPanel
|
||||||
* @deprecated
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
public ExplorerPanel getTreePanel(){
|
public ExplorerPanel getTreePanel(){
|
||||||
|
|
||||||
|
@ -1922,7 +1922,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
this.explorerPanel = getPanel();
|
this.explorerPanel = getPanel();
|
||||||
this.explorerPanel.getAsycTreePanel().setSizeTreePanel(width, height);
|
this.explorerPanel.getAsycTreePanel().setSizeTreePanel(width, height);
|
||||||
this.explorerPanel.getAsycTreePanel().setHeaderTreeVisible(false);
|
this.explorerPanel.getAsycTreePanel().setHeaderTreeVisible(false);
|
||||||
|
|
||||||
return explorerPanel.getAsycTreePanel();
|
return explorerPanel.getAsycTreePanel();
|
||||||
}
|
}
|
||||||
|
@ -1932,7 +1932,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
*/
|
*/
|
||||||
public void hideSharingFacilities() {
|
public void hideSharingFacilities() {
|
||||||
explorerPanel.getAsycTreePanel().getContextMenuTree().setHideSharing();
|
explorerPanel.getAsycTreePanel().getContextMenuTree().setHideSharing();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh root.
|
* Refresh root.
|
||||||
|
@ -1946,7 +1946,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instance only Async Tree. Select by default root items of tree.
|
* Instance only Async Tree. Select by default root items of tree.
|
||||||
* @return ExplorerPanel
|
* @return ExplorerPanel
|
||||||
*/
|
*/
|
||||||
public ExplorerPanel getPanel(){
|
public ExplorerPanel getPanel(){
|
||||||
|
@ -1971,34 +1971,34 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
loadMyLogin();
|
loadMyLogin();
|
||||||
return this.explorerPanel;
|
return this.explorerPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edi permissions.
|
* Edi permissions.
|
||||||
*
|
*
|
||||||
* @param file the file
|
* @param file the file
|
||||||
*/
|
*/
|
||||||
private void ediPermissions(final FileModel file) {
|
private void ediPermissions(final FileModel file) {
|
||||||
|
|
||||||
GWT.log("Edit Permissions on "+file);
|
GWT.log("Edit Permissions on "+file);
|
||||||
MultiDragConstants.HEADING_DIALOG = "Edit User/s permissions to: "+file.getName();
|
MultiDragConstants.HEADING_DIALOG = "Edit User/s permissions to: "+file.getName();
|
||||||
MultiDragConstants.ALL_CONTACTS_LEFT_LIST = "Shared User/s";
|
MultiDragConstants.ALL_CONTACTS_LEFT_LIST = "Shared User/s";
|
||||||
MultiDragConstants.SHARE_WITH_RIGHT_LIST = "Set permissions for User/s";
|
MultiDragConstants.SHARE_WITH_RIGHT_LIST = "Set permissions for User/s";
|
||||||
|
|
||||||
final MultiDragContactsEditPermissions multiDragContact = new MultiDragContactsEditPermissions(LOAD_CONTACTS_AS.SHARED_USER, file.getIdentifier(), true);
|
final MultiDragContactsEditPermissions multiDragContact = new MultiDragContactsEditPermissions(LOAD_CONTACTS_AS.SHARED_USER, file.getIdentifier(), true);
|
||||||
|
|
||||||
final DialogMultiDragContact multidrag = multiDragContact.getDialog();
|
final DialogMultiDragContact multidrag = multiDragContact.getDialog();
|
||||||
|
|
||||||
multidrag.setTxtHelp("Sets the permission for the user(s) dragged in the right list");
|
multidrag.setTxtHelp("Sets the permission for the user(s) dragged in the right list");
|
||||||
|
|
||||||
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(BaseEvent be) {
|
public void handleEvent(BaseEvent be) {
|
||||||
final List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> targets = multiDragContact.getTargetContacts();
|
final List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> targets = multiDragContact.getTargetContacts();
|
||||||
|
|
||||||
if(targets.size()==0){
|
if(targets.size()==0){
|
||||||
MessageBoxConfirm info = new MessageBoxConfirm("Any User/s?", "You have not selected any Users, confirm exit?");
|
MessageBoxConfirm info = new MessageBoxConfirm("Any User/s?", "You have not selected any Users, confirm exit?");
|
||||||
|
|
||||||
info.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
info.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||||
|
|
||||||
public void handleEvent(MessageBoxEvent be) {
|
public void handleEvent(MessageBoxEvent be) {
|
||||||
|
@ -2012,11 +2012,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
|
|
||||||
// GWT.log(targets.toString());
|
// GWT.log(targets.toString());
|
||||||
|
|
||||||
if(targets.size()>=1 && multiDragContact.getSelectedAcl()!=null){
|
if(targets.size()>=1 && multiDragContact.getSelectedAcl()!=null){
|
||||||
|
|
||||||
final List<String> logins = new ArrayList<String>(targets.size());
|
final List<String> logins = new ArrayList<String>(targets.size());
|
||||||
|
|
||||||
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) {
|
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) {
|
||||||
GWT.log(infoContactModel.toString());
|
GWT.log(infoContactModel.toString());
|
||||||
logins.add(infoContactModel.getLogin());
|
logins.add(infoContactModel.getLogin());
|
||||||
|
@ -2027,24 +2027,24 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(ReportAssignmentACL result) {
|
public void onSuccess(ReportAssignmentACL result) {
|
||||||
|
|
||||||
String msg = "";
|
String msg = "";
|
||||||
|
|
||||||
if(result.getErrors().size()>0){
|
if(result.getErrors().size()>0){
|
||||||
for (String error : result.getErrors()){
|
for (String error : result.getErrors()){
|
||||||
msg+="<li>"+error +";</li><br/>";
|
msg+="<li>"+error +";</li><br/>";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
new MessageBoxAlert("Warning!!", msg, null);
|
new MessageBoxAlert("Warning!!", msg, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String names = "";
|
String names = "";
|
||||||
for (String name : result.getValidLogins()) {
|
for (String name : result.getValidLogins()) {
|
||||||
// String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin();
|
// String name = infoContactModel.getName()!=null? infoContactModel.getName():infoContactModel.getLogin();
|
||||||
|
@ -2067,21 +2067,21 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}else if(clickedButton.equals(Dialog.CANCEL)){
|
}else if(clickedButton.equals(Dialog.CANCEL)){
|
||||||
multidrag.hide();
|
multidrag.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
multidrag.show();
|
multidrag.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show add administrators dialog.
|
* Show add administrators dialog.
|
||||||
*
|
*
|
||||||
|
@ -2092,19 +2092,19 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
MultiDragConstants.HEADING_DIALOG = "Edit Administrator/s to: "+file.getName();
|
MultiDragConstants.HEADING_DIALOG = "Edit Administrator/s to: "+file.getName();
|
||||||
MultiDragConstants.ALL_CONTACTS_LEFT_LIST = "All Contacts";
|
MultiDragConstants.ALL_CONTACTS_LEFT_LIST = "All Contacts";
|
||||||
MultiDragConstants.SHARE_WITH_RIGHT_LIST = "New Administrator/s";
|
MultiDragConstants.SHARE_WITH_RIGHT_LIST = "New Administrator/s";
|
||||||
|
|
||||||
final SimpleMultiDragWorkspaceContact multiDragContact = new SimpleMultiDragWorkspaceContact(LOAD_CONTACTS_AS.ADMINISTRATOR, file.getIdentifier(), true, false, true);
|
final SimpleMultiDragWorkspaceContact multiDragContact = new SimpleMultiDragWorkspaceContact(LOAD_CONTACTS_AS.ADMINISTRATOR, file.getIdentifier(), true, false, true);
|
||||||
final Dialog multidrag = multiDragContact.getDialogMultiDragContact();
|
final Dialog multidrag = multiDragContact.getDialogMultiDragContact();
|
||||||
|
|
||||||
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
multidrag.getButtonById(Dialog.OK).addListener(Events.Select, new Listener<BaseEvent>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleEvent(BaseEvent be) {
|
public void handleEvent(BaseEvent be) {
|
||||||
final List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> targets = multiDragContact.getTargetContactsWithMyLogin();
|
final List<org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel> targets = multiDragContact.getTargetContactsWithMyLogin();
|
||||||
|
|
||||||
if(targets.size()==1){
|
if(targets.size()==1){
|
||||||
MessageBoxConfirm info = new MessageBoxConfirm("Any Administrator/s?", "You have not selected any Administrator, confirm only you as Administrator and exit?");
|
MessageBoxConfirm info = new MessageBoxConfirm("Any Administrator/s?", "You have not selected any Administrator, confirm only you as Administrator and exit?");
|
||||||
|
|
||||||
info.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
info.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||||
|
|
||||||
public void handleEvent(MessageBoxEvent be) {
|
public void handleEvent(MessageBoxEvent be) {
|
||||||
|
@ -2119,21 +2119,21 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if(targets.size()>1){
|
if(targets.size()>1){
|
||||||
|
|
||||||
final List<String> logins = new ArrayList<String>(targets.size());
|
final List<String> logins = new ArrayList<String>(targets.size());
|
||||||
String names = "<ul>";
|
String names = "<ul>";
|
||||||
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) {
|
for (org.gcube.portlets.widgets.workspacesharingwidget.shared.InfoContactModel infoContactModel : targets) {
|
||||||
logins.add(infoContactModel.getLogin());
|
logins.add(infoContactModel.getLogin());
|
||||||
names+="<li><i>"+infoContactModel.getName() +";</i></li>";
|
names+="<li><i>"+infoContactModel.getName() +";</i></li>";
|
||||||
}
|
}
|
||||||
|
|
||||||
String tail = "</ul>as new ";
|
String tail = "</ul>as new ";
|
||||||
tail += logins.size()>1?"administrators":"administrator";
|
tail += logins.size()>1?"administrators":"administrator";
|
||||||
tail+= ", confirm?";
|
tail+= ", confirm?";
|
||||||
MessageBoxConfirm confirm = new MessageBoxConfirm("Setting new Administrator/s?", "You have selected: <br/>"+names +tail);
|
MessageBoxConfirm confirm = new MessageBoxConfirm("Setting new Administrator/s?", "You have selected: <br/>"+names +tail);
|
||||||
|
|
||||||
confirm.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
confirm.getMessageBoxConfirm().addCallback(new Listener<MessageBoxEvent>() {
|
||||||
|
|
||||||
public void handleEvent(MessageBoxEvent be) {
|
public void handleEvent(MessageBoxEvent be) {
|
||||||
|
@ -2147,7 +2147,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
if(clickedButton.equals(Dialog.CANCEL)){
|
if(clickedButton.equals(Dialog.CANCEL)){
|
||||||
multidrag.hide();
|
multidrag.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2155,11 +2155,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
multidrag.show();
|
multidrag.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Do add administrator to folder id.
|
* Do add administrator to folder id.
|
||||||
*
|
*
|
||||||
|
@ -2167,7 +2167,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
* @param logins the logins
|
* @param logins the logins
|
||||||
*/
|
*/
|
||||||
private void doAddAdministratorToFolderId(final FileModel file, final List<String> logins) {
|
private void doAddAdministratorToFolderId(final FileModel file, final List<String> logins) {
|
||||||
|
|
||||||
rpcWorkspaceService.addAdministratorsByFolderId(file.getIdentifier(), logins, new AsyncCallback<Boolean>() {
|
rpcWorkspaceService.addAdministratorsByFolderId(file.getIdentifier(), logins, new AsyncCallback<Boolean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2179,11 +2179,11 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
public void onSuccess(Boolean arg0) {
|
public void onSuccess(Boolean arg0) {
|
||||||
String msg = "Updating administrator/s completed successfully";
|
String msg = "Updating administrator/s completed successfully";
|
||||||
MessageBox.info("Operation completed", msg, null);
|
MessageBox.info("Operation completed", msg, null);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the acl to folder id.
|
* Sets the acl to folder id.
|
||||||
*
|
*
|
||||||
|
@ -2192,13 +2192,13 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
* @param aclTypeID the acl type id
|
* @param aclTypeID the acl type id
|
||||||
*/
|
*/
|
||||||
private void setACLToFolderId(final String folderId, final List<String> logins, String aclTypeID) {
|
private void setACLToFolderId(final String folderId, final List<String> logins, String aclTypeID) {
|
||||||
|
|
||||||
rpcWorkspaceService.setACLs(folderId, logins, aclTypeID, new AsyncCallback<Void>() {
|
rpcWorkspaceService.setACLs(folderId, logins, aclTypeID, new AsyncCallback<Void>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
new MessageBoxAlert("Error", caught.getMessage(), null);
|
new MessageBoxAlert("Error", caught.getMessage(), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2208,26 +2208,26 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Load my login.
|
* Load my login.
|
||||||
*/
|
*/
|
||||||
private void loadMyLogin(){
|
private void loadMyLogin(){
|
||||||
|
|
||||||
rpcWorkspaceService.getMyLogin(new AsyncCallback<UserBean>() {
|
rpcWorkspaceService.getMyLogin(new AsyncCallback<UserBean>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Throwable caught) {
|
public void onFailure(Throwable caught) {
|
||||||
GWT.log("Error on loading my login is empty");
|
GWT.log("Error on loading my login is empty");
|
||||||
myLogin = "";
|
myLogin = "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(UserBean user) {
|
public void onSuccess(UserBean user) {
|
||||||
GWT.log("My login is: "+user.getUsername());
|
GWT.log("My login is: "+user.getUsername());
|
||||||
myLogin = user.getUsername();
|
myLogin = user.getUsername();
|
||||||
myLoginFirstName = user.getFirstName();
|
myLoginFirstName = user.getFirstName();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -2293,7 +2293,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
}
|
}
|
||||||
|
|
||||||
ArrayList<FileModel> pathParentsList = (ArrayList<FileModel>) getListParentsByIdentifierFromTree(itemIdentifier);
|
ArrayList<FileModel> pathParentsList = (ArrayList<FileModel>) getListParentsByIdentifierFromTree(itemIdentifier);
|
||||||
|
|
||||||
selectItemInTree(itemIdentifier);
|
selectItemInTree(itemIdentifier);
|
||||||
explorerPanel.getAsycTreePanel().setSubTreeLoaded(false);
|
explorerPanel.getAsycTreePanel().setSubTreeLoaded(false);
|
||||||
explorerPanel.getAsycTreePanel().unmask();
|
explorerPanel.getAsycTreePanel().unmask();
|
||||||
|
@ -2330,7 +2330,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
FileModel item = this.explorerPanel.getAsycTreePanel().getFileModelByIdentifier(itemIdentifier);
|
FileModel item = this.explorerPanel.getAsycTreePanel().getFileModelByIdentifier(itemIdentifier);
|
||||||
|
|
||||||
if(item==null){
|
if(item==null){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
|
@ -2377,7 +2377,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean addFile(String itemIdentifier, String name, String parentIdentifier) {
|
public boolean addFile(String itemIdentifier, String name, String parentIdentifier) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2421,7 +2421,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
if(fileModel.isDirectory())
|
if(fileModel.isDirectory())
|
||||||
return fileModel;
|
return fileModel;
|
||||||
else
|
else
|
||||||
return fileModel.getParentFileModel();
|
return fileModel.getParentFileModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
@ -2489,7 +2489,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
windowOpenParam.getBrowserWindow().setUrl(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+params);
|
windowOpenParam.getBrowserWindow().setUrl(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+params);
|
||||||
|
|
||||||
|
|
||||||
// com.google.gwt.user.client.Window.open(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+params, windowOpenParam.getOption(), "");
|
// com.google.gwt.user.client.Window.open(ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE+params, windowOpenParam.getOption(), "");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2534,10 +2534,10 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
|
||||||
|
|
||||||
if(fileModel==null)
|
if(fileModel==null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
GWT.log("do click url");
|
GWT.log("do click url");
|
||||||
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_blank", "");
|
final NewBrowserWindow newBrowserWindow = NewBrowserWindow.open("", "_blank", "");
|
||||||
|
|
||||||
rpcWorkspaceService.getUrlById(fileModel.getIdentifier(), fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.URL_DOCUMENT), false, new AsyncCallback<GWTWorkspaceItem>() {
|
rpcWorkspaceService.getUrlById(fileModel.getIdentifier(), fileModel.getGXTFolderItemType().equals(GXTFolderItemTypeEnum.URL_DOCUMENT), false, new AsyncCallback<GWTWorkspaceItem>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2339,38 +2339,6 @@ public class GWTWorkspaceServiceImpl extends RemoteServiceServlet implements GWT
|
||||||
|
|
||||||
if(wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
if(wsItem.getType().equals(WorkspaceItemType.FOLDER_ITEM)){
|
||||||
|
|
||||||
/*FolderItem folderItem = (FolderItem) wsItem;
|
|
||||||
String storageID = builder.getStorageIDForFolderItem(folderItem);
|
|
||||||
|
|
||||||
if(storageID==null || storageID.isEmpty())
|
|
||||||
throw new Exception("Sorry, public link on "+wsItem.getName() +" is not available");
|
|
||||||
|
|
||||||
UriResolverReaderParameterForResolverIndex uriResolver = getUriResolver();
|
|
||||||
String uriRequest = "";
|
|
||||||
|
|
||||||
if(uriResolver!=null && uriResolver.isAvailable()){
|
|
||||||
|
|
||||||
// String itemName = StringUtil.removeSpecialCharacters(folderItem.getName());
|
|
||||||
// itemName = StringUtil.replaceAllWhiteSpace(itemName, "_");
|
|
||||||
// uriRequest = uriResolver.resolveAsUriRequest(storageID, itemName, folderItem.getMimeType(), true);
|
|
||||||
|
|
||||||
uriRequest = uriResolver.resolveAsStorageIdRequest(storageID, true);
|
|
||||||
|
|
||||||
|
|
||||||
//VALIDATE CONNECTION
|
|
||||||
// if(!HttpRequestUtil.urlExists(uriRequest+"&validation=true"))
|
|
||||||
// throw new Exception("Sorry, The Public Link for selected file is unavailable");
|
|
||||||
|
|
||||||
String shortURL = null;
|
|
||||||
|
|
||||||
if(shortenUrl)
|
|
||||||
shortURL = getShortUrl(uriRequest);
|
|
||||||
|
|
||||||
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// throw new Exception("Sorry, The Uri resolver service is temporarily unavailable. Please try again later");*/
|
|
||||||
|
|
||||||
FolderItem folderItem = (FolderItem) wsItem;
|
FolderItem folderItem = (FolderItem) wsItem;
|
||||||
String uriRequest = folderItem.getPublicLink(false);
|
String uriRequest = folderItem.getPublicLink(false);
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.user.workspace.server.shortener;
|
package org.gcube.portlets.user.workspace.server.shortener;
|
||||||
|
|
||||||
|
@ -31,111 +31,112 @@ import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public final class UrlShortener {
|
public final class UrlShortener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected static final String NO_HTTP_URL_SHORTENER_AVAILABLE = "No HTTP URL Shortener available";
|
protected static final String NO_HTTP_URL_SHORTENER_AVAILABLE = "No HTTP URL Shortener available";
|
||||||
protected static final String APPLICATION_JSON = "application/json";
|
protected static final String APPLICATION_JSON = "application/json";
|
||||||
protected static final String LONG_URL = "longUrl";
|
protected static final String LONG_URL = "longUrl";
|
||||||
|
|
||||||
// protected static String shortnerServerUrl = "https://www.googleapis.com/urlshortener/v1/url";
|
// protected static String shortnerServerUrl = "https://www.googleapis.com/urlshortener/v1/url";
|
||||||
// protected static String urlMethod = "";
|
// protected static String urlMethod = "";
|
||||||
// protected static String authenticationKeyParam = "key";
|
// protected static String authenticationKeyParam = "key";
|
||||||
// protected static String authenticationKeyValue ="AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
// protected static String authenticationKeyValue ="AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
||||||
|
|
||||||
private static String shortnerServerUrl = "";
|
private static String shortnerServerUrl = "";
|
||||||
protected static final String KEY = "key";
|
protected static final String KEY = "key";
|
||||||
private static String paramKeyValue ="";
|
private static String paramKeyValue ="";
|
||||||
|
|
||||||
protected static Logger logger = Logger.getLogger(UrlShortener.class);
|
protected static Logger logger = Logger.getLogger(UrlShortener.class);
|
||||||
private String uriRequest;
|
private String uriRequest;
|
||||||
private boolean isAvailable = false;
|
private boolean isAvailable = false;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws InvalidResultException
|
* @throws InvalidResultException
|
||||||
* @throws DiscoveryException
|
* @throws DiscoveryException
|
||||||
* @throws IllegalStateException *
|
* @throws IllegalStateException *
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public UrlShortener(String scope) throws Exception {
|
public UrlShortener(String scope) throws Exception {
|
||||||
|
|
||||||
try{
|
try{
|
||||||
logger.trace("Tentative reading HTTP-URL-Shortener RR");
|
logger.trace("Tentative reading HTTP-URL-Shortener RR");
|
||||||
|
|
||||||
ScopeUtilFilter scopeUtil = new ScopeUtilFilter(scope,true);
|
ScopeUtilFilter scopeUtil = new ScopeUtilFilter(scope,true);
|
||||||
|
|
||||||
ScopeProvider.instance.set(scopeUtil.getScopeRoot());
|
ScopeProvider.instance.set(scopeUtil.getScopeRoot());
|
||||||
|
|
||||||
XQuery query = queryFor(ServiceEndpoint.class);
|
XQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URL-Shortener'").setResult("$resource/Profile/AccessPoint");
|
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URL-Shortener'").setResult("$resource/Profile/AccessPoint");
|
||||||
|
|
||||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||||
|
|
||||||
List<AccessPoint> endpoints = client.submit(query);
|
List<AccessPoint> endpoints = client.submit(query);
|
||||||
|
|
||||||
if (endpoints.size() == 0){
|
if (endpoints.size() == 0){
|
||||||
isAvailable = false;
|
isAvailable = false;
|
||||||
logger.trace("HTTP-URL-Shortener not found");
|
logger.trace("HTTP-URL-Shortener not found");
|
||||||
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Base Address
|
//Base Address
|
||||||
// System.out.println(endpoints.get(0).address());
|
// System.out.println(endpoints.get(0).address());
|
||||||
|
|
||||||
shortnerServerUrl = endpoints.get(0)!=null?endpoints.get(0).address():"";
|
shortnerServerUrl = endpoints.get(0)!=null?endpoints.get(0).address():"";
|
||||||
|
|
||||||
if(endpoints.get(0)!=null){
|
if(endpoints.get(0)!=null){
|
||||||
|
|
||||||
paramKeyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():"";
|
paramKeyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():"";
|
||||||
}
|
}
|
||||||
|
|
||||||
String getParam = "";
|
String getParam = "";
|
||||||
|
logger.trace("paramKeyValue: "+paramKeyValue);
|
||||||
|
|
||||||
//ACTIVE THIS AFTER RELEASE
|
//ACTIVE THIS AFTER RELEASE
|
||||||
if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
||||||
getParam = "?"+KEY +"="+paramKeyValue;
|
getParam = "?"+KEY +"="+paramKeyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
uriRequest = shortnerServerUrl+getParam;
|
uriRequest = shortnerServerUrl+getParam;
|
||||||
|
|
||||||
logger.trace("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
logger.trace("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
||||||
|
|
||||||
//DEBUG
|
//DEBUG
|
||||||
// System.out.println("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
// System.out.println("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
||||||
|
|
||||||
isAvailable = true;
|
isAvailable = true;
|
||||||
|
|
||||||
}catch (Exception e) {
|
}catch (Exception e) {
|
||||||
isAvailable = false;
|
isAvailable = false;
|
||||||
logger.error("an error occurred in reading RR: ", e);
|
logger.error("an error occurred in reading RR: ", e);
|
||||||
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return isAvailable;
|
return isAvailable;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param longUrl
|
* @param longUrl
|
||||||
* @return a shorten url
|
* @return a shorten url
|
||||||
*/
|
*/
|
||||||
public String shorten(String longUrl) throws Exception{
|
public String shorten(String longUrl) throws Exception{
|
||||||
|
|
||||||
if (longUrl == null) {
|
if (longUrl == null) {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
logger.trace("shorten longUrl: "+longUrl);
|
logger.trace("shorten longUrl: "+longUrl);
|
||||||
|
|
||||||
URL url = new URL(uriRequest);
|
URL url = new URL(uriRequest);
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
@ -145,42 +146,42 @@ public final class UrlShortener {
|
||||||
|
|
||||||
JSONObject jsonObj = new JSONObject();
|
JSONObject jsonObj = new JSONObject();
|
||||||
jsonObj.put(LONG_URL, longUrl);
|
jsonObj.put(LONG_URL, longUrl);
|
||||||
|
|
||||||
// //ACTIVE THIS AFTER RELEASE
|
// //ACTIVE THIS AFTER RELEASE
|
||||||
// if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
// if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
||||||
// jsonObj.put(KEY, paramKeyValue);
|
// jsonObj.put(KEY, paramKeyValue);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
logger.trace("request json : "+jsonObj.toString());
|
logger.trace("request json : "+jsonObj.toString());
|
||||||
|
|
||||||
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
||||||
wr.write(jsonObj.toString());
|
wr.write(jsonObj.toString());
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
JSONTokener tokener = new JSONTokener(rd);
|
JSONTokener tokener = new JSONTokener(rd);
|
||||||
JSONObject jsonObject = new JSONObject(tokener);
|
JSONObject jsonObject = new JSONObject(tokener);
|
||||||
// JSONParser parser = new JSONParser();
|
// JSONParser parser = new JSONParser();
|
||||||
// JSONObject jsonObject = (JSONObject) parser.parse(rd);
|
// JSONObject jsonObject = (JSONObject) parser.parse(rd);
|
||||||
logger.trace("response received json : "+jsonObject.toString());
|
logger.trace("response received json : "+jsonObject.toString());
|
||||||
|
|
||||||
wr.close();
|
wr.close();
|
||||||
rd.close();
|
rd.close();
|
||||||
return (String) jsonObject.get("id"); //is shorted url
|
return (String) jsonObject.get("id"); //is shorted url
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
logger.error("MalformedURLException error in UrlShortener", e);
|
logger.error("MalformedURLException error in UrlShortener", e);
|
||||||
return longUrl;
|
return longUrl;
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
logger.error("IOException error in UrlShortener", e);
|
logger.error("IOException error in UrlShortener", e);
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getShortnerServerUrl() {
|
public static String getShortnerServerUrl() {
|
||||||
return shortnerServerUrl;
|
return shortnerServerUrl;
|
||||||
}
|
}
|
||||||
|
@ -196,24 +197,6 @@ public final class UrlShortener {
|
||||||
public String getUriRequest() {
|
public String getUriRequest() {
|
||||||
return uriRequest;
|
return uriRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String shorten;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
UrlShortener urlSh = new UrlShortener("/d4science.research-infrastructures.eu");
|
|
||||||
System.out.println("UrlShortener: "+urlSh);
|
|
||||||
|
|
||||||
shorten = urlSh.shorten("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=056648-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder");
|
|
||||||
|
|
||||||
System.out.println("Shorted: "+shorten);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
|
@ -225,5 +208,23 @@ public final class UrlShortener {
|
||||||
builder.append("]");
|
builder.append("]");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String shorten;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
UrlShortener urlSh = new UrlShortener("/d4science.research-infrastructures.eu");
|
||||||
|
System.out.println("UrlShortener: "+urlSh);
|
||||||
|
|
||||||
|
shorten = urlSh.shorten("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=056648-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder");
|
||||||
|
|
||||||
|
System.out.println("Shorted: "+shorten);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.user.workspace;
|
package org.gcube.portlets.user.workspace;
|
||||||
|
|
||||||
|
@ -16,50 +16,58 @@ import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONTokener;
|
import org.json.JSONTokener;
|
||||||
|
|
||||||
|
|
||||||
public final class GoogleUrlShortener {
|
public final class GoogleUrlShortener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected static final String APPLICATION_JSON = "application/json";
|
protected static final String APPLICATION_JSON = "application/json";
|
||||||
protected static final String LONG_URL = "longUrl";
|
protected static final String LONG_URL = "longUrl";
|
||||||
|
|
||||||
static String shortnerServerUrl = "https://www.googleapis.com/urlshortener/v1/url";
|
static String shortnerServerUrl = "https://www.googleapis.com/urlshortener/v1/url";
|
||||||
|
|
||||||
static String urlMethod = "";
|
static String urlMethod = "";
|
||||||
static String authenticationKeyValue ="AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
// static String authenticationKeyValue ="AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
||||||
|
static String authenticationKeyValue ="AIzaSyCQSY7UU3xiBqqlzU5ovr-efs6EXKz5e7Y";
|
||||||
|
|
||||||
|
|
||||||
static String authenticationKeyParam = "key";
|
static String authenticationKeyParam = "key";
|
||||||
|
|
||||||
// static String shortUrl = "https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=062c558c-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder";
|
// static String shortUrl = "https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=062c558c-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String shorten(String longUrl) throws Exception {
|
public static String shorten(String longUrl) throws Exception {
|
||||||
|
|
||||||
if (longUrl == null) {
|
if (longUrl == null) {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
URL url = new URL(shortnerServerUrl);
|
URL url = new URL(shortnerServerUrl);
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setRequestMethod("POST");
|
connection.setRequestMethod("POST");
|
||||||
connection.setRequestProperty("Content-Type", APPLICATION_JSON);
|
connection.setRequestProperty("Content-Type", APPLICATION_JSON);
|
||||||
|
|
||||||
JSONObject jsonObj = new JSONObject();
|
JSONObject jsonObj = new JSONObject();
|
||||||
|
|
||||||
|
String decrypt = StringEncrypter.getEncrypter().decrypt(authenticationKeyValue);
|
||||||
|
System.out.println(decrypt);
|
||||||
|
|
||||||
jsonObj.put(LONG_URL, longUrl);
|
jsonObj.put(LONG_URL, longUrl);
|
||||||
jsonObj.put(authenticationKeyParam, authenticationKeyValue);
|
jsonObj.put(authenticationKeyParam, authenticationKeyValue);
|
||||||
|
|
||||||
System.out.println("sending request json : "+jsonObj.toString());
|
System.out.println("sending request json : "+jsonObj.toString());
|
||||||
|
|
||||||
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
||||||
wr.write(jsonObj.toString());
|
wr.write(jsonObj.toString());
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
@ -70,13 +78,13 @@ public final class GoogleUrlShortener {
|
||||||
JSONObject jsonObject = new JSONObject(tokener);
|
JSONObject jsonObject = new JSONObject(tokener);
|
||||||
|
|
||||||
System.out.println("response received json : "+jsonObject.toString());
|
System.out.println("response received json : "+jsonObject.toString());
|
||||||
|
|
||||||
wr.close();
|
wr.close();
|
||||||
rd.close();
|
rd.close();
|
||||||
return (String) jsonObject.get("id"); //is shorted url
|
return (String) jsonObject.get("id"); //is shorted url
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return longUrl;
|
return longUrl;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -84,30 +92,36 @@ public final class GoogleUrlShortener {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String shorten4(String longUrl) throws Exception {
|
public static String shorten4(String longUrl) throws Exception {
|
||||||
|
|
||||||
if (longUrl == null) {
|
if (longUrl == null) {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
JSONObject jsonObj = new JSONObject();
|
JSONObject jsonObj = new JSONObject();
|
||||||
|
|
||||||
jsonObj.put(LONG_URL, longUrl);
|
jsonObj.put(LONG_URL, longUrl);
|
||||||
|
|
||||||
|
ScopeProvider.instance.set("/gcube");
|
||||||
|
|
||||||
|
String decrypt = StringEncrypter.getEncrypter().decrypt(authenticationKeyValue);
|
||||||
|
System.out.println(decrypt);
|
||||||
|
|
||||||
jsonObj.put(authenticationKeyParam, authenticationKeyValue);
|
jsonObj.put(authenticationKeyParam, authenticationKeyValue);
|
||||||
String body = jsonObj.toString();
|
String body = jsonObj.toString();
|
||||||
|
|
||||||
HttpCallerUtil httpCaller = new HttpCallerUtil(shortnerServerUrl, "", "");
|
HttpCallerUtil httpCaller = new HttpCallerUtil(shortnerServerUrl, "", "");
|
||||||
|
|
||||||
String json = httpCaller.callPost("", body, APPLICATION_JSON);
|
String json = httpCaller.callPost("", body, APPLICATION_JSON);
|
||||||
|
|
||||||
System.out.println("json: "+json);
|
System.out.println("json: "+json);
|
||||||
|
|
||||||
|
|
||||||
JSONTokener tokener = new JSONTokener(json);
|
JSONTokener tokener = new JSONTokener(json);
|
||||||
JSONObject jsonObject = new JSONObject(tokener);
|
JSONObject jsonObject = new JSONObject(tokener);
|
||||||
|
|
||||||
|
@ -116,7 +130,7 @@ public final class GoogleUrlShortener {
|
||||||
return (String) jsonObject.get("id"); //is shorted url
|
return (String) jsonObject.get("id"); //is shorted url
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return longUrl;
|
return longUrl;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -124,48 +138,48 @@ public final class GoogleUrlShortener {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static String shorten3(String longUrl) throws Exception {
|
public static String shorten3(String longUrl) throws Exception {
|
||||||
|
|
||||||
if (longUrl == null) {
|
if (longUrl == null) {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
HttpCallerUtil httpCaller = new HttpCallerUtil(shortnerServerUrl, "", "");
|
HttpCallerUtil httpCaller = new HttpCallerUtil(shortnerServerUrl, "", "");
|
||||||
|
|
||||||
// Map<String, String> parameters = new HashMap<String, String>();
|
// Map<String, String> parameters = new HashMap<String, String>();
|
||||||
//
|
//
|
||||||
// parameters.put("shortUrl", longUrl);
|
// parameters.put("shortUrl", longUrl);
|
||||||
// parameters.put("key", authenticationKey);
|
// parameters.put("key", authenticationKey);
|
||||||
|
|
||||||
|
|
||||||
// String json = httpCaller.callGet(ulrMethod, parameters);
|
// String json = httpCaller.callGet(ulrMethod, parameters);
|
||||||
|
|
||||||
String body = "{\"longUrl\":\"" + longUrl + "\", \"key\":\"" + authenticationKeyValue + "\"}";
|
String body = "{\"longUrl\":\"" + longUrl + "\", \"key\":\"" + authenticationKeyValue + "\"}";
|
||||||
|
|
||||||
urlMethod += authenticationKeyParam +"="+authenticationKeyValue;
|
urlMethod += authenticationKeyParam +"="+authenticationKeyValue;
|
||||||
|
|
||||||
String json = httpCaller.callPost("", body, APPLICATION_JSON);
|
String json = httpCaller.callPost("", body, APPLICATION_JSON);
|
||||||
|
|
||||||
System.out.println("json: "+json);
|
System.out.println("json: "+json);
|
||||||
|
|
||||||
|
|
||||||
// return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
// return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
|
|
||||||
// httpCaller.callGet(urlMethod, parameters);
|
// httpCaller.callGet(urlMethod, parameters);
|
||||||
|
|
||||||
// return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
// return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return longUrl;
|
return longUrl;
|
||||||
|
@ -174,11 +188,11 @@ public final class GoogleUrlShortener {
|
||||||
return longUrl;
|
return longUrl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String googUrl = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
private static String googUrl = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
||||||
|
|
||||||
|
|
||||||
public static String shorten2(String longUrl)
|
public static String shorten2(String longUrl)
|
||||||
{
|
{
|
||||||
String shortUrl = "";
|
String shortUrl = "";
|
||||||
|
@ -193,7 +207,7 @@ public final class GoogleUrlShortener {
|
||||||
wr.write("{\"longUrl\":\"" + longUrl + "\"}");
|
wr.write("{\"longUrl\":\"" + longUrl + "\"}");
|
||||||
wr.flush();
|
wr.flush();
|
||||||
|
|
||||||
|
|
||||||
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
String line = null;
|
String line = null;
|
||||||
|
@ -202,11 +216,11 @@ public final class GoogleUrlShortener {
|
||||||
}
|
}
|
||||||
String json = sb.toString();
|
String json = sb.toString();
|
||||||
System.out.println("json: "+json);
|
System.out.println("json: "+json);
|
||||||
|
|
||||||
wr.close();
|
wr.close();
|
||||||
rd.close();
|
rd.close();
|
||||||
return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
return json.substring(json.indexOf("http"), json.indexOf("\"", json.indexOf("http")));
|
||||||
|
|
||||||
// Get the response
|
// Get the response
|
||||||
// BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
// BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
// String line;
|
// String line;
|
||||||
|
@ -221,7 +235,7 @@ public final class GoogleUrlShortener {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (MalformedURLException ex)
|
catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
|
@ -235,21 +249,21 @@ public final class GoogleUrlShortener {
|
||||||
return shortUrl;
|
return shortUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String shorten;
|
String shorten;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
shorten = GoogleUrlShortener.shorten4("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=062c558c-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder");
|
shorten = GoogleUrlShortener.shorten4("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=062c558c-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder");
|
||||||
|
|
||||||
System.out.println("Shorted: "+shorten);
|
System.out.println("Shorted: "+shorten);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,230 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.gcube.portlets.user.workspace;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
|
||||||
|
* @Jun 28, 2013
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||||
|
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
|
import org.gcube.common.scope.api.ScopeProvider;
|
||||||
|
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter;
|
||||||
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.json.JSONTokener;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public final class UrlShortener {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected static final String NO_HTTP_URL_SHORTENER_AVAILABLE = "No HTTP URL Shortener available";
|
||||||
|
protected static final String APPLICATION_JSON = "application/json";
|
||||||
|
protected static final String LONG_URL = "longUrl";
|
||||||
|
|
||||||
|
// protected static String shortnerServerUrl = "https://www.googleapis.com/urlshortener/v1/url";
|
||||||
|
// protected static String urlMethod = "";
|
||||||
|
// protected static String authenticationKeyParam = "key";
|
||||||
|
// protected static String authenticationKeyValue ="AIzaSyDfMO0VY3o8GjRUqnTfqScjm_EsFEuBa3g";
|
||||||
|
|
||||||
|
private static String shortnerServerUrl = "";
|
||||||
|
protected static final String KEY = "key";
|
||||||
|
private static String paramKeyValue ="";
|
||||||
|
|
||||||
|
protected static Logger logger = Logger.getLogger(UrlShortener.class);
|
||||||
|
private String uriRequest;
|
||||||
|
private boolean isAvailable = false;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @throws Exception
|
||||||
|
* @throws InvalidResultException
|
||||||
|
* @throws DiscoveryException
|
||||||
|
* @throws IllegalStateException *
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public UrlShortener(String scope) throws Exception {
|
||||||
|
|
||||||
|
try{
|
||||||
|
logger.trace("Tentative reading HTTP-URL-Shortener RR");
|
||||||
|
|
||||||
|
ScopeUtilFilter scopeUtil = new ScopeUtilFilter(scope,true);
|
||||||
|
|
||||||
|
ScopeProvider.instance.set(scopeUtil.getScopeRoot());
|
||||||
|
|
||||||
|
XQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
|
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URL-Shortener'").setResult("$resource/Profile/AccessPoint");
|
||||||
|
|
||||||
|
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||||
|
|
||||||
|
List<AccessPoint> endpoints = client.submit(query);
|
||||||
|
|
||||||
|
if (endpoints.size() == 0){
|
||||||
|
isAvailable = false;
|
||||||
|
logger.trace("HTTP-URL-Shortener not found");
|
||||||
|
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Base Address
|
||||||
|
// System.out.println(endpoints.get(0).address());
|
||||||
|
|
||||||
|
shortnerServerUrl = endpoints.get(0)!=null?endpoints.get(0).address():"";
|
||||||
|
|
||||||
|
if(endpoints.get(0)!=null){
|
||||||
|
|
||||||
|
paramKeyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():"";
|
||||||
|
}
|
||||||
|
|
||||||
|
String getParam = "";
|
||||||
|
logger.trace("paramKeyValue: "+paramKeyValue);
|
||||||
|
|
||||||
|
//ACTIVE THIS AFTER RELEASE
|
||||||
|
if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
||||||
|
getParam = "?"+KEY +"="+paramKeyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
uriRequest = shortnerServerUrl+getParam;
|
||||||
|
|
||||||
|
logger.trace("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
||||||
|
|
||||||
|
//DEBUG
|
||||||
|
// System.out.println("HTTP-URL-Shortener found, uriRequest: "+uriRequest);
|
||||||
|
|
||||||
|
isAvailable = true;
|
||||||
|
|
||||||
|
}catch (Exception e) {
|
||||||
|
isAvailable = false;
|
||||||
|
logger.error("an error occurred in reading RR: ", e);
|
||||||
|
throw new Exception(NO_HTTP_URL_SHORTENER_AVAILABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAvailable() {
|
||||||
|
return isAvailable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param longUrl
|
||||||
|
* @return a shorten url
|
||||||
|
*/
|
||||||
|
public String shorten(String longUrl) throws Exception{
|
||||||
|
|
||||||
|
if (longUrl == null) {
|
||||||
|
return longUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
logger.trace("shorten longUrl: "+longUrl);
|
||||||
|
|
||||||
|
URL url = new URL(uriRequest);
|
||||||
|
|
||||||
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setRequestMethod("POST");
|
||||||
|
connection.setRequestProperty("Content-Type", APPLICATION_JSON);
|
||||||
|
|
||||||
|
JSONObject jsonObj = new JSONObject();
|
||||||
|
jsonObj.put(LONG_URL, longUrl);
|
||||||
|
|
||||||
|
// //ACTIVE THIS AFTER RELEASE
|
||||||
|
// if(paramKeyValue!=null && !paramKeyValue.isEmpty()){
|
||||||
|
// jsonObj.put(KEY, paramKeyValue);
|
||||||
|
// }
|
||||||
|
|
||||||
|
logger.trace("request json : "+jsonObj.toString());
|
||||||
|
|
||||||
|
OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
|
||||||
|
wr.write(jsonObj.toString());
|
||||||
|
wr.flush();
|
||||||
|
|
||||||
|
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
|
||||||
|
JSONTokener tokener = new JSONTokener(rd);
|
||||||
|
JSONObject jsonObject = new JSONObject(tokener);
|
||||||
|
// JSONParser parser = new JSONParser();
|
||||||
|
// JSONObject jsonObject = (JSONObject) parser.parse(rd);
|
||||||
|
logger.trace("response received json : "+jsonObject.toString());
|
||||||
|
|
||||||
|
wr.close();
|
||||||
|
rd.close();
|
||||||
|
return (String) jsonObject.get("id"); //is shorted url
|
||||||
|
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
|
||||||
|
logger.error("MalformedURLException error in UrlShortener", e);
|
||||||
|
return longUrl;
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
logger.error("IOException error in UrlShortener", e);
|
||||||
|
return longUrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getShortnerServerUrl() {
|
||||||
|
return shortnerServerUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getKey() {
|
||||||
|
return KEY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getParamKeyValue() {
|
||||||
|
return paramKeyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUriRequest() {
|
||||||
|
return uriRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append("UrlShortener [uriRequest=");
|
||||||
|
builder.append(uriRequest);
|
||||||
|
builder.append(", isAvailable=");
|
||||||
|
builder.append(isAvailable);
|
||||||
|
builder.append("]");
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
String shorten;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
UrlShortener urlSh = new UrlShortener("/d4science.research-infrastructures.eu");
|
||||||
|
System.out.println("UrlShortener: "+urlSh);
|
||||||
|
|
||||||
|
shorten = urlSh.shorten("https://dev.d4science.org/group/data-e-infrastructure-gateway/workspace?itemid=056648-c7ce-4de3-a4c7-e1411816cc12&operation=gotofolder");
|
||||||
|
|
||||||
|
System.out.println("Shorted: "+shorten);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.gcube.portlets.user.workspace;
|
package org.gcube.portlets.user.workspace;
|
||||||
|
|
||||||
|
@ -21,62 +21,63 @@ import org.gcube.resources.discovery.client.queries.impl.XQuery;
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class UrlShortenerReaderRR {
|
public class UrlShortenerReaderRR {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
protected static final String KEY = "key";
|
protected static final String KEY = "key";
|
||||||
|
|
||||||
//Base Address
|
//Base Address
|
||||||
protected String uri = "";
|
protected String uri = "";
|
||||||
|
|
||||||
//Query URL parameter
|
//Query URL parameter
|
||||||
protected String keyValue = "";
|
protected String keyValue = "";
|
||||||
|
|
||||||
private String uriRequest = "";
|
private String uriRequest = "";
|
||||||
|
|
||||||
public static Logger log = Logger.getLogger(UrlShortenerReaderRR.class);
|
public static Logger log = Logger.getLogger(UrlShortenerReaderRR.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public UrlShortenerReaderRR() throws Exception {
|
public UrlShortenerReaderRR() throws Exception {
|
||||||
|
|
||||||
ScopeProvider.instance.set("/gcube");
|
ScopeProvider.instance.set("/gcube");
|
||||||
|
|
||||||
XQuery query = queryFor(ServiceEndpoint.class);
|
XQuery query = queryFor(ServiceEndpoint.class);
|
||||||
|
|
||||||
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URL-Shortener'").setResult("$resource/Profile/AccessPoint");
|
query.addCondition("$resource/Profile/Name/text() eq 'HTTP-URL-Shortener'").setResult("$resource/Profile/AccessPoint");
|
||||||
|
|
||||||
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
DiscoveryClient<AccessPoint> client = clientFor(AccessPoint.class);
|
||||||
|
|
||||||
List<AccessPoint> endpoints = client.submit(query);
|
List<AccessPoint> endpoints = client.submit(query);
|
||||||
|
|
||||||
if (endpoints.size() == 0)
|
if (endpoints.size() == 0)
|
||||||
throw new Exception("No Shortener available");
|
throw new Exception("No Shortener available");
|
||||||
|
|
||||||
//Base Address
|
//Base Address
|
||||||
// System.out.println(endpoints.get(0).address());
|
// System.out.println(endpoints.get(0).address());
|
||||||
|
|
||||||
uri = endpoints.get(0)!=null?endpoints.get(0).address():"";
|
uri = endpoints.get(0)!=null?endpoints.get(0).address():"";
|
||||||
|
|
||||||
if(endpoints.get(0)!=null){
|
if(endpoints.get(0)!=null){
|
||||||
|
|
||||||
keyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():"";
|
keyValue = endpoints.get(0).propertyMap()!=null?endpoints.get(0).propertyMap().get(KEY).value():"";
|
||||||
}
|
}
|
||||||
|
|
||||||
uriRequest = uri+"?"+KEY+"="+keyValue;
|
uriRequest = uri+"?"+KEY+"="+keyValue;
|
||||||
|
|
||||||
|
System.out.println(uriRequest);
|
||||||
|
|
||||||
//Query URL parameter
|
//Query URL parameter
|
||||||
// System.out.println(endpoints.get(0).propertyMap().get("parameter").value());
|
// System.out.println(endpoints.get(0).propertyMap().get("parameter").value());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return Base Address of Uri Resolver
|
* @return Base Address of Uri Resolver
|
||||||
*/
|
*/
|
||||||
public String getUri() {
|
public String getUri() {
|
||||||
|
@ -85,15 +86,15 @@ public class UrlShortenerReaderRR {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return Query URL parameter of Uri Resolver
|
* @return Query URL parameter of Uri Resolver
|
||||||
*/
|
*/
|
||||||
public String getParameter() {
|
public String getParameter() {
|
||||||
return keyValue;
|
return keyValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
log.trace(new UrlShortenerReaderRR());
|
log.trace(new UrlShortenerReaderRR());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue