Commit 0c2a9743 authored by Arnaud Saval's avatar Arnaud Saval

WEBLAB-999 Tag metadata portlet v2.0.0

git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/tags/WebLabServices/Portlets/metadata-portlet/v2.0.0@3483 a803c184-d8de-4a0e-a52b-d3eef88212b6
parents
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.5</version>
</parent>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-metaview</artifactId>
<version>2.0.0</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>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc-portlet</artifactId>
<version>3.0.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-client</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-portlet-filters</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
</dependencies>
<description>This portlet displays WebLab resources metadata.</description>
<build>
<finalName>${project.artifactId}</finalName>
</build>
</project>
package org.ow2.weblab.portlet.business.bean;
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2012 Cassidian, an EADS company
*
* 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
*/
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;
}
}
package org.ow2.weblab.portlet.business.bean;
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2012 Cassidian, an EADS company
*
* 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
*/
import java.util.Map;
/**
* Bean to store annotations description and it value.
* @author emilien
*
*/
public class RDFPropertiesConfBean {
/*
* attributes
*/
private Map<String, String> properties;
/**
* @return the properties
*/
public Map<String, String> getProperties() {
return properties;
}
/**
* @param properties the properties to set
*/
public void setProperties(Map<String, String> properties) {
this.properties = properties;
}
/*
* getters and setter
*/
public String[] getDisctinctAnnotationsNS() {
return this.properties.values().toArray(new String[this.properties.values().size()]);
}
/*
* getters and setter
*/
/**
* get the value for the annotation name-space.
* @param namespace of annotation
* @return value for this annotation
*/
public String getAnnotationValue(String namespace) {
return this.properties.get(namespace).toString();
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2013 Cassidian, an EADS company
*
* 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 wsdlURL;
private String serviceURL;
private String serviceURI;
public String getWsdlURL() {
return wsdlURL;
}
public void setWsdlURL(String wsdlURL) {
this.wsdlURL = wsdlURL;
}
public String getServiceURL() {
return serviceURL;
}
public void setServiceURL(String serviceURL) {
this.serviceURL = serviceURL;
}
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 - 2012 Cassidian, an EADS company
*
* 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.List;
import java.util.Map;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.services.ContentNotAvailableException;
public interface MetaViewBusinessServices {
public Map<String, List<String>> getResourceDescription(Resource resource, String remoteUser, String[] properties) throws ContentNotAvailableException;
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2012 Cassidian, an EADS company
*
* 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.util.List;
import java.util.Map;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.core.services.ContentNotAvailableException;
import org.ow2.weblab.portlet.business.service.MetaViewBusinessServices;
public class SPARQLBusinessServicesImpl implements MetaViewBusinessServices {
@Override
public Map<String, List<String>> getResourceDescription(Resource resource, String remoteUser, String[] properties)
throws ContentNotAvailableException {
// TODO Auto-generated method stub
return null;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2012 Cassidian, an EADS company
*
* 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.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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.WebLabRetrieval;
import org.ow2.weblab.core.helper.impl.AdvancedSelector;
import org.ow2.weblab.core.helper.impl.RDFSelectorFactory;
import org.ow2.weblab.core.helper.impl.Statements;
import org.ow2.weblab.core.helper.impl.WTriple;
import org.ow2.weblab.core.model.MediaUnit;
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.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.service.MetaViewBusinessServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
@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;
@SuppressWarnings("unchecked")
public Map<String, List<String>> getResourceDescription(Resource resource, String remoteUser, String[] properties) throws ContentNotAvailableException {
if (resource instanceof PieceOfKnowledge) {
// getting the document URI from pok using RDFSelector
String docURI = getURIFromPoK((PieceOfKnowledge)resource);
if (docURI != null) {
// loading resource
logger.info("context :"+context+" configuration:"+configuration);
resource = getWLResource(docURI, remoteUser);
}
}
if (resource instanceof MediaUnit) {
// getting rdf description map using selector
Statements mediaUnitWTMap = null;
HashMap<String, List<String>> resourceDescMap = new HashMap<String, List<String>>();
AdvancedSelector rdfSelector = RDFSelectorFactory.getSelector(true);
rdfSelector.limitToFirstLevelAnnotation(true);
mediaUnitWTMap = rdfSelector.searchFor(resource, properties);
// filling result map
for (WTriple statement : mediaUnitWTMap.get(resource.getUri()).getStatements()) {
LinkedList<String> l = new LinkedList<String>();
if (mediaUnitWTMap.get(resource.getUri()).getValue(statement.getPredicate()) instanceof List<?>) {
l.addAll((List<String>)mediaUnitWTMap.get(resource.getUri()).getValue(statement.getPredicate()));
} else {
l.add((String) mediaUnitWTMap.get(resource.getUri()).getValue(statement.getPredicate()));
}
resourceDescMap.put(statement.getPredicate(), l);
}
return resourceDescMap;
}
return null;
}
private 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
*/
private static 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;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2012 Cassidian, an EADS company
*
* 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.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", "resourceDesc", "isEmptyModel", "isLoadedMap", "rdfProperties", "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"));
}
//#############################################################################
// 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
logger.debug("receiving the event : {http://weblab.ow2.org/portlet/metaview/reaction}displayMeta");
model.addAttribute("resource", (Document) request.getEvent().getValue());
model.addAttribute("resourceDesc", new HashMap<String, List<String>>());
model.addAttribute("isLoadedMap", false);
model.addAttribute("isEmptyModel", false);
}
@EventMapping(value="{http://weblab.ow2.org/portlet/metaview/reaction}loadDocumentAndDisplayMeta")
public void processNotLoadedDocumentEvent(EventRequest request, EventResponse response, ModelMap model) {
// receive a event containing an unloaded document
logger.debug("receiving the event : {http://weblab.ow2.org/portlet/metaview/reaction}loadDocumentAndDisplayMeta");
model.addAttribute("resource", (PieceOfKnowledge) request.getEvent().getValue());
model.addAttribute("resourceDesc", new HashMap<String, List<String>>());
model.addAttribute("isLoadedMap", false);
model.addAttribute("isEmptyModel", false);
//response.setEvent(QName.valueOf("{http://weblab.ow2.org/portlet/metaview/action}sendUnloadedDocument"), (PieceOfKnowledge)model.get("resource"));
}
//#############################################################################
// resource mapping methods #
//#############################################################################
@ResourceMapping("showMetadata")
public ModelAndView serveMetadata(ResourceRequest request, ResourceResponse response, ModelMap model) throws ContentNotAvailableException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
ModelAndView mav = new ModelAndView();
mav.setView("view_meta_ajax");
mav.addAllObjects(model);
Resource resource= (Resource) model.get("resource");
logger.debug("serving the metadata content table from resource :"+resource.getUri());
// loading map if needed
boolean isLoadedMap = false;