copy content of temp files into files with "original" uploading name
This commit is contained in:
parent
a3cc2aeaa9
commit
cc3595d4d9
|
@ -1,6 +1,8 @@
|
||||||
package org.gcube.portlets.user.geoportaldataentry.server;
|
package org.gcube.portlets.user.geoportaldataentry.server;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -175,7 +177,7 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
|
|
||||||
LifecycleInformation lifecycleInfo = theProject.getLifecycleInformation();
|
LifecycleInformation lifecycleInfo = theProject.getLifecycleInformation();
|
||||||
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lifecycleInfo);
|
LifecycleInformationDV liDV = ConvertToDataValueObjectModel.toLifecycleInformationDV(lifecycleInfo);
|
||||||
|
|
||||||
return new CommitReport(theProject.getId(), theProject.getProfileID(), theProject.getTheDocument().toJson(),
|
return new CommitReport(theProject.getId(), theProject.getProfileID(), theProject.getTheDocument().toJson(),
|
||||||
liDV);
|
liDV);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -265,8 +267,17 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
collFieldDef = new FileSetDataObject();
|
collFieldDef = new FileSetDataObject();
|
||||||
collFieldDef.setFilePathDV(filePath);
|
collFieldDef.setFilePathDV(filePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
collFieldDef.addFile(new File(file.getTempSystemPath()));
|
try {
|
||||||
|
File input = new File(file.getTempSystemPath());
|
||||||
|
File output = new File(file.getFileName());
|
||||||
|
copyContent(input, output);
|
||||||
|
collFieldDef.addFile(output);
|
||||||
|
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);
|
collectFilesetPerFieldDef.put(filePath.getFieldDefinition(), collFieldDef);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -308,6 +319,37 @@ public class GeoportalDataEntryServiceImpl extends RemoteServiceServlet implemen
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void copyContent(File a, File b) throws Exception {
|
||||||
|
FileInputStream in = new FileInputStream(a);
|
||||||
|
FileOutputStream out = new FileOutputStream(b);
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
int n;
|
||||||
|
|
||||||
|
// read() function to read the
|
||||||
|
// byte of data
|
||||||
|
while ((n = in.read()) != -1) {
|
||||||
|
// write() function to write
|
||||||
|
// the byte of data
|
||||||
|
out.write(n);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (in != null) {
|
||||||
|
|
||||||
|
// close() function to close the
|
||||||
|
// stream
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
// close() function to close
|
||||||
|
// the stream
|
||||||
|
if (out != null) {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println("File Copied");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve file path for gcube profile field name.
|
* Retrieve file path for gcube profile field name.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue