Commit 880ff055 authored by Emilien Bondu's avatar Emilien Bondu

WEBLAB-1271. Add links to select available translations.

git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/trunk/WebLabServices/Portlets/metadata-portlet@3909 a803c184-d8de-4a0e-a52b-d3eef88212b6
parent 49ab0d99
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<groupId>org.ow2.weblab.portlets</groupId> <groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-metaview</artifactId> <artifactId>weblab-metaview</artifactId>
<version>2.1.2</version> <version>2.1.3-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>WebLab Metaview</name> <name>WebLab Metaview</name>
...@@ -55,6 +55,10 @@ ...@@ -55,6 +55,10 @@
<groupId>org.ow2.weblab.core</groupId> <groupId>org.ow2.weblab.core</groupId>
<artifactId>annotator</artifactId> <artifactId>annotator</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.ow2.weblab.core.helpers</groupId>
<artifactId>rdf-helper-jena-structure</artifactId>
</dependency>
</dependencies> </dependencies>
<description>This portlet displays WebLab resources metadata.</description> <description>This portlet displays WebLab resources metadata.</description>
...@@ -68,7 +72,7 @@ ...@@ -68,7 +72,7 @@
<dependency> <dependency>
<groupId>org.ow2.weblab.components</groupId> <groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-taglib</artifactId> <artifactId>weblab-taglib</artifactId>
<version>0.0.4</version> <version>0.0.5</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.ow2.weblab.core</groupId> <groupId>org.ow2.weblab.core</groupId>
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2014 Airbus Defence and Space
*
* This library is free software; you can redistribute it and/or modify it under the terms of
* the GNU Lesser General Public License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*/
package org.ow2.weblab.portlet.business.bean;
/**
* A service description bean.
*
* @author emilienbondu
*
*/
public class ServiceDescription {
private String uri,label;
public String getUri() {
return uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
}
...@@ -18,13 +18,21 @@ ...@@ -18,13 +18,21 @@
package org.ow2.weblab.portlet.business.service; package org.ow2.weblab.portlet.business.service;
import java.util.Locale;
import java.util.Map;
import org.ow2.weblab.core.model.PieceOfKnowledge; import org.ow2.weblab.core.model.PieceOfKnowledge;
import org.ow2.weblab.core.model.Resource; import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.services.ContentNotAvailableException; import org.ow2.weblab.core.services.ContentNotAvailableException;
import org.ow2.weblab.portlet.business.bean.ServiceDescription;
public interface MetaViewBusinessServices { public interface MetaViewBusinessServices {
public Resource getWLResource(String docURI, String remoteUser) throws ContentNotAvailableException; public Resource getWLResource(String docURI, String remoteUser) throws ContentNotAvailableException;
public String getURIFromPoK(PieceOfKnowledge pok); public String getURIFromPoK(PieceOfKnowledge pok);
public Map<String, ServiceDescription> getTranslations(Resource res, Locale prefered);
public PieceOfKnowledge getPoKForSelectedTranslation(String uri, String serviceURI, String lang);
} }
...@@ -19,28 +19,46 @@ ...@@ -19,28 +19,46 @@
package org.ow2.weblab.portlet.business.service.impl; package org.ow2.weblab.portlet.business.service.impl;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import javax.portlet.PortletContext; import javax.portlet.PortletContext;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.components.client.WebLabClient; import org.ow2.weblab.components.client.WebLabClient;
import org.ow2.weblab.core.extended.exception.WebLabCheckedException; import org.ow2.weblab.core.extended.exception.WebLabCheckedException;
import org.ow2.weblab.core.extended.ontologies.DublinCore;
import org.ow2.weblab.core.extended.ontologies.RDFS;
import org.ow2.weblab.core.extended.ontologies.WebLabModel;
import org.ow2.weblab.core.extended.ontologies.WebLabProcessing;
import org.ow2.weblab.core.extended.ontologies.WebLabRetrieval; import org.ow2.weblab.core.extended.ontologies.WebLabRetrieval;
import org.ow2.weblab.core.helper.impl.AdvancedSelector; import org.ow2.weblab.core.helper.impl.AdvancedSelector;
import org.ow2.weblab.core.helper.impl.RDFSelectorFactory; import org.ow2.weblab.core.helper.impl.RDFSelectorFactory;
import org.ow2.weblab.core.helper.impl.SemanticResource;
import org.ow2.weblab.core.helper.impl.Statements; import org.ow2.weblab.core.helper.impl.Statements;
import org.ow2.weblab.core.model.PieceOfKnowledge; import org.ow2.weblab.core.model.PieceOfKnowledge;
import org.ow2.weblab.core.model.Resource; import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.model.processing.WProcessingAnnotator;
import org.ow2.weblab.core.services.ContentNotAvailableException; import org.ow2.weblab.core.services.ContentNotAvailableException;
import org.ow2.weblab.core.services.ResourceContainer; import org.ow2.weblab.core.services.ResourceContainer;
import org.ow2.weblab.core.services.resourcecontainer.LoadResourceArgs; import org.ow2.weblab.core.services.resourcecontainer.LoadResourceArgs;
import org.ow2.weblab.core.services.resourcecontainer.LoadResourceReturn; import org.ow2.weblab.core.services.resourcecontainer.LoadResourceReturn;
import org.ow2.weblab.portlet.business.bean.ServiceConfBean; import org.ow2.weblab.portlet.business.bean.ServiceConfBean;
import org.ow2.weblab.portlet.business.bean.ServiceDescription;
import org.ow2.weblab.portlet.business.service.MetaViewBusinessServices; import org.ow2.weblab.portlet.business.service.MetaViewBusinessServices;
import org.purl.dc.elements.DublinCoreAnnotator;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
@Service(value="metaviewBusinessService") @Service(value="metaviewBusinessService")
public class WSBusinessServicesImpl implements MetaViewBusinessServices { public class WSBusinessServicesImpl implements MetaViewBusinessServices {
...@@ -114,4 +132,65 @@ public class WSBusinessServicesImpl implements MetaViewBusinessServices { ...@@ -114,4 +132,65 @@ public class WSBusinessServicesImpl implements MetaViewBusinessServices {
} }
return null; return null;
} }
@Override
public Map<String, ServiceDescription> getTranslations(Resource res, Locale prefered) {
HashMap<String, ServiceDescription> translations= new HashMap<String, ServiceDescription>();
SemanticResource sem = new SemanticResource(res);
String query =
"SELECT DISTINCT ?lang ?service ?label WHERE {"
+ "<"+res.getUri()+"> <"+WebLabModel.IS_COMPOSED_BY_MEDIA_UNIT+"> ?mu."
+ "?mu <"+WebLabProcessing.IS_PRODUCED_BY+"> ?service."
+ "?service <"+RDFS.LABEL+"> ?label."
+ "?mu <"+WebLabProcessing.IS_TRANSLATION_OF+"> ?translation."
+ "?mu <"+DublinCore.LANGUAGE_PROPERTY_NAME+"> ?lang "
+ "FILTER (langMatches(lang(?label), \""+prefered.getLanguage()+"\") || langMatches(lang(?label), \"\"))"
+ "}";
logger.info("Query :"+query );
ResultSetMem rs = sem.selectAsJenaResultSet(query);
while (rs.hasNext()) {
QuerySolution qs = rs.next();
if (!translations.containsKey(qs.getLiteral("lang").toString())) {
ServiceDescription service = new ServiceDescription();
service.setUri(qs.getResource("service").getURI().toString());
service.setLabel(qs.getLiteral("label").getLexicalForm());
translations.put(qs.getLiteral("lang").toString(), service);
logger.debug("Translation founded :"+qs.getLiteral("lang").toString()+" : "+qs.getLiteral("label").getLexicalForm());
}
if (translations.containsKey(qs.get("lang")) && !qs.getLiteral("label").getLanguage().equalsIgnoreCase("")) {
ServiceDescription service = new ServiceDescription();
service.setUri(qs.getResource("service").getURI().toString());
service.setLabel(qs.getLiteral("label").getLexicalForm());
translations.put(qs.getLiteral("lang").toString(), service);
logger.debug("Translation founded :"+qs.getLiteral("lang").toString()+" : "+qs.getLiteral("label").getLexicalForm());
}
}
return translations;
}
@Override
public PieceOfKnowledge getPoKForSelectedTranslation(String uri, String serviceURI, String lang) {
PieceOfKnowledge pok = new PieceOfKnowledge();
pok.setUri("weblab://"+UUID.randomUUID());
try {
WProcessingAnnotator wpa = new WProcessingAnnotator(new URI(uri), pok);
DublinCoreAnnotator dca = new DublinCoreAnnotator(new URI(uri), pok);
wpa.writeProducedBy(new URI(serviceURI));
dca.writeLanguage(lang);
} catch (URISyntaxException e) {
logger.error("Unable to create event POK, returning an empty one :"+e.getLocalizedMessage());
}
return pok;
}
} }
...@@ -24,6 +24,7 @@ import java.util.HashMap; ...@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse; import javax.portlet.ActionResponse;
import javax.portlet.EventRequest; import javax.portlet.EventRequest;
import javax.portlet.EventResponse; import javax.portlet.EventResponse;
...@@ -66,7 +67,7 @@ import org.springframework.web.portlet.bind.annotation.ResourceMapping; ...@@ -66,7 +67,7 @@ import org.springframework.web.portlet.bind.annotation.ResourceMapping;
@Controller @Controller
@RequestMapping(value="VIEW") @RequestMapping(value="VIEW")
@SessionAttributes({"resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "metaDisplay"}) @SessionAttributes({"resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay"})
public class MetaViewContoller { public class MetaViewContoller {
// attributes // attributes
...@@ -105,6 +106,27 @@ public class MetaViewContoller { ...@@ -105,6 +106,27 @@ public class MetaViewContoller {
response.setEvent(QName.valueOf("{http://weblab.ow2.org/portlet/metaview/action}sendUnloadedDocument"), (PieceOfKnowledge)model.get("resource")); response.setEvent(QName.valueOf("{http://weblab.ow2.org/portlet/metaview/action}sendUnloadedDocument"), (PieceOfKnowledge)model.get("resource"));
} }
@ActionMapping(params="action=selectTranslation")
public void selectTranslation(ActionRequest request, ActionResponse response, ModelMap model) {
String lang = request.getParameter("language");
String service = request.getParameter("service");
logger.debug("select translation for language :"+lang+" and service"+ service);
response.setEvent(QName.valueOf("{http://weblab.ow2.org/portlet/metaview/action}selectTranslatedVersion"),
metaviewBusinessService.getPoKForSelectedTranslation(((Resource)model.get("resource")).getUri(), service, lang));
}
@ActionMapping(params="action=selectOriginalVersion")
public void selectOriginal(ActionRequest request, ActionResponse response, ModelMap model) {
logger.debug("select original version");
response.setEvent(QName.valueOf("{http://weblab.ow2.org/portlet/metaview/action}selectOriginalVersion"), ((Resource)model.get("resource")).getUri());
}
//############################################################################# //#############################################################################
// event mapping methods # // event mapping methods #
//############################################################################# //#############################################################################
...@@ -164,6 +186,9 @@ public class MetaViewContoller { ...@@ -164,6 +186,9 @@ public class MetaViewContoller {
request.getRemoteUser())); request.getRemoteUser()));
mav.getModelMap().addAttribute("isLoadedResource", true); mav.getModelMap().addAttribute("isLoadedResource", true);
mav.getModelMap().addAttribute("translations", metaviewBusinessService.getTranslations(
(Resource) mav.getModelMap().get("resource"), request.getLocale()));
} }
return mav; return mav;
} }
......
...@@ -39,6 +39,9 @@ meta.projectName = Crawling project name&nbsp;: ...@@ -39,6 +39,9 @@ meta.projectName = Crawling project name&nbsp;:
meta.hasOriginalFileSize = Original file size&nbsp;: meta.hasOriginalFileSize = Original file size&nbsp;:
meta.refersTo = Refers to&nbsp;: meta.refersTo = Refers to&nbsp;:
meta.seeAlso = See also&nbsp;: meta.seeAlso = See also&nbsp;:
meta.availableTranslations = Translations&nbsp;:
meta.originalLanguageVersion = Original version
portlet.meta.configuration = Displayed meta-data portlet.meta.configuration = Displayed meta-data
meta.save_config = Save meta.save_config = Save
......
...@@ -38,6 +38,8 @@ meta.projectName = Bestehender Projektname&nbsp;: ...@@ -38,6 +38,8 @@ meta.projectName = Bestehender Projektname&nbsp;:
meta.hasOriginalFileSize = Originale Verzeichnisgre&nbsp;: meta.hasOriginalFileSize = Originale Verzeichnisgre&nbsp;:
meta.refersTo = Bezieht sich auf&nbsp;: meta.refersTo = Bezieht sich auf&nbsp;:
meta.seeAlso = Siehe auch&nbsp;: meta.seeAlso = Siehe auch&nbsp;:
meta.availableTranslations = bersetzungen&nbsp;:
meta.originalLanguageVersion = Ursprngliche version
portlet.meta.configuration = Dargestellte Meta-Daten portlet.meta.configuration = Dargestellte Meta-Daten
meta.save_config = Speichern meta.save_config = Speichern
......
...@@ -39,6 +39,8 @@ meta.projectName = Crawling project name: ...@@ -39,6 +39,8 @@ meta.projectName = Crawling project name:
meta.hasOriginalFileSize = Original file size: meta.hasOriginalFileSize = Original file size:
meta.refersTo = Refers to: meta.refersTo = Refers to:
meta.seeAlso = See also: meta.seeAlso = See also:
meta.availableTranslations = Translations&nbsp;:
meta.originalLanguageVersion = Original version
portlet.meta.configuration = Displayed meta-data portlet.meta.configuration = Displayed meta-data
meta.save_config = Save meta.save_config = Save
......
...@@ -39,6 +39,8 @@ meta.projectName = Nombre del proyecto de rastreo&nbsp;: ...@@ -39,6 +39,8 @@ meta.projectName = Nombre del proyecto de rastreo&nbsp;:
meta.hasOriginalFileSize = Tamao del fichero original&nbsp;: meta.hasOriginalFileSize = Tamao del fichero original&nbsp;:
meta.refersTo = Se refiere a&nbsp;: meta.refersTo = Se refiere a&nbsp;:
meta.seeAlso = Ver tambin&nbsp;: meta.seeAlso = Ver tambin&nbsp;:
meta.availableTranslations = Traducciones&nbsp;:
meta.originalLanguageVersion = Versin original
portlet.meta.configuration = Meta-datos mostrados portlet.meta.configuration = Meta-datos mostrados
meta.save_config = Guardar meta.save_config = Guardar
......
...@@ -41,6 +41,8 @@ meta.projectName = Nom du projet li ...@@ -41,6 +41,8 @@ meta.projectName = Nom du projet li
meta.hasOriginalFileSize = Taille du fichier source&nbsp;: meta.hasOriginalFileSize = Taille du fichier source&nbsp;:
meta.refersTo = Documents externes lis&nbsp;: meta.refersTo = Documents externes lis&nbsp;:
meta.seeAlso = Voir galement&nbsp;: meta.seeAlso = Voir galement&nbsp;:
meta.availableTranslations = Traductions&nbsp;:
meta.originalLanguageVersion = Version d'origine
portlet.meta.configuration = Affichage des mta-donnes portlet.meta.configuration = Affichage des mta-donnes
meta.save_config = Enregister meta.save_config = Enregister
......
...@@ -26,7 +26,9 @@ when possible (as meta-data). ...@@ -26,7 +26,9 @@ when possible (as meta-data).
<property name="actions"> <property name="actions">
<map> <map>
<entry key="{http://weblab.ow2.org/portlet/metaview/action}sendUnloadedDocument" value="{http://weblab.ow2.org/events/meta}selectNotLoadedDocument"/> <entry key="{http://weblab.ow2.org/portlet/metaview/action}sendUnloadedDocument" value="{http://weblab.ow2.org/events/meta}selectNotLoadedDocument" />
<entry key="{http://weblab.ow2.org/portlet/metaview/action}selectTranslatedVersion" value="{http://weblab.ow2.org/events/meta}selectTranslation" />
<entry key="{http://weblab.ow2.org/portlet/metaview/action}selectOriginalVersion" value="{http://weblab.ow2.org/events/meta}selectOriginal" />
</map> </map>
</property> </property>
......
...@@ -21,7 +21,8 @@ when possible (as meta-data). ...@@ -21,7 +21,8 @@ when possible (as meta-data).
<entry key="projectName" value="http://weblab-project.org/core/model/property/crawler/projectName" /> <entry key="projectName" value="http://weblab-project.org/core/model/property/crawler/projectName" />
<entry key="hasOriginalFileSize" value="http://weblab.ow2.org/core/1.2/ontology/processing#hasOriginalFileSize" /> <entry key="hasOriginalFileSize" value="http://weblab.ow2.org/core/1.2/ontology/processing#hasOriginalFileSize" />
<entry key="refersTo" value="http://weblab.ow2.org/core/1.2/ontology/processing#refersTo" /> <entry key="refersTo" value="http://weblab.ow2.org/core/1.2/ontology/processing#refersTo" />
<entry key="hasScore" value="http://weblab.ow2.org/core/1.2/ontology/retrieval#hasScore" /> <entry key="hasScore" value="http://weblab.ow2.org/core/1.2/ontology/retrieval#hasScore" />
<entry key="translation" value="http://weblab.ow2.org/core/1.2/ontology/processing#availableTranslation" />
<!-- DublinCore properties--> <!-- DublinCore properties-->
<entry key="title" value="http://purl.org/dc/elements/1.1/title" /> <entry key="title" value="http://purl.org/dc/elements/1.1/title" />
...@@ -61,6 +62,7 @@ when possible (as meta-data). ...@@ -61,6 +62,7 @@ when possible (as meta-data).
<entry key="hasOriginalFileSize" value="true" /> <entry key="hasOriginalFileSize" value="true" />
<entry key="refersTo" value="false" /> <entry key="refersTo" value="false" />
<entry key="hasScore" value="false" /> <entry key="hasScore" value="false" />
<entry key="translation" value="true" />
<!-- DublinCore properties--> <!-- DublinCore properties-->
<entry key="title" value="true" /> <entry key="title" value="true" />
......
...@@ -48,6 +48,13 @@ ...@@ -48,6 +48,13 @@
<supported-publishing-event> <supported-publishing-event>
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectNotLoadedDocument</qname> <qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectNotLoadedDocument</qname>
</supported-publishing-event> </supported-publishing-event>
<supported-publishing-event>
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectTranslation</qname>
</supported-publishing-event>
<supported-publishing-event>
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectOriginal</qname>
</supported-publishing-event>
</portlet> </portlet>
<!-- filters --> <!-- filters -->
...@@ -95,4 +102,12 @@ ...@@ -95,4 +102,12 @@
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectNotLoadedDocument</qname> <qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectNotLoadedDocument</qname>
<value-type>org.ow2.weblab.core.model.PieceOfKnowledge</value-type> <value-type>org.ow2.weblab.core.model.PieceOfKnowledge</value-type>
</event-definition> </event-definition>
<event-definition>
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectTranslation</qname>
<value-type>org.ow2.weblab.core.model.PieceOfKnowledge</value-type>
</event-definition>
<event-definition>
<qname xmlns:meta="http://weblab.ow2.org/events/meta">meta:selectOriginal</qname>
<value-type>java.lang.String</value-type>
</event-definition>
</portlet-app> </portlet-app>
\ No newline at end of file
...@@ -406,6 +406,51 @@ jQuery('.warnUserOnClick').live("click", function() { ...@@ -406,6 +406,51 @@ jQuery('.warnUserOnClick').live("click", function() {
</td> </td>
</tr> </tr>
</c:if> </c:if>
<c:if test="${metaDisplay['translation'] && !empty(translations)}">
<tr>
<th>
<fmt:message key="meta.availableTranslations" />
</th>
<td>
<portlet:actionURL var="selectOriginalVersion">
<portlet:param name="action" value="selectOriginalVersion" />
</portlet:actionURL>
<a href="${selectOriginalVersion }">
<weblab:renderValues style="icon" cssClass="meta_data_formatIconText">
<weblab:getPropertyValues uri="${rdfProperties['language'] }"/>
</weblab:renderValues><fmt:message key="meta.originalLanguageVersion" />
</a>
<br/>
<br/>
<i>
<c:forEach var="translation" items="${translations }" varStatus="status">
<c:if test="${status.count != 1}">
<br/>
</c:if>
<portlet:actionURL var="selectTranslation">
<portlet:param name="action" value="selectTranslation" />
<portlet:param name="language" value="${translation.key }" />
<portlet:param name="service" value="${translation.value.uri}" />
</portlet:actionURL>
<a href="${selectTranslation }">
<weblab:renderValues style="icon+text" cssClass="meta_data_formatIconText">
${translation.key }
</weblab:renderValues></a>(${translation.value.label })
</c:forEach>
</i>
</td>
</tr>
</c:if>
</tbody> </tbody>
</table> </table>
</div> </div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment