Ticket #628: was completed. I've added notification for updating of files

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@77407 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-07-01 10:19:53 +00:00
parent fe9d853eef
commit 72b9df7e4d
6 changed files with 114 additions and 25 deletions

View File

@ -199,4 +199,10 @@ public class ConstantsExplorer {
public static final String ERROR_ITEM_DOES_NOT_EXIST = "Item does not exist. It may have been deleted by another user"; public static final String ERROR_ITEM_DOES_NOT_EXIST = "Item does not exist. It may have been deleted by another user";
public static final String VALIDATEITEM = "validateitem"; public static final String VALIDATEITEM = "validateitem";
public static final String REDIRECTONERROR = "redirectonerror"; public static final String REDIRECTONERROR = "redirectonerror";
//UPLOAD SERVLET PARAMETERS
public static final String IS_OVERWRITE = "isOverwrite";
public static final String UPLOAD_TYPE = "uploadType";
public static final String ID_FOLDER = "idFolder";
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement";
} }

View File

@ -35,12 +35,19 @@ import com.google.gwt.user.client.ui.Hidden;
public class DialogUpload extends Window { public class DialogUpload extends Window {
/**
*
*/
private final FormPanel formPanel = new FormPanel(); private final FormPanel formPanel = new FormPanel();
private FileUploadField fileUploadField = new FileUploadField(); private FileUploadField fileUploadField = new FileUploadField();
private MessageBoxWait messageBoxWait = null; private MessageBoxWait messageBoxWait = null;
private boolean isStatusCompleted = false; private boolean isStatusCompleted = false;
private Button btnSubmit = new Button("Submit"); private Button btnSubmit = new Button("Submit");
private Button btnCancel = new Button("Cancel"); private Button btnCancel = new Button("Cancel");
private Hidden hiddenOverwrite = new Hidden(ConstantsExplorer.IS_OVERWRITE,"false");
private String parentIdentifier = ""; private String parentIdentifier = "";
@ -71,12 +78,13 @@ public class DialogUpload extends Window {
// formPanel.add(name); // formPanel.add(name);
fileUploadField.setAllowBlank(false); fileUploadField.setAllowBlank(false);
fileUploadField.setName("uploadFormElement"); fileUploadField.setName(ConstantsExplorer.UPLOAD_FORM_ELEMENT);
// Add a label // Add hidden parameters
formPanel.add(new Hidden("idFolder",parent.getIdentifier())); formPanel.add(new Hidden(ConstantsExplorer.ID_FOLDER,parent.getIdentifier()));
formPanel.add(new Hidden(ConstantsExplorer.UPLOAD_TYPE,fieldLabel));
formPanel.add(new Hidden("uploadType",fieldLabel)); formPanel.add(hiddenOverwrite);
// fileUploadField.setFieldLabel(ConstantsExplorer.FILE); // fileUploadField.setFieldLabel(ConstantsExplorer.FILE);
fileUploadField.setFieldLabel(fieldLabel); fileUploadField.setFieldLabel(fieldLabel);
formPanel.add(fileUploadField); formPanel.add(fileUploadField);
@ -277,8 +285,10 @@ public class DialogUpload extends Window {
@Override @Override
public void onSuccess(Boolean result) { public void onSuccess(Boolean result) {
if(result) if(result){
hiddenOverwrite.setValue("true");
submitForm(); submitForm();
}
} }

View File

@ -40,6 +40,7 @@ import org.gcube.portlets.user.homelibrary.util.Extensions;
import org.gcube.portlets.user.homelibrary.util.MimeTypeUtil; import org.gcube.portlets.user.homelibrary.util.MimeTypeUtil;
import org.gcube.portlets.user.homelibrary.util.WorkspaceUtil; import org.gcube.portlets.user.homelibrary.util.WorkspaceUtil;
import org.gcube.portlets.user.homelibrary.util.zip.UnzipUtil; import org.gcube.portlets.user.homelibrary.util.zip.UnzipUtil;
import org.gcube.portlets.user.workspace.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil; import org.gcube.portlets.user.workspace.server.notifications.NotificationsUtil;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
@ -50,12 +51,14 @@ import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
*/ */
public class UploadServlet extends HttpServlet { public class UploadServlet extends HttpServlet {
public static final String UPLOAD_TYPE = "uploadType"; public static final String UPLOAD_TYPE = ConstantsExplorer.UPLOAD_TYPE;
public static final String ID_FOLDER = "idFolder"; public static final String ID_FOLDER = ConstantsExplorer.ID_FOLDER;
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement"; public static final String UPLOAD_FORM_ELEMENT = ConstantsExplorer.UPLOAD_FORM_ELEMENT;
public static final String IS_OVERWRITE = ConstantsExplorer.IS_OVERWRITE;
public static final String FILE = "File"; public static final String FILE = "File";
protected GCUBELog logger = new GCUBELog(UploadServlet.class); protected GCUBELog logger = new GCUBELog(UploadServlet.class);
@ -102,6 +105,7 @@ public class UploadServlet extends HttpServlet {
FileItem uploadItem = null; FileItem uploadItem = null;
String destinationId = null; String destinationId = null;
String uploadType = null; String uploadType = null;
boolean isOverwrite = false;
try { try {
logger.trace("parsing request"); logger.trace("parsing request");
@ -122,8 +126,15 @@ public class UploadServlet extends HttpServlet {
if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){ if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())){
uploadType = item.getString(); uploadType = item.getString();
} }
if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
isOverwrite = Boolean.parseBoolean(item.getString());
}
} }
logger.trace("Upload servlet parameters: [uploadItem: "+uploadItem +", destinationId: "+destinationId +", uploadType: "+uploadType+", isOverwrite: "+isOverwrite+"]");
} catch (FileUploadException e) { } catch (FileUploadException e) {
logger.error("Error processing request in upload servlet", e); logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing"); sendError(response, "Internal error: Error during request processing");
@ -203,7 +214,7 @@ public class UploadServlet extends HttpServlet {
// System.out.println("itemwithoutext " +itemwithoutext); // System.out.println("itemwithoutext " +itemwithoutext);
logger.trace("createTemplate: "+itemwithoutext); logger.trace("createTemplate: "+itemwithoutext);
createTemplate(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response); createTemplate(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT }else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
@ -212,11 +223,11 @@ public class UploadServlet extends HttpServlet {
// System.out.println("itemwithoutext " +itemwithoutext); // System.out.println("itemwithoutext " +itemwithoutext);
logger.trace("createReport: "+itemwithoutext); logger.trace("createReport: "+itemwithoutext);
createReport(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response); createReport(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE }else{ //CREATE AN EXTERNAL FILE
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response); createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
} }
}else {//IS ARCHIVE UPLOAD }else {//IS ARCHIVE UPLOAD
@ -228,7 +239,7 @@ public class UploadServlet extends HttpServlet {
//TODO NOTIFY UPLOAD ARCHIVE //TODO NOTIFY UPLOAD ARCHIVE
sendMessage(response, "Archive "+uploadItem.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "Archive "+uploadItem.getName()+" imported correctly in "+destinationFolder.getPath());
} else } else
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response); createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
} }
uploadItem.delete(); uploadItem.delete();
@ -254,7 +265,7 @@ public class UploadServlet extends HttpServlet {
* @param itemId * @param itemId
* @param destinationFolderId * @param destinationFolderId
*/ */
private void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId){ private void notifyUploadInSharedFolder(final HttpSession httpSession, final Workspace workspace, final String itemId, final String destinationFolderId, final boolean isOverwrite){
new Thread(){ new Thread(){
@ -265,7 +276,10 @@ public class UploadServlet extends HttpServlet {
sourceItem = workspace.getItem(itemId); sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder(); String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId); WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsUtil.checkSendNotifyAddItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem);
NotificationsUtil.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) { } catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e); logger.error("Error in notifyUploadInSharedFolder", e);
@ -276,25 +290,25 @@ public class UploadServlet extends HttpServlet {
}.start(); }.start();
} }
private void createExternalFile(HttpSession httpSession, Workspace wa, String itemName, FileItem uploadItem, WorkspaceFolder destinationFolder, String contentType, HttpServletResponse response) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, IOException { private void createExternalFile(HttpSession httpSession, Workspace wa, String itemName, FileItem uploadItem, WorkspaceFolder destinationFolder, String contentType, HttpServletResponse response, boolean isOverwrite) throws InternalErrorException, InsufficientPrivilegesException, ItemAlreadyExistException, IOException {
//we need to recalculate the item name //we need to recalculate the item name
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder); itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
FolderItem createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem.getInputStream()); FolderItem createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem.getInputStream());
notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId()); notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
} }
private void createReport(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createReport(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
Report report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", stream, destinationFolder.getId()); Report report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId()); notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
@ -308,13 +322,13 @@ public class UploadServlet extends HttpServlet {
} }
private void createTemplate(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{ private void createTemplate(HttpSession httpSession, Workspace wa, String itemName, InputStream stream, WorkspaceFolder destinationFolder, HttpServletResponse response, boolean isOverwrite) throws InsufficientPrivilegesException, ItemAlreadyExistException, InternalErrorException, IOException{
try { try {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder); itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
ReportTemplate template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", stream, destinationFolder.getId()); ReportTemplate template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId()); notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath()); sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());

View File

@ -395,6 +395,60 @@ public class NotificationsProducer {
} }
/**
* Runs a new thread to notify the contacts passed in input
* @param listContacts
* @param workspaceItem
*/
public void notifyUpdatedItemToSharing(final List<InfoContactModel> listContacts, final WorkspaceItem workspaceItem, final WorkspaceFolder sharedFolder) {
new Thread() {
@Override
public void run() {
// printContacts(listContacts);
gcubeLogger.trace("Send notifies updated item in shared folder is running...");
//DEBUG
System.out.println("Send notifies updated item in shared folder is running...");
for (InfoContactModel infoContactModel : listContacts) {
try{
//NOTIFIES ONLY THE USERS THAT ARE DIFFERENT FROM CURRENT USER
if(infoContactModel.getLogin().compareTo(userId)!=0){
gcubeLogger.trace("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
System.out.println("Sending notification to user "+infoContactModel.getLogin() +" updated item "+workspaceItem.getName()+" in shared folder "+sharedFolder.getName());
//DEBUG
// System.out.println("Send notify folder un share user "+infoContactModel.getLogin());
boolean notify = notificationsMng.notifyUpdatedItem(infoContactModel.getLogin(), workspaceItem, sharedFolder);
if(!notify){
gcubeLogger.error("An error updated when notify user: "+infoContactModel.getLogin());
//DEBUG
System.out.println("An error updated when notify user: "+infoContactModel.getLogin());
}
}
}catch (Exception e) {
gcubeLogger.error("An error updated in notifyAddedItemToSharing ", e);
e.printStackTrace();
}
}
gcubeLogger.trace("notifies of updated item in shared folder is completed");
//DEBUG
System.out.println("notifies of updated item in shared folder is completed");
}
}.start();
}

View File

@ -29,13 +29,13 @@ public class NotificationsUtil {
protected static Logger logger = Logger.getLogger(NotificationsUtil.class); protected static Logger logger = Logger.getLogger(NotificationsUtil.class);
/** /**
* * Send a notification if an item is added or updated to sharing folder
* @param httpSession * @param httpSession
* @param sourceItem * @param sourceItem
* @param sourceSharedId * @param sourceSharedId
* @param folderDestinationItem * @param folderDestinationItem
*/ */
public static void checkSendNotifyAddItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem) { public static void checkSendNotifyChangedItemToShare(HttpSession httpSession, final WorkspaceItem sourceItem, final String sourceSharedId, final WorkspaceItem folderDestinationItem, boolean isOverwrite) {
logger.trace("checkSendNotifyAddItemToShare"); logger.trace("checkSendNotifyAddItemToShare");
@ -65,7 +65,12 @@ public class NotificationsUtil {
NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession)); NotificationsProducer np = new NotificationsProducer(WsUtil.getAslSession(httpSession));
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceFolder) destinationSharedFolder); //SWITCH BEETWEEN ADDED OR UPDATED
if(!isOverwrite)
np.notifyAddedItemToSharing(listContacts, sourceItem, (WorkspaceFolder) destinationSharedFolder);
else
np.notifyUpdatedItemToSharing(listContacts, sourceItem, (WorkspaceFolder) destinationSharedFolder);
logger.trace("The notifies was sent correctly"); logger.trace("The notifies was sent correctly");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem); // np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);

View File

@ -68,7 +68,7 @@ public class WsUtil {
if (user == null) { if (user == null) {
user=TEST_USER; user=TEST_USER;
defaultLogger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:"); defaultLogger.warn("WORKSPACE PORTLET STARTING IN TEST MODE - NO USER FOUND - PORTLETS STARTING WITH FOLLOWING SETTINGS:");
defaultLogger.warn("session id: "+sessionID); defaultLogger.warn("session id: "+sessionID);
defaultLogger.warn("TEST_USER: "+user); defaultLogger.warn("TEST_USER: "+user);