Commit 15339627 authored by Yann Mombrun's avatar Yann Mombrun

WEBLAB-1462 - Integrate edition and other features that have been done on the branch

New version 2.2.1-SNAPSHOT

git-svn-id: svn://svn.forge.objectweb.org/svnroot/weblab/trunk/WebLabServices/Portlets/metadata-portlet@4329 a803c184-d8de-4a0e-a52b-d3eef88212b6
parents 7f2fc275 fe375d93
......@@ -10,7 +10,7 @@
<groupId>org.ow2.weblab.portlets</groupId>
<artifactId>weblab-metaview</artifactId>
<version>2.2.0</version>
<version>2.2.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>WebLab Metaview</name>
......@@ -23,8 +23,8 @@
<weblab.snapshot.url>scp://weblab-project.org/home/ipccproj/public_html/maven-snapshot</weblab.snapshot.url>
<weblab.release.url>scp://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>
<weblab.repositoryId>${weblab.snapshot.repositoryId}</weblab.repositoryId>
<weblab.url>${weblab.snapshot.url}</weblab.url>
</properties>
<dependencies>
......@@ -52,4 +52,13 @@
<finalName>${project.artifactId}</finalName>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.ow2.weblab.components</groupId>
<artifactId>weblab-taglib</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
</project>
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......
/**
* 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.bean;
import java.util.List;
import java.util.Map;
public class EditMetaConfBean {
private Map<String, List<String>> properties;
public Map<String, List<String>> getProperties() {
return this.properties;
}
public void setProperties(final Map<String, List<String>> properties) {
this.properties = properties;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......@@ -15,7 +15,6 @@
* 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;
......
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......@@ -15,7 +15,6 @@
* 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;
/**
......
/**
* 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.bean;
import java.util.Date;
public class TimeConfig {
private long maxEndDateMS;
public TimeConfig() {
this.setMaxEndDateMS(new Date());
}
public long getMaxEndDateMS() {
return this.maxEndDateMS;
}
public void setMaxEndDateMS(final Date maxEndDateMS) {
this.maxEndDateMS = maxEndDateMS.getTime();
}
}
/**
* 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.bean.taglib;
import java.util.Map;
/**
* A class to load data taglib properties such as formats and languages.
*
* @author kdesir
*/
public class DataTaglib {
private Map<String, String> formats;
private Map<String, String> languages;
public Map<String, String> getLanguages() {
return this.languages;
}
public void setLanguages(final Map<String, String> languages) {
this.languages = languages;
}
public Map<String, String> getFormats() {
return this.formats;
}
public void setFormats(final Map<String, String> formats) {
this.formats = formats;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......@@ -15,7 +15,6 @@
* 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.net.URI;
......
/**
* 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.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import javax.portlet.ActionRequest;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ow2.weblab.core.annotator.AbstractAnnotator.Operator;
import org.ow2.weblab.core.annotator.BaseAnnotator;
import org.ow2.weblab.core.model.Resource;
import org.purl.dc.elements.DublinCoreAnnotator;
/**
* A class to edit meta data contained in resources.
*
* @author kdesir
*
*/
public class EditMetaServices {
private final Map<String, List<String>> editMetaConf;
private final Log logger = LogFactory.getLog(this.getClass());
private final String pattern = "MM/dd/yyyy HH:mm";
public EditMetaServices(final Map<String, List<String>> editMeta) {
this.editMetaConf = editMeta;
}
public Map<String, String[]> getParameterMap(final ActionRequest request) {
return request.getParameterMap();
}
/**
* Modify the resource according field that the user have filled.
*
* @param resource
* the current resource to modify
* @param parameterMap
* a map which represents the key-value parameters of the edit
* form
* @return
* the modified resource.
*/
public Resource writeContent(final Resource resource, final Map<String, String[]> parameterMap) {
for (final String keyParam : parameterMap.keySet()) {
if (this.editMetaConf.containsKey(keyParam)) {
final List<String> valueEditConf = this.editMetaConf.get(keyParam);
try {
this.writeWithType(resource, valueEditConf, keyParam, parameterMap);
} catch (final ParseException e) {
this.logger.error("Unable to parse date value, the correct format must be MM/dd/yyyy HH:mm", e);
}
}
}
return resource;
}
/**
* @param resource
* the current resource to modify.
* @param valueEditConf
* the list of value linked with the meta data field such as
* "title" field will have : [dc , http://namespace , string ].
* @param keyParam
* the actual field that will be modified.
* @param parameterMap
* a map which represents the key-value parameters of the edit
* form.
* @throws ParseException
* if the date is not in the right format.
*/
private void writeWithType(final Resource resource, final List<String> valueEditConf, final String keyParam, final Map<String, String[]> parameterMap) throws ParseException {
final String value = parameterMap.get(keyParam)[0];
final String xlmns = valueEditConf.get(0);
final String entireNameSpace = valueEditConf.get(1);
final String valueType = valueEditConf.get(2);
// use the right method according to the key Parameter we have.
if (!value.isEmpty()) {
if (valueType.equals("string")) {
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, String.class, value);
} else if (valueType.equals("long")) {
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, Long.class, Long.valueOf(value));
} else if (valueType.equals("double")) {
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, Double.class, Double.valueOf(value));
} else if (valueType.equals("date")) {
final SimpleDateFormat dateFormat = new SimpleDateFormat(this.pattern);
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, Date.class, dateFormat.parse(value.toString()));
} else if (valueType.equals("integer")) {
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, Integer.class, Integer.valueOf(value));
}
}
// if empty, erase the current field of the resource.
else {
this.write(resource, xlmns, URI.create(entireNameSpace), keyParam, null, null);
}
}
public Map<String, List<String>> getEditMetaConf() {
return this.editMetaConf;
}
/**
*
* @param resource
* the current resource to modify.
* @param prefix
* the prefix
* @param propertyURI
* the namespace of the property.
* @param localname
* the localname of the property.
* @param clazz
* the class of the value
* @param val
* the current value
*/
public <T> void write(final Resource resource, final String prefix, final URI propertyURI, final String localname, final Class<T> clazz, final T val) {
final BaseAnnotator ba = new BaseAnnotator(resource);
if (localname.equals("subject") && (val != null)) {
final DublinCoreAnnotator dc = new DublinCoreAnnotator(resource);
final String[] mySubject = ((String) val).split(",");
ba.setAppendMode(false);
ba.applyOperator(Operator.WRITE, prefix, propertyURI, localname, clazz, null);
for (final String value : mySubject) {
dc.writeSubject(value.trim());
}
} else {
ba.setAppendMode(false);
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.File;
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
*/
public class SaveMeta {
private final Log logger = LogFactory.getLog(this.getClass());
public SaveMeta() {
}
/**
* 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.
*/
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);
}
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......@@ -15,8 +15,6 @@
* 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;
......
/**
* 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.mvc.spring.controller;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.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;
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.ResourceMapping;
@Controller
@RequestMapping(value = "VIEW")
@SessionAttributes({ "resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay", "editMetaData", "timeConfig", "dataTaglib", "dataLanguage" })
public class EditMetaController {
private final Log logger = LogFactory.getLog(this.getClass());
private EditMetaConfBean editMetaData;
private DataTaglib dataTaglib;
@ResourceMapping("editmeta")
public ModelAndView displayEditMenu(final ResourceRequest request, final ResourceResponse response, ModelMap model) {
response.setContentType("text/html");
response.setCharacterEncoding("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());
}
if (!model.containsAttribute("dataTaglib") || !model.containsAttribute("dataLanguage")) {
model.addAttribute("dataTaglib", this.dataTaglib.getFormats());
model.addAttribute("dataLanguage", this.dataTaglib.getLanguages());
}
if (!model.containsAttribute("editMetaData")) {
model.addAttribute("editMetaData", this.editMetaData.getProperties());
}
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");
final ModelAndView mav = new ModelAndView();
mav.setView("view_meta_ajax");
mav.addAllObjects(model);
return mav;
}
@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");
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);
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;
}
}
/**
* WEBLAB: Service oriented integration platform for media mining and intelligence applications
*
* Copyright (C) 2004 - 2015 Airbus Defence and Space
* 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
......@@ -15,8 +15,6 @@
* 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.URI;
......@@ -63,12 +61,11 @@ import org.springframework.web.portlet.bind.annotation.ResourceMapping;
* Control actions, renders, resources and events requests.
*
* @author emilienbondu
*
*/
@Controller
@RequestMapping(value="VIEW")
@SessionAttributes({"resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay"})
@SessionAttributes({"resource", "isEmptyModel", "isLoadedResource", "rdfProperties", "translations", "metaDisplay", "editMetaData", "dataTaglib", "dataLanguage"})
public class MetaViewContoller {
// attributes
......@@ -96,6 +93,7 @@ public class MetaViewContoller {
return this.rdfProperties.getProperties();
}
//#############################################################################
// action mapping methods #
//#############################################################################
......@@ -166,6 +164,10 @@ public class MetaViewContoller {
ModelAndView mav = new ModelAndView();
mav.setView("view_meta_ajax");
// if ( !((ModelMap) request.getPortletSession().getAttribute("model")).isEmpty()){
// model = (ModelMap) request.getPortletSession().getAttribute("model");
// this.logger.debug("model has been replaced by the modified one");
// }
mav.addAllObjects(model);