History updated: case update was added

Download and Upload servlet was updated for overriding

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@79556 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2013-07-23 12:24:17 +00:00
parent 70834a661a
commit 3cb12c6d93
7 changed files with 186 additions and 26 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 114 B

View File

@ -218,7 +218,8 @@ public class DialogUpload extends Window {
if(clickedButton.equals(Dialog.YES)){
removeItemAndSubmitForm(itemId);
// removeItemAndSubmitForm(itemId);
updateItemSubmitForm(itemId);
}
@ -294,5 +295,13 @@ public class DialogUpload extends Window {
});
}
private void updateItemSubmitForm(String itemId){
hiddenOverwrite.setValue("true");
submitForm();
}
}

View File

@ -116,6 +116,8 @@ public class AccoutingInfoContainer extends LayoutContainer {
return Resources.getIconCancel().createImage();
else if(model.get(OPERATION).equals(GxtAccountingEntryType.RENAME))
return Resources.getIconRenameItem().createImage();
else if(model.get(OPERATION).equals(GxtAccountingEntryType.UPDATED))
return Resources.getIconRefresh().createImage();
}
return null;
}

View File

@ -17,6 +17,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.common.core.utils.logging.GCUBELog;
@ -164,10 +165,23 @@ public class DownloadServlet extends HttpServlet{
FolderItem folderItem = (FolderItem) item;
switch (folderItem.getFolderItemType()) {
case REPORT_TEMPLATE:{
try{
ReportTemplate reportTemplate = (ReportTemplate)folderItem;
String itemName = item.getName() + "." + Extensions.REPORT_TEMPLATE.getValue();
String extension = FilenameUtils.getExtension(item.getName());
String itemName = item.getName();
logger.trace("case REPORT_TEMPLATE extension is" +extension);
if(extension.compareToIgnoreCase(Extensions.REPORT_TEMPLATE.getName())!=0) //ADD EXTENSION?
itemName = "." + Extensions.REPORT_TEMPLATE.getName();
logger.trace("case REPORT_TEMPLATE itemName is" +extension);
// String itemName = item.getName() + "." + Extensions.REPORT_TEMPLATE.getValue();
String contentDisposition = (viewContent)?"inline":"attachment";
resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );
@ -195,8 +209,18 @@ public class DownloadServlet extends HttpServlet{
case REPORT:{
try{
Report report = (Report)folderItem;
String extension = FilenameUtils.getExtension(item.getName());
String itemName = item.getName();
logger.trace("case REPORT extension is" +extension);
if(extension.compareToIgnoreCase(Extensions.REPORT.getName())!=0) //ADD EXTENSION?
itemName = "." + Extensions.REPORT.getName();
String itemName = item.getName() + "." + Extensions.REPORT.getValue();
logger.trace("case REPORT itemName is" +extension);
// String itemName = item.getName() + "." + Extensions.REPORT.getValue();
String contentDisposition = (viewContent)?"inline":"attachment";
resp.setHeader( "Content-Disposition", contentDisposition+"; filename=\"" + itemName + "\"" );

View File

@ -21,6 +21,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceFolder;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceItem;
import org.gcube.portlets.user.homelibrary.home.workspace.WorkspaceSmartFolder;
import org.gcube.portlets.user.homelibrary.home.workspace.accounting.AccountingEntry;
import org.gcube.portlets.user.homelibrary.home.workspace.accounting.AccountingEntryAdd;
import org.gcube.portlets.user.homelibrary.home.workspace.accounting.AccountingEntryCut;
import org.gcube.portlets.user.homelibrary.home.workspace.accounting.AccountingEntryPaste;
import org.gcube.portlets.user.homelibrary.home.workspace.accounting.AccountingEntryRead;
@ -1792,6 +1793,30 @@ public class GWTWorkspaceBuilder {
af.setDescription(GxtAccountingEntryType.RENAME.getName()+ " by "+user.getName() +", last name: "+ren.getOldItemName());
}
break;
case ADD:
if(gxtEntryType==null || gxtEntryType.equals(GxtAccountingEntryType.ALLWITHOUTREAD) || gxtEntryType.equals(GxtAccountingEntryType.ADDED)){
af.setOperation(GxtAccountingEntryType.ADDED);
AccountingEntryAdd acc = (AccountingEntryAdd) accountingEntry;
af.setDescription(GxtAccountingEntryType.ADDED.getName()+ " by "+user.getName());
}
break;
case UPDATE:
if(gxtEntryType==null || gxtEntryType.equals(GxtAccountingEntryType.ALLWITHOUTREAD) || gxtEntryType.equals(GxtAccountingEntryType.UPDATED)){
af.setOperation(GxtAccountingEntryType.UPDATED);
// AccountingEntryUpdate acc = (AccountingEntryUpdate) accountingEntry;
af.setDescription(GxtAccountingEntryType.UPDATED.getName()+ " by "+user.getName());
}
break;
}

View File

@ -33,6 +33,7 @@ import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.ItemAlready
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.ItemNotFoundException;
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WorkspaceFolderNotFoundException;
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WrongDestinationException;
import org.gcube.portlets.user.homelibrary.home.workspace.exceptions.WrongItemTypeException;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.Report;
import org.gcube.portlets.user.homelibrary.home.workspace.folder.items.ReportTemplate;
@ -63,8 +64,8 @@ public class UploadServlet extends HttpServlet {
protected GCUBELog logger = new GCUBELog(UploadServlet.class);
public static final String D4ST = Extensions.REPORT_TEMPLATE.getValue(); //extension of Report Template type
public static final String D4SR = Extensions.REPORT.getValue(); //extension of Report type
public static final String D4ST = Extensions.REPORT_TEMPLATE.getName(); //extension of Report Template type
public static final String D4SR = Extensions.REPORT.getName(); //extension of Report type
/**
*
*/
@ -191,7 +192,12 @@ public class UploadServlet extends HttpServlet {
try {
//we calculate an unique name for the current destination
String itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
String itemName = "";
if(!isOverwrite)
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
else
itemName = uploadItem.getName();
String contentType = MimeTypeUtil.getMimeType(new BufferedInputStream(uploadItem.getInputStream()));
logger.trace("Content type: "+contentType + " unique name: "+itemName);
@ -209,21 +215,33 @@ public class UploadServlet extends HttpServlet {
if(isZipFile && (extension.compareToIgnoreCase(D4ST)==0)){ //Create REPORT TEMPLATE
String itemwithoutext = itemName.substring(0,itemName.lastIndexOf(D4ST)-1); //remove extension
// String newItemName = "";
//
// if(!isOverwrite)
// newItemName = itemName.substring(0,itemName.lastIndexOf(D4ST)-1); //remove extension
// else
// newItemName = item.getName();
// System.out.println("itemwithoutext " +itemwithoutext);
logger.trace("createTemplate: "+itemwithoutext);
createTemplate(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
String newItemName = itemName;
logger.trace("createTemplate: "+newItemName);
createTemplate(request.getSession(), wa, newItemName, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else if(isZipFile && (extension.compareToIgnoreCase(D4SR)==0)){ //Create REPORT
String itemwithoutext = itemName.substring(0,itemName.lastIndexOf(D4SR)-1); //remove extension
// String newItemName = "";
//
// if(!isOverwrite)
// newItemName = itemName.substring(0,itemName.lastIndexOf(D4SR)-1); //remove extension
// else
// newItemName = item.getName();
// System.out.println("itemwithoutext " +itemwithoutext);
logger.trace("createReport: "+itemwithoutext);
createReport(request.getSession(), wa, itemwithoutext, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
String newItemName = itemName;
logger.trace("createReport: "+newItemName);
createReport(request.getSession(), wa, newItemName, uploadItem.getInputStream(), destinationFolder, response, isOverwrite);
}else{ //CREATE AN EXTERNAL FILE
@ -292,26 +310,86 @@ public class UploadServlet extends HttpServlet {
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());
FolderItem createdItem = null;
notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId(), isOverwrite);
if(!isOverwrite){
//we need to recalculate the item name
itemName = WorkspaceUtil.getUniqueName(uploadItem.getName(), destinationFolder);
createdItem = WorkspaceUtil.createExternalFile(destinationFolder, itemName, "", contentType, uploadItem.getInputStream());
}
else
createdItem = overwriteItem(wa, itemName, uploadItem.getInputStream(), destinationFolder); //CASE OVERWRITE
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
if(createdItem!=null){
notifyUploadInSharedFolder(httpSession,wa,createdItem.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+createdItem.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
private FolderItem overwriteItem(Workspace wa, String itemName, InputStream fileData, WorkspaceFolder destinationFolder){
FolderItem overwriteItem = null;
try {
logger.trace("case overwriting item.. "+itemName);
overwriteItem = (FolderItem) wa.find(itemName, destinationFolder.getId());
logger.trace("overwriteItem item was found, id is: "+overwriteItem.getId());
wa.updateItem(overwriteItem.getId(), fileData);
logger.trace("updateItem with id: "+overwriteItem.getId()+ ", is completed");
} catch (ItemNotFoundException e) {
logger.error("Error in createExternalFile, ItemNotFoundException", e);
} catch (WrongItemTypeException e) {
logger.error("Error in createExternalFile, WrongItemTypeException", e);
} catch (WorkspaceFolderNotFoundException e) {
logger.error("Error in createExternalFile, WorkspaceFolderNotFoundException", e);
} catch (WrongDestinationException e) {
logger.error("Error in createExternalFile, WrongDestinationException", e);
} catch (InsufficientPrivilegesException e) {
logger.error("Error in createExternalFile, InsufficientPrivilegesException", e);
} catch (ItemAlreadyExistException e) {
logger.error("Error in createExternalFile, ItemAlreadyExistException", e);
} catch (InternalErrorException e) {
logger.error("Error in createExternalFile, InternalErrorException", e);
}catch (Exception e) {
logger.error("Error in createExternalFile, Exception", e);
}
return overwriteItem;
}
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(), isOverwrite);
Report report = null;
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
report = wa.createReport(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,report.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+report.getName()+" imported correctly in "+destinationFolder.getPath());
}
else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");
@ -325,13 +403,31 @@ public class UploadServlet extends HttpServlet {
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(), isOverwrite);
ReportTemplate template = null;
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
if(!isOverwrite){
itemName = WorkspaceUtil.getUniqueName(itemName, destinationFolder);
template = wa.createReportTemplate(itemName, "", Calendar.getInstance(), Calendar.getInstance(), "", "", 0, "", stream, destinationFolder.getId());
notifyUploadInSharedFolder(httpSession,wa,template.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+template.getName()+" imported correctly in "+destinationFolder.getPath());
}else{ //CASE OVERWRITE
FolderItem rep = overwriteItem(wa, itemName, stream, destinationFolder);
if(rep!=null){
notifyUploadInSharedFolder(httpSession,wa,rep.getId(),destinationFolder.getId(), isOverwrite);
sendMessage(response, "File "+rep.getName()+" imported correctly in "+destinationFolder.getPath());
}
else
sendError(response,"Internal error: Workspace Item Not Found");
}
} catch (WrongDestinationException e) {
logger.error("Error creating elements", e);
sendError(response, "Internal error: Wrong Destination");

View File

@ -22,6 +22,10 @@ public enum GxtAccountingEntryType {
READ("read", "Read"),
ADDED("added", "Added"),
UPDATED("updated", "Updated"),
ALLWITHOUTREAD("all", "all");
private String id;