Commit 68c8f0f7 authored by Yann Mombrun's avatar Yann Mombrun

New version 2.2.3-SNAPSHOT

WEBLAB-1516 - Enable in the configuration the use of OpenStreetMap and use this conf by default
WEBLAB-1518 - Replace save method by a REST based call
WEBLAB-1517 - Lots of refactoring of the code. Remove unused JS/CSS/images files, remove weblab client and replace it by Spring JAXWS proxy, use a single configuration file and remove autowiring, 


git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/trunk/WebLabServices/Portlets/metadata-portlet@4384 a803c184-d8de-4a0e-a52b-d3eef88212b6
parent 15bb781b
......@@ -4,27 +4,19 @@
<parent>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>parent</artifactId>
<version>1.2.8</version>
<version>1.2.8.1-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-metaview</artifactId>
<version>2.2.2</version>
<version>2.2.3-SNAPSHOT</version>
<packaging>war</packaging>
<name>WebLab Metaview</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<weblab.snapshot.repositoryId>weblab.snapshot</weblab.snapshot.repositoryId>
<weblab.release.repositoryId>weblab.release</weblab.release.repositoryId>
<weblab.snapshot.url>sftp://weblab-project.org/home/ipccproj/public_html/maven-snapshot</weblab.snapshot.url>
<weblab.release.url>sftp://weblab-project.org/home/ipccproj/public_html/maven</weblab.release.url>
<weblab.repositoryId>${weblab.release.repositoryId}</weblab.repositoryId>
<weblab.url>${weblab.release.url}</weblab.url>
<spring.version>3.0.7.RELEASE</spring.version>
</properties>
......@@ -55,11 +47,6 @@
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-taglib</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
......@@ -113,26 +100,4 @@
</dependencies>
</dependencyManagement>
<distributionManagement>
<site>
<id>WebLab</id>
<name>WebLab Web Site</name>
<url>http://weblab.ow2.org</url>
</site>
<repository>
<uniqueVersion>false</uniqueVersion>
<id>weblab.release</id>
<name>WebLab Repository</name>
<url>${weblab.release.url}</url>
<layout>default</layout>
</repository>
<snapshotRepository>
<uniqueVersion>false</uniqueVersion>
<id>weblab.snapshot</id>
<name>WebLab Snapshot Repository</name>
<url>${weblab.snapshot.url}</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
</project>
......@@ -21,18 +21,23 @@ import java.util.Map;
import java.util.TreeMap;
/**
* Class representing a result configuration for meta.
* Class containing the configuration of the metadata properties to be displayed.
*
* @author emilien
*
*/
public class DisplayMetaConfBean {
private boolean useGeoserverExposedMap;
private Map<String, Boolean> properties;
public DisplayMetaConfBean() {
this.properties = new TreeMap<>();
this.useGeoserverExposedMap = false;
}
......@@ -47,4 +52,21 @@ public class DisplayMetaConfBean {
this.properties = properties;
}
/**
* @return the useGeoserverExposedMap
*/
public boolean isUseGeoserverExposedMap() {
return this.useGeoserverExposedMap;
}
/**
* @param useGeoserverExposedMap the useGeoserverExposedMap to set
*/
public void setUseGeoserverExposedMap(boolean useGeoserverExposedMap) {
this.useGeoserverExposedMap = useGeoserverExposedMap;
}
}
......@@ -20,9 +20,17 @@ package org.ow2.weblab.portlet.business.bean;
import java.util.List;
import java.util.Map;
/**
* Contains edition configuration
*
* @author kdesir
*/
public class EditMetaConfBean {
private boolean useGeoserverExposedMap;
private Map<String, List<String>> properties;
......@@ -35,4 +43,21 @@ public class EditMetaConfBean {
this.properties = properties;
}
/**
* @return the useGeoserverExposedMap
*/
public boolean isUseGeoserverExposedMap() {
return this.useGeoserverExposedMap;
}
/**
* @param useGeoserverExposedMap
* the useGeoserverExposedMap to set
*/
public void setUseGeoserverExposedMap(boolean useGeoserverExposedMap) {
this.useGeoserverExposedMap = useGeoserverExposedMap;
}
}
......@@ -21,24 +21,28 @@ package org.ow2.weblab.portlet.business.bean;
* A service description bean.
*
* @author emilienbondu
*
*/
public class ServiceDescription {
private String uri,label;
private String uri, label;
public String getUri() {
return this.uri;
}
public void setUri(String uri) {
this.uri = uri;
}
public String getLabel() {
return this.label;
}
public void setLabel(String label) {
this.label = label;
}
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
*
* Copyright (C) 2004 - 2016 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;
package org.ow2.weblab.portlet.business.service;
import java.io.File;
import java.io.IOException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.core.extended.exception.WebLabCheckedException;
import org.ow2.weblab.core.extended.jaxb.WebLabMarshaller;
import org.ow2.weblab.core.model.Resource;
/**
* A class to process weblab resource in order to reindex it by metaDataprocessing routes.
*
* @author kdesir
* Interface defining the service is charge of saving the resource back
*
* @author ymombrun
*/
public class SaveMeta {
private final Log logger = LogFactory.getLog(this.getClass());
public SaveMeta() {
}
public interface ResourceSaverService {
/**
* This method uses the current resource to save it in the repository
*
* @param resource
* the resource which will be saved as a WL xml document.
* The resource to be saved
* @return Whether or not we are sure that the resource has been saved. <code>false</code> can be used when we are not sure
* @throws IOException
* If an error occurred saving the resource
* @throws WebLabCheckedException
* If the resource cannot be serialised as XML
*/
public void sendToReIndexFolder(final Resource resource) {
final WebLabMarshaller wlm = new WebLabMarshaller();
try {
wlm.marshalResource(resource, new File(System.getProperty("files.to.reIndex") + "/" + System.nanoTime() + ".xml"));
this.logger.info("Save the resource : " + resource.getUri() + " : " + System.getProperty("files.to.reIndex"));
} catch (final WebLabCheckedException e) {
this.logger.error("Unable to save the File for Reindexing", e);
}
}
public boolean saveResource(final Resource resource) throws IOException, WebLabCheckedException;
}
......@@ -167,7 +167,6 @@ public class EditMetaServices {
ba.applyOperator(Operator.WRITE, prefix, propertyURI, localname, clazz, null);
ba.applyOperator(Operator.WRITE, prefix, propertyURI, localname, clazz, val);
}
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2016 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.io.IOException;
import java.net.MalformedURLException;
import java.net.ProxySelector;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.Consts;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.PoolingClientConnectionManager;
import org.apache.http.impl.conn.ProxySelectorRoutePlanner;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.ow2.weblab.core.extended.exception.WebLabCheckedException;
import org.ow2.weblab.core.extended.util.ResourceUtil;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.portlet.business.service.ResourceSaverService;
import org.springframework.stereotype.Service;
/**
* Implementation of {@link ResourceSaverService} that calls a REST endpoint to post the resource as XML.
*
* @author ymombrun
*/
@Service
public class RestResourceSaverService implements ResourceSaverService {
private final URI url;
private final PoolingClientConnectionManager cm;
private final HttpParams httpParams;
private final Log logger;
private static final ContentType APPLICATION_XML = ContentType.create("application/xml", Consts.UTF_8);
/**
* @param url
* The URL of the rest service to be called in order to save the edition
* @throws MalformedURLException
* If the URL is not valid
* @throws URISyntaxException
*/
public RestResourceSaverService(final String url) throws MalformedURLException, URISyntaxException {
super();
this.logger = LogFactory.getLog(this.getClass());
this.url = new URL(url).toURI();
this.cm = new PoolingClientConnectionManager();
this.cm.setMaxTotal(10);
this.cm.setDefaultMaxPerRoute(10);
this.httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(this.httpParams, 4000);
HttpConnectionParams.setSoTimeout(this.httpParams, 30000);
this.logger.debug("RestResourceSaverService created for " + url);
}
@Override
public boolean saveResource(final Resource resource) throws IOException, WebLabCheckedException {
final DefaultHttpClient httpClient = new DefaultHttpClient(this.cm, this.httpParams);
if ((System.getProperty("http.proxyHost") != null) || "true".equals(System.getProperty("java.net.useSystemProxies"))) {
this.logger.debug("Proxy information found in system properties. Use default proxy selector.");
httpClient.setRoutePlanner(new ProxySelectorRoutePlanner(this.cm.getSchemeRegistry(), ProxySelector.getDefault()));
} else {
this.logger.trace("No proxy configured.");
}
final HttpPost httpPost = new HttpPost(this.url);
final StringEntity xmlEntity = new StringEntity(ResourceUtil.saveToXMLString(resource), APPLICATION_XML);
httpPost.setEntity(xmlEntity);
final HttpResponse response = httpClient.execute(httpPost);
final int statusCode = response.getStatusLine().getStatusCode();
if (((statusCode >= 200) && (statusCode < 300)) || (statusCode == 304)) {
return true;
}
this.logger.warn("Received an error HTTP code (" + statusCode + ") when accessing saving resource " + resource.getUri() + ".");
return false;
}
}
......@@ -25,7 +25,6 @@ import java.util.UUID;
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.factory.ExceptionFactory;
import org.ow2.weblab.core.helper.impl.SemanticResource;
......@@ -48,7 +47,7 @@ import com.hp.hpl.jena.query.QuerySolutionMap;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.sparql.resultset.ResultSetMem;
@Service(value = "metaviewBusinessService")
@Service
public class WSBusinessServicesImpl implements MetaViewBusinessServices {
......@@ -74,10 +73,10 @@ public class WSBusinessServicesImpl implements MetaViewBusinessServices {
/**
* Standard constructor of the class, setting the resource container URI to find it in the weblab-client.
* Standard constructor of the class, setting the resource container and some parameters
*
* @param resourceContainerUri
* The identifier of the resource container
* @param service
* The the resource container client
* @param linkedToQuery
* The query that search the linked resource URI inside the received pok
* @param translationsQueryTemplate
......@@ -85,13 +84,8 @@ public class WSBusinessServicesImpl implements MetaViewBusinessServices {
* @throws WebLabCheckedException
* If the resource container cannot be loaded
*/
public WSBusinessServicesImpl(final String resourceContainerUri, final String linkedToQuery, final String translationsQueryTemplate) throws WebLabCheckedException {
this.service = WebLabClient.getResourceContainer("Not used", "Not used", resourceContainerUri);
if (this.service == null) {
final String message = "Unable to initialise the resource container needed for metadata.";
this.logger.fatal(message);
throw new WebLabCheckedException(message);
}
public WSBusinessServicesImpl(final ResourceContainer service, final String linkedToQuery, final String translationsQueryTemplate) throws WebLabCheckedException {
this.service = service;
this.linkedToQuery = linkedToQuery;
this.translationsQueryTemplate = translationsQueryTemplate;
}
......
......@@ -17,6 +17,7 @@
*/
package org.ow2.weblab.portlet.mvc.spring.controller;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -28,12 +29,13 @@ import javax.portlet.ResourceResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.core.extended.exception.WebLabCheckedException;
import org.ow2.weblab.core.model.Resource;
import org.ow2.weblab.portlet.business.bean.EditMetaConfBean;
import org.ow2.weblab.portlet.business.bean.TimeConfig;
import org.ow2.weblab.portlet.business.bean.taglib.DataTaglib;
import org.ow2.weblab.portlet.business.service.ResourceSaverService;
import org.ow2.weblab.portlet.business.service.impl.EditMetaServices;
import org.ow2.weblab.portlet.business.service.impl.SaveMeta;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -42,50 +44,94 @@ import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.bind.annotation.ActionMapping;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;
/**
* The controller in charge of the edition.
*
* @author kdesir, ymombrun
*/
@Controller
@RequestMapping(value = "VIEW")
@SessionAttributes({ "resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay", "editMetaData", "timeConfig", "dataTaglib", "dataLanguage" })
@SessionAttributes({ "resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay", "editMetaData", "timeConfig", "dataTaglib", "dataLanguage",
"useGeoserverExposedMap" })
public class EditMetaController {
private static final String USE_GEOSERVER_EXPOSED_MAP = "useGeoserverExposedMap";
private static final String RESOURCE = "resource";
private static final String TIME_CONFIG = "timeConfig";
private static final String EDIT_META_DATA = "editMetaData";
private static final String DATA_LANGUAGE = "dataLanguage";
private static final String DATA_TAGLIB = "dataTaglib";
private static final String UTF_8 = "UTF-8";
private static final String TEXT_HTML = "text/html";
private final Log logger = LogFactory.getLog(this.getClass());
private EditMetaConfBean editMetaData;
private final EditMetaConfBean editMetaData;
private DataTaglib dataTaglib;
private final DataTaglib dataTaglib;
private final ResourceSaverService resourceSaverService;
public EditMetaController(final EditMetaConfBean editMetaData, final DataTaglib dataTaglib, final ResourceSaverService resourceSaverService) {
super();
this.editMetaData = editMetaData;
this.dataTaglib = dataTaglib;
this.resourceSaverService = resourceSaverService;
}
@ResourceMapping("editmeta")
public ModelAndView displayEditMenu(final ResourceRequest request, final ResourceResponse response, ModelMap model) {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
public ModelAndView displayEditMenu(final ResourceRequest request, final ResourceResponse response) {
response.setContentType(EditMetaController.TEXT_HTML);
response.setCharacterEncoding(EditMetaController.UTF_8);
this.logger.debug("ShowView EditMetaController called");
final ModelAndView mav = new ModelAndView();
model = (ModelMap) request.getPortletSession().getAttribute("model");
if (!model.containsAttribute("timeConfig")) {
model.addAttribute("timeConfig", new TimeConfig());
final ModelMap model = (ModelMap) request.getPortletSession().getAttribute("model");
if (!model.containsAttribute(EditMetaController.TIME_CONFIG)) {
model.addAttribute(EditMetaController.TIME_CONFIG, new TimeConfig());
}
if (!model.containsAttribute(EditMetaController.DATA_TAGLIB) || !model.containsAttribute(EditMetaController.DATA_LANGUAGE)) {
model.addAttribute(EditMetaController.DATA_TAGLIB, this.dataTaglib.getFormats());
model.addAttribute(EditMetaController.DATA_LANGUAGE, this.dataTaglib.getLanguages());
}
if (!model.containsAttribute("dataTaglib") || !model.containsAttribute("dataLanguage")) {
model.addAttribute("dataTaglib", this.dataTaglib.getFormats());
model.addAttribute("dataLanguage", this.dataTaglib.getLanguages());
if (!model.containsAttribute(EditMetaController.EDIT_META_DATA)) {
model.addAttribute(EditMetaController.EDIT_META_DATA, this.editMetaData.getProperties());
}
if (!model.containsAttribute("editMetaData")) {
model.addAttribute("editMetaData", this.editMetaData.getProperties());
if (!model.containsAttribute(EditMetaController.USE_GEOSERVER_EXPOSED_MAP)) {
model.addAttribute(EditMetaController.USE_GEOSERVER_EXPOSED_MAP, Boolean.valueOf(this.editMetaData.isUseGeoserverExposedMap()));
}
mav.setView("editview");
mav.addAllObjects(model);
return mav;
}
@ResourceMapping("canceledit")
public ModelAndView cancelEdit(final ResourceRequest request, final ResourceResponse response, final ModelMap model) {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
response.setContentType(EditMetaController.TEXT_HTML);
response.setCharacterEncoding(EditMetaController.UTF_8);
final ModelAndView mav = new ModelAndView();
mav.setView("view_meta_ajax");
mav.addAllObjects(model);
......@@ -96,39 +142,27 @@ public class EditMetaController {
@ActionMapping(params = "action=save")
public void saveEdit(final ActionRequest request, final ActionResponse response, final ModelMap model) {
this.logger.debug("saveEdit method called");
final Resource resource = (Resource) model.get("resource");
final Map<String, List<String>> editMeta = (LinkedHashMap<String, List<String>>) model.get("editMetaData");
if (this.resourceSaverService == null) {
this.logger.error("No resource saver service configured !!!");
return;
}
final Resource resource = (Resource) model.get(EditMetaController.RESOURCE);
final Map<String, List<String>> editMeta = (LinkedHashMap<String, List<String>>) model.get(EditMetaController.EDIT_META_DATA);
final Map<String, String[]> parameterMap = request.getParameterMap();
final EditMetaServices editMetaServices = new EditMetaServices(editMeta);
final SaveMeta saveMyFile = new SaveMeta();
editMetaServices.writeContent(resource, parameterMap);
saveMyFile.sendToReIndexFolder(resource);
model.addAttribute("resource", resource);
try {
final boolean worked = this.resourceSaverService.saveResource(resource);
if (!worked) {
this.logger.warn("The resource " + resource.getUri() + " may not be saved.");
}
} catch (final IOException | WebLabCheckedException e) {
this.logger.error("An error occured saving the resource " + resource.getUri() + ".", e);
}
model.addAttribute(EditMetaController.RESOURCE, resource);
request.getPortletSession().setAttribute("model", model);
}
public DataTaglib getDataTaglib() {
return this.dataTaglib;
}
public void setDataTaglib(final DataTaglib dataTaglib) {
this.dataTaglib = dataTaglib;
}
public EditMetaConfBean getEditMetaData() {
return this.editMetaData;
}
public void setEditMetaData(final EditMetaConfBean editMetaData) {
this.editMetaData = editMetaData;
}
}
......@@ -24,4 +24,4 @@ log4j.rootLogger = DEBUG, console, rollingfile
# You can decrease the level of a specific package by adding it here
log4j.logger.org.springframework = INFO
log4j.logger.com.hp.hpl.jena.sparql.engine.optimizer = INFO
\ No newline at end of file
log4j.logger.com.hp.hpl.jena = INFO
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"><beans> <bean id="servicesConfig" class="org.ow2.weblab.components.client.config.ServiceConfigMap"> <description> This is the main bean that will handle the weblab-client configuration. The principle is simple: for each service port (ie implementation of one generic interface) the configuration will have the implementation URI (in general linked to the application service taxonomy) and will link it to the actual URL to be used. </description> <constructor-arg> <map> <entry key="http://weblab.ow2.org/services/resourceContainer/file-repo"> <value>http://localhost:8181/simple-file-repository/resourceContainer</value> </entry> </map> </constructor-arg> </bean></beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
</beans>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">