added check when the file uploaded is null

This commit is contained in:
Francesco Mangiacrapa 2024-09-24 16:31:02 +02:00
parent 58fc9d0d52
commit f6a0682777
1 changed files with 59 additions and 52 deletions

View File

@ -137,7 +137,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
* Save geona data forms.
*
* @param profileID the profile ID
* @param optionalMessage the optional message
* @param optionalMessage the optional message
* @param tree_Node the tree node
* @param stepsOnPostCreation the steps on post creation
* @return the commit report
@ -484,43 +484,50 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
// Iterating on the files upload for the section
for (int i = 0; i < files.size(); i++) {
FileUploaded file = files.get(i);
String formFieldName = file.getFilePath().getFormFieldLabel();
LOG.debug("Uploading file: " + file.getFileName() + ", from formFieldName: " + formFieldName);
FilePathDV filePath = retrieveFilePathForGcubeProfileFieldName(formFieldName, profile);
LOG.info("Found {} for the form fieldName {}", filePath, formFieldName);
if (filePath == null) {
String error = "It is not possible to register the file " + formFieldName
+ ", missing configuration in the filePaths config of: " + profile;
throw new Exception(error);
if (file != null && file.getFilePath() != null) {
String formFieldName = file.getFilePath().getFormFieldLabel();
LOG.debug(
"Uploading file: " + file.getFileName() + ", from formFieldName: " + formFieldName);
FilePathDV filePath = retrieveFilePathForGcubeProfileFieldName(formFieldName, profile);
LOG.info("Found {} for the form fieldName {}", filePath, formFieldName);
if (filePath == null) {
String error = "It is not possible to register the file " + formFieldName
+ ", missing configuration in the filePaths config of: " + profile;
throw new Exception(error);
}
// Collecting Fileset per Field Definition
FileSetDataObject collFieldDef = collectFilesetPerFieldDef
.get(filePath.getFieldDefinition());
if (collFieldDef == null) {
collFieldDef = new FileSetDataObject();
collFieldDef.setFilePathDV(filePath);
}
try {
File input = new File(file.getTempSystemPath());
LOG.debug("Temp file is: " + file.getTempSystemPath());
File tempDir = Files.createTempDirectory("GEOPORTAL_UPLOAD_").toFile();
String tmpDirPath = tempDir.getAbsolutePath();
File output = new File(tmpDirPath, file.getFileName());
// input.renameTo(output);
copyContent(input, output);
collFieldDef.addFile(output);
tempDirs.add(tempDir);
tempDir.deleteOnExit();
LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: "
+ file.getFileName());
} catch (Exception e) {
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
}
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
} else {
throw new Exception("Error occurred on uploading file in the section: " + sectionJSONPath
+ ". Please upload it/them again and retry");
}
// Collecting Fileset per Field Definition
FileSetDataObject collFieldDef = collectFilesetPerFieldDef.get(filePath.getFieldDefinition());
if (collFieldDef == null) {
collFieldDef = new FileSetDataObject();
collFieldDef.setFilePathDV(filePath);
}
try {
File input = new File(file.getTempSystemPath());
LOG.debug("Temp file is: " + file.getTempSystemPath());
File tempDir = Files.createTempDirectory("GEOPORTAL_UPLOAD_").toFile();
String tmpDirPath = tempDir.getAbsolutePath();
File output = new File(tmpDirPath, file.getFileName());
// input.renameTo(output);
copyContent(input, output);
collFieldDef.addFile(output);
tempDirs.add(tempDir);
tempDir.deleteOnExit();
LOG.info("Temp file: " + file.getTempSystemPath() + ", copied to new file: "
+ file.getFileName());
} catch (Exception e) {
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
}
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
}
}
@ -1010,18 +1017,18 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
SessionUtil.getCurrentContext(getThreadLocalRequest(), true);
client.deleteProject(profileID, projectID, true);
try {
Project deletedP = client.getProjectByID(profileID, projectID);
if(deletedP!=null) {
String error = "The project with id "+projectID+" still exists";
LOG.error(error +". Sending exception..");
if (deletedP != null) {
String error = "The project with id " + projectID + " still exists";
LOG.error(error + ". Sending exception..");
throw new Exception(error);
}
}catch (Exception e) {
} catch (Exception e) {
throw e;
}
// Updating count of Documents in session per profileID
Integer totalProjectForProfile = client.getTotalDocument(profileID);
SessionUtil.setTotalDocumentForProfileID(getThreadLocalRequest(), profileID, totalProjectForProfile);
@ -1138,8 +1145,8 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
long groupId = pContext.getCurrentGroupId(this.getThreadLocalRequest());
if (user == null || scope == null) {
LOG.warn("called readDataEntryPresentationConfig with invalid parameter user: " + user + ", in the scope: "
+ scope, ", returning null");
LOG.warn("called readDataEntryPresentationConfig with invalid parameter user: " + user
+ ", in the scope: " + scope, ", returning null");
return null;
}
@ -1276,16 +1283,16 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
/**
* Perform action steps.
*
* @param profileID the profile ID
* @param projectID the project ID
* @param profileID the profile ID
* @param projectID the project ID
* @param optionalMessage the optional message
* @param action the action
* @param action the action
* @return the project DV
* @throws Exception the exception
*/
@Override
public StepPerformedResultDV performActionSteps(String profileID, String projectID, String optionalMessage, ActionDefinitionDV action)
throws Exception {
public StepPerformedResultDV performActionSteps(String profileID, String projectID, String optionalMessage,
ActionDefinitionDV action) throws Exception {
LOG.info("performActionSteps called for profileID {}, projectID {}, action: " + action, profileID, projectID);
ProjectsCaller client = GeoportalClientCaller.projects();
@ -1301,12 +1308,12 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
LOG.info("calling stepID {} on projectID {}", stepID, projectID);
project = client.performStep(profileID, projectID, stepID, optionalMessage, null);
}
LifecycleInformationDV lifecycleInfo = getLifecycleInfoForProjectId(profileID, projectID);
lifecycleInfo.getLastOperationStatus();
StepPerformedResultDV sprv = new StepPerformedResultDV(profileID, projectID, lifecycleInfo);
// ProjectDVBuilder projectBuilder = ProjectDVBuilder.newBuilder().fullDocumentMap(true);
// ProjectDV theProject = ConvertToDataValueObjectModel.toProjectDV(project, projectBuilder);
LOG.info("performActionSteps returning theProject with ID {}", sprv);