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 VALIDATEITEM = "validateitem";
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 {
/**
*
*/
private final FormPanel formPanel = new FormPanel();
private FileUploadField fileUploadField = new FileUploadField();
private MessageBoxWait messageBoxWait = null;
private boolean isStatusCompleted = false;
private Button btnSubmit = new Button("Submit");
private Button btnCancel = new Button("Cancel");
private Hidden hiddenOverwrite = new Hidden(ConstantsExplorer.IS_OVERWRITE,"false");
private String parentIdentifier = "";
@ -71,12 +78,13 @@ public class DialogUpload extends Window {
// formPanel.add(name);
fileUploadField.setAllowBlank(false);
fileUploadField.setName("uploadFormElement");
fileUploadField.setName(ConstantsExplorer.UPLOAD_FORM_ELEMENT);
// Add a label
formPanel.add(new Hidden("idFolder",parent.getIdentifier()));
// Add hidden parameters
formPanel.add(new Hidden(ConstantsExplorer.ID_FOLDER,parent.getIdentifier()));
formPanel.add(new Hidden(ConstantsExplorer.UPLOAD_TYPE,fieldLabel));
formPanel.add(hiddenOverwrite);
formPanel.add(new Hidden("uploadType",fieldLabel));
// fileUploadField.setFieldLabel(ConstantsExplorer.FILE);
fileUploadField.setFieldLabel(fieldLabel);
formPanel.add(fileUploadField);
@ -277,8 +285,10 @@ public class DialogUpload extends Window {
@Override
public void onSuccess(Boolean result) {
if(result)
if(result){
hiddenOverwrite.setValue("true");
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.WorkspaceUtil;
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.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
@ -50,11 +51,13 @@ import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
*/
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";
@ -102,6 +105,7 @@ public class UploadServlet extends HttpServlet {
FileItem uploadItem = null;
String destinationId = null;
String uploadType = null;
boolean isOverwrite = false;
try {
logger.trace("parsing request");
@ -123,7 +127,14 @@ public class UploadServlet extends HttpServlet {
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) {
logger.error("Error processing request in upload servlet", e);
sendError(response, "Internal error: Error during request processing");
@ -203,7 +214,7 @@ public class UploadServlet extends HttpServlet {
// System.out.println("itemwithoutext " +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
@ -212,11 +223,11 @@ public class UploadServlet extends HttpServlet {
// System.out.println("itemwithoutext " +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
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response);
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
}
}else {//IS ARCHIVE UPLOAD
@ -228,7 +239,7 @@ public class UploadServlet extends HttpServlet {
//TODO NOTIFY UPLOAD ARCHIVE
sendMessage(response, "Archive "+uploadItem.getName()+" imported correctly in "+destinationFolder.getPath());
} else
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response);
createExternalFile(request.getSession(), wa, itemName, uploadItem, destinationFolder, contentType, response, isOverwrite);
}
uploadItem.delete();
@ -254,7 +265,7 @@ public class UploadServlet extends HttpServlet {
* @param itemId
* @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(){
@ -265,7 +276,10 @@ public class UploadServlet extends HttpServlet {
sourceItem = workspace.getItem(itemId);
String sourceSharedId = sourceItem.getIdSharedFolder();
WorkspaceItem folderDestinationItem = workspace.getItem(destinationFolderId);
NotificationsUtil.checkSendNotifyAddItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem);
NotificationsUtil.checkSendNotifyChangedItemToShare(httpSession, sourceItem, sourceSharedId, folderDestinationItem,isOverwrite);
} catch (Exception e) {
logger.error("Error in notifyUploadInSharedFolder", e);
@ -276,25 +290,25 @@ public class UploadServlet extends HttpServlet {
}.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
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
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());
}
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 {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
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());
@ -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 {
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
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());

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);
/**
*
* Send a notification if an item is added or updated to sharing folder
* @param httpSession
* @param sourceItem
* @param sourceSharedId
* @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");
@ -65,7 +65,12 @@ public class NotificationsUtil {
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");
// np.notifyAddedItemToSharing(listContacts, (WorkspaceFolder) folderDestinationItem);