Get File from Url

This commit is contained in:
Fabio Sinibaldi 2022-04-08 14:52:11 +02:00
parent fdd5c4845c
commit 00536fc8b4
3 changed files with 11 additions and 6 deletions

View File

@ -11,10 +11,11 @@ import org.gcube.application.geoportal.common.faults.InvalidRequestException;
public class TempFile {
private String id;
private String url;
private String filename;
public void validate()throws InvalidRequestException {
if(id==null || id.isEmpty()) throw new InvalidRequestException("Invalid temp file "+this+" : ID null or empty");
if((id==null || id.isEmpty() )&&(url==null||url.isEmpty())) throw new InvalidRequestException("Invalid temp file "+this+" : ID null or empty and no url defined");
if(filename==null || filename.isEmpty()) throw new InvalidRequestException("Invalid temp file "+this+" : filename null or empty");
}
}

View File

@ -792,7 +792,11 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
InputStream is=null;
try{
log.debug("Opening temp file {}",f);
String fileUrl=storage.getURL(f.getId());
String fileUrl=null;
if(f.getId()==null||f.getId().isEmpty())
fileUrl=f.getUrl();
else fileUrl=storage.getURL(f.getId());
log.debug("Got URL {} from ID {}",fileUrl,f.getId());
is=new URL(fileUrl).openStream();
RegisteredFile registered=ws.registerFile(new WorkspaceManager.FileOptions(f.getFilename(),is,

View File

@ -62,16 +62,16 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
public void testUploadFileSet() throws Exception {
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
Document baseDoc=new Document();
baseDoc.put("relazioneScavo",new Document("title","My Title"));
baseDoc.put("section",new Document("title","My Title"));
Project doc = createNew(baseDoc);
assertTrue(doc.getTheDocument().containsKey("relazioneScavo"));
assertTrue(doc.getTheDocument().containsKey("section"));
// Try set releazione scavo
String parentPath="relazioneScavo";
String parentPath="section";
String fieldName="fileset";
String fieldDefinition="relazioneScavo."+Field.CHILDREN+"[?(@.fileset)]";
String fieldDefinition="section."+Field.CHILDREN+"[?(@.fileset)]";
String filename = "relazione.pdf";