Commit 979a7426 authored by Yann Mombrun's avatar Yann Mombrun

WEBLAB-1319 - Tag version 2.1.3 of metadata

git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/tags/WebLabServices/Portlets/metadata-portlet/v2.1.3@3962 a803c184-d8de-4a0e-a52b-d3eef88212b6
parent 5d5a32e3
This diff is collapsed.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>parent</artifactId>
<version>1.2.6</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-metaview</artifactId>
<version>2.1.3</version>
<packaging>war</packaging>
<name>WebLab Metaview</name>
<dependencies>
<dependency>
<groupId>org.ow2.weblab.core.helpers</groupId>
<artifactId>rdf-helper-jena</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.core.helpers</groupId>
<artifactId>rdf-helper-jena-selection</artifactId>
</dependency>
<dependency>
<groupId>xalan</groupId>
<artifactId>xalan</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-client</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-portlet-filters</artifactId>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-taglib</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.core</groupId>
<artifactId>annotator</artifactId>
</dependency>
<dependency>
<groupId>org.ow2.weblab.core.helpers</groupId>
<artifactId>rdf-helper-jena-structure</artifactId>
</dependency>
</dependencies>
<description>This portlet displays WebLab resources metadata.</description>
<build>
<finalName>${project.artifactId}</finalName>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-taglib</artifactId>
<version>0.0.5</version>
</dependency>
<dependency>
<groupId>org.ow2.weblab.core</groupId>
<artifactId>annotator</artifactId>
<version>1.2.7</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
/**
* 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;
import java.util.Map;
import java.util.TreeMap;
/**
* Class representing a result configuration for meta.
*
* @author emilien
*
*/
public class DisplayMetaConfBean {
private Map<String, Boolean> properties;
public DisplayMetaConfBean() {
properties = new TreeMap<String, Boolean>();
}
public Map<String, Boolean> getProperties() {
return properties;
}
public void setProperties(Map<String, Boolean> properties) {
this.properties = properties;
}
}
/**
* 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;
import java.util.Map;
/**
* Bean to store annotations description and it value.
*
* @author emilien
*/
public class RDFPropertiesConfBean {
private Map<String, String> properties;
/**
* @return the properties
*/
public Map<String, String> getProperties() {
return this.properties;
}
/**
* @param properties
* the properties to set
*/
public void setProperties(final Map<String, String> properties) {
this.properties = properties;
}
/**
* @return An array of the property values.
*/
public String[] getDistinctAnnotationsNS() {
return this.properties.values().toArray(new String[this.properties.values().size()]);
}
/**
* get the value for the annotation name-space.
*
* @param namespace
* of annotation
* @return value for this annotation
*/
public String getAnnotationValue(final String namespace) {
return this.properties.get(namespace).toString();
}
}
/**
* 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;
public class ServiceConfBean {
private String serviceURI;
public String getServiceURI() {
return serviceURI;
}
public void setServiceURI(String serviceURI) {
this.serviceURI = serviceURI;
}
}
/**
* 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;
}
}
/**
* 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.service;
import java.util.Locale;
import java.util.Map;
import org.ow2.weblab.core.model.PieceOfKnowledge;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.services.ContentNotAvailableException;
import org.ow2.weblab.portlet.business.bean.ServiceDescription;
public interface MetaViewBusinessServices {
public Resource getWLResource(String docURI, String remoteUser) throws ContentNotAvailableException;
public String getURIFromPoK(PieceOfKnowledge pok);
public Map<String, ServiceDescription> getTranslations(Resource res, Locale prefered);
public PieceOfKnowledge getPoKForSelectedTranslation(String uri, String serviceURI, String lang);
}
/**
* 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.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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.components.client.WebLabClient;
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.helper.impl.AdvancedSelector;
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.model.PieceOfKnowledge;
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.ResourceContainer;
import org.ow2.weblab.core.services.resourcecontainer.LoadResourceArgs;
import org.ow2.weblab.core.services.resourcecontainer.LoadResourceReturn;
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.purl.dc.elements.DublinCoreAnnotator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
@Service(value="metaviewBusinessService")
public class WSBusinessServicesImpl implements MetaViewBusinessServices {
// attributes
private static final String DEFAULT_USER_URI = "http://weblab.ow2.org/user#Weblab";
private static final String DEFAULT_USER_NAMESPACE = "http://weblab.ow2.org/user#";
private static final String DEFAULT_USAGE_CONTEXT = "http://defaultContext.org";
protected Log logger = LogFactory.getLog(this.getClass());
@Autowired()
@Qualifier("WSBusinessServiceConfig")
protected ServiceConfBean configuration;
@Autowired
private PortletContext context;
public Resource getWLResource(String docURI, String remoteUser) throws ContentNotAvailableException {
// getting resource from repository
LoadResourceArgs args = new LoadResourceArgs();
args.setResourceId(docURI);
//setting user repo url
ResourceContainer service = null;
if (remoteUser != null) {
try {
service = WebLabClient.getResourceContainer(DEFAULT_USER_NAMESPACE+remoteUser, DEFAULT_USAGE_CONTEXT, configuration.getServiceURI());
} catch (WebLabCheckedException e) {
throw new ContentNotAvailableException("Unable to handle a valid service to get the content");
}
logger.info("Using WL service "+service+ "to get resource:"+docURI+" for user:"+remoteUser);
} else {
try {
service = WebLabClient.getResourceContainer(DEFAULT_USER_URI, DEFAULT_USAGE_CONTEXT, configuration.getServiceURI());
} catch (WebLabCheckedException e) {
throw new ContentNotAvailableException("Unable to handle a valid service to get the content");
}
logger.info("Using WL service "+service+ "to get resource:"+docURI);
}
if (service == null) {
throw new ContentNotAvailableException("Unable to handle a valid service to get the content");
}
LoadResourceReturn res;
try {
res = service.loadResource(args);
return res.getResource();
} catch (Exception e) {
throw new ContentNotAvailableException("Unable to get the content ("+e.getMessage()+")");
}
}
/**
* Method to get URI from a receive PieceOfKnowledge using
* POK_PROPERTY_DOC_URI
*
* @param pok
* @return URI if exist null otherwise
*/
public String getURIFromPoK(PieceOfKnowledge pok) {
if (pok != null) {
AdvancedSelector rdfSelector = RDFSelectorFactory.getSelector(true);
Statements map = rdfSelector.searchFor(pok, WebLabRetrieval.IS_LINKED_TO);
if (map != null && !map.entrySet().isEmpty()) {
return (String) map.entrySet().iterator().next().getValue().getValue(WebLabRetrieval.IS_LINKED_TO);
}
}
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;
}
}
/**
* 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.mvc.spring.controller;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.EventRequest;
import javax.portlet.EventResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.core.model.Document;
import org.ow2.weblab.core.model.PieceOfKnowledge;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.services.ContentNotAvailableException;
import org.ow2.weblab.portlet.business.bean.DisplayMetaConfBean;
import org.ow2.weblab.portlet.business.bean.RDFPropertiesConfBean;
import org.ow2.weblab.portlet.business.service.MetaViewBusinessServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.EventMapping;
import org.springframework.web.portlet.bind.annotation.RenderMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
/**
* Metaview portlet Spring MVC controller.
* Business layer is accessible by Spring business services
*
* Control actions, renders, resources and events requests.
*
* @author emilienbondu
*
*/
@Controller
@RequestMapping(value="VIEW")
@SessionAttributes({"resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay"})
public class MetaViewContoller {
// attributes
protected Log logger = LogFactory.getLog(this.getClass());
protected URL WSDL_REPO_URL;
@Autowired
@Qualifier("metaviewBusinessService")
protected MetaViewBusinessServices metaviewBusinessService;
@Autowired
@Qualifier("displayMeta")
protected DisplayMetaConfBean metaDisplayConf;
@ModelAttribute("metaDisplay")
public Map<String, Boolean> getDisplayMeta() {
return metaDisplayConf.getProperties();
}
@Autowired
@Qualifier("rdfProperties")
protected RDFPropertiesConfBean rdfProperties;
@ModelAttribute("rdfProperties")
public Map<String, String> getRDFProperties() {
return rdfProperties.getProperties();
}
//#############################################################################
// action mapping methods #
//#############################################################################
@ActionMapping(params="action=goToEntity")
public void goToEntity(ActionResponse response, ModelMap model) {
logger.debug("receiving action gotToEntity");
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 #
//#############################################################################
@EventMapping(value="{http://weblab.ow2.org/portlet/metaview/reaction}displayMeta")
public void processLoadedDocumentEvent(EventRequest request, EventResponse response, ModelMap model) {
// receive a event containing a document