|
|
|
@ -232,6 +232,17 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update geportal data form.
|
|
|
|
|
*
|
|
|
|
|
* @param profileID the profile ID
|
|
|
|
|
* @param projectID the project ID
|
|
|
|
|
* @param section the section
|
|
|
|
|
* @param sectionPath the section path
|
|
|
|
|
* @param listFilePaths the list file paths
|
|
|
|
|
* @return the commit report
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public CommitReport updateGeportalDataForm(String profileID, String projectID, GeoNaFormDataObject section,
|
|
|
|
|
String sectionPath, List<FilePathDV> listFilePaths) throws Exception {
|
|
|
|
@ -327,6 +338,14 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
|
|
|
|
|
if (listFilePaths != null) {
|
|
|
|
|
|
|
|
|
|
// Collecting new files
|
|
|
|
|
List<? extends FileUploaded> filesUploaded = sectionBean.getFilesUploaded();
|
|
|
|
|
Map<String, FileSetDataObject> mapFilesToRegistrer = null;
|
|
|
|
|
if (filesUploaded != null && !filesUploaded.isEmpty()) {
|
|
|
|
|
mapFilesToRegistrer = collectFiles(currentProject, sectionPath, section.getGcubeProfileDV(),
|
|
|
|
|
filesUploaded);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Cleaning all the fileset path of the section (defined in the UCD)
|
|
|
|
|
for (FilePathDV filePath : listFilePaths) {
|
|
|
|
|
|
|
|
|
@ -342,11 +361,27 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Registering new files
|
|
|
|
|
List<? extends FileUploaded> filesUploaded = sectionBean.getFilesUploaded();
|
|
|
|
|
if (filesUploaded != null && !filesUploaded.isEmpty()) {
|
|
|
|
|
replaceFiles(currentProject, sectionPath, section.getGcubeProfileDV(), filesUploaded);
|
|
|
|
|
// Registering fileset in the section according to mapFilesToRegistrer
|
|
|
|
|
if (mapFilesToRegistrer != null && mapFilesToRegistrer.size()>0) {
|
|
|
|
|
LOG.info("Cluster of fileset per fieldDefinition is: " + mapFilesToRegistrer);
|
|
|
|
|
String theJSONDocument = currentProject.getTheDocument().toJson();
|
|
|
|
|
MongoServiceUtil mongoService = new MongoServiceUtil();
|
|
|
|
|
|
|
|
|
|
for (String fieldDefinition : mapFilesToRegistrer.keySet()) {
|
|
|
|
|
FileSetDataObject uploadedFileset = mapFilesToRegistrer.get(fieldDefinition);
|
|
|
|
|
LOG.info("Uploading fileset: " + uploadedFileset);
|
|
|
|
|
File[] fileset = uploadedFileset.getFileset();
|
|
|
|
|
FilePathDV filePath = uploadedFileset.getFilePathDV();
|
|
|
|
|
Access access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument,
|
|
|
|
|
sectionPath);
|
|
|
|
|
|
|
|
|
|
LOG.info("Going to register fileset: " + Arrays.asList(fileset).toString());
|
|
|
|
|
mongoService.registerFileSet(currentProject.getProfileID(), currentProject, sectionPath,
|
|
|
|
|
filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info("Project with id " + currentProject.getId() + " updated correclty");
|
|
|
|
@ -530,6 +565,84 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Collect files.
|
|
|
|
|
*
|
|
|
|
|
* @param theProject the the project
|
|
|
|
|
* @param sectionJSONPath the section JSON path
|
|
|
|
|
* @param gcubeProfile the gcube profile
|
|
|
|
|
* @param files the files
|
|
|
|
|
* @return the map of files that must be registered
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
protected Map<String, FileSetDataObject> collectFiles(Project theProject, String sectionJSONPath,
|
|
|
|
|
GcubeProfileDV gcubeProfile, List<? extends FileUploaded> files) throws Exception {
|
|
|
|
|
LOG.debug("collectFiles called [projectID: " + theProject.getId() + "], [sectionJSONPath: " + sectionJSONPath
|
|
|
|
|
+ "], [files: " + files + "]");
|
|
|
|
|
|
|
|
|
|
Map<String, FileSetDataObject> collectFilesetPerFieldDef = new HashMap<String, FileSetDataObject>();
|
|
|
|
|
if (files.size() > 0) {
|
|
|
|
|
// 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, gcubeProfile);
|
|
|
|
|
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: " + gcubeProfile;
|
|
|
|
|
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 tempDir = Files.createTempDirectory("GEOPORTAL_REPLACE_FILES_").toFile();
|
|
|
|
|
String tmpDirPath = tempDir.getAbsolutePath();
|
|
|
|
|
File input;
|
|
|
|
|
File output;
|
|
|
|
|
if (file instanceof FileUploadedRemote) {
|
|
|
|
|
FileUploadedRemote remote = (FileUploadedRemote) file;
|
|
|
|
|
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
|
|
|
|
InputStream in = new URL(remote.getUrl()).openStream();
|
|
|
|
|
String fileName = (remote.getFileName() == null || remote.getFileName().isEmpty())
|
|
|
|
|
? "file_" + Random.nextInt()
|
|
|
|
|
: remote.getFileName();
|
|
|
|
|
output = new File(tmpDirPath, fileName);
|
|
|
|
|
Path outputAbsolutePath = Paths.get(output.getAbsolutePath());
|
|
|
|
|
Files.copy(in, outputAbsolutePath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
|
LOG.info("Remote file: " + remote.getUrl() + ", copied to new file: " + output.getName());
|
|
|
|
|
} else {
|
|
|
|
|
LOG.info("Uploaded file is local: " + file.getTempSystemPath());
|
|
|
|
|
input = new File(file.getTempSystemPath());
|
|
|
|
|
output = new File(tmpDirPath, file.getFileName());
|
|
|
|
|
copyContent(input, output);
|
|
|
|
|
LOG.info(
|
|
|
|
|
"Temp file: " + file.getTempSystemPath() + ", copied to new file: " + output.getName());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
collFieldDef.addFile(output);
|
|
|
|
|
tempDir.deleteOnExit();
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOG.warn("Skipping file: " + file.getFileName() + ". Error: " + e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return collectFilesetPerFieldDef;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Replace files.
|
|
|
|
|
*
|
|
|
|
@ -576,7 +689,9 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
FileUploadedRemote remote = (FileUploadedRemote) file;
|
|
|
|
|
LOG.info("Uploaded file is remote: " + remote.getUrl());
|
|
|
|
|
InputStream in = new URL(remote.getUrl()).openStream();
|
|
|
|
|
String fileName = (remote.getFileName()==null || remote.getFileName().isEmpty())?"file_"+Random.nextInt():remote.getFileName();
|
|
|
|
|
String fileName = (remote.getFileName() == null || remote.getFileName().isEmpty())
|
|
|
|
|
? "file_" + Random.nextInt()
|
|
|
|
|
: remote.getFileName();
|
|
|
|
|
output = new File(tmpDirPath, fileName);
|
|
|
|
|
Path outputAbsolutePath = Paths.get(output.getAbsolutePath());
|
|
|
|
|
Files.copy(in, outputAbsolutePath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
@ -613,7 +728,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
FilePathDV filePath = uploadedFileset.getFilePathDV();
|
|
|
|
|
Access access = ConvertToDataServiceModel.getAccessFromDocumentSection(theJSONDocument, sectionJSONPath);
|
|
|
|
|
|
|
|
|
|
LOG.info("Going to registrer files: " + Arrays.asList(fileset).toString());
|
|
|
|
|
LOG.info("Going to register files: " + Arrays.asList(fileset).toString());
|
|
|
|
|
mongoService.registerFileSet(theProject.getProfileID(), theProject, sectionJSONPath,
|
|
|
|
|
filePath.getFieldName(), filePath.getFieldDefinition(), access, fileset);
|
|
|
|
|
|
|
|
|
@ -1397,6 +1512,14 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the project edit.
|
|
|
|
|
*
|
|
|
|
|
* @param profileID the profile ID
|
|
|
|
|
* @param projectID the project ID
|
|
|
|
|
* @return the project edit
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ProjectEdit getProjectEdit(String profileID, String projectID) throws Exception {
|
|
|
|
|
LOG.info("getProjectEdit called for profileID: {}, and projectID: {}", profileID, projectID);
|
|
|
|
@ -1417,16 +1540,25 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectEdit(projectEdit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info(ProjectEdit.class.getSimpleName()+" returing not null: " + (projectEdit != null));
|
|
|
|
|
LOG.info(ProjectEdit.class.getSimpleName() + " returing not null: " + (projectEdit != null));
|
|
|
|
|
return projectEdit;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String erroMsg = "Error occurred on reading "+ProjectEdit.class.getSimpleName()+" DTO for id: " + projectID;
|
|
|
|
|
String erroMsg = "Error occurred on reading " + ProjectEdit.class.getSimpleName() + " DTO for id: "
|
|
|
|
|
+ projectID;
|
|
|
|
|
LOG.warn(erroMsg, e);
|
|
|
|
|
throw new Exception(
|
|
|
|
|
erroMsg + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Gets the project view.
|
|
|
|
|
*
|
|
|
|
|
* @param profileID the profile ID
|
|
|
|
|
* @param projectID the project ID
|
|
|
|
|
* @return the project view
|
|
|
|
|
* @throws Exception the exception
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public ProjectView getProjectView(String profileID, String projectID) throws Exception {
|
|
|
|
|
LOG.info("getProjectEdit called for profileID: {}, and projectID: {}", profileID, projectID);
|
|
|
|
@ -1447,10 +1579,11 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
|
|
|
|
Geoportal_JSON_Mapper.prettyPrintProjectView(projectView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LOG.info(ProjectView.class.getSimpleName()+" returing not null: " + (projectView != null));
|
|
|
|
|
LOG.info(ProjectView.class.getSimpleName() + " returing not null: " + (projectView != null));
|
|
|
|
|
return projectView;
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
String erroMsg = "Error occurred on reading "+ProjectView.class.getSimpleName()+" DTO for id: " + projectID;
|
|
|
|
|
String erroMsg = "Error occurred on reading " + ProjectView.class.getSimpleName() + " DTO for id: "
|
|
|
|
|
+ projectID;
|
|
|
|
|
LOG.warn(erroMsg, e);
|
|
|
|
|
throw new Exception(
|
|
|
|
|
erroMsg + ". Error: " + e.getMessage() + ". Refresh and try again or contact the support");
|
|
|
|
|