ref 18096: DataMiner - HTML file does not open in view widget but in a new browser window

https://support.d4science.org/issues/18096

Fixed Content-Type in output files

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-analysis/DataMiner@182280 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2019-11-20 15:43:27 +00:00
parent b1fcb7a96f
commit 1b1117997e
3 changed files with 159 additions and 103 deletions

View File

@ -1,24 +1,36 @@
<ReleaseNotes>
<Changeset component="${groupId}.${artifactId}.1-5-8" date="2019-10-01">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-9"
date="2019-11-20">
<Change>Fixed Content-Type support for files in the results of
computations[ticket #18096]</Change>
</Changeset>
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-8"
date="2019-10-01">
<Change>Fixed https link for output parameter [ticket #17659]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-7" date="2019-03-01">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-7"
date="2019-03-01">
<Change>Updated https support [ticket #13024]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-6" date="2018-12-13">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-6"
date="2018-12-13">
<Change>Added https support [ticket #13024]</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-2" date="2017-12-13">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-2"
date="2017-12-13">
<Change>added the right extension on output file</Change>
<Change>lock file created on execution</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-1" date="2017-09-14">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-1"
date="2017-09-14">
<Change>added accounting on algorithm execution</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-5-0" date="2017-07-31">
<Changeset component="org.gcube.dataanalysis.dataminer.1-5-0"
date="2017-07-31">
<Change>service interface classes moved to wps project</Change>
</Changeset>
<Changeset component="${groupId}.${artifactId}.1-1-0" date="2016-10-03">
<Changeset component="org.gcube.dataanalysis.dataminer.1-1-0"
date="2016-10-03">
<Change>First Release</Change>
</Changeset>
</ReleaseNotes>

19
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.dataanalysis</groupId>
<artifactId>dataminer</artifactId>
<version>1.5.8-SNAPSHOT</version>
<version>1.5.9-SNAPSHOT</version>
<name>dataminer</name>
<description>An e-Infrastructure service providing state-of-the art DataMining algorithms and ecological modelling approaches under the Web Processing Service (WPS) standard.</description>
<scm>
@ -125,25 +125,14 @@
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- <dependency> <groupId>org.gcube.common</groupId> <artifactId>common-authorization</artifactId>
</dependency> <dependency> <groupId>org.gcube.core</groupId> <artifactId>common-scope</artifactId>
</dependency> -->
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!-- <dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library-jcr</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>home-library</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
</dependency> -->
<dependency >
<groupId>org.gcube.common</groupId>
<artifactId>storagehub-client-library</artifactId>

View File

@ -21,7 +21,7 @@ import org.slf4j.LoggerFactory;
public class OutputsManager {
private static Logger LOGGER = LoggerFactory.getLogger(OutputsManager.class);
private AlgorithmConfiguration config;
private List<File> generatedFiles = new ArrayList<File>();
@ -29,7 +29,7 @@ public class OutputsManager {
private IClient storageclient;
private String computationsession;
private List<StoredData> provenanceData = new ArrayList<StoredData>();
public List<StoredData> getProvenanceData() {
return provenanceData;
}
@ -37,7 +37,7 @@ public class OutputsManager {
public List<File> getGeneratedData() {
return generatedFiles;
}
public List<File> getGeneratedFiles() {
return generatedFiles;
}
@ -46,12 +46,13 @@ public class OutputsManager {
return generatedTables;
}
public OutputsManager(AlgorithmConfiguration config,String computationsession) {
public OutputsManager(AlgorithmConfiguration config, String computationsession) {
this.config = config;
this.computationsession=computationsession;
this.computationsession = computationsession;
}
public LinkedHashMap<String, Object> createOutput(StatisticalType prioroutput, StatisticalType posterioroutput) throws Exception {
public LinkedHashMap<String, Object> createOutput(StatisticalType prioroutput, StatisticalType posterioroutput)
throws Exception {
LinkedHashMap<String, Object> outputs = new LinkedHashMap<String, Object>();
@ -66,10 +67,10 @@ public class OutputsManager {
StatisticalTypeToWPSType postconverter = new StatisticalTypeToWPSType();
postconverter.convert2WPSType(posterioroutput, false, config);
generatedFiles.addAll(postconverter.getGeneratedFiles());
LOGGER.debug("Generated Files "+generatedFiles);
LOGGER.debug("Generated Files " + generatedFiles);
generatedTables.addAll(postconverter.getGeneratedTables());
LOGGER.debug("Generated Tables "+generatedFiles);
LOGGER.debug("Generated Tables " + generatedFiles);
LinkedHashMap<String, IOWPSInformation> postOutput = postconverter.outputSet;
LinkedHashMap<String, IOWPSInformation> ndoutput = new LinkedHashMap<String, IOWPSInformation>();
@ -102,21 +103,23 @@ public class OutputsManager {
if (ConfigurationManager.useStorage()) {
if (postInfo.getLocalMachineContent() != null) {
// return the url from storage manager
String storageurl = uploadFileOnStorage(postInfo.getLocalMachineContent(), postInfo.getMimetype());
String storageurl = uploadFileOnStorage(postInfo.getLocalMachineContent(),
postInfo.getMimetype());
postInfo.setContent(storageurl);
}
}
/*
else if (postInfo.getLocalMachineContent() != null) {
String url = "<wps:Reference mimeType=\""+postInfo.getMimetype()+"\" xlink:href=\""+postInfo.getContent()+"\" method=\"GET\"/>";
LOGGER.debug("Reference URL: " + url);
outputs.put(okey, url);
}
else*/
* else if (postInfo.getLocalMachineContent() != null) { String
* url = "<wps:Reference mimeType=\""+postInfo.getMimetype()
* +"\" xlink:href=\""+postInfo.getContent()
* +"\" method=\"GET\"/>"; LOGGER.debug("Reference URL: " +
* url); outputs.put(okey, url); } else
*/
if (info != null) {
LOGGER.debug("Found a corresponding output: " + okey);
outputs.put(okey, postInfo.getContent());
//add link to the file also among the non deterministic output
// add link to the file also among the non deterministic
// output
if (postInfo.getLocalMachineContent() != null) {
ndoutput.put(okey, postInfo);
}
@ -129,23 +132,23 @@ public class OutputsManager {
System.gc();
}
XmlObject ndxml = generateNonDeterministicOutput(ndoutput);
outputs.put("non_deterministic_output", ndxml);
//safety check for declared output, i.e. a priori output
for (String pkey:priorOutput.keySet()){
if (outputs.get(pkey)==null){
LOGGER.debug("Safety check: adding empty string for " + pkey+ " of type "+priorOutput.get(pkey).getClassname());
// safety check for declared output, i.e. a priori output
for (String pkey : priorOutput.keySet()) {
if (outputs.get(pkey) == null) {
LOGGER.debug("Safety check: adding empty string for " + pkey + " of type "
+ priorOutput.get(pkey).getClassname());
outputs.put(pkey, "");
}
}
LOGGER.debug("OutputsManager outputs "+outputs);
LOGGER.debug("OutputsManager outputs " + outputs);
return outputs;
}
private void saveProvenanceData(IOWPSInformation info){
private void saveProvenanceData(IOWPSInformation info) {
String name = info.getName();
String id = info.getName();
DataProvenance provenance = DataProvenance.COMPUTED;
@ -153,59 +156,97 @@ public class OutputsManager {
String operator = config.getAgent();
String computationId = computationsession;
String type = info.getMimetype();
/* if (info.getLocalMachineContent() != null) {
type = StoredType.DATA;
}
*/
/*
* if (info.getLocalMachineContent() != null) { type = StoredType.DATA;
* }
*/
String payload = info.getContent();
StoredData data = new StoredData(name, info.getAbstractStr(),id, provenance, creationDate, operator, computationId, type,payload,config.getGcubeScope());
StoredData data = new StoredData(name, info.getAbstractStr(), id, provenance, creationDate, operator,
computationId, type, payload, config.getGcubeScope());
provenanceData.add(data);
}
private void prepareForStoring() {
LOGGER.debug("Preparing storage client");
//String scope = config.getGcubeScope();
//ScopeProvider.instance.set(scope);
// String scope = config.getGcubeScope();
// ScopeProvider.instance.set(scope);
String serviceClass = "WPS";
String serviceName = "wps.synch";
String owner = config.getParam(ConfigurationManager.serviceUserNameParameterVariable);
storageclient = new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, MemoryType.VOLATILE).getClient();
storageclient = new StorageClient(serviceClass, serviceName, owner, AccessType.SHARED, MemoryType.VOLATILE)
.getClient();
LOGGER.debug("Storage client ready");
}
private String uploadFileOnStorage(String localfile, String mimetype) throws Exception {
LOGGER.debug("Storing->Start uploading on storage the following file: " + localfile);
File localFile = new File(localfile);
String remotef = "/wps_synch_output/" +config.getAgent()+"/"+computationsession+"/"+ localFile.getName();
storageclient.put(true).LFile(localfile).RFile(remotef);
String remotef = "/wps_synch_output/" + config.getAgent() + "/" + computationsession + "/"
+ localFile.getName();
String contentType=retrieveContentType(localfile);
LOGGER.debug("Retrieved Content-Type: "+contentType);
if(contentType==null||contentType.isEmpty()){
storageclient.put(true).LFile(localfile).RFile(remotef);
} else {
storageclient.put(true,contentType).LFile(localfile).RFile(remotef);
}
String url = storageclient.getHttpsUrl().RFile(remotef);
/*
if (config.getGcubeScope().startsWith("/gcube"))
url = "http://data-d.d4science.org/uri-resolver/smp?smp-uri=" + url + "&fileName=" + localFile.getName() + "&contentType=" + mimetype;
else
url = "http://data.d4science.org/uri-resolver/smp?smp-uri=" + url+ "&fileName=" + localFile.getName() + "&contentType=" + mimetype;
*/
* if (config.getGcubeScope().startsWith("/gcube")) url =
* "http://data-d.d4science.org/uri-resolver/smp?smp-uri=" + url +
* "&fileName=" + localFile.getName() + "&contentType=" + mimetype; else
* url = "http://data.d4science.org/uri-resolver/smp?smp-uri=" + url+
* "&fileName=" + localFile.getName() + "&contentType=" + mimetype;
*/
LOGGER.info("Storing->Uploading finished - URL: " + url);
return url;
}
private String retrieveContentType(String fileName) {
String contentType=null;
if (fileName != null && !fileName.isEmpty()) {
String fileNameLowerCase = fileName.toLowerCase();
if (fileNameLowerCase.endsWith(".html") || fileNameLowerCase.endsWith(".htm")) {
contentType="text/html";
} else {
if (fileNameLowerCase.endsWith(".pdf")) {
contentType="application/pdf";
} else {
if (fileNameLowerCase.endsWith(".log") || fileNameLowerCase.endsWith(".txt")) {
contentType="text/plain";
} else {
if (fileNameLowerCase.endsWith(".json")) {
contentType="application/json";
} else {
}
}
}
}
}
return contentType;
}
public String cleanTagString(String tag) {
return tag.replace(" ", "_").replaceAll("[\\]\\[!\"#$%&'()*+,\\./:;<=>?@\\^`{|}~-]", "");
}
public XmlObject generateNonDeterministicOutputPlain(LinkedHashMap<String, IOWPSInformation> ndoutput) throws Exception {
String XMLString = "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">\n" + " <d4science:output fid=\"outputcollection\">\n";
public XmlObject generateNonDeterministicOutputPlain(LinkedHashMap<String, IOWPSInformation> ndoutput)
throws Exception {
String XMLString = "<gml:featureMember xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">\n"
+ " <d4science:output fid=\"outputcollection\">\n";
for (String key : ndoutput.keySet()) {
IOWPSInformation info = ndoutput.get(key);
String payload = info.getContent();
String mimetype = info.getMimetype();
XMLString += " <d4science:k_" + cleanTagString(key) + ">" + " <d4science:Data><![CDATA[" + payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA[" + (info.getAbstractStr() != null ? info.getAbstractStr() : "") + "]]></d4science:Description>\n" + " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </d4science:k_" + cleanTagString(key) + ">\n";
XMLString += " <d4science:k_" + cleanTagString(key) + ">" + " <d4science:Data><![CDATA["
+ payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA["
+ (info.getAbstractStr() != null ? info.getAbstractStr() : "") + "]]></d4science:Description>\n"
+ " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </d4science:k_"
+ cleanTagString(key) + ">\n";
}
XMLString += " </d4science:output>\n" + "</gml:featureMember>\n";
@ -219,16 +260,21 @@ public class OutputsManager {
return xmlData;
}
public XmlObject generateNonDeterministicOutputCollection(LinkedHashMap<String, IOWPSInformation> ndoutput) throws Exception {
String XMLString = "<ogr:FeatureCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://ogr.maptools.org/ result_8751.xsd\" xmlns:ogr=\"http://ogr.maptools.org/\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">" +
"\n<gml:featureMember>\n" + " <ogr:Result fid=\"F0\">\n" +
" <d4science:output fid=\"outputcollection\">\n";
public XmlObject generateNonDeterministicOutputCollection(LinkedHashMap<String, IOWPSInformation> ndoutput)
throws Exception {
String XMLString = "<ogr:FeatureCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://ogr.maptools.org/ result_8751.xsd\" xmlns:ogr=\"http://ogr.maptools.org/\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">"
+ "\n<gml:featureMember>\n" + " <ogr:Result fid=\"F0\">\n"
+ " <d4science:output fid=\"outputcollection\">\n";
for (String key : ndoutput.keySet()) {
IOWPSInformation info = ndoutput.get(key);
String payload = info.getContent();
String mimetype = info.getMimetype();
XMLString += " <d4science:k_" + cleanTagString(key) + ">" + " <d4science:Data><![CDATA[" + payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA[" + (info.getAbstractStr() != null ? info.getAbstractStr() : "") + "]]></d4science:Description>\n" + " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </d4science:k_" + cleanTagString(key) + ">\n";
XMLString += " <d4science:k_" + cleanTagString(key) + ">" + " <d4science:Data><![CDATA["
+ payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA["
+ (info.getAbstractStr() != null ? info.getAbstractStr() : "") + "]]></d4science:Description>\n"
+ " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </d4science:k_"
+ cleanTagString(key) + ">\n";
}
XMLString += " </d4science:output>\n" + " </ogr:Result>\n</gml:featureMember>\n</ogr:FeatureCollection>";
@ -241,37 +287,46 @@ public class OutputsManager {
return xmlData;
}
public XmlObject generateNonDeterministicOutput(LinkedHashMap<String, IOWPSInformation> ndoutput) throws Exception {
if (ndoutput.size()==0)
if (ndoutput.size() == 0)
return null;
String XMLString = "<ogr:FeatureCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://ogr.maptools.org/ result_8751.xsd\" xmlns:ogr=\"http://ogr.maptools.org/\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">" +
"\n<gml:featureMember>\n";
String XMLString = "<ogr:FeatureCollection xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://ogr.maptools.org/ result_8751.xsd\" xmlns:ogr=\"http://ogr.maptools.org/\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:d4science=\"http://www.d4science.org\">"
+ "\n<gml:featureMember>\n";
int count = 0;
for (String key : ndoutput.keySet()) {
IOWPSInformation info = ndoutput.get(key);
String payload = info.getContent();
String mimetype = info.getMimetype();
String abstractStr = info.getAbstractStr();
LOGGER.debug("IOWPS Information [name="+info.getName()+", abstr="+info.getAbstractStr()+", content="+info.getContent()+", def="+info.getDefaultVal()+"]");
if ((abstractStr==null || abstractStr.trim().length()==0) && (payload!= null && payload.trim().length()>0))
LOGGER.debug("IOWPS Information [name=" + info.getName() + ", abstr=" + info.getAbstractStr() + ", content="
+ info.getContent() + ", def=" + info.getDefaultVal() + "]");
if ((abstractStr == null || abstractStr.trim().length() == 0)
&& (payload != null && payload.trim().length() > 0))
abstractStr = info.getName();
else if (abstractStr == null)
abstractStr = "";
//geospatialized
// XMLString += " <ogr:Result fid=\"F" + count+ "\">" + "<ogr:geometryProperty><gml:Point><gml:coordinates>0,0</gml:coordinates></gml:Point></ogr:geometryProperty>"+ " <d4science:Data><![CDATA[" + payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA[" + (info.getAbstractStr() != null ? info.getAbstractStr() : "") + "]]></d4science:Description>\n" + " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </ogr:Result>\n";
XMLString += " <ogr:Result fid=\"F" + count+ "\">" + " <d4science:Data><![CDATA[" + payload + "]]></d4science:Data>\n" + " <d4science:Description><![CDATA[" + abstractStr + "]]></d4science:Description>\n" + " <d4science:MimeType>" + mimetype + "</d4science:MimeType>\n" + " </ogr:Result>\n";
// geospatialized
// XMLString += " <ogr:Result fid=\"F" + count+ "\">" +
// "<ogr:geometryProperty><gml:Point><gml:coordinates>0,0</gml:coordinates></gml:Point></ogr:geometryProperty>"+
// " <d4science:Data><![CDATA[" + payload + "]]></d4science:Data>\n"
// + " <d4science:Description><![CDATA[" + (info.getAbstractStr() !=
// null ? info.getAbstractStr() : "") +
// "]]></d4science:Description>\n" + " <d4science:MimeType>" +
// mimetype + "</d4science:MimeType>\n" + " </ogr:Result>\n";
XMLString += " <ogr:Result fid=\"F" + count + "\">" + " <d4science:Data><![CDATA[" + payload
+ "]]></d4science:Data>\n" + " <d4science:Description><![CDATA[" + abstractStr
+ "]]></d4science:Description>\n" + " <d4science:MimeType>" + mimetype
+ "</d4science:MimeType>\n" + " </ogr:Result>\n";
count++;
}
XMLString += " </gml:featureMember>\n</ogr:FeatureCollection>";
LOGGER.debug("Non deterministic output: " + XMLString);
XmlObject xmlData = XmlObject.Factory.newInstance();
@ -281,12 +336,12 @@ public class OutputsManager {
return xmlData;
}
public void shutdown(){
try{
storageclient.close();
}catch(Exception e){
public void shutdown() {
try {
storageclient.close();
} catch (Exception e) {
}
}
}