Added the parameter "FIELD_NAME" (as hidden parameter) in the form

uploader
This commit is contained in:
Francesco Mangiacrapa 2022-03-21 16:31:43 +01:00
parent 0887144f9c
commit 1b79e7bf74
11 changed files with 497 additions and 347 deletions

View File

@ -0,0 +1,7 @@
<root>
<facet id="jst.jaxrs">
<node name="libprov">
<attribute name="provider-id" value="jaxrs-no-op-library-provider"/>
</node>
</facet>
</root>

View File

@ -10,6 +10,7 @@ public class ConstantsMPFormBuilder {
//public static final String CURR_USER_ID = "currUserId";
public static final String IS_OVERWRITE = "isOverwrite";
public static final String UPLOAD_TYPE = "uploadType";
public static final String FIELD_NAME = "fieldName";
public static enum THE_UPLOAD_TYPE {File, Archive};
public static final String ID_FOLDER = "idFolder";
public static final String UPLOAD_FORM_ELEMENT = "uploadFormElement";

View File

@ -384,7 +384,7 @@ public class MetaDataFieldSkeleton extends Composite {
case File:
holder = new MultipleDilaogUpload();
holder = new MultipleDilaogUpload(field.getFieldName());
break;

View File

@ -1,6 +1,5 @@
package org.gcube.portlets.widgets.mpformbuilder.client.ui.upload;
import java.util.ArrayList;
import java.util.List;
@ -25,13 +24,11 @@ import com.google.gwt.user.client.ui.Hidden;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
// TODO: Auto-generated Javadoc
/**
* The Class DialogUploadStream.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 24, 2015
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 24, 2015
*/
public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotificationListener {
@ -51,11 +48,12 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
/** The timer. */
protected TimerUpload timer;
private String fieldName;
/**
* The Enum UPLOAD_TYPE.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* Sep 11, 2015
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Sep 11, 2015
*/
private HTML UPLOADING = new HTML("Uploading...");
@ -74,7 +72,6 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
* Instantiates a new dialog upload stream.
*/
public DialogUpload() {
//setWidth("400px");
fileUpload = new FileUpload();
// fileUpload.getElement().setAttribute("multiple", "multiple");
setAction(ConstantsMPFormBuilder.METADATA_FORM_BUILDER_UPLOADING_SERVLET);
@ -89,8 +86,12 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
fileUpload.setName(ConstantsMPFormBuilder.UPLOAD_FORM_ELEMENT);
// Add hidden parameters
verticalMainPanel.add(new Hidden(ConstantsMPFormBuilder.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()));
verticalMainPanel.add(new Hidden(ConstantsMPFormBuilder.UPLOAD_TYPE, ConstantsMPFormBuilder.THE_UPLOAD_TYPE.File.name()));
verticalMainPanel
.add(new Hidden(ConstantsMPFormBuilder.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId()));
verticalMainPanel.add(
new Hidden(ConstantsMPFormBuilder.UPLOAD_TYPE, ConstantsMPFormBuilder.THE_UPLOAD_TYPE.File.name()));
verticalMainPanel.add(new Hidden(ConstantsMPFormBuilder.FIELD_NAME, fieldName));
initJsonClientKeys();
verticalMainPanel.add(jsonClientKeys);
@ -105,6 +106,24 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
verticalMainPanel.add(hp);
}
/**
* Sets the field name.
*
* @param fieldName the new field name
*/
public void setFieldName(String fieldName) {
this.fieldName = fieldName;
}
/**
* Gets the field name.
*
* @return the field name
*/
public String getFieldName() {
return fieldName;
}
/**
* Gets the panel.
*
@ -146,7 +165,8 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
if (result == null) {
removeLoading();
Window.alert("An error occurred during file upload");
//new DialogResult(null, "Error during upload", "An error occurred during file upload.").center();
// new DialogResult(null, "Error during upload", "An error occurred during file
// upload.").center();
return;
}
String strippedResult = new HTML(result).getText();
@ -216,11 +236,15 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
GWT.log("fileUpload.getFilename() " + fileUpload.getFilename());
/*
* TODO: recall: Some browser would write in fileUploadField.getValue() C:\fakepath\$fileName
* TODO: recall: Some browser would write in fileUploadField.getValue()
* C:\fakepath\$fileName
*/
String normalizedFileName = fileUpload.getFilename();
if (normalizedFileName.contains("\\")) {
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\")+1); //remove C:\fakepath\ if exists
normalizedFileName = normalizedFileName.substring(normalizedFileName.lastIndexOf("\\") + 1); // remove
// C:\fakepath\
// if
// exists
}
purgedUploadingFileName = normalizedFileName;
@ -252,7 +276,6 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
fakeUploaders.clear();
}
/**
* Gets the file uploading state.
*
@ -301,7 +324,6 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
submit();
}
/**
* Removes the item and submit form.
*
@ -309,25 +331,22 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
*/
protected void removeItemAndSubmitForm(String itemId) {
/*
AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new AsyncCallback<Boolean>() {
@Override
public void onFailure(Throwable caught) {
Info.display("Error", caught.getMessage());
}
@Override
public void onSuccess(Boolean result) {
if(result){
hiddenOverwrite.setValue("true");
submitForm();
}
}
});*/
* AppControllerExplorer.rpcWorkspaceService.removeItem(itemId, new
* AsyncCallback<Boolean>() {
*
* @Override public void onFailure(Throwable caught) { Info.display("Error",
* caught.getMessage());
*
*
* }
*
* @Override public void onSuccess(Boolean result) { if(result){
* hiddenOverwrite.setValue("true"); submitForm(); }
*
* }
*
* });
*/
}
/**
@ -345,8 +364,14 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
*
* @param handler the handler
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#addWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* addWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.
* workspaceuploader.client.WorkspaceUploadNotification.
* WorskpaceUploadNotificationListener)
*/
@Override
public void addWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
@ -358,15 +383,20 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
*
* @param handler the handler
*/
/* (non-Javadoc)
* @see org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#removeWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.workspaceuploader.client.WorkspaceUploadNotification.WorskpaceUploadNotificationListener)
/*
* (non-Javadoc)
*
* @see org.gcube.portlets.widgets.workspaceuploader.client.
* WorkspaceUploadNotification.HasWorskpaceUploadNotificationListener#
* removeWorkspaceUploadNotificationListener(org.gcube.portlets.widgets.
* workspaceuploader.client.WorkspaceUploadNotification.
* WorskpaceUploadNotificationListener)
*/
@Override
public void removeWorkspaceUploadNotificationListener(WorskpaceUploadNotificationListener handler) {
controller.removeWorkspaceUploadListener(handler);
}
/**
* Enable upload.
*
@ -376,4 +406,3 @@ public class DialogUpload extends FormPanel implements HasWorskpaceUploadNotific
fileUpload.setEnabled(bool);
}
}

View File

@ -16,9 +16,9 @@ public class FileUpload extends Composite {
@UiField HTMLPanel fileUploadPanel;
public FileUpload() {
public FileUpload(String fielName) {
initWidget(uiBinder.createAndBindUi(this));
fileUploadPanel.add(new MultipleDilaogUpload());
fileUploadPanel.add(new MultipleDilaogUpload(fielName));
}
}

View File

@ -49,9 +49,10 @@ public class MultipleDilaogUpload extends DialogUpload {
/**
* Instantiates a new multiple dilaog upload.
*/
public MultipleDilaogUpload() {
fileUploadID = GenerateUUID.get(10, 16); // is tagID
fileUpload.getElement().setId(fileUploadID);
public MultipleDilaogUpload(String fieldName) {
this.fileUploadID = GenerateUUID.get(10, 16); // is tagID
this.fileUpload.getElement().setId(fileUploadID);
super.setFieldName(fieldName);
this.addHandlers();
}
@ -165,7 +166,7 @@ public class MultipleDilaogUpload extends DialogUpload {
@Override
public void onChange(ChangeEvent event) {
GWT.log("file upload change handler, browse return...");
GWT.log("file upload change handler, browse returns...");
if (fileUpload.getFilename() == null || fileUpload.getFilename().isEmpty()) {
GWT.log("No file specified ");
//MultipleDilaogUpload.this.hide();

View File

@ -33,6 +33,7 @@ import org.gcube.common.portal.PortalContext;
import org.gcube.portlets.widgets.mpformbuilder.client.ConstantsMPFormBuilder;
import org.gcube.portlets.widgets.mpformbuilder.server.util.WsUtil;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.AbstractUploadProgressListener;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FilePath;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadingState;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploadingState.UPLOAD_STATUS;
@ -73,7 +74,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
/** The Constant CURR_GROUP_ID. */
public static final String CURR_GROUP_ID = ConstantsMPFormBuilder.CURR_GROUP_ID;
//public static final String CURR_USER_ID = ConstantsWorkspaceUploader.CURR_USER_ID;
// public static final String CURR_USER_ID =
// ConstantsWorkspaceUploader.CURR_USER_ID;
/** The Constant UPLOAD_FORM_ELEMENT. */
public static final String UPLOAD_FORM_ELEMENT = ConstantsMPFormBuilder.UPLOAD_FORM_ELEMENT;
@ -90,6 +92,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
/** The Constant UPLOAD_TYPE. */
public static final String UPLOAD_TYPE = ConstantsMPFormBuilder.UPLOAD_TYPE;
public static final String FIELD_NAME = ConstantsMPFormBuilder.FIELD_NAME;
/** The logger. */
public static Logger logger = LoggerFactory.getLogger(MetadataProfileFormBuilderUploadServlet.class);
@ -147,9 +151,9 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
// }catch (Exception e) {
// logger.warn("An error occurred during removing cancelled upload from session ");
// }
}
else
sendWarnMessage(response, "Upload aborted for id: "+clientUploadKey +" has skipped, already aborted or completed?");
} else
sendWarnMessage(response,
"Upload aborted for id: " + clientUploadKey + " has skipped, already aborted or completed?");
} else
logger.debug(CANCEL_UPLOAD + " param not found");
return;
@ -161,7 +165,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
logger.info("POST on UploadServlet");
boolean requestIsNull = request == null;
logger.trace("[1] HttpServletRequest is: null? "+requestIsNull+", URI: "+request.getRequestURI() +", ServerName: "+request.getServerName());
logger.trace("[1] HttpServletRequest is: null? " + requestIsNull + ", URI: " + request.getRequestURI()
+ ", ServerName: " + request.getServerName());
if (!ServletFileUpload.isMultipartContent(request)) {
logger.error("ERROR: multipart request not found");
@ -183,6 +188,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
String uploadType = null;
String fieldName = null;
// String clientUploadKey = null;
FileItemStream uploadItem = null;
ArrayList<String> listClientUploadKeys = null;
@ -192,9 +198,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
ServletFileUpload servletFileUpload = new ServletFileUpload(factory);
/**
* An iterator to instances of <code>FileItemStream</code>
* parsed from the request, in the order that they were
*transmitted.
* An iterator to instances of <code>FileItemStream</code> parsed from the
* request, in the order that they were transmitted.
*/
FileItemIterator fileItemIterator = servletFileUpload.getItemIterator(request);
@ -206,7 +211,12 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
if (item.isFormField() && UPLOAD_TYPE.equals(item.getFieldName())) {
uploadType = Streams.asString(item.openStream());
logger.debug("UPLOAD_TYPE OK " +uploadType);
logger.debug(UPLOAD_TYPE + " OK " + uploadType);
}
if (item.isFormField() && FIELD_NAME.equals(item.getFieldName())) {
fieldName = Streams.asString(item.openStream());
logger.debug(FIELD_NAME + " OK " + fieldName);
}
// if (item.isFormField() && IS_OVERWRITE.equals(item.getFieldName())){
@ -220,22 +230,25 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
if (item.isFormField() && CLIENT_UPLOAD_KEYS.equals(item.getFieldName())) {
String jsonClientUploadKey = Streams.asString(item.openStream());
logger.debug("CLIENT_UPLOAD_KEY OK "+jsonClientUploadKey);
logger.debug(CLIENT_UPLOAD_KEYS + " OK " + jsonClientUploadKey);
LinkedHashMap<String, String> mapKeys = parseJSONClientUploadKeys(jsonClientUploadKey);
listClientUploadKeys = new ArrayList<String>(mapKeys.keySet());
removeListenersIfDone(session, listClientUploadKeys);
for (String clientUploadKey : listClientUploadKeys) {
String fileName = mapKeys.get(clientUploadKey);
FileUploadingState workspaceUploader = createNewWorkspaceUploader(clientUploadKey,fileName, user.getUsername());
FileUploadingState workspaceUploader = createNewWorkspaceUploader(clientUploadKey, fileName,
user.getUsername(), fieldName);
logger.debug("created " + workspaceUploader);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT, "Uploading "+fileName+" at 0%", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.WAIT,
"Uploading " + fileName + " at 0%", request.getSession());
}
}
if (item.isFormField() && CURR_GROUP_ID.equals(item.getFieldName())) {
scopeGroupId = Streams.asString(item.openStream());
logger.debug("currentGroupId passed as parameter = " + scopeGroupId);
logger.debug("currentGroupId into PortalContext scope= " + PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
logger.debug("currentGroupId into PortalContext scope= "
+ PortalContext.getConfiguration().getCurrentScope(scopeGroupId));
}
// if (item.isFormField() && CURR_USER_ID.equals(item.getFieldName())){
@ -249,7 +262,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
uploadItem = item;
logger.debug("UPLOAD_FORM_ELEMENT OK " + uploadItem.getName() + " scopeGroupId=" + scopeGroupId);
// break;
uploadData(user, scopeGroupId, request, response, uploadItem, uploadType, listClientUploadKeys.get(uploadItemsCnt));
uploadData(user, scopeGroupId, request, response, uploadItem, uploadType,
listClientUploadKeys.get(uploadItemsCnt), fieldName);
uploadItemsCnt++;
}
}
@ -265,7 +279,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
}
/**
* Removes the listener if done.
*
@ -297,7 +310,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
* @throws FileUploadException the file upload exception
*/
@SuppressWarnings("rawtypes")
private static LinkedHashMap<String, String> parseJSONClientUploadKeys(final String jsonClientUploadKeys) throws FileUploadException{
private static LinkedHashMap<String, String> parseJSONClientUploadKeys(final String jsonClientUploadKeys)
throws FileUploadException {
JSONTokener tokener = new JSONTokener(jsonClientUploadKeys);
JSONObject root;
LinkedHashMap<String, String> keyFiles = null;
@ -325,7 +339,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
return keyFiles;
}
/**
* Upload data.
*
@ -336,13 +349,17 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
* @param uploadItem the upload item
* @param uploadType the upload type
* @param clientUploadKey the client upload key
* @param fieldName the field name
* @throws ServletException the servlet exception
* @throws IOException Signals that an I/O exception has occurred.
*/
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request, final HttpServletResponse response, final FileItemStream uploadItem, String uploadType,String clientUploadKey) throws ServletException, IOException{
private void uploadData(GCubeUser user, String scopeGroupId, HttpServletRequest request,
final HttpServletResponse response, final FileItemStream uploadItem, String uploadType,
String clientUploadKey, String fieldName) throws ServletException, IOException {
String fileName = uploadItem.getName();
logger.info("Upload servlet parameters: [fileName: "+fileName+ ", uploadType: "+uploadType+", clientUploadKey: "+clientUploadKey+"]");
logger.info("Upload servlet parameters: [fileName: " + fileName + ", uploadType: " + uploadType
+ ", clientUploadKey: " + clientUploadKey + "]");
if (uploadType == null || uploadType.isEmpty()) {
logger.error("Error processing request in upload servlet for: " + fileName + ". No upload type found");
@ -351,7 +368,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
if (clientUploadKey == null || clientUploadKey.isEmpty()) {
logger.error("Error processing request in upload servlet for: "+fileName+". No client upload key found");
logger.error(
"Error processing request in upload servlet for: " + fileName + ". No client upload key found");
sendError(response, "Internal error: No client upload key found");
return;
}
@ -367,8 +385,11 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
workspaceUploader = WsUtil.getWorkspaceUploaderInSession(request, clientUploadKey);
} catch (Exception e) {
logger.error("Error during workspace uploader retrieving", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "An error occurred during upload: "+fileName+". Error processing request in upload servlet", request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error processing request in upload servlet");
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED,
"An error occurred during upload: " + fileName + ". Error processing request in upload servlet",
request.getSession());
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Error processing request in upload servlet");
return;
}
@ -392,7 +413,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
logger.debug("size: " + size + " bytes");
// Instancing the progress listener
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(), clientUploadKey);
final AbstractUploadProgressListener uploadProgressListener = createNewListener(request.getSession(),
clientUploadKey);
final UploadProgressInputStream inputStream = new UploadProgressInputStream(uploadItem.openStream(), size);
inputStream.addListener(uploadProgressListener);
workspaceUploader.setUploadProgress(uploadProgressListener.getUploadProgress());
@ -404,7 +426,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
// UPLOAD FILE. IT IS DEFAULT CASE
logger.debug("Uploading file in the TEMP system folder...");
workspaceUploader = createStreamToTempFile(request, workspaceUploader, inputStream, user.getUsername(), clientUploadKey, fileName, extension);
workspaceUploader = createStreamToTempFile(request, workspaceUploader, inputStream, user.getUsername(),
clientUploadKey, fileName, extension);
saveWorkspaceUploaderInSession(workspaceUploader, request.getSession());
@ -412,22 +435,23 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
throw new Exception("Error when creating uploader, it is null!");
/*
* Incident #10095. Commented OK as response
* in order to avoid downloading of .dms file by Safari
* from MAC
* Incident #10095. Commented OK as response in order to avoid downloading of
* .dms file by Safari from MAC
*/
// sendMessage(response, workspaceUploader.getIdentifier());
} catch (IOException e) {
logger.error("Error creating elements, is it cancel?", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error", request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error",
request.getSession());
sendError(response, "Internal error: An item with that name already exists");
return;
// sendError(response, "Internal error: An item with that name already exists");
// return;
} catch (Exception e) {
logger.error("Error creating elements", e);
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. "+e.getMessage(), request.getSession());
saveWorkspaceUploaderStatus(workspaceUploader, UPLOAD_STATUS.FAILED, "Uploading error. " + e.getMessage(),
request.getSession());
// sendError(response, "Internal error: An error occurred on uploading the file, try again later");
// return;
} finally {
@ -436,7 +460,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
}
/**
* Save workspace uploader status.
*
@ -446,7 +469,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
* @param session the session
* @return the workspace uploader item
*/
private synchronized FileUploadingState saveWorkspaceUploaderStatus(FileUploadingState workspaceUploader, UPLOAD_STATUS status, String description, HttpSession session){
private synchronized FileUploadingState saveWorkspaceUploaderStatus(FileUploadingState workspaceUploader,
UPLOAD_STATUS status, String description, HttpSession session) {
workspaceUploader.setUploadStatus(status);
workspaceUploader.setStatusDescription(description);
try {
@ -457,20 +481,21 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
return workspaceUploader;
}
/**
* Creates the new workspace uploader.
*
* @param clientUploadKey the client upload key
* @param fileName the file name
* @param user the user
* @param formFieldName the form field name
* @return the workspace uploader item
*/
private FileUploadingState createNewWorkspaceUploader(String clientUploadKey, String fileName, String user){
private FileUploadingState createNewWorkspaceUploader(String clientUploadKey, String fileName, String user, String formFieldName) {
// CLIENT UPLOAD IS THE KEY
FileUploadingState workspaceUploader = new FileUploadingState(clientUploadKey);
workspaceUploader.setClientUploadKey(clientUploadKey);
// Create File
FileUploaded wsUploadFile = new FileUploaded(fileName, null, user);
FileUploaded wsUploadFile = new FileUploaded(fileName, null, user, new FilePath(formFieldName));
workspaceUploader.setFile(wsUploadFile);
return workspaceUploader;
}
@ -483,24 +508,26 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
* @return the workspace uploader item
* @throws Exception the exception
*/
public static void saveWorkspaceUploaderInSession(FileUploadingState workspaceUploader, HttpSession httpSession) throws Exception {
public static void saveWorkspaceUploaderInSession(FileUploadingState workspaceUploader, HttpSession httpSession)
throws Exception {
if (workspaceUploader != null) {
try {
WsUtil.putWorkspaceUploaderInSession(httpSession, workspaceUploader);
} catch (Exception e) {
logger.error("Error during WorkspaceUploaderItem save in session workspace uploader: "+workspaceUploader,e);
logger.error(
"Error during WorkspaceUploaderItem save in session workspace uploader: " + workspaceUploader,
e);
throw new Exception("An error occurred in the upload. Try again");
}
} else
throw new Exception("An error occurred in the upload. Workspace Uploader not found. Abort and try again");
}
/**
* Creates the stream to temp file.
* @param request
*
* @param request the request
* @param workspaceUploader the workspace uploader
* @param in the in
* @param username the username
@ -510,7 +537,9 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
* @return the workspace uploader item
* @throws IOException Signals that an I/O exception has occurred.
*/
public FileUploadingState createStreamToTempFile(HttpServletRequest request, FileUploadingState workspaceUploader, InputStream in, String username, String clientUploadKey, String fileName, String fileExtension) throws IOException{
public FileUploadingState createStreamToTempFile(HttpServletRequest request, FileUploadingState workspaceUploader,
InputStream in, String username, String clientUploadKey, String fileName, String fileExtension)
throws IOException {
if (fileExtension == null)
fileExtension = "";
@ -547,7 +576,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
/**
* Save file uploded in session.
*
@ -556,7 +584,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
*/
private void saveFileUplodedInSession(FileUploaded fileUploaded, HttpSession httpSession) {
if (fileUploaded != null) {
List<FileUploaded> listFiles = (List<FileUploaded>) httpSession.getAttribute(ConstantsMPFormBuilder.FILE_UPLOADED_SESSION_ATTR);
List<FileUploaded> listFiles = (List<FileUploaded>) httpSession
.getAttribute(ConstantsMPFormBuilder.FILE_UPLOADED_SESSION_ATTR);
if (listFiles == null)
listFiles = new ArrayList<FileUploaded>();
@ -578,6 +607,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
logger.debug("Start time: " + startTime);
return startTime;
}
// TEST TIME
/**
* Prints the elapsed time.
@ -603,7 +633,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
HandlerResultMessage resultMessage = HandlerResultMessage.errorResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -614,7 +645,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
}
/**
* Send session expired.
*
@ -628,7 +658,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
HandlerResultMessage resultMessage = HandlerResultMessage.sessionExpiredResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -653,7 +684,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
HandlerResultMessage resultMessage = HandlerResultMessage.okResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -677,7 +709,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
HandlerResultMessage resultMessage = HandlerResultMessage.warnResult(message);
response.getWriter().write(resultMessage.toString());
// 5.6 Closure of Response Object:
//When a response is closed, the container must immediately flush all remaining content in the response buffer to the client
// When a response is closed, the container must immediately flush all remaining
// content in the response buffer to the client
// response.flushBuffer();
} catch (IOException e) {
logger.warn("IOException class name: " + e.getClass().getSimpleName());
@ -724,8 +757,8 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
/**
* Just a method to detect whether the web container is running with
* appengine restrictions.
* Just a method to detect whether the web container is running with appengine
* restrictions.
*
* @return true if the case of the application is running in appengine
*/
@ -748,7 +781,6 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
}
}
/**
* Gets the content length.
*
@ -758,8 +790,7 @@ public class MetadataProfileFormBuilderUploadServlet extends HttpServlet impleme
private long getContentLength(HttpServletRequest request) {
long size = -1;
try {
size = Long.parseLong(request
.getHeader(FileUploadBase.CONTENT_LENGTH));
size = Long.parseLong(request.getHeader(FileUploadBase.CONTENT_LENGTH));
} catch (NumberFormatException e) {
}
return size;

View File

@ -3,7 +3,6 @@ package org.gcube.portlets.widgets.mpformbuilder.shared;
import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.portlets.widgets.mpformbuilder.shared.metadata.MetaDataProfileBean;
import org.gcube.portlets.widgets.mpformbuilder.shared.upload.FileUploaded;

View File

@ -38,7 +38,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
}
/**
* Instantiates a new metadata field.
* Instantiates a new metadata field wrapper.
*
* @param fieldName the field name
* @param mandatory the mandatory
@ -83,7 +83,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
/**
* Gets the field name.
*
* @return the fieldName
* @return the serviceFieldName
*/
public String getFieldName() {
@ -143,7 +143,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
/**
* Sets the field name.
*
* @param fieldName the fieldName to set
* @param fieldName the new field name
*/
public void setFieldName(String fieldName) {
@ -339,7 +339,7 @@ public class MetadataFieldWrapper implements UpdatableField, Serializable {
*/
@Override
public String toString() {
return "MetadataFieldWrapper [" + (fieldName != null ? "fieldName=" + fieldName + ", " : "")
return "MetadataFieldWrapper [" + (fieldName != null ? "serviceFieldName=" + fieldName + ", " : "")
+ (fieldNameFromCategory != null ? "fieldNameFromCategory=" + fieldNameFromCategory + ", " : "")
+ (mandatory != null ? "mandatory=" + mandatory + ", " : "")
+ (maxOccurs != null ? "maxOccurs=" + maxOccurs + ", " : "")

View File

@ -0,0 +1,67 @@
package org.gcube.portlets.widgets.mpformbuilder.shared.upload;
import java.io.Serializable;
/**
* The Class FilePath.
*
* @author Francesco Mangiacrapa at ISTI-CNR francesco.mangiacrapa@isti.cnr.it
*
* Mar 21, 2022
*/
public class FilePath implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5321133561716734223L;
String formFieldLabel; // is the gcubeProfileFieldName in the UCD of Geoportal
/**
* Instantiates a new file paths.
*/
public FilePath() {
}
/**
* Instantiates a new file path.
*
* @param formFieldLabel the form field label
*/
public FilePath(String formFieldLabel) {
this.formFieldLabel = formFieldLabel;
}
/**
* Gets the form field label.
*
* @return the form field label
*/
public String getFormFieldLabel() {
return formFieldLabel;
}
/**
* Sets the form field label.
*
* @param formFieldLabel the new form field label
*/
public void setFormFieldLabel(String formFieldLabel) {
this.formFieldLabel = formFieldLabel;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("FilePath [formFieldLabel=");
builder.append(formFieldLabel);
builder.append("]");
return builder.toString();
}
}

View File

@ -7,7 +7,6 @@ import java.io.Serializable;
import com.google.gwt.user.client.rpc.IsSerializable;
/**
* The Class FileUploaded.
*
@ -17,11 +16,10 @@ import com.google.gwt.user.client.rpc.IsSerializable;
*/
public class FileUploaded implements Serializable, IsSerializable {
/**
*
*/
private static final long serialVersionUID = -7869956386977214114L;
private static final long serialVersionUID = -6666006742990360875L;
/** The file name. */
private String fileName;
@ -31,25 +29,28 @@ public class FileUploaded implements Serializable, IsSerializable{
private String createdByUser;
private FilePath filePath;
/**
* Instantiates a new workspace upload file.
*/
public FileUploaded() {
}
/**
* Instantiates a new workspace upload file.
* Instantiates a new file uploaded.
*
* @param fileName the file name
* @param tempSystemPath the temp system path
* @param createdByUser the created by user
* @param filePath the file path
*/
public FileUploaded(String fileName, String tempSystemPath, String createdByUser) {
public FileUploaded(String fileName, String tempSystemPath, String createdByUser, FilePath filePath) {
super();
this.fileName = fileName;
this.tempSystemPath = tempSystemPath;
this.createdByUser = createdByUser;
this.filePath = filePath;
}
/**
@ -61,8 +62,6 @@ public class FileUploaded implements Serializable, IsSerializable{
return fileName;
}
/**
* Sets the file name.
*
@ -72,8 +71,6 @@ public class FileUploaded implements Serializable, IsSerializable{
this.fileName = fileName;
}
/**
* Gets the temp system path.
*
@ -83,8 +80,6 @@ public class FileUploaded implements Serializable, IsSerializable{
return tempSystemPath;
}
/**
* Sets the temp system path.
*
@ -94,8 +89,6 @@ public class FileUploaded implements Serializable, IsSerializable{
this.tempSystemPath = tempSystemPath;
}
/**
* Gets the created by user.
*
@ -105,8 +98,6 @@ public class FileUploaded implements Serializable, IsSerializable{
return createdByUser;
}
/**
* Sets the created by user.
*
@ -116,7 +107,29 @@ public class FileUploaded implements Serializable, IsSerializable{
this.createdByUser = createdByUser;
}
/**
* Gets the file paths.
*
* @return the file paths
*/
public FilePath getFilePath() {
return filePath;
}
/**
* Sets the file paths.
*
* @param filePaths the new file paths
*/
public void setFilePaths(FilePath filePaths) {
this.filePath = filePaths;
}
/**
* To string.
*
* @return the string
*/
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
@ -126,6 +139,8 @@ public class FileUploaded implements Serializable, IsSerializable{
builder.append(tempSystemPath);
builder.append(", createdByUser=");
builder.append(createdByUser);
builder.append(", filePath=");
builder.append(filePath);
builder.append("]");
return builder.toString();
}