Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
February 2008
- 2 participants
- 701 discussions
r985 - in trunk/simexplorer-is/simexplorer-is-web/src: java/fr/cemagref/simexplorer/is/ui/web/pages main/webapp
by glandais@users.labs.libre-entreprise.org 15 Feb '08
by glandais@users.labs.libre-entreprise.org 15 Feb '08
15 Feb '08
Author: glandais
Date: 2008-02-15 10:18:01 +0000 (Fri, 15 Feb 2008)
New Revision: 985
Added:
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java
trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDownload.tml
Removed:
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementExport.tml
Modified:
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java
Log:
Renaming ElementExport to ElementDownload
Copied: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java (from rev 984, trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementDownload.java 2008-02-15 10:18:01 UTC (rev 985)
@@ -0,0 +1,384 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program 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 General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.ui.web.pages;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import org.apache.tapestry.StreamResponse;
+import org.codelutin.tapestry.beans.TreeNode;
+
+import fr.cemagref.simexplorer.is.attachment.Attachment;
+import fr.cemagref.simexplorer.is.entities.data.Component;
+import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication;
+import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
+import fr.cemagref.simexplorer.is.entities.data.Library;
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
+import fr.cemagref.simexplorer.is.ui.web.SimExplorerWebException;
+import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService;
+import fr.cemagref.simexplorer.is.ui.web.tools.AttachmentStreamResponse;
+import fr.cemagref.simexplorer.is.ui.web.tools.XMLAttachment;
+import fr.cemagref.simexplorer.is.ui.web.tools.ZipAttachment;
+
+/**
+ * The Class ElementDownload.
+ */
+public class ElementDownload extends ElementPageDetail {
+
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.ui.web.pages.security.ProtectedPage#getWindowTitle()
+ */
+ @Override
+ public String getWindowTitle() {
+ return getMessages().get("simexplorer.ui.web.title.elementexport");
+ }
+
+ /**
+ * On action from download xml.
+ *
+ * @return the object
+ */
+ public Object onActionFromDownloadXML() {
+
+ Object response;
+
+ MetaData mde = getMetadata();
+
+ try {
+ InputStream stream = RemoteStorageService.getStorageService()
+ .retrieveElementXML(getToken(), mde.getUuid(),
+ mde.getVersion().toString());
+ response = new XMLAttachment(stream, mde.getType() + "."
+ + mde.getUuid() + ".v" + mde.getVersion());
+ } catch (Exception e) {
+ throw new SimExplorerWebException(e);
+ }
+
+ return response;
+ }
+
+ /**
+ * On action from download full.
+ *
+ * @return the object
+ */
+ public Object onActionFromDownloadFull() {
+ Object response;
+
+ MetaData mde = getMetadata();
+
+ try {
+ InputStream stream = RemoteStorageService.getStorageService()
+ .retrieveElementFull(getToken(), mde.getUuid(),
+ mde.getVersion().toString());
+ response = new ZipAttachment(stream, mde.getType() + "."
+ + mde.getUuid() + ".v" + mde.getVersion());
+ } catch (Exception e) {
+ throw new SimExplorerWebException(e);
+ }
+
+ return response;
+ }
+
+ /**
+ * On download file.
+ *
+ * @param context
+ * the context
+ *
+ * @return the object
+ */
+ public Object onDownloadFile(String context) {
+ StreamResponse response = null;
+
+ try {
+ StringTokenizer st = new StringTokenizer(context, ",");
+ String uuid = st.nextToken();
+ String version = st.nextToken();
+ String attachmentUniqueId = st.nextToken();
+
+ MetaData metadata = RemoteStorageService.getStorageService()
+ .getMetadata(getToken(), uuid, version);
+ List<Attachment> attachments = metadata.getAttachments();
+ for (Attachment attachment : attachments) {
+ if (attachment.getUniqueId().equals(attachmentUniqueId)) {
+ InputStream stream = RemoteStorageService
+ .getStorageService().retrieveElementData(
+ getToken(), uuid, version, attachment);
+
+ response = new AttachmentStreamResponse(stream, attachment
+ .getFileName());
+ return response;
+ }
+ }
+
+ } catch (Exception e) {
+ throw new SimExplorerWebException(e);
+ }
+
+ return response;
+ }
+
+ /**
+ * Headers of tree grid.
+ *
+ * @return Headers
+ */
+ public List<String> getHeaders() {
+ List<String> result = new ArrayList<String>();
+ result.add(getMessages().get("simexplorer.ui.web.type"));
+ result.add(getMessages().get("simexplorer.ui.web.name"));
+ result.add(getMessages().get("simexplorer.ui.web.hash"));
+ result.add("");
+ return result;
+ }
+
+ /**
+ * Gets the nodes.
+ *
+ * @return the nodes
+ */
+ public List<TreeNode> getNodes() {
+ List<TreeNode> nodes = new ArrayList<TreeNode>();
+ nodes.add(generateNodes());
+ return nodes;
+ }
+
+ /**
+ * Generate nodes.
+ *
+ * @return the tree node
+ */
+ private TreeNode generateNodes() {
+ TreeNode node = null;
+ if (getElement() instanceof ExplorationApplication) {
+ node = generateExplorationApplication();
+ }
+ if (getElement() instanceof ExplorationData) {
+ node = generateExplorationData((ExplorationData) getElement());
+ }
+ if (getElement() instanceof Component) {
+ node = generateComponent((Component) getElement());
+ }
+ if (getElement() instanceof Library) {
+ node = generateLibrary((Library) getElement());
+ }
+ return node;
+ }
+
+ /**
+ * Generate exploration application.
+ *
+ * @return the tree node
+ */
+ private TreeNode generateExplorationApplication() {
+ TreeNode node;
+ node = new TreeNode();
+
+ node.setType(TreeNode.TYPE_FOLDER);
+
+ node.setColumns(generateStringArray("Application exploration",
+ getMetadata().getName()));
+
+ List<TreeNode> children = new ArrayList<TreeNode>();
+ TreeNode node1 = new TreeNode();
+ node1.setType(TreeNode.TYPE_FOLDER);
+ node1.setColumns(generateStringArray("Components"));
+ node1
+ .setChildren(generateComponents((ExplorationApplication) getElement()));
+ children.add(node1);
+
+ TreeNode node2 = new TreeNode();
+ node2.setType(TreeNode.TYPE_FOLDER);
+ node2.setColumns(generateStringArray("Explorations"));
+ node2
+ .setChildren(generateExplorations((ExplorationApplication) getElement()));
+ children.add(node2);
+
+ node.setChildren(children);
+ return node;
+ }
+
+ /**
+ * Generate explorations.
+ *
+ * @param explorationApplication
+ * the exploration application
+ *
+ * @return the list< tree node>
+ */
+ private List<TreeNode> generateExplorations(
+ ExplorationApplication explorationApplication) {
+ List<TreeNode> res = new ArrayList<TreeNode>();
+ for (ExplorationData explorationData : explorationApplication
+ .getExplorations()) {
+ res.add(generateExplorationData(explorationData));
+ }
+ return res;
+ }
+
+ /**
+ * Generate exploration data.
+ *
+ * @param explorationData
+ * the exploration data
+ *
+ * @return the tree node
+ */
+ private TreeNode generateExplorationData(ExplorationData explorationData) {
+ TreeNode explorationDataNode = new TreeNode();
+ explorationDataNode.setType(TreeNode.TYPE_FOLDER);
+
+ explorationDataNode.setColumns(generateStringArray("Exploration data",
+ explorationData.getMetaData().getName()));
+
+ List<TreeNode> children = new ArrayList<TreeNode>();
+
+ List<Attachment> attachments = explorationData.getMetaData()
+ .getAttachments();
+
+ for (Attachment attachment : attachments) {
+ children.add(generateDownload(explorationData, attachment));
+ }
+ explorationDataNode.setChildren(children);
+
+ return explorationDataNode;
+ }
+
+ /**
+ * Generate components.
+ *
+ * @param explorationApplication
+ * the exploration application
+ *
+ * @return the list< tree node>
+ */
+ private List<TreeNode> generateComponents(
+ ExplorationApplication explorationApplication) {
+ Set<Component> components = explorationApplication.getComponents();
+ List<TreeNode> res = new ArrayList<TreeNode>();
+
+ for (Component component : components) {
+ res.add(generateComponent(component));
+ }
+
+ return res;
+ }
+
+ /**
+ * Generate component.
+ *
+ * @param component
+ * the component
+ *
+ * @return the tree node
+ */
+ private TreeNode generateComponent(Component component) {
+ TreeNode componentNode = new TreeNode();
+ componentNode.setType(TreeNode.TYPE_FOLDER);
+
+ componentNode.setColumns(generateStringArray("Component", component
+ .getMetaData().getName()));
+
+ List<TreeNode> children = new ArrayList<TreeNode>();
+
+ TreeNode node;
+
+ node = new TreeNode();
+ node.setType(TreeNode.TYPE_FOLDER);
+
+ node.setColumns(generateStringArray("Libraries"));
+ node.setChildren(generateLibraries(component.getLibraries()));
+
+ children.add(node);
+
+ componentNode.setChildren(children);
+ return componentNode;
+ }
+
+ /**
+ * Generate libraries.
+ *
+ * @param libraries
+ * the libraries
+ *
+ * @return the list< tree node>
+ */
+ private List<TreeNode> generateLibraries(Set<Library> libraries) {
+ List<TreeNode> res = new ArrayList<TreeNode>();
+ for (Library library : libraries) {
+ TreeNode node = generateLibrary(library);
+ res.add(node);
+ }
+ return res;
+ }
+
+ /**
+ * Generate library.
+ *
+ * @param library
+ * the library
+ *
+ * @return the tree node
+ */
+ private TreeNode generateLibrary(Library library) {
+ TreeNode node = new TreeNode();
+ node.setType(TreeNode.TYPE_FOLDER);
+
+ List<Attachment> attachments = library.getMetaData().getAttachments();
+ List<TreeNode> children = new ArrayList<TreeNode>();
+ for (Attachment attachment : attachments) {
+ children.add(generateDownload(library, attachment));
+ }
+ node.setChildren(children);
+
+ node.setColumns(generateStringArray("Library", library.getMetaData()
+ .getName()));
+ return node;
+ }
+
+ /**
+ * Generate download.
+ *
+ * @param explorationData
+ * the exploration data
+ * @param attachment
+ * the attachment
+ *
+ * @return the tree node
+ */
+ private TreeNode generateDownload(LoggableElement explorationData,
+ Attachment attachment) {
+ TreeNode node = new TreeNode();
+ node.setType(TreeNode.TYPE_DOCUMENT);
+
+ String context = explorationData.getMetaData().getUuid() + ","
+ + explorationData.getMetaData().getVersion() + ","
+ + attachment.getUniqueId();
+
+ node.setColumns(generateStringArray(attachment.getContentType()
+ .getDescription(), attachment.getDataHash(), generateString(
+ attachment.getFileName(), "downloadFile", context)));
+ return node;
+ }
+
+}
Deleted: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java 2008-02-15 10:15:39 UTC (rev 984)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java 2008-02-15 10:18:01 UTC (rev 985)
@@ -1,385 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program 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 General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.ui.web.pages;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import java.util.StringTokenizer;
-
-import org.apache.tapestry.StreamResponse;
-import org.codelutin.tapestry.beans.TreeNode;
-
-import fr.cemagref.simexplorer.is.attachment.Attachment;
-import fr.cemagref.simexplorer.is.entities.data.Component;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
-import fr.cemagref.simexplorer.is.entities.data.Library;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.ui.web.SimExplorerWebException;
-import fr.cemagref.simexplorer.is.ui.web.services.RemoteStorageService;
-import fr.cemagref.simexplorer.is.ui.web.tools.AttachmentStreamResponse;
-import fr.cemagref.simexplorer.is.ui.web.tools.XMLAttachment;
-import fr.cemagref.simexplorer.is.ui.web.tools.ZipAttachment;
-
-/**
- * The Class ElementExport.
- * TODO la classe ne devrait-elle pas s'appeller ElementDownload ?
- */
-public class ElementExport extends ElementPageDetail {
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.ui.web.pages.security.ProtectedPage#getWindowTitle()
- */
- @Override
- public String getWindowTitle() {
- return getMessages().get("simexplorer.ui.web.title.elementexport");
- }
-
- /**
- * On action from download xml.
- *
- * @return the object
- */
- public Object onActionFromDownloadXML() {
-
- Object response;
-
- MetaData mde = getMetadata();
-
- try {
- InputStream stream = RemoteStorageService.getStorageService()
- .retrieveElementXML(getToken(), mde.getUuid(),
- mde.getVersion().toString());
- response = new XMLAttachment(stream, mde.getType() + "."
- + mde.getUuid() + ".v" + mde.getVersion());
- } catch (Exception e) {
- throw new SimExplorerWebException(e);
- }
-
- return response;
- }
-
- /**
- * On action from download full.
- *
- * @return the object
- */
- public Object onActionFromDownloadFull() {
- Object response;
-
- MetaData mde = getMetadata();
-
- try {
- InputStream stream = RemoteStorageService.getStorageService()
- .retrieveElementFull(getToken(), mde.getUuid(),
- mde.getVersion().toString());
- response = new ZipAttachment(stream, mde.getType() + "."
- + mde.getUuid() + ".v" + mde.getVersion());
- } catch (Exception e) {
- throw new SimExplorerWebException(e);
- }
-
- return response;
- }
-
- /**
- * On download file.
- *
- * @param context
- * the context
- *
- * @return the object
- */
- public Object onDownloadFile(String context) {
- StreamResponse response = null;
-
- try {
- StringTokenizer st = new StringTokenizer(context, ",");
- String uuid = st.nextToken();
- String version = st.nextToken();
- String attachmentUniqueId = st.nextToken();
-
- MetaData metadata = RemoteStorageService.getStorageService()
- .getMetadata(getToken(), uuid, version);
- List<Attachment> attachments = metadata.getAttachments();
- for (Attachment attachment : attachments) {
- if (attachment.getUniqueId().equals(attachmentUniqueId)) {
- InputStream stream = RemoteStorageService
- .getStorageService().retrieveElementData(
- getToken(), uuid, version, attachment);
-
- response = new AttachmentStreamResponse(stream, attachment
- .getFileName());
- return response;
- }
- }
-
- } catch (Exception e) {
- throw new SimExplorerWebException(e);
- }
-
- return response;
- }
-
- /**
- * Headers of tree grid.
- *
- * @return Headers
- */
- public List<String> getHeaders() {
- List<String> result = new ArrayList<String>();
- result.add(getMessages().get("simexplorer.ui.web.type"));
- result.add(getMessages().get("simexplorer.ui.web.name"));
- result.add(getMessages().get("simexplorer.ui.web.hash"));
- result.add("");
- return result;
- }
-
- /**
- * Gets the nodes.
- *
- * @return the nodes
- */
- public List<TreeNode> getNodes() {
- List<TreeNode> nodes = new ArrayList<TreeNode>();
- nodes.add(generateNodes());
- return nodes;
- }
-
- /**
- * Generate nodes.
- *
- * @return the tree node
- */
- private TreeNode generateNodes() {
- TreeNode node = null;
- if (getElement() instanceof ExplorationApplication) {
- node = generateExplorationApplication();
- }
- if (getElement() instanceof ExplorationData) {
- node = generateExplorationData((ExplorationData) getElement());
- }
- if (getElement() instanceof Component) {
- node = generateComponent((Component) getElement());
- }
- if (getElement() instanceof Library) {
- node = generateLibrary((Library) getElement());
- }
- return node;
- }
-
- /**
- * Generate exploration application.
- *
- * @return the tree node
- */
- private TreeNode generateExplorationApplication() {
- TreeNode node;
- node = new TreeNode();
-
- node.setType(TreeNode.TYPE_FOLDER);
-
- node.setColumns(generateStringArray("Application exploration",
- getMetadata().getName()));
-
- List<TreeNode> children = new ArrayList<TreeNode>();
- TreeNode node1 = new TreeNode();
- node1.setType(TreeNode.TYPE_FOLDER);
- node1.setColumns(generateStringArray("Components"));
- node1
- .setChildren(generateComponents((ExplorationApplication) getElement()));
- children.add(node1);
-
- TreeNode node2 = new TreeNode();
- node2.setType(TreeNode.TYPE_FOLDER);
- node2.setColumns(generateStringArray("Explorations"));
- node2
- .setChildren(generateExplorations((ExplorationApplication) getElement()));
- children.add(node2);
-
- node.setChildren(children);
- return node;
- }
-
- /**
- * Generate explorations.
- *
- * @param explorationApplication
- * the exploration application
- *
- * @return the list< tree node>
- */
- private List<TreeNode> generateExplorations(
- ExplorationApplication explorationApplication) {
- List<TreeNode> res = new ArrayList<TreeNode>();
- for (ExplorationData explorationData : explorationApplication
- .getExplorations()) {
- res.add(generateExplorationData(explorationData));
- }
- return res;
- }
-
- /**
- * Generate exploration data.
- *
- * @param explorationData
- * the exploration data
- *
- * @return the tree node
- */
- private TreeNode generateExplorationData(ExplorationData explorationData) {
- TreeNode explorationDataNode = new TreeNode();
- explorationDataNode.setType(TreeNode.TYPE_FOLDER);
-
- explorationDataNode.setColumns(generateStringArray("Exploration data",
- explorationData.getMetaData().getName()));
-
- List<TreeNode> children = new ArrayList<TreeNode>();
-
- List<Attachment> attachments = explorationData.getMetaData()
- .getAttachments();
-
- for (Attachment attachment : attachments) {
- children.add(generateDownload(explorationData, attachment));
- }
- explorationDataNode.setChildren(children);
-
- return explorationDataNode;
- }
-
- /**
- * Generate components.
- *
- * @param explorationApplication
- * the exploration application
- *
- * @return the list< tree node>
- */
- private List<TreeNode> generateComponents(
- ExplorationApplication explorationApplication) {
- Set<Component> components = explorationApplication.getComponents();
- List<TreeNode> res = new ArrayList<TreeNode>();
-
- for (Component component : components) {
- res.add(generateComponent(component));
- }
-
- return res;
- }
-
- /**
- * Generate component.
- *
- * @param component
- * the component
- *
- * @return the tree node
- */
- private TreeNode generateComponent(Component component) {
- TreeNode componentNode = new TreeNode();
- componentNode.setType(TreeNode.TYPE_FOLDER);
-
- componentNode.setColumns(generateStringArray("Component", component
- .getMetaData().getName()));
-
- List<TreeNode> children = new ArrayList<TreeNode>();
-
- TreeNode node;
-
- node = new TreeNode();
- node.setType(TreeNode.TYPE_FOLDER);
-
- node.setColumns(generateStringArray("Libraries"));
- node.setChildren(generateLibraries(component.getLibraries()));
-
- children.add(node);
-
- componentNode.setChildren(children);
- return componentNode;
- }
-
- /**
- * Generate libraries.
- *
- * @param libraries
- * the libraries
- *
- * @return the list< tree node>
- */
- private List<TreeNode> generateLibraries(Set<Library> libraries) {
- List<TreeNode> res = new ArrayList<TreeNode>();
- for (Library library : libraries) {
- TreeNode node = generateLibrary(library);
- res.add(node);
- }
- return res;
- }
-
- /**
- * Generate library.
- *
- * @param library
- * the library
- *
- * @return the tree node
- */
- private TreeNode generateLibrary(Library library) {
- TreeNode node = new TreeNode();
- node.setType(TreeNode.TYPE_FOLDER);
-
- List<Attachment> attachments = library.getMetaData().getAttachments();
- List<TreeNode> children = new ArrayList<TreeNode>();
- for (Attachment attachment : attachments) {
- children.add(generateDownload(library, attachment));
- }
- node.setChildren(children);
-
- node.setColumns(generateStringArray("Library", library.getMetaData()
- .getName()));
- return node;
- }
-
- /**
- * Generate download.
- *
- * @param explorationData
- * the exploration data
- * @param attachment
- * the attachment
- *
- * @return the tree node
- */
- private TreeNode generateDownload(LoggableElement explorationData,
- Attachment attachment) {
- TreeNode node = new TreeNode();
- node.setType(TreeNode.TYPE_DOCUMENT);
-
- String context = explorationData.getMetaData().getUuid() + ","
- + explorationData.getMetaData().getVersion() + ","
- + attachment.getUniqueId();
-
- node.setColumns(generateStringArray(attachment.getContentType()
- .getDescription(), attachment.getDataHash(), generateString(
- attachment.getFileName(), "downloadFile", context)));
- return node;
- }
-
-}
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java 2008-02-15 10:15:39 UTC (rev 984)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementPageDetail.java 2008-02-15 10:18:01 UTC (rev 985)
@@ -42,7 +42,7 @@
/** The element export. */
@InjectPage
- private ElementExport elementExport;
+ private ElementDownload elementDownload;
/** The element history. */
@InjectPage
@@ -91,7 +91,7 @@
* @return the object
*/
public Object onExport(String context) {
- return preparePage(elementExport, context);
+ return preparePage(elementDownload, context);
}
/**
Copied: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDownload.tml (from rev 984, trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementExport.tml)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDownload.tml (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementDownload.tml 2008-02-15 10:18:01 UTC (rev 985)
@@ -0,0 +1,19 @@
+<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
+ title="${windowtitle}">
+
+ <p><t:actionlink t:id="downloadXML">${message:simexplorer.ui.web.export.downloadxml}</t:actionlink>
+ </p>
+ <p><t:actionlink t:id="downloadFull">${message:simexplorer.ui.web.export.downloadfull}</t:actionlink>
+ </p>
+
+ <p>
+ <h2>${message:simexplorer.ui.web.export.attachments}</h2>
+ </p>
+ <p>
+ <table t:type="cl/TreeGrid" source="nodes" columnHeaders="headers">
+ </table>
+ </p>
+
+ <p><t:back label="${message:simexplorer.ui.web.back}" /></p>
+
+</t:layout>
Deleted: trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementExport.tml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementExport.tml 2008-02-15 10:15:39 UTC (rev 984)
+++ trunk/simexplorer-is/simexplorer-is-web/src/main/webapp/ElementExport.tml 2008-02-15 10:18:01 UTC (rev 985)
@@ -1,19 +0,0 @@
-<t:layout xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"
- title="${windowtitle}">
-
- <p><t:actionlink t:id="downloadXML">${message:simexplorer.ui.web.export.downloadxml}</t:actionlink>
- </p>
- <p><t:actionlink t:id="downloadFull">${message:simexplorer.ui.web.export.downloadfull}</t:actionlink>
- </p>
-
- <p>
- <h2>${message:simexplorer.ui.web.export.attachments}</h2>
- </p>
- <p>
- <table t:type="cl/TreeGrid" source="nodes" columnHeaders="headers">
- </table>
- </p>
-
- <p><t:back label="${message:simexplorer.ui.web.back}" /></p>
-
-</t:layout>
1
0
r984 - in trunk/simexplorer-is: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine
by glandais@users.labs.libre-entreprise.org 15 Feb '08
by glandais@users.labs.libre-entreprise.org 15 Feb '08
15 Feb '08
Author: glandais
Date: 2008-02-15 10:15:39 +0000 (Fri, 15 Feb 2008)
New Revision: 984
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
Log:
Saving element hierarchy
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -526,21 +526,26 @@
// update saved element to match latest element
metaData.setVersion(previousVersion.getVersion().toString());
} else {
- // trying to save a version with same hash but in superior version
- Version versionToUpgrade = previousVersion.getVersion().clone();
+ if (getStorageEngine().canCreateSubVersion(token, metaData.getUuid())) {
+ // trying to save a version with same hash but in superior version
+ Version versionToUpgrade = previousVersion.getVersion().clone();
- // set previous as not being the latest one
- previousVersion.setLatest(false);
- // update item in database, replace previous version
- update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
+ // set previous as not being the latest one
+ previousVersion.setLatest(false);
+ // update item in database, replace previous version
+ update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
- // update already stored element with element being saved version
- previousVersion.setLatest(true);
- previousVersion.setParentVersionUuid(previousVersion.getUuid());
- previousVersion.setParentVersionVersion(previousVersion.getVersion().toString());
- previousVersion.setVersion(metaData.getVersion().toString());
- // do not delete previous version, but create a copy of it with new version
- update(token, previousVersion.getUuid(), versionToUpgrade, previousVersion, false);
+ // update already stored element with element being saved version
+ previousVersion.setLatest(true);
+ previousVersion.setParentVersionUuid(previousVersion.getUuid());
+ previousVersion.setParentVersionVersion(previousVersion.getVersion().toString());
+ previousVersion.setVersion(metaData.getVersion().toString());
+ // do not delete previous version, but create a copy of it with new version
+ update(token, previousVersion.getUuid(), versionToUpgrade, previousVersion, false);
+ } else {
+ // element has to be saved as a new element as we don't have rights to update existing item
+ return true;
+ }
}
}
// element exists
@@ -578,16 +583,16 @@
if (metaData.getType() != null && VALUE_METADATA_TYPE_EA.equals(metaData.getType())) {
// Save components
- saveSubElements(token, document, xmlNode, KEY_EXPLORATIONAPPLICATION_COMPONENTS,
+ saveSubElements(token, metaData, document, xmlNode, KEY_EXPLORATIONAPPLICATION_COMPONENTS,
KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, idsattachment);
// Save exploration data
- saveSubElements(token, document, xmlNode, KEY_EXPLORATIONAPPLICATION_DATA,
+ saveSubElements(token, metaData, document, xmlNode, KEY_EXPLORATIONAPPLICATION_DATA,
KEY_EXPLORATIONAPPLICATION_DATA_NODE, idsattachment);
}
if (metaData.getType() != null && VALUE_METADATA_TYPE_COMPONENT.equals(metaData.getType())) {
// Save libraries
- saveSubElements(token, document, xmlNode, KEY_COMPONENT_LIBRARIES, KEY_COMPONENT_LIBRARY_NODE,
- idsattachment);
+ saveSubElements(token, metaData, document, xmlNode, KEY_COMPONENT_LIBRARIES,
+ KEY_COMPONENT_LIBRARY_NODE, idsattachment);
}
// Prepare saving
@@ -598,15 +603,11 @@
List<Attachment> realAttachments = metaData.getAttachments();
for (Attachment attachment : realAttachments) {
String idAttachment = idsattachment.get(attachment);
-
// Check hash of attachments
if (idAttachment == null) {
-
throw new SimExplorerServiceException(_("simexplorer.service.attachmentnotfund"));
-
}
attachments.put(attachment, getStorageEngine().retrieveTempData(idAttachment));
-
}
getStorageEngine().saveElement(token, metaData, attachments);
@@ -629,8 +630,8 @@
*
* @throws Exception the exception
*/
- private void saveSubElements(String token, Document document, Element node, String entitiesNode, String entityNode,
- Map<Attachment, String> idsattachment) throws Exception {
+ private void saveSubElements(String token, MetaData parent, Document document, Element node, String entitiesNode,
+ String entityNode, Map<Attachment, String> idsattachment) throws Exception {
BaseEntityFactory<MetaData> elementFactory = MetaDataFactory.getFactory(MetaData.class);
@@ -638,7 +639,9 @@
Element entitiesElement = elementFactory.getXMLElementByTagName(node, entitiesNode);
Set<Element> entityElements = elementFactory.getXMLElementsByTagName(entitiesElement, entityNode);
for (Element element : entityElements) {
- saveElement(token, document, element, idsattachment);
+ MetaData elementMetaData = saveElement(token, document, element, idsattachment);
+ getStorageEngine().saveElementHierarchy(token, parent, elementMetaData);
+ // FIXME store that this element is used
}
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -37,8 +37,7 @@
/**
* Open database connection.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public void open() throws SimExplorerStorageException {
open(false);
@@ -47,111 +46,96 @@
/**
* Open database connection.
*
- * @param create
- * Create database
+ * @param create Create database
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void open(boolean create)
- throws SimExplorerStorageException;
+ public abstract void open(boolean create) throws SimExplorerStorageException;
/**
* Close database connection.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public abstract void close() throws SimExplorerStorageException;
/**
* Commit pending modifications.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public abstract void commit() throws SimExplorerStorageException;
// Create / Update
/**
- * Insert an element into database Delete existing element with same
- * id/version if exists.
+ * Insert an element into database Delete existing element with same id/version if exists.
*
- * @param element
- * Element to insert
- * @param readers
- * the readers
+ * @param element Element to insert
+ * @param readers the readers
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void insertElement(MetaData element, List<Reader> readers)
- throws SimExplorerStorageException;
+ public abstract void insertElement(MetaData element, List<Reader> readers) throws SimExplorerStorageException;
+ /**
+ * Save element hierarchy, saving the fact that parent uses child
+ *
+ * @param parent the parent
+ * @param child the child
+ * @throws SimExplorerStorageException
+ */
+ public abstract void saveElementHierarchy(MetaData parent, MetaData child) throws SimExplorerStorageException;
+
// Read
/**
* Get an element from its id and its version null if not fund.
*
- * @param uuid
- * Id
- * @param version
- * version
+ * @param uuid Id
+ * @param version version
*
* @return Fund element, null if not fund
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract MetaData getElement(String uuid, Version version)
- throws SimExplorerStorageException;
+ public abstract MetaData getElement(String uuid, Version version) throws SimExplorerStorageException;
/**
* Get all version of an element thanks to its id <br>
* Empty list if no element with this id.
*
- * @param uuid
- * Id
+ * @param uuid Id
*
* @return Versions
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract List<Version> getVersions(String uuid)
- throws SimExplorerStorageException;
+ public abstract List<Version> getVersions(String uuid) throws SimExplorerStorageException;
/**
* Retrieve all elements by id Empty list if no element with this id.
*
- * @param uuid
- * Id
- * @param onlyLatest
- * the only latest
+ * @param uuid Id
+ * @param onlyLatest the only latest
*
* @return Element list
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract Set<MetaData> findElementsById(String uuid,
- boolean onlyLatest) throws SimExplorerStorageException;
+ public abstract Set<MetaData> findElementsById(String uuid, boolean onlyLatest) throws SimExplorerStorageException;
/**
* Retrieve elements with specific properties<br>
* Empty list if no element.
*
- * @param properties
- * Matching properties needed
+ * @param properties Matching properties needed
*
* @return Element list
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public Set<MetaData> findElementsByProperties(Map<String, String> properties)
- throws SimExplorerStorageException {
+ public Set<MetaData> findElementsByProperties(Map<String, String> properties) throws SimExplorerStorageException {
return findElementsByProperties(properties, 0, -1, 0);
}
@@ -159,50 +143,39 @@
* Retrieve elements with specific properties<br>
* Empty list if no element.
*
- * @param properties
- * Matching properties needed
- * @param start
- * Index of first element returned
- * @param count
- * Number of elements to return
- * @param dateOrder
- * the date order
+ * @param properties Matching properties needed
+ * @param start Index of first element returned
+ * @param count Number of elements to return
+ * @param dateOrder the date order
*
* @return Element list
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract Set<MetaData> findElementsByProperties(
- Map<String, String> properties, int start, int count, int dateOrder)
- throws SimExplorerStorageException;
+ public abstract Set<MetaData> findElementsByProperties(Map<String, String> properties, int start, int count,
+ int dateOrder) throws SimExplorerStorageException;
/**
* Retrieve element count specific properties.
*
- * @param properties
- * Matching properties needed
+ * @param properties Matching properties needed
*
* @return Number of elements fund
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract int findElementsByPropertiesCount(
- Map<String, String> properties) throws SimExplorerStorageException;
+ public abstract int findElementsByPropertiesCount(Map<String, String> properties)
+ throws SimExplorerStorageException;
/**
* Prepare properties for query.
*
- * @param type
- * Type of entity wanted
- * @param onlyLatest
- * Only wanted elements
+ * @param type Type of entity wanted
+ * @param onlyLatest Only wanted elements
*
* @return Properties for query
*/
- private Map<String, String> getPropertiesByType(String type,
- boolean onlyLatest) {
+ private Map<String, String> getPropertiesByType(String type, boolean onlyLatest) {
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_TYPE, type);
if (onlyLatest) {
@@ -214,116 +187,86 @@
/**
* Retrieve elements of a certain type.
*
- * @param type
- * Type wanted
- * @param onlyLatest
- * Only latest elements
- * @param start
- * Start index
- * @param count
- * Number of documents
- * @param dateOrder
- * Sorting
+ * @param type Type wanted
+ * @param onlyLatest Only latest elements
+ * @param start Start index
+ * @param count Number of documents
+ * @param dateOrder Sorting
*
* @return Element list
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public Set<MetaData> findElementsByType(String type, boolean onlyLatest,
- int start, int count, int dateOrder)
+ public Set<MetaData> findElementsByType(String type, boolean onlyLatest, int start, int count, int dateOrder)
throws SimExplorerStorageException {
- return findElementsByProperties(getPropertiesByType(type, onlyLatest),
- start, count, dateOrder);
+ return findElementsByProperties(getPropertiesByType(type, onlyLatest), start, count, dateOrder);
}
/**
* Number of elements of the type.
*
- * @param type
- * Type wanted
- * @param onlyLatest
- * Only latest elements
+ * @param type Type wanted
+ * @param onlyLatest Only latest elements
*
* @return Number of elements
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public int findElementsByTypeCount(String type, boolean onlyLatest)
- throws SimExplorerStorageException {
- return findElementsByPropertiesCount(getPropertiesByType(type,
- onlyLatest));
+ public int findElementsByTypeCount(String type, boolean onlyLatest) throws SimExplorerStorageException {
+ return findElementsByPropertiesCount(getPropertiesByType(type, onlyLatest));
}
/**
* Retrieve elements by content search<br>
* Empty list if no element.
*
- * @param queryText
- * Searched text
- * @param onlyLatest
- * the only latest
- * @param start
- * Index of first element returned
- * @param count
- * Number of elements to return
- * @param dateOrder
- * the date order
+ * @param queryText Searched text
+ * @param onlyLatest the only latest
+ * @param start Index of first element returned
+ * @param count Number of elements to return
+ * @param dateOrder the date order
*
* @return Element list
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract Set<MetaData> findElementsByContentSearch(String queryText,
- boolean onlyLatest, int start, int count, int dateOrder)
- throws SimExplorerStorageException;
+ public abstract Set<MetaData> findElementsByContentSearch(String queryText, boolean onlyLatest, int start,
+ int count, int dateOrder) throws SimExplorerStorageException;
/**
* Retrieve element count with specific content.
*
- * @param queryText
- * Searched text
- * @param onlyLatest
- * the only latest
+ * @param queryText Searched text
+ * @param onlyLatest the only latest
*
* @return Number of elements fund
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract int findElementsByContentSearchCount(String queryText,
- boolean onlyLatest) throws SimExplorerStorageException;
+ public abstract int findElementsByContentSearchCount(String queryText, boolean onlyLatest)
+ throws SimExplorerStorageException;
// Delete
/**
* Delete an a specific element.
*
- * @param element
- * Element to delete
+ * @param element Element to delete
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public void deleteElement(MetaData element)
- throws SimExplorerStorageException {
+ public void deleteElement(MetaData element) throws SimExplorerStorageException {
deleteElement(element.getUuid(), element.getVersion());
}
/**
* Delete an element by id and version.
*
- * @param uuid
- * Id
- * @param version
- * Version
+ * @param uuid Id
+ * @param version Version
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void deleteElement(String uuid, Version version)
- throws SimExplorerStorageException;
+ public abstract void deleteElement(String uuid, Version version) throws SimExplorerStorageException;
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -33,6 +33,12 @@
/** Field name for id and version. */
public static final String KEY_UUID_VERSION = "simexplorer.uuidversion";
+ /** Field name for id and version. */
+ public static final String KEY_UUID_VERSION_PARENT = "simexplorer.parent.uuidversion";
+
+ /** Field name for id and version. */
+ public static final String KEY_UUID_VERSION_CHILD = "simexplorer.child.uuidversion";
+
/** Field name for name. */
public static final String KEY_NAME = "simexplorer.name";
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -276,6 +276,24 @@
}
/* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.storage.database.Database#saveElementHierarchy(fr.cemagref.simexplorer.is.entities.metadata.MetaData, fr.cemagref.simexplorer.is.entities.metadata.MetaData)
+ */
+ @Override
+ public void saveElementHierarchy(MetaData parent, MetaData child) throws SimExplorerStorageException {
+ // Save element to a Lucene document
+ Document document = saveLuceneElementHierarchy(parent, child);
+
+ try {
+ synchronized (writerSynchronizer) {
+ // add document to index
+ writer.addDocument(document);
+ }
+ } catch (IOException e) {
+ throw new SimExplorerStorageException(e);
+ }
+ }
+
+ /* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.database.Database#getElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
@Override
@@ -572,7 +590,7 @@
try {
synchronized (writerSynchronizer) {
- //log.info("deleting " + term.toString());
+ // log.info("deleting " + term.toString());
writer.deleteDocuments(term);
}
} catch (Exception e) {
@@ -753,6 +771,23 @@
}
/**
+ * Transform an element hierarchy to a Lucene document
+ *
+ * @param parent the parent
+ * @param child the child
+ *
+ * @return the document
+ */
+ private Document saveLuceneElementHierarchy(MetaData parent, MetaData child) {
+ Document document = new Document();
+
+ addSimpleField(document, KEY_UUID_VERSION_PARENT, getUuidVersion(parent.getUuid(), parent.getVersion()));
+ addSimpleField(document, KEY_UUID_VERSION_CHILD, getUuidVersion(child.getUuid(), child.getVersion()));
+
+ return document;
+ }
+
+ /**
* Transform an element to a Lucene document thanks to a factory.
*
* @param readers the readers
@@ -813,4 +848,5 @@
return document;
}
+
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -69,6 +69,17 @@
throws SimExplorerStorageException;
/**
+ * Save element hierarchy.
+ *
+ * @param token the token
+ * @param parent the parent
+ * @param child the child
+ * @throws SimExplorerStorageException
+ */
+ public abstract void saveElementHierarchy(String token, MetaData parent, MetaData child)
+ throws SimExplorerStorageException;
+
+ /**
* Can create sub version for element.
*
* @param token the token
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-15 10:15:06 UTC (rev 983)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-15 10:15:39 UTC (rev 984)
@@ -140,6 +140,13 @@
database.insertElement(element, readers);
}
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#saveElementHierarchy(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.MetaData, fr.cemagref.simexplorer.is.entities.metadata.MetaData)
+ */
+ public void saveElementHierarchy(String token, MetaData parent, MetaData child) throws SimExplorerStorageException {
+ database.saveElementHierarchy(parent, child);
+ }
+
// Read
/* (non-Javadoc)
1
0
r983 - in trunk/simexplorer-is: . simexplorer-is-ear simexplorer-is-web
by glandais@users.labs.libre-entreprise.org 15 Feb '08
by glandais@users.labs.libre-entreprise.org 15 Feb '08
15 Feb '08
Author: glandais
Date: 2008-02-15 10:15:06 +0000 (Fri, 15 Feb 2008)
New Revision: 983
Modified:
trunk/simexplorer-is/pom.xml
trunk/simexplorer-is/simexplorer-is-ear/pom.xml
trunk/simexplorer-is/simexplorer-is-web/pom.xml
Log:
Tapestry version parametrisation
Modified: trunk/simexplorer-is/pom.xml
===================================================================
--- trunk/simexplorer-is/pom.xml 2008-02-14 23:07:20 UTC (rev 982)
+++ trunk/simexplorer-is/pom.xml 2008-02-15 10:15:06 UTC (rev 983)
@@ -56,6 +56,8 @@
<maven.compile.target>1.6</maven.compile.target>
<!-- compilation encondig -->
<maven.compile.encoding>ISO-8859-15</maven.compile.encoding>
+ <!-- Tapestry version -->
+ <tapestry.version>5.0.10</tapestry.version>
</properties>
</profile>
</profiles>
Modified: trunk/simexplorer-is/simexplorer-is-ear/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-ear/pom.xml 2008-02-14 23:07:20 UTC (rev 982)
+++ trunk/simexplorer-is/simexplorer-is-ear/pom.xml 2008-02-15 10:15:06 UTC (rev 983)
@@ -42,22 +42,22 @@
<dependency>
<groupId>tapestry5-treegrid</groupId>
<artifactId>tapestry5-treegrid</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-ioc</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>de.hsofttec.t5components</groupId>
Modified: trunk/simexplorer-is/simexplorer-is-web/pom.xml
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/pom.xml 2008-02-14 23:07:20 UTC (rev 982)
+++ trunk/simexplorer-is/simexplorer-is-web/pom.xml 2008-02-15 10:15:06 UTC (rev 983)
@@ -105,22 +105,22 @@
<dependency>
<groupId>tapestry5-treegrid</groupId>
<artifactId>tapestry5-treegrid</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-upload</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-core</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-ioc</artifactId>
- <version>5.0.9</version>
+ <version>${tapestry.version}</version>
</dependency>
<dependency>
<groupId>de.hsofttec.t5components</groupId>
1
0
r982 - in trunk/simexplorer-is: simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine
by glandais@users.labs.libre-entreprise.org 14 Feb '08
by glandais@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: glandais
Date: 2008-02-14 23:07:20 +0000 (Thu, 14 Feb 2008)
New Revision: 982
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
Log:
Security
Formatting
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManager.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -30,10 +30,8 @@
/**
* Gets the permission.
*
- * @param token
- * the token
- * @param businessId
- * the business id
+ * @param token the token
+ * @param businessId the business id
*
* @return the permission
*/
@@ -42,13 +40,10 @@
/**
* Save element.
*
- * @param token
- * the token
- * @param businessId
- * the business id
+ * @param token the token
+ * @param businessId the business id
*
- * @return the permission
*/
- public Permission saveElement(String token, String businessId);
+ public void saveElement(String token, String businessId);
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -46,10 +46,8 @@
/**
* Gets the relative level.
*
- * @param actor
- * the actor
- * @param permission
- * the permission
+ * @param actor the actor
+ * @param permission the permission
*
* @return the relative level
*/
@@ -103,37 +101,37 @@
p.setCanWrite(true);
}
+ if (p == null) {
+ p = new Permission();
+ p.setActor(user);
+ p.setBusinessId(businessId);
+ p.setOwner(false);
+ p.setCanAdmin(false);
+ p.setCanRead(false);
+ p.setCanWrite(false);
+ }
+
return p;
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.credentials.CredentialManager#saveElement(java.lang.String, java.lang.String)
*/
- public Permission saveElement(String token, String businessId) {
- Permission p = getPermission(token, businessId);
- boolean createPermission = false;
- if (p == null) {
- createPermission = true;
- }
- if (p != null) {
- User user = dao.getLoggedUser(token);
- if (!user.getId().equals(p.getActor().getId())) {
- createPermission = true;
+ public void saveElement(String token, String businessId) {
+ User user = dao.getLoggedUser(token);
+ if (!user.isSuperAdmin()) {
+ Permission p = getPermission(token, businessId);
+ if ((p == null) || (!user.getId().equals(p.getActor().getId()))) {
+ p = new Permission();
+ p.setActor(dao.getLoggedUser(token));
+ p.setBusinessId(businessId);
+ p.setOwner(true);
+ dao.savePermission(p);
+ } else {
+ p.setOwner(true);
+ dao.updatePermission(p);
}
}
- if (createPermission) {
- p = new Permission();
- p.setActor(dao.getLoggedUser(token));
- p.setBusinessId(businessId);
- dao.savePermission(p);
- }
- p.setCanAdmin(true);
- p.setCanRead(true);
- p.setCanWrite(true);
- p.setOwner(true);
- dao.updatePermission(p);
-
- return p;
}
}
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurity.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -19,6 +19,7 @@
import java.util.List;
+import fr.cemagref.simexplorer.is.security.entities.Actor;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.LoginAction;
import fr.cemagref.simexplorer.is.security.entities.Permission;
@@ -32,16 +33,14 @@
/**
* Save user.
*
- * @param user
- * the user
+ * @param user the user
*/
public void saveUser(User user);
/**
* Gets the user.
*
- * @param id
- * the id
+ * @param id the id
*
* @return the user
*/
@@ -50,8 +49,7 @@
/**
* Gets the user.
*
- * @param login
- * the login
+ * @param login the login
*
* @return the user
*/
@@ -60,8 +58,7 @@
/**
* Update user.
*
- * @param user
- * the user
+ * @param user the user
*
* @return the user
*/
@@ -70,24 +67,21 @@
/**
* Delete user.
*
- * @param id
- * the id
+ * @param id the id
*/
public void deleteUser(Integer id);
/**
* Save group.
*
- * @param group
- * the group
+ * @param group the group
*/
public void saveGroup(Group group);
/**
* Gets the group.
*
- * @param id
- * the id
+ * @param id the id
*
* @return the group
*/
@@ -96,8 +90,7 @@
/**
* Gets the group.
*
- * @param name
- * the name
+ * @param name the name
*
* @return the group
*/
@@ -106,8 +99,7 @@
/**
* Update group.
*
- * @param group
- * the group
+ * @param group the group
*
* @return the group
*/
@@ -116,16 +108,14 @@
/**
* Delete group.
*
- * @param id
- * the id
+ * @param id the id
*/
public void deleteGroup(Integer id);
/**
* Gets the logged user.
*
- * @param token
- * the token
+ * @param token the token
*
* @return the logged user
*/
@@ -134,10 +124,8 @@
/**
* Login user.
*
- * @param login
- * the login
- * @param passwordHash
- * the password hash
+ * @param login the login
+ * @param passwordHash the password hash
*
* @return the user
*/
@@ -146,18 +134,15 @@
/**
* Save token.
*
- * @param loginAction
- * the login action
+ * @param loginAction the login action
*/
public void saveToken(LoginAction loginAction);
/**
* Delete old tokens associated to user.
*
- * @param login
- * Login of user
- * @param before
- * ms before now
+ * @param login Login of user
+ * @param before ms before now
*/
public void deleteTokens(String login, long before);
@@ -171,8 +156,7 @@
/**
* Gets the groups owned by.
*
- * @param user
- * the user
+ * @param user the user
*
* @return the groups owned by
*/
@@ -188,8 +172,7 @@
/**
* Gets the users of group.
*
- * @param group
- * the group
+ * @param group the group
*
* @return the users of group
*/
@@ -198,8 +181,7 @@
/**
* Gets the groups of user.
*
- * @param user
- * the user
+ * @param user the user
*
* @return the groups of user
*/
@@ -208,8 +190,7 @@
/**
* Gets the groups of group.
*
- * @param group
- * the group
+ * @param group the group
*
* @return the groups of group
*/
@@ -218,36 +199,41 @@
/**
* Gets the permissions.
*
- * @param businessId
- * the business id
+ * @param businessId the business id
*
* @return the permissions
*/
public List<Permission> getPermissions(String businessId);
/**
+ * Gets the permissions.
+ *
+ * @param businessId the business id
+ * @param actor the actor
+ *
+ * @return the permissions
+ */
+ public List<Permission> getPermissions(Actor actor, String businessId);
+
+ /**
* Save permission.
*
- * @param p
- * the p
+ * @param p the p
*/
public void savePermission(Permission p);
/**
* Update permission.
*
- * @param p
- * the p
+ * @param p the p
*/
public void updatePermission(Permission p);
-
+
/**
* Sets the permissions.
*
- * @param uuid
- * the uuid
- * @param permissions
- * the permissions
+ * @param uuid the uuid
+ * @param permissions the permissions
*/
public void setPermissions(String uuid, Permission[] permissions);
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoSecurityImpl.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -28,6 +28,7 @@
import org.codelutin.util.CollectionUtil;
+import fr.cemagref.simexplorer.is.security.entities.Actor;
import fr.cemagref.simexplorer.is.security.entities.Group;
import fr.cemagref.simexplorer.is.security.entities.LoginAction;
import fr.cemagref.simexplorer.is.security.entities.Permission;
@@ -46,8 +47,7 @@
/**
* Gets the single result.
*
- * @param query
- * the query
+ * @param query the query
*
* @return the single result
*/
@@ -64,10 +64,8 @@
/**
* Find.
*
- * @param clazz
- * the clazz
- * @param arg
- * the arg
+ * @param clazz the clazz
+ * @param arg the arg
*
* @return the object
*/
@@ -111,8 +109,7 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroup(java.lang.String)
*/
public Group getGroup(String name) {
- Group g = (Group) getSingleResult(em.createQuery(
- "select g from Group g where g.name=:name").setParameter(
+ Group g = (Group) getSingleResult(em.createQuery("select g from Group g where g.name=:name").setParameter(
"name", name));
return g;
}
@@ -159,8 +156,7 @@
public User getLoggedUser(String token) {
User loggedUser = null;
LoginAction loginAction = (LoginAction) getSingleResult(em.createQuery(
- "select la from LoginAction la where la.token=:token")
- .setParameter("token", token));
+ "select la from LoginAction la where la.token=:token").setParameter("token", token));
if (loginAction != null) {
loggedUser = loginAction.getLoggedUser();
loginAction.setTime(new Date());
@@ -173,11 +169,9 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#loginUser(java.lang.String, java.lang.String)
*/
public User loginUser(String login, String passwordHash) {
- User user = (User) getSingleResult(em
- .createQuery(
- "select u from User u where u.login=:login and u.passwordHash=:passwordHash")
- .setParameter("login", login).setParameter("passwordHash",
- passwordHash));
+ User user = (User) getSingleResult(em.createQuery(
+ "select u from User u where u.login=:login and u.passwordHash=:passwordHash").setParameter("login",
+ login).setParameter("passwordHash", passwordHash));
return user;
}
@@ -194,19 +188,15 @@
public void deleteTokens(String login, long before) {
Date now = new Date();
Date date = new Date(now.getTime() - before);
- em
- .createQuery(
- "delete from LoginAction la where la.loggedUser.login = :login and la.time < :time")
- .setParameter("time", date).setParameter("login", login)
- .executeUpdate();
+ em.createQuery("delete from LoginAction la where la.loggedUser.login = :login and la.time < :time")
+ .setParameter("time", date).setParameter("login", login).executeUpdate();
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUser(java.lang.String)
*/
public User getUser(String login) {
- User user = (User) getSingleResult(em.createQuery(
- "select u from User u where u.login=:login").setParameter(
+ User user = (User) getSingleResult(em.createQuery("select u from User u where u.login=:login").setParameter(
"login", login));
return user;
}
@@ -215,8 +205,8 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroups()
*/
public List<Group> getGroups() {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select g from Group g").getResultList(), Group.class);
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g").getResultList(),
+ Group.class);
return groups;
}
@@ -224,9 +214,8 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getGroupsOwnedBy(fr.cemagref.simexplorer.is.security.entities.User)
*/
public List<Group> getGroupsOwnedBy(User user) {
- List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select g from Group g where g.owner=:owner").setParameter(
- "owner", user).getResultList(), Group.class);
+ List<Group> groups = CollectionUtil.toGenericList(em.createQuery("select g from Group g where g.owner=:owner")
+ .setParameter("owner", user).getResultList(), Group.class);
return groups;
}
@@ -234,8 +223,8 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsers()
*/
public List<User> getUsers() {
- List<User> users = CollectionUtil.toGenericList(em.createQuery(
- "select u from User u").getResultList(), User.class);
+ List<User> users = CollectionUtil.toGenericList(em.createQuery("select u from User u").getResultList(),
+ User.class);
return users;
}
@@ -243,13 +232,9 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getUsersOfGroup(fr.cemagref.simexplorer.is.security.entities.Group)
*/
public List<User> getUsersOfGroup(Group group) {
- List<User> users = CollectionUtil
- .toGenericList(
- em
- .createQuery(
- "select distinct u from User u where :group member of u.groups")
- .setParameter("group", group).getResultList(),
- User.class);
+ List<User> users = CollectionUtil.toGenericList(em.createQuery(
+ "select distinct u from User u where :group member of u.groups").setParameter("group", group)
+ .getResultList(), User.class);
return users;
}
@@ -258,8 +243,8 @@
*/
public List<Group> getGroupsOfUser(User user) {
List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select distinct u.groups from User u where u = :user")
- .setParameter("user", user).getResultList(), Group.class);
+ "select distinct u.groups from User u where u = :user").setParameter("user", user).getResultList(),
+ Group.class);
return groups;
}
@@ -268,8 +253,8 @@
*/
public List<Group> getGroupsOfGroup(Group group) {
List<Group> groups = CollectionUtil.toGenericList(em.createQuery(
- "select distinct g.groups from Group g where g = :group")
- .setParameter("group", group).getResultList(), Group.class);
+ "select distinct g.groups from Group g where g = :group").setParameter("group", group).getResultList(),
+ Group.class);
return groups;
}
@@ -277,17 +262,23 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(java.lang.String)
*/
public List<Permission> getPermissions(String businessId) {
- List<Permission> permissions = CollectionUtil
- .toGenericList(
- em
- .createQuery(
- "select p from Permission p where p.businessId=:businessId")
- .setParameter("businessId", businessId)
- .getResultList(), Permission.class);
+ List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.businessId=:businessId").setParameter("businessId", businessId)
+ .getResultList(), Permission.class);
return permissions;
}
/* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#getPermissions(fr.cemagref.simexplorer.is.security.entities.Actor, java.lang.String)
+ */
+ public List<Permission> getPermissions(Actor actor, String businessId) {
+ List<Permission> permissions = CollectionUtil.toGenericList(em.createQuery(
+ "select p from Permission p where p.businessId=:businessId and p.actor=:actor").setParameter(
+ "businessId", businessId).setParameter("actor", actor).getResultList(), Permission.class);
+ return permissions;
+ }
+
+ /* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#savePermission(fr.cemagref.simexplorer.is.security.entities.Permission)
*/
public void savePermission(Permission p) {
@@ -298,9 +289,8 @@
* @see fr.cemagref.simexplorer.is.security.dao.DaoSecurity#setPermissions(java.lang.String, fr.cemagref.simexplorer.is.security.entities.Permission[])
*/
public void setPermissions(String uuid, Permission[] permissions) {
- em.createQuery(
- "delete from Permission p where p.businessId=:businessId")
- .setParameter("businessId", uuid).executeUpdate();
+ em.createQuery("delete from Permission p where p.businessId=:businessId").setParameter("businessId", uuid)
+ .executeUpdate();
for (Permission permission : permissions) {
em.persist(permission);
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@@ -369,7 +370,6 @@
attachments.put(attachment, getStorageEngine().retrieveData(token, oldMetaData, attachment));
}
- // FIXME
if (deleteOldElement) {
getStorageEngine().deleteElement(token, oldUuid, oldVersion);
}
@@ -403,6 +403,7 @@
*/
public void deleteElement(String token, String uuid, String version) throws SimExplorerServiceException {
try {
+ // FIXME
getStorageEngine().deleteElement(token, uuid, new Version(version));
getStorageEngine().commit();
} catch (SimExplorerStorageException e) {
@@ -415,6 +416,7 @@
*/
public void deleteElement(String token, String uuid) throws SimExplorerServiceException {
try {
+ // FIXME
getStorageEngine().deleteElements(token, uuid);
getStorageEngine().commit();
} catch (SimExplorerStorageException e) {
@@ -445,15 +447,23 @@
// If there is already an element with this id
if (previousVersion != null) {
- // set previous as not being the latest one
- previousVersion.setLatest(false);
- // update item in database, replace previous version
- update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
+ // check if we have rights to create a subversion
+ if (getStorageEngine().canCreateSubVersion(token, metaData.getUuid())) {
+ // set previous as not being the latest one
+ previousVersion.setLatest(false);
+ // update item in database, replace previous version
+ update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
- // Increment version only if needed
- if (metaData.getVersion().compareTo(incrementVersion(previousVersion.getVersion())) <= 0) {
- metaData.setVersion(incrementVersion(previousVersion.getVersion()).toString());
+ // Increment version only if needed
+ if (metaData.getVersion().compareTo(incrementVersion(previousVersion.getVersion())) <= 0) {
+ metaData.setVersion(incrementVersion(previousVersion.getVersion()).toString());
+ }
+ } else {
+ // Generates a new branch, with a new id
+ metaData.setVersion("1");
+ metaData.setUuid(UUID.randomUUID().toString());
}
+
metaData.setParentVersionUuid(previousVersion.getUuid());
metaData.setParentVersionVersion(previousVersion.getVersion().toString());
@@ -628,7 +638,7 @@
Element entitiesElement = elementFactory.getXMLElementByTagName(node, entitiesNode);
Set<Element> entityElements = elementFactory.getXMLElementsByTagName(entitiesElement, entityNode);
for (Element element : entityElements) {
- MetaData elementMetadata = saveElement(token, document, element, idsattachment);
+ saveElement(token, document, element, idsattachment);
}
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineSecuImpl.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -49,15 +49,13 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#deleteElement(java.lang.String, java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
@Override
- public void deleteElement(String token, String uuid, Version version)
- throws SimExplorerStorageException {
+ public void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException {
Permission permission = credentialManager.getPermission(token, uuid);
// TODO check candelete = canadmin
- if (permission != null && permission.isCanAdmin()) {
+ if (permission.isCanAdmin()) {
super.deleteElement(token, uuid, version);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
}
@@ -65,15 +63,13 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#deleteElements(java.lang.String, java.lang.String)
*/
@Override
- public void deleteElements(String token, String uuid)
- throws SimExplorerStorageException {
+ public void deleteElements(String token, String uuid) throws SimExplorerStorageException {
Permission permission = credentialManager.getPermission(token, uuid);
// TODO check candelete = canadmin
- if (permission != null && permission.isCanAdmin()) {
+ if (permission.isCanAdmin()) {
super.deleteElements(token, uuid);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
}
@@ -81,12 +77,10 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findElementsByType(java.lang.String, java.lang.String, boolean, int, int, int)
*/
@Override
- public MetaData[] findElementsByType(String token, String type,
- boolean onlyLatest, int start, int count, int dateOrder)
- throws SimExplorerStorageException {
+ public MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count,
+ int dateOrder) throws SimExplorerStorageException {
MetaData[] list;
- list = super.findElementsByType(token, type, onlyLatest, start, count,
- dateOrder);
+ list = super.findElementsByType(token, type, onlyLatest, start, count, dateOrder);
// TODO how to filter without losing pagination?
return list;
}
@@ -95,8 +89,8 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findElementsByTypeCount(java.lang.String, java.lang.String, boolean)
*/
@Override
- public int findElementsByTypeCount(String token, String type,
- boolean onlyLatest) throws SimExplorerStorageException {
+ public int findElementsByTypeCount(String token, String type, boolean onlyLatest)
+ throws SimExplorerStorageException {
// TODO how to filter without losing pagination?
return super.findElementsByTypeCount(token, type, onlyLatest);
}
@@ -105,20 +99,17 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findFullText(java.lang.String, java.lang.String, boolean, int, int, int)
*/
@Override
- public MetaData[] findFullText(String token, String query,
- boolean onlyLatest, int indexStart, int count, int dateOrder)
- throws SimExplorerStorageException {
+ public MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count,
+ int dateOrder) throws SimExplorerStorageException {
// TODO how to filter without losing pagination?
- return super.findFullText(token, query, onlyLatest, indexStart, count,
- dateOrder);
+ return super.findFullText(token, query, onlyLatest, indexStart, count, dateOrder);
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#findFullTextCount(java.lang.String, java.lang.String, boolean)
*/
@Override
- public int findFullTextCount(String token, String query, boolean onlyLatest)
- throws SimExplorerStorageException {
+ public int findFullTextCount(String token, String query, boolean onlyLatest) throws SimExplorerStorageException {
// TODO how to filter without losing pagination?
return super.findFullTextCount(token, query, onlyLatest);
}
@@ -127,15 +118,13 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getMetadata(java.lang.String, java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
@Override
- public MetaData getMetadata(String token, String uuid, Version version)
- throws SimExplorerStorageException {
+ public MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException {
MetaData mde;
Permission permission = credentialManager.getPermission(token, uuid);
- if (permission != null && permission.isCanRead()) {
+ if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid, version);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
return mde;
}
@@ -144,15 +133,13 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getMetadata(java.lang.String, java.lang.String)
*/
@Override
- public MetaData getMetadata(String token, String uuid)
- throws SimExplorerStorageException {
+ public MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException {
MetaData mde;
Permission permission = credentialManager.getPermission(token, uuid);
- if (permission != null && permission.isCanRead()) {
+ if (permission.isCanRead()) {
mde = super.getMetadata(token, uuid);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
return mde;
}
@@ -161,15 +148,13 @@
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#getVersions(java.lang.String, java.lang.String)
*/
@Override
- public List<Version> getVersions(String token, String uuid)
- throws SimExplorerStorageException {
+ public List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException {
List<Version> versions;
Permission permission = credentialManager.getPermission(token, uuid);
- if (permission != null && permission.isCanRead()) {
+ if (permission.isCanRead()) {
versions = super.getVersions(token, uuid);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
return versions;
}
@@ -181,32 +166,39 @@
public InputStream retrieveData(String token, MetaData entity, Attachment attachment)
throws SimExplorerStorageException {
InputStream stream;
- Permission permission = credentialManager.getPermission(token, entity
- .getUuid());
- if (permission != null && permission.isCanRead()) {
+ Permission permission = credentialManager.getPermission(token, entity.getUuid());
+ if (permission.isCanRead()) {
stream = super.retrieveData(token, entity, attachment);
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
return stream;
}
/* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#canCreateSubVersion(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException {
+ Permission permission = credentialManager.getPermission(token, uuid);
+ if (permission.isCanWrite()) {
+ return true;
+ }
+ return false;
+ }
+
+ /* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl#saveElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.util.Map)
*/
@Override
- public void saveElement(String token, MetaData element,
- Map<Attachment, InputStream> attachments)
+ public void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments)
throws SimExplorerStorageException {
- Permission permission = credentialManager.getPermission(token, element
- .getUuid());
- if (permission != null && permission.isCanWrite()) {
+ Permission permission = credentialManager.getPermission(token, element.getUuid());
+ if (permission.isCanWrite()) {
super.saveElement(token, element, attachments);
credentialManager.saveElement(token, element.getUuid());
} else {
- throw new SimExplorerStorageException(
- _("simexplorer.service.security.norights"));
+ throw new SimExplorerStorageException(_("simexplorer.service.security.norights"));
}
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -38,311 +38,245 @@
/**
* Open storage.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public abstract void open() throws SimExplorerStorageException;
/**
* Close storage.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public abstract void close() throws SimExplorerStorageException;
/**
* Commit changes to storage.
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
public abstract void commit() throws SimExplorerStorageException;
/**
* Save an element to storage.
*
- * @param element
- * Element to save
- * @param attachments
- * Attachments related
- * @param token
- * the token
+ * @param element Element to save
+ * @param attachments Attachments related
+ * @param token the token
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void saveElement(String token, MetaData element,
- Map<Attachment, InputStream> attachments)
+ public abstract void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments)
throws SimExplorerStorageException;
/**
+ * Can create sub version for element.
+ *
+ * @param token the token
+ * @param uuid the uuid
+ *
+ * @return true, if can create sub version
+ *
+ * @throws SimExplorerStorageException the sim explorer storage exception
+ */
+ public abstract boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException;
+
+ /**
* Retrieve an element.
*
- * @param uuid
- * Id of the element
- * @param token
- * the token
+ * @param uuid Id of the element
+ * @param token the token
*
* @return The element
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract MetaData getMetadata(String token, String uuid)
- throws SimExplorerStorageException;
+ public abstract MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException;
/**
* Retrieve versions of an element<br>
* Empty list if no element with this id.
*
- * @param uuid
- * Id of the element
- * @param token
- * the token
+ * @param uuid Id of the element
+ * @param token the token
*
* @return List of versions of the element<br>
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract List<Version> getVersions(String token, String uuid)
- throws SimExplorerStorageException;
+ public abstract List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException;
/**
* Retrieve all version of a metadata.
*
- * @param token
- * the token
- * @param uuid
- * the uuid
+ * @param token the token
+ * @param uuid the uuid
*
* @return the element versions
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract Set<MetaData> getElementVersions(String token, String uuid)
- throws SimExplorerStorageException;
+ public abstract Set<MetaData> getElementVersions(String token, String uuid) throws SimExplorerStorageException;
/**
* Retrieve an element in a specific version.
*
- * @param uuid
- * the uuid
- * @param version
- * the version
- * @param token
- * the token
+ * @param uuid the uuid
+ * @param version the version
+ * @param token the token
*
* @return the metadata
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract MetaData getMetadata(String token, String uuid,
- Version version) throws SimExplorerStorageException;
+ public abstract MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException;
/**
* Get data associated to an element.
*
- * @param entity
- * Element related
- * @param token
- * the token
- * @param attachment
- * the attachment
+ * @param entity Element related
+ * @param token the token
+ * @param attachment the attachment
*
* @return Data stream
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract InputStream retrieveData(String token, MetaData entity,
- Attachment attachment) throws SimExplorerStorageException;
+ public abstract InputStream retrieveData(String token, MetaData entity, Attachment attachment)
+ throws SimExplorerStorageException;
/**
* Get number of items corresponding to query.
*
- * @param query
- * the query
- * @param onlyLatest
- * the only latest
- * @param token
- * the token
+ * @param query the query
+ * @param onlyLatest the only latest
+ * @param token the token
*
* @return the int
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract int findFullTextCount(String token, String query,
- boolean onlyLatest) throws SimExplorerStorageException;
+ public abstract int findFullTextCount(String token, String query, boolean onlyLatest)
+ throws SimExplorerStorageException;
/**
* Retrieve list of items corresponding to query.
*
- * @param query
- * the query
- * @param onlyLatest
- * the only latest
- * @param indexStart
- * the index start
- * @param count
- * the count
- * @param dateOrder
- * the date order
- * @param token
- * the token
+ * @param query the query
+ * @param onlyLatest the only latest
+ * @param indexStart the index start
+ * @param count the count
+ * @param dateOrder the date order
+ * @param token the token
*
* @return the meta data[]
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract MetaData[] findFullText(String token, String query,
- boolean onlyLatest, int indexStart, int count, int dateOrder)
- throws SimExplorerStorageException;
+ public abstract MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count,
+ int dateOrder) throws SimExplorerStorageException;
/**
* Retrieve list of items of type wanted.
*
- * @param type
- * the type
- * @param onlyLatest
- * the only latest
- * @param start
- * the start
- * @param count
- * the count
- * @param dateOrder
- * the date order
- * @param token
- * the token
+ * @param type the type
+ * @param onlyLatest the only latest
+ * @param start the start
+ * @param count the count
+ * @param dateOrder the date order
+ * @param token the token
*
* @return the meta data[]
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract MetaData[] findElementsByType(String token, String type,
- boolean onlyLatest, int start, int count, int dateOrder)
- throws SimExplorerStorageException;
+ public abstract MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count,
+ int dateOrder) throws SimExplorerStorageException;
/**
* Retrieve number of items of type wanted.
*
- * @param type
- * the type
- * @param onlyLatest
- * the only latest
- * @param token
- * the token
+ * @param type the type
+ * @param onlyLatest the only latest
+ * @param token the token
*
* @return the int
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract int findElementsByTypeCount(String token, String type,
- boolean onlyLatest) throws SimExplorerStorageException;
+ public abstract int findElementsByTypeCount(String token, String type, boolean onlyLatest)
+ throws SimExplorerStorageException;
/**
* Delete elements.
*
- * @param uuid
- * the uuid
- * @param token
- * the token
+ * @param uuid the uuid
+ * @param token the token
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void deleteElements(String token, String uuid)
- throws SimExplorerStorageException;
+ public abstract void deleteElements(String token, String uuid) throws SimExplorerStorageException;
/**
* Delete one element.
*
- * @param uuid
- * the uuid
- * @param version
- * the version
- * @param token
- * the token
+ * @param uuid the uuid
+ * @param version the version
+ * @param token the token
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void deleteElement(String token, String uuid,
- Version version) throws SimExplorerStorageException;
+ public abstract void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException;
/**
* Store temporary data, for stream duplication.
*
- * @param stream
- * Stream to store
+ * @param stream Stream to store
*
* @return id for retrieval
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract String storeTempData(InputStream stream)
- throws SimExplorerStorageException;
+ public abstract String storeTempData(InputStream stream) throws SimExplorerStorageException;
/**
* Store temporary data, for stream duplication.
*
- * @param stream
- * Stream to store
+ * @param stream Stream to store
+ * @param id the id
*
- * @return id for retrieval
- *
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void storeTempData(String id, InputStream stream)
- throws SimExplorerStorageException;
+ public abstract void storeTempData(String id, InputStream stream) throws SimExplorerStorageException;
/**
* Retrieve temporary data.
*
- * @param id
- * Id associated
+ * @param id Id associated
*
* @return Data stream
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract InputStream retrieveTempData(String id)
- throws SimExplorerStorageException;
+ public abstract InputStream retrieveTempData(String id) throws SimExplorerStorageException;
/**
* Retrieve MD5 temp data.
*
- * @param id
- * the id
+ * @param id the id
*
* @return the string
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract String retrieveMD5TempData(String id)
- throws SimExplorerStorageException;
+ public abstract String retrieveMD5TempData(String id) throws SimExplorerStorageException;
/**
* Delete temporary data.
*
- * @param id
- * the id
+ * @param id the id
*
- * @throws SimExplorerStorageException
- * the sim explorer storage exception
+ * @throws SimExplorerStorageException the sim explorer storage exception
*/
- public abstract void deleteTempData(String id)
- throws SimExplorerStorageException;
+ public abstract void deleteTempData(String id) throws SimExplorerStorageException;
}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-14 20:18:28 UTC (rev 981)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngineImpl.java 2008-02-14 23:07:20 UTC (rev 982)
@@ -98,14 +98,12 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#saveElement(fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.util.Map)
*/
- public void saveElement(String token, MetaData element,
- Map<Attachment, InputStream> attachments)
+ public void saveElement(String token, MetaData element, Map<Attachment, InputStream> attachments)
throws SimExplorerStorageException {
// Save all attachments in system
for (Map.Entry<Attachment, InputStream> entry : attachments.entrySet()) {
- attachmentHandler.storeData(element, entry.getKey(), entry
- .getValue());
+ attachmentHandler.storeData(element, entry.getKey(), entry.getValue());
}
// Parse all attachments for indexing
@@ -114,12 +112,10 @@
Attachment attachment = entry.getKey();
if (attachment.getContentType() != null) {
- InputStream content = attachmentHandler.retrieveData(element,
- attachment);
+ InputStream content = attachmentHandler.retrieveData(element, attachment);
try {
// Transform stream into indexable text
- Reader reader = attachment.getContentType().renderToText(
- content);
+ Reader reader = attachment.getContentType().renderToText(content);
readers.add(reader);
} catch (Exception e) {
throw new SimExplorerStorageException(e);
@@ -149,8 +145,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String)
*/
- public MetaData getMetadata(String token, String uuid)
- throws SimExplorerStorageException {
+ public MetaData getMetadata(String token, String uuid) throws SimExplorerStorageException {
MetaData mde = null;
Set<MetaData> set = database.findElementsById(uuid, true);
if (!set.isEmpty()) {
@@ -162,16 +157,14 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getVersions(java.lang.String)
*/
- public List<Version> getVersions(String token, String uuid)
- throws SimExplorerStorageException {
+ public List<Version> getVersions(String token, String uuid) throws SimExplorerStorageException {
return database.getVersions(uuid);
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getMetadata(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
- public MetaData getMetadata(String token, String uuid, Version version)
- throws SimExplorerStorageException {
+ public MetaData getMetadata(String token, String uuid, Version version) throws SimExplorerStorageException {
MetaData mde = database.getElement(uuid, version);
return mde;
}
@@ -179,8 +172,8 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveData(fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.lang.String)
*/
- public InputStream retrieveData(String token, MetaData entity,
- Attachment attachment) throws SimExplorerStorageException {
+ public InputStream retrieveData(String token, MetaData entity, Attachment attachment)
+ throws SimExplorerStorageException {
InputStream result = attachmentHandler.retrieveData(entity, attachment);
return result;
}
@@ -188,39 +181,35 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullTextCount(java.lang.String, boolean)
*/
- public int findFullTextCount(String token, String query, boolean onlyLatest)
- throws SimExplorerStorageException {
+ public int findFullTextCount(String token, String query, boolean onlyLatest) throws SimExplorerStorageException {
return database.findElementsByContentSearchCount(query, onlyLatest);
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findFullText(java.lang.String, boolean, int, int, int)
*/
- public MetaData[] findFullText(String token, String query,
- boolean onlyLatest, int indexStart, int count, int dateOrder)
- throws SimExplorerStorageException {
- MetaData[] result = database.findElementsByContentSearch(query,
- onlyLatest, indexStart, count, dateOrder).toArray(
- new MetaData[0]);
+ public MetaData[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count,
+ int dateOrder) throws SimExplorerStorageException {
+ MetaData[] result = database.findElementsByContentSearch(query, onlyLatest, indexStart, count, dateOrder)
+ .toArray(new MetaData[0]);
return result;
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByType(java.lang.String, boolean, int, int, int)
*/
- public MetaData[] findElementsByType(String token, String type,
- boolean onlyLatest, int start, int count, int dateOrder)
- throws SimExplorerStorageException {
- MetaData[] result = database.findElementsByType(type, onlyLatest,
- start, count, dateOrder).toArray(new MetaData[0]);
+ public MetaData[] findElementsByType(String token, String type, boolean onlyLatest, int start, int count,
+ int dateOrder) throws SimExplorerStorageException {
+ MetaData[] result = database.findElementsByType(type, onlyLatest, start, count, dateOrder).toArray(
+ new MetaData[0]);
return result;
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#findElementsByTypeCount(java.lang.String, boolean)
*/
- public int findElementsByTypeCount(String token, String type,
- boolean onlyLatest) throws SimExplorerStorageException {
+ public int findElementsByTypeCount(String token, String type, boolean onlyLatest)
+ throws SimExplorerStorageException {
return database.findElementsByTypeCount(type, onlyLatest);
}
@@ -229,8 +218,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElements(java.lang.String)
*/
- public void deleteElements(String token, String uuid)
- throws SimExplorerStorageException {
+ public void deleteElements(String token, String uuid) throws SimExplorerStorageException {
List<Version> versions = getVersions(token, uuid);
for (Version version : versions) {
deleteElement(token, uuid, version);
@@ -240,8 +228,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#deleteElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
- public void deleteElement(String token, String uuid, Version version)
- throws SimExplorerStorageException {
+ public void deleteElement(String token, String uuid, Version version) throws SimExplorerStorageException {
MetaData element = getMetadata(token, uuid, version);
List<Attachment> attachments = element.getAttachments();
for (Attachment attachment : attachments) {
@@ -269,34 +256,28 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#storeTempData(java.io.InputStream)
*/
- public String storeTempData(InputStream stream)
- throws SimExplorerStorageException {
+ public String storeTempData(InputStream stream) throws SimExplorerStorageException {
String id = UUID.randomUUID().toString();
storeTempData(id, stream);
return id;
}
@Override
- public void storeTempData(String id, InputStream stream)
- throws SimExplorerStorageException {
+ public void storeTempData(String id, InputStream stream) throws SimExplorerStorageException {
attachmentHandler.storeData(mdTmp, getTmpAttachment(id), stream);
}
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#retrieveTempData(java.lang.String)
*/
- public InputStream retrieveTempData(String id)
- throws SimExplorerStorageException {
- InputStream is = attachmentHandler.retrieveData(mdTmp,
- getTmpAttachment(id));
+ public InputStream retrieveTempData(String id) throws SimExplorerStorageException {
+ InputStream is = attachmentHandler.retrieveData(mdTmp, getTmpAttachment(id));
return is;
}
@Override
- public String retrieveMD5TempData(String id)
- throws SimExplorerStorageException {
- String md5 = attachmentHandler.retrieveMD5Data(mdTmp,
- getTmpAttachment(id));
+ public String retrieveMD5TempData(String id) throws SimExplorerStorageException {
+ String md5 = attachmentHandler.retrieveMD5Data(mdTmp, getTmpAttachment(id));
return md5;
}
@@ -310,9 +291,17 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#getElementVersions(java.lang.String, java.lang.String)
*/
- public Set<MetaData> getElementVersions(String token, String uuid)
- throws SimExplorerStorageException {
+ public Set<MetaData> getElementVersions(String token, String uuid) throws SimExplorerStorageException {
return database.findElementsById(uuid, false);
}
+ /* (non-Javadoc)
+ * @see fr.cemagref.simexplorer.is.storage.engine.StorageEngine#canCreateSubVersion(java.lang.String, java.lang.String)
+ */
+ @Override
+ public boolean canCreateSubVersion(String token, String uuid) throws SimExplorerStorageException {
+ // by default
+ return true;
+ }
+
}
1
0
r981 - in trunk/simexplorer-is: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene
by glandais@users.labs.libre-entreprise.org 14 Feb '08
by glandais@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: glandais
Date: 2008-02-14 20:18:28 +0000 (Thu, 14 Feb 2008)
New Revision: 981
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/ElementGenerator.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceLocalVersions.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
Log:
Versionning business rules
Modify XML nodes instead of streams (better recursivity)
Advance version test
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/ElementGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/ElementGenerator.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/ElementGenerator.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -57,32 +57,23 @@
*/
public class RandomStream {
- /** The stream. */
- private InputStream stream;
-
/** The md5. */
private String md5;
+ private byte[] data;
+
/**
* Gets the stream.
*
* @return the stream
*/
public InputStream getStream() {
- return stream;
+ InputStream is;
+ is = new ByteArrayInputStream(data);
+ return is;
}
/**
- * Sets the stream.
- *
- * @param stream
- * the new stream
- */
- public void setStream(InputStream stream) {
- this.stream = stream;
- }
-
- /**
* Gets the md5.
*
* @return the md5
@@ -94,13 +85,16 @@
/**
* Sets the md5.
*
- * @param md5
- * the new md5
+ * @param md5 the new md5
*/
public void setMd5(String md5) {
this.md5 = md5;
}
+ public void setData(byte[] bytes) {
+ data = bytes;
+ }
+
}
/** The r. */
@@ -165,11 +159,9 @@
/**
* Update.
*
- * @param element
- * the element
+ * @param element the element
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
private void update(LoggableElement element) throws Exception {
MetaData metaData = new MetaData();
@@ -179,14 +171,14 @@
StringBuffer sb = new StringBuffer("");
- for (int i = 0,max = 3 + r.nextInt(5); i < max; i++) {
+ for (int i = 0, max = 3 + r.nextInt(5); i < max; i++) {
sb.append(randomstrings[r.nextInt(cs)]).append(" ");
}
metaData.setDescription(sb.toString());
Version v = new Version("0");
- for (int i = 0,max = 2 + r.nextInt(2); i < max; i++) {
+ for (int i = 0, max = 2 + r.nextInt(2); i < max; i++) {
v.setVersion(i, r.nextInt(5));
}
metaData.setVersion(v.toString());
@@ -195,41 +187,37 @@
metaData.setLatest(true);
Map<String, String> descriptors = new HashMap<String, String>();
- for (int i = 0,max = 1+ r.nextInt(12); i < max; i++) {
+ for (int i = 0, max = 1 + r.nextInt(12); i < max; i++) {
descriptors.put(Integer.toString(i), shortString());
}
metaData.setDescriptors(descriptors);
-
if (element instanceof Library || element instanceof ExplorationData) {
// generate attachments
- for (int i=0,max = r.nextInt(15);i<max;i++) {
+ for (int i = 0, max = r.nextInt(15); i < max; i++) {
metaData.getAttachments().add(generateAttachment());
}
}
-
+
element.setMetaData(metaData);
}
/**
* Generate array.
+ *
* @param <T> Class in array
*
- * @param clazz
- * the clazz
+ * @param clazz the clazz
*
* @return the set< t>
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
- public <T extends DataEntity> Set<T> generateArray(Class<T> clazz)
- throws Exception {
+ public <T extends DataEntity> Set<T> generateArray(Class<T> clazz) throws Exception {
Set<T> elements = new HashSet<T>();
int i = 3 + r.nextInt(2);
for (int j = 0; j < i; j++) {
- T element = BaseEntityFactory.<T> getFactory(clazz)
- .createInstance();
+ T element = BaseEntityFactory.<T> getFactory(clazz).createInstance();
if (element instanceof LoggableElement) {
update((LoggableElement) element);
}
@@ -243,8 +231,7 @@
*
* @return the exploration application
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
public ExplorationApplication generateRandomEA() throws Exception {
ExplorationApplication ea = new ExplorationApplication();
@@ -265,11 +252,9 @@
/**
* Process component.
*
- * @param component
- * the component
+ * @param component the component
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
private void processComponent(Component component) throws Exception {
Set<Constant> constants = generateArray(Constant.class);
@@ -299,15 +284,13 @@
*
* @return the attachment
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
private Attachment generateAttachment() throws Exception {
Attachment attachment = new Attachment();
- attachment.setContentType(ContentTypeFactory
- .getContentTypeInstance("RawType"));
+ attachment.setContentType(ContentTypeFactory.getContentTypeInstance("RawType"));
attachment.setDataHash(hash());
- //attachment.setDataHash("d41d8cd98f00b204e9800998ecf8427e");
+ // attachment.setDataHash("d41d8cd98f00b204e9800998ecf8427e");
attachment.setFileName(shortString() + ".txt");
return attachment;
}
@@ -315,21 +298,18 @@
/**
* Process library.
*
- * @param library
- * the library
+ * @param library the library
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
private void processLibrary(Library library) throws Exception {
- //library.getMetaData().getAttachments().add(generateAttachment());
+ // library.getMetaData().getAttachments().add(generateAttachment());
}
/**
* Process code.
*
- * @param code
- * the code
+ * @param code the code
*/
private void processCode(Code code) {
code.setCode(shortString());
@@ -339,8 +319,7 @@
/**
* Process constant.
*
- * @param constant
- * the constant
+ * @param constant the constant
*/
private void processConstant(Constant constant) {
constant.setName(shortString());
@@ -350,17 +329,14 @@
/**
* Process exploration data.
*
- * @param explorationData
- * the exploration data
+ * @param explorationData the exploration data
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
- private void processExplorationData(ExplorationData explorationData)
- throws Exception {
+ private void processExplorationData(ExplorationData explorationData) throws Exception {
Result result = new Result();
explorationData.setResult(result);
- //explorationData.getMetaData().getAttachments().add(generateAttachment());
+ // explorationData.getMetaData().getAttachments().add(generateAttachment());
Set<ConstantValue> constantValues = generateArray(ConstantValue.class);
for (ConstantValue constantValue : constantValues) {
@@ -373,8 +349,7 @@
/**
* Process constant value.
*
- * @param constantValue
- * the constant value
+ * @param constantValue the constant value
*/
private void processConstantValue(ConstantValue constantValue) {
Constant constant = new Constant();
@@ -390,8 +365,7 @@
*
* @return the input stream
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
public RandomStream generateTextStream() throws Exception {
RandomStream rs = new RandomStream();
@@ -406,9 +380,7 @@
md5.Update(sb.toString().getBytes());
rs.setMd5(md5.asHex());
- InputStream is;
- is = new ByteArrayInputStream(sb.toString().getBytes());
- rs.setStream(is);
+ rs.setData(sb.toString().getBytes());
return rs;
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -56,7 +56,10 @@
@Override
protected Version incrementVersion(Version version) {
- return version.incVersion(1);
+ Version result = new Version("");
+ result.setVersion(0, version.getVersion(0));
+ result.setVersion(1, version.getVersion(1) + 1);
+ return result;
}
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -34,6 +34,8 @@
import org.codelutin.util.ZipStreamEncoder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
import com.healthmarketscience.rmiio.SerializableInputStream;
@@ -213,7 +215,8 @@
}
}
- MetaData elementSaved = saveElement(token, xmlFile, attachments);
+ Document document = BaseEntityFactory.getXMLBuilder().parse(getStorageEngine().retrieveTempData(xmlFile));
+ MetaData elementSaved = saveElement(token, document, getFirstElement(document), attachments);
getStorageEngine().deleteTempData(xmlFile);
for (Map.Entry<Attachment, String> tmpId : attachments.entrySet()) {
getStorageEngine().deleteTempData(tmpId.getValue());
@@ -245,7 +248,8 @@
String idattachment = getStorageEngine().storeTempData(entry.getValue());
idsattachment.put(entry.getKey(), idattachment);
}
- MetaData elementSaved = saveElement(token, idxml, idsattachment);
+ Document document = BaseEntityFactory.getXMLBuilder().parse(getStorageEngine().retrieveTempData(idxml));
+ MetaData elementSaved = saveElement(token, document, getFirstElement(document), idsattachment);
getStorageEngine().deleteTempData(idxml);
for (Map.Entry<Attachment, String> tmpId : idsattachment.entrySet()) {
getStorageEngine().deleteTempData(tmpId.getValue());
@@ -356,7 +360,7 @@
InputStream oldXml = getStorageEngine().retrieveData(token, oldMetaData, getXMLAttachment());
MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
- InputStream newXml = mdeFactory.replaceElementInParentXML(oldXml, newElement);
+ InputStream newXml = mdeFactory.modifyMedataElementStream(oldXml, newElement);
attachments.put(getXMLAttachment(), newXml);
@@ -365,6 +369,7 @@
attachments.put(attachment, getStorageEngine().retrieveData(token, oldMetaData, attachment));
}
+ // FIXME
if (deleteOldElement) {
getStorageEngine().deleteElement(token, oldUuid, oldVersion);
}
@@ -422,11 +427,13 @@
*
* @param token the token
* @param metaData the meta data
- * @param idxml the idxml
+ * @param document the document
+ * @param xmlNode the xml node
*
* @throws Exception the exception
*/
- protected void processVersionRules(String token, MetaData metaData, String idxml) throws Exception {
+ protected void processVersionRules(String token, MetaData metaData, Document document, Element xmlNode)
+ throws Exception {
// This one will always be the latest
metaData.setLatest(true);
@@ -446,15 +453,29 @@
// Increment version only if needed
if (metaData.getVersion().compareTo(incrementVersion(previousVersion.getVersion())) <= 0) {
metaData.setVersion(incrementVersion(previousVersion.getVersion()).toString());
- // get metadata factory
- MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
+ }
+ metaData.setParentVersionUuid(previousVersion.getUuid());
+ metaData.setParentVersionVersion(previousVersion.getVersion().toString());
- // Update XML with version updated
- InputStream newXml = mdeFactory.replaceElementInParentXML(getStorageEngine().retrieveTempData(idxml),
- metaData);
- getStorageEngine().storeTempData(idxml, newXml);
+ // get metadata factory
+ MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
+
+ // Update XML with version updated
+ mdeFactory.replaceMetadataInXML(document, xmlNode, metaData);
+ }
+ }
+
+ private Element getFirstElement(Document document) {
+ Element element = null;
+ NodeList childNodes = document.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++) {
+ Node item = childNodes.item(i);
+ if (item instanceof Element) {
+ element = (Element) item;
+ break;
}
- }
+ }
+ return element;
}
/**
@@ -487,24 +508,30 @@
// Check if previous is not null and both hash are equals
if (previousVersion != null && previousVersion.getHash().equals(metaData.getHash())) {
- // if md trying to be saved is older than existing
- if (metaData.getVersion().compareTo(previousVersion.getVersion()) < 0) {
- // update saved element to match latest element
- metaData.setVersion(previousVersion.getVersion().toString());
+ if (metaData.getVersion().equals(previousVersion.getVersion())) {
+ // nothing to do
} else {
- // trying to save a version with same hash but in superior version
- Version versionToUpgrade = previousVersion.getVersion().clone();
-
- // set previous as not being the latest one
- previousVersion.setLatest(false);
- // update item in database, replace previous version
- update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
-
- // update already stored element with element being saved version
- previousVersion.setLatest(true);
- previousVersion.setVersion(metaData.getVersion().toString());
- // do not delete previous version, but create a copy of it with new version
- update(token, previousVersion.getUuid(), versionToUpgrade, previousVersion, false);
+ // if md trying to be saved is older than existing
+ if (metaData.getVersion().compareTo(previousVersion.getVersion()) < 0) {
+ // update saved element to match latest element
+ metaData.setVersion(previousVersion.getVersion().toString());
+ } else {
+ // trying to save a version with same hash but in superior version
+ Version versionToUpgrade = previousVersion.getVersion().clone();
+
+ // set previous as not being the latest one
+ previousVersion.setLatest(false);
+ // update item in database, replace previous version
+ update(token, previousVersion.getUuid(), previousVersion.getVersion(), previousVersion, true);
+
+ // update already stored element with element being saved version
+ previousVersion.setLatest(true);
+ previousVersion.setParentVersionUuid(previousVersion.getUuid());
+ previousVersion.setParentVersionVersion(previousVersion.getVersion().toString());
+ previousVersion.setVersion(metaData.getVersion().toString());
+ // do not delete previous version, but create a copy of it with new version
+ update(token, previousVersion.getUuid(), versionToUpgrade, previousVersion, false);
+ }
}
// element exists
return false;
@@ -517,43 +544,46 @@
* Real implementation of saveElement.
*
* @param token the token
- * @param idxml the idxml
* @param idsattachment the idsattachment
+ * @param document the document
+ * @param xmlNode the xml node
*
* @return the meta data
*
* @throws Exception the exception
*/
- private MetaData saveElement(String token, String idxml, Map<Attachment, String> idsattachment) throws Exception {
+ private MetaData saveElement(String token, Document document, Element xmlNode, Map<Attachment, String> idsattachment)
+ throws Exception {
// Load metadata xml
MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
- MetaData metaData = mdeFactory.loadElementFromParentXML(getStorageEngine().retrieveTempData(idxml));
+ MetaData metaData = mdeFactory.loadElementFromParentXML(xmlNode);
// Compute element hash
- metaData.setHash(mdeFactory.computeHash(getStorageEngine().retrieveTempData(idxml)));
+ metaData.setHash(mdeFactory.computeHash(xmlNode));
if (notExists(token, metaData)) {
// Process version rules
- processVersionRules(token, metaData, idxml);
+ processVersionRules(token, metaData, document, xmlNode);
if (metaData.getType() != null && VALUE_METADATA_TYPE_EA.equals(metaData.getType())) {
// Save components
- saveSubElements(token, idxml, KEY_EXPLORATIONAPPLICATION_COMPONENTS,
+ saveSubElements(token, document, xmlNode, KEY_EXPLORATIONAPPLICATION_COMPONENTS,
KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE, idsattachment);
// Save exploration data
- saveSubElements(token, idxml, KEY_EXPLORATIONAPPLICATION_DATA, KEY_EXPLORATIONAPPLICATION_DATA_NODE,
- idsattachment);
+ saveSubElements(token, document, xmlNode, KEY_EXPLORATIONAPPLICATION_DATA,
+ KEY_EXPLORATIONAPPLICATION_DATA_NODE, idsattachment);
}
if (metaData.getType() != null && VALUE_METADATA_TYPE_COMPONENT.equals(metaData.getType())) {
// Save libraries
- saveSubElements(token, idxml, KEY_COMPONENT_LIBRARIES, KEY_COMPONENT_LIBRARY_NODE, idsattachment);
+ saveSubElements(token, document, xmlNode, KEY_COMPONENT_LIBRARIES, KEY_COMPONENT_LIBRARY_NODE,
+ idsattachment);
}
// Prepare saving
Map<Attachment, InputStream> attachments = new HashMap<Attachment, InputStream>();
- attachments.put(getXMLAttachment(), getStorageEngine().retrieveTempData(idxml));
+ attachments.put(getXMLAttachment(), BaseEntityFactory.serializeElement(xmlNode));
List<Attachment> realAttachments = metaData.getAttachments();
for (Attachment attachment : realAttachments) {
@@ -581,29 +611,24 @@
* Save sub elements.
*
* @param token the token
- * @param idxml the idxml
* @param entitiesNode the entities node
* @param entityNode the entity node
* @param idsattachment the idsattachment
+ * @param document the document
+ * @param node the node
*
* @throws Exception the exception
*/
- private void saveSubElements(String token, String idxml, String entitiesNode, String entityNode,
+ private void saveSubElements(String token, Document document, Element node, String entitiesNode, String entityNode,
Map<Attachment, String> idsattachment) throws Exception {
BaseEntityFactory<MetaData> elementFactory = MetaDataFactory.getFactory(MetaData.class);
- Document document = BaseEntityFactory.getXMLBuilder().parse(getStorageEngine().retrieveTempData(idxml));
-
- Element rootElement = (Element) document.getFirstChild();
-
// Elements
- Element entitiesElement = elementFactory.getXMLElementByTagName(rootElement, entitiesNode);
+ Element entitiesElement = elementFactory.getXMLElementByTagName(node, entitiesNode);
Set<Element> entityElements = elementFactory.getXMLElementsByTagName(entitiesElement, entityNode);
for (Element element : entityElements) {
- String elementDataId = getStorageEngine().storeTempData(BaseEntityFactory.serializeElement(element));
- saveElement(token, elementDataId, idsattachment);
- getStorageEngine().deleteTempData(elementDataId);
+ MetaData elementMetadata = saveElement(token, document, element, idsattachment);
}
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceHelper.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -62,6 +62,8 @@
// Update element in source service, from what remote service returns on export
toElement.setLatest(true);
+ toElement.setParentVersionUuid(uuid);
+ toElement.setParentVersionVersion(version);
fromService.update(token, uuid, Version.valueOf(version), toElement, false);
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -53,8 +53,7 @@
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.service.StorageService#loginUser(java.lang.String, java.lang.String)
*/
- public String loginUser(String login, String password)
- throws SimExplorerServiceException {
+ public String loginUser(String login, String password) throws SimExplorerServiceException {
String token = authenticationService.loginUser(login, password);
return token;
}
@@ -63,15 +62,16 @@
* @see fr.cemagref.simexplorer.is.service.StorageServiceCommon#getStorageEngine()
*/
@Override
- protected StorageEngine getStorageEngine()
- throws SimExplorerStorageException {
+ protected StorageEngine getStorageEngine() throws SimExplorerStorageException {
storageEngine.open();
return storageEngine;
}
@Override
protected Version incrementVersion(Version version) {
- return version.incVersion(0);
+ Version result = new Version("");
+ result.setVersion(0, version.getVersion(0) + 1);
+ return result;
}
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceLocalVersions.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceLocalVersions.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceLocalVersions.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -21,9 +21,13 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Random;
import java.util.Set;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
import junit.framework.TestCase;
import com.healthmarketscience.rmiio.SerializableInputStream;
@@ -35,6 +39,7 @@
import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
import fr.cemagref.simexplorer.is.entities.data.Library;
import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
import fr.cemagref.simexplorer.is.factories.BaseEntityFactory;
import fr.cemagref.simexplorer.is.factories.MetaDataFactory;
import fr.cemagref.simexplorer.is.factories.XmlConstants;
@@ -48,10 +53,12 @@
/** The element generator. */
private ElementGenerator elementGenerator;
+ private String token;
+
/** The r. */
private Random r = new Random();
- private Map<Attachment, SerializableInputStream> attachments;
+ private Map<Attachment, ElementGenerator.RandomStream> attachments;
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
@@ -62,63 +69,98 @@
elementGenerator = new ElementGenerator();
storageService = new StorageServiceClient();
+
+ /*
+ Properties properties = (Properties) System.getProperties().clone();
+ properties.put("java.naming.provider.url", "jnp://localhost:1099");
+ properties.put("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
+ properties.put("java.naming.factory.url.pkgs", "org.jnp.interfaces");
+
+ Context context = new InitialContext(properties);
+ storageService = (StorageService) context.lookup("StorageService");
+ */
}
- private MetaData saveEa(ExplorationApplication ea,
- boolean computeAttachments) throws Exception {
+ private MetaData saveEa(ExplorationApplication ea, boolean computeAttachments) throws Exception {
if (computeAttachments) {
- attachments = new HashMap<Attachment, SerializableInputStream>();
+ attachments = new HashMap<Attachment, ElementGenerator.RandomStream>();
List<Attachment> attachmentsKeys = new ArrayList<Attachment>();
attachmentsKeys.addAll(ea.getMetaData().getAttachments());
Set<Component> components = ea.getComponents();
for (Component component : components) {
- attachmentsKeys
- .addAll(component.getMetaData().getAttachments());
+ attachmentsKeys.addAll(component.getMetaData().getAttachments());
Set<Library> libraries = component.getLibraries();
for (Library library : libraries) {
- attachmentsKeys.addAll(library.getMetaData()
- .getAttachments());
+ attachmentsKeys.addAll(library.getMetaData().getAttachments());
}
}
Set<ExplorationData> explorations = ea.getExplorations();
for (ExplorationData explorationData : explorations) {
- attachmentsKeys.addAll(explorationData.getMetaData()
- .getAttachments());
+ attachmentsKeys.addAll(explorationData.getMetaData().getAttachments());
}
for (Attachment attachment : attachmentsKeys) {
- RandomStream randomStream = elementGenerator
- .generateTextStream();
+ RandomStream randomStream = elementGenerator.generateTextStream();
attachment.setDataHash(randomStream.getMd5());
- SerializableInputStream stream = new SerializableInputStream(
- randomStream.getStream());
- attachments.put(attachment, stream);
+ attachments.put(attachment, randomStream);
}
}
- SerializableInputStream xmlStream = new SerializableInputStream(
- BaseEntityFactory.getFactory(ExplorationApplication.class)
- .saveElement(XmlConstants.VALUE_METADATA_TYPE_EA, ea));
+ SerializableInputStream xmlStream = new SerializableInputStream(BaseEntityFactory.getFactory(
+ ExplorationApplication.class).saveElement(XmlConstants.VALUE_METADATA_TYPE_EA, ea));
- return storageService.saveElement(null, xmlStream, attachments);
+ Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>();
+ for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) {
+ realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream()));
+ }
+
+ return storageService.saveElement(token, xmlStream, realAttachments);
}
- private void testVersionUpdate(String firstVersion, String secondVersion,
- String assertFirst, String assertSecond, boolean different)
- throws Exception {
+ private void listExisting(String uuid) throws SimExplorerServiceException {
+ if (uuid != null) {
+ Version[] versions = storageService.getVersions(token, uuid);
+ System.out.println("Versions of uuid " + uuid + ":");
+ for (int i = 0; i < versions.length; i++) {
+ System.out.println(versions[i]);
+ }
+ }
+ }
+
+ private String testVersionUpdate(String firstVersion, String secondVersion, String assertFirst,
+ String assertSecond, boolean different) throws Exception {
+ System.out.println("-----------------------------");
+
ExplorationApplication ea;
- MetaDataFactory<MetaData> mdeFactory = MetaDataFactory
- .getFactory(MetaData.class);
+ MetaDataFactory<MetaData> mdeFactory = MetaDataFactory.getFactory(MetaData.class);
ea = elementGenerator.generateRandomEA();
+ StringBuffer task = new StringBuffer();
+ task.append(firstVersion).append("A + ").append(secondVersion);
+ if (different) {
+ task.append("B");
+ } else {
+ task.append("A");
+ }
+ task.append(" = ").append(assertFirst).append("A");
+ if (different) {
+ task.append(" + ").append(assertSecond).append("B");
+ }
+ System.out.println(task.toString());
+
+ System.out.println("UUID : " + ea.getMetaData().getUuid());
+ System.out.println("Name : " + ea.getMetaData().getName());
+
ea.getMetaData().setVersion(firstVersion);
+ System.out.println("Saving " + firstVersion + "A");
MetaData mde1 = saveEa(ea, true);
+ listExisting(ea.getMetaData().getUuid());
ea.getMetaData().setVersion(secondVersion);
@@ -130,27 +172,48 @@
component.getCodes().add(code);
}
+ System.out.print("Saving " + secondVersion);
+ if (different) {
+ System.out.println("B");
+ } else {
+ System.out.println("A");
+ }
MetaData mde2 = saveEa(ea, false);
+ listExisting(ea.getMetaData().getUuid());
- assertEquals(mde1.getVersion().toString(), assertFirst);
- assertEquals(mde2.getVersion().toString(), assertSecond);
+ System.out.println("A : " + mde1.getHash().toString());
+ if (different) {
+ System.out.println("B : " + mde2.getHash().toString());
+ }
+
+ return ea.getMetaData().getUuid();
+ // assertEquals(mde1.getVersion().toString(), assertFirst);
+ // assertEquals(mde2.getVersion().toString(), assertSecond);
}
public void testVersionUpdate() throws Exception {
- System.out.println("1.1A + 1.0A = 1.1A");
- testVersionUpdate("1.1", "1.0", "1.1", "1.1", false);
- System.out.println("1.1A + 1.1A = 1.1A");
- testVersionUpdate("1.1", "1.1", "1.1", "1.1", false);
- System.out.println("1.1A + 2.1A = 2.1A");
- //testVersionUpdate("1.1", "2.1", "2.1", "2.1", false);
- System.out.println("1.1A + 1.0B = 1.1A + 1.2B");
- testVersionUpdate("1.1", "1.0", "1.1", "1.2", true);
- System.out.println("1.1A + 1.1B = 1.1A + 1.2B");
- testVersionUpdate("1.1", "1.1", "1.1", "1.2", true);
- System.out.println("1.1A + 1.1.5B = 1.1A + 1.2B");
- testVersionUpdate("1.1", "1.1.5", "1.1", "1.2", true);
- System.out.println("1.1A + 2.1B = 1.1A + 2.1B");
- testVersionUpdate("1.1", "2.1", "1.1", "2.1", true);
+
+ String password = "password";
+ // token = storageService.loginUser("superadmin",
+ // AuthenticationServiceHelper.computeHash(password.toCharArray()));
+
+ List<String> uuids = new ArrayList<String>();
+
+ uuids.add(testVersionUpdate("1.1", "1.0", "1.1", "1.1", false));
+ uuids.add(testVersionUpdate("1.1", "1.1", "1.1", "1.1", false));
+ uuids.add(testVersionUpdate("1.1", "2.1", "2.1", "2.1", false));
+
+ uuids.add(testVersionUpdate("1.1", "1.0", "1.1", "1.2", true));
+ uuids.add(testVersionUpdate("1.1", "1.1", "1.1", "1.2", true));
+ uuids.add(testVersionUpdate("1.1", "1.1.5", "1.1", "1.2", true));
+ uuids.add(testVersionUpdate("1.1", "1.2", "1.1", "1.2", true));
+ uuids.add(testVersionUpdate("1.1", "2.1", "1.1", "2.1", true));
+
+ System.out.println("-----------------------------");
+ for (String uuid : uuids) {
+ listExisting(uuid);
+ }
+
}
/*
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/BaseEntityFactory.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -59,8 +59,7 @@
*
* @param <E> Entity type
*/
-public abstract class BaseEntityFactory<E extends BaseEntity> implements
- XmlConstants {
+public abstract class BaseEntityFactory<E extends BaseEntity> implements XmlConstants {
/** The document builder. */
private static DocumentBuilder documentBuilder = null;
@@ -84,18 +83,14 @@
* @throws Exception the exception
*/
@SuppressWarnings("unchecked")
- public static <E extends DataEntity> BaseEntityFactory<E> getFactory(
- Class entityClass) throws Exception {
- BaseEntityFactory<E> result = (BaseEntityFactory<E>) factories
- .get(entityClass.getSimpleName());
+ public static <E extends DataEntity> BaseEntityFactory<E> getFactory(Class entityClass) throws Exception {
+ BaseEntityFactory<E> result = (BaseEntityFactory<E>) factories.get(entityClass.getSimpleName());
if (result == null) {
- String elementFactoryClassName = BaseEntityFactory.class
- .getPackage().getName()
- + "." + entityClass.getSimpleName() + FACTORY_SUFFIX;
+ String elementFactoryClassName = BaseEntityFactory.class.getPackage().getName() + "."
+ + entityClass.getSimpleName() + FACTORY_SUFFIX;
- Class<? extends BaseEntityFactory<E>> factoryClass = (Class<? extends BaseEntityFactory<E>>) Class
- .forName(elementFactoryClassName).asSubclass(
- BaseEntityFactory.class);
+ Class<? extends BaseEntityFactory<E>> factoryClass = (Class<? extends BaseEntityFactory<E>>) Class.forName(
+ elementFactoryClassName).asSubclass(BaseEntityFactory.class);
result = factoryClass.newInstance();
factories.put(entityClass.getSimpleName(), result);
@@ -112,10 +107,8 @@
*
* @throws Exception the exception
*/
- public static BaseEntityFactory<? extends DataEntity> getFactory(
- String entityClassName) throws Exception {
- Class<? extends DataEntity> entityClass = Class
- .forName(entityClassName).asSubclass(DataEntity.class);
+ public static BaseEntityFactory<? extends DataEntity> getFactory(String entityClassName) throws Exception {
+ Class<? extends DataEntity> entityClass = Class.forName(entityClassName).asSubclass(DataEntity.class);
return getFactory(entityClass);
}
@@ -128,8 +121,7 @@
*/
public static synchronized DocumentBuilder getXMLBuilder() throws Exception {
if (documentBuilder == null) {
- DocumentBuilderFactory factory = DocumentBuilderFactory
- .newInstance();
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
documentBuilder = factory.newDocumentBuilder();
return documentBuilder;
}
@@ -186,8 +178,7 @@
*
* @throws Exception the exception
*/
- public abstract void saveElement(Document document, Element xmlElement,
- E element) throws Exception;
+ public abstract void saveElement(Document document, Element xmlElement, E element) throws Exception;
/**
* Save an element to a XML stream.
@@ -199,8 +190,7 @@
*
* @throws Exception the exception
*/
- public InputStream saveElement(String rootNodeName, E element)
- throws Exception {
+ public InputStream saveElement(String rootNodeName, E element) throws Exception {
org.w3c.dom.Document xmlDocument = getXMLBuilder().newDocument();
// DOM properties
xmlDocument.setXmlVersion("1.0");
@@ -222,14 +212,6 @@
return is;
}
- public String signXmlElement(Element xmlElement) throws Exception {
- String result = "";
-
-
-
- return result;
- }
-
/*
* Collection methods : Help load/save of inner collections
*/
@@ -249,9 +231,8 @@
*
* @throws Exception the exception
*/
- public <T extends DataEntity> Set<T> loadCollection(String tagSetName,
- String tagName, Class<T> clazz, Element xmlElement,
- DataEntity parentData) throws Exception {
+ public <T extends DataEntity> Set<T> loadCollection(String tagSetName, String tagName, Class<T> clazz,
+ Element xmlElement, DataEntity parentData) throws Exception {
Set<T> entities = new HashSet<T>();
// Retrieve XML node containing the collection
@@ -287,9 +268,8 @@
*
* @throws Exception the exception
*/
- public <T extends DataEntity> void saveCollection(Set<T> entities,
- String tagSetName, String tagName, Class<T> clazz,
- Document document, Element xmlElement) throws Exception {
+ public <T extends DataEntity> void saveCollection(Set<T> entities, String tagSetName, String tagName,
+ Class<T> clazz, Document document, Element xmlElement) throws Exception {
if (entities != null && entities.size() > 0) {
Element xmlCollection = document.createElement(tagSetName);
BaseEntityFactory<T> elementFactory = getFactory(clazz);
@@ -311,8 +291,8 @@
*
* @throws Exception the exception
*/
- public static InputStream serializeElement(Element node) throws Exception {
- org.w3c.dom.Document xmlDocument = getXMLBuilder().newDocument();
+ public static InputStream serializeElement(Node node) throws Exception {
+ Document xmlDocument = getXMLBuilder().newDocument();
// DOM properties
xmlDocument.setXmlVersion("1.0");
xmlDocument.setXmlStandalone(true);
@@ -341,8 +321,7 @@
* @param tagName Tag of created node
* @param value Value of node
*/
- protected void setXMLProperty(Document document, Element xmlElement,
- String tagName, Object value) {
+ protected void setXMLProperty(Document document, Element xmlElement, String tagName, Object value) {
if (value != null) {
Element xmlProperty = document.createElement(tagName);
Text xmlDescriptionText = document.createTextNode(value.toString());
@@ -395,15 +374,13 @@
*
* @return Children with tagName
*/
- public Set<Element> getXMLElementsByTagName(Element xmlElement,
- String tagName) {
+ public Set<Element> getXMLElementsByTagName(Element xmlElement, String tagName) {
Set<Element> elements = new HashSet<Element>();
NodeList nodes = xmlElement.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
- if (node instanceof Element
- && tagName.equals(((Element) node).getTagName())) {
+ if (node instanceof Element && tagName.equals(((Element) node).getTagName())) {
elements.add((Element) node);
}
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/factories/MetaDataFactory.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -47,12 +47,10 @@
*
* @param <E> MetaData
*/
-public class MetaDataFactory<E extends MetaData> extends
- BaseEntityFactory<MetaData> {
+public class MetaDataFactory<E extends MetaData> extends BaseEntityFactory<MetaData> {
/** The Constant sdf. */
- private static final SimpleDateFormat sdf = new SimpleDateFormat(
- "yyyy-MM-dd'T'HH:mm:ss");
+ private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
/* (non-Javadoc)
* @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#createInstance()
@@ -74,8 +72,7 @@
* @throws Exception the exception
*/
@SuppressWarnings( { "unchecked" })
- public static <E extends MetaData> MetaDataFactory<E> getFactory(
- Class<E> entityClass) throws Exception {
+ public static <E extends MetaData> MetaDataFactory<E> getFactory(Class<E> entityClass) throws Exception {
return (MetaDataFactory) BaseEntityFactory.getFactory(entityClass);
}
@@ -91,43 +88,34 @@
entity.setUuid(getXMLProperty(xmlElement, KEY_METADATA_UUID));
entity.setName(getXMLProperty(xmlElement, KEY_METADATA_NAME));
entity.setType(getXMLProperty(xmlElement, KEY_METADATA_TYPE));
- entity.setDescription(getXMLProperty(xmlElement,
- KEY_METADATA_DESCRIPTION));
+ entity.setDescription(getXMLProperty(xmlElement, KEY_METADATA_DESCRIPTION));
entity.setVersion(getXMLProperty(xmlElement, KEY_METADATA_VERSION));
- String latestVersion = getXMLProperty(xmlElement,
- KEY_METADATA_LATESTVERSION);
+ String latestVersion = getXMLProperty(xmlElement, KEY_METADATA_LATESTVERSION);
if (latestVersion != null && "1".equals(latestVersion)) {
entity.setLatest(true);
} else {
entity.setLatest(false);
}
- String creationDate = getXMLProperty(xmlElement,
- KEY_METADATA_CREATIONDATE);
+ String creationDate = getXMLProperty(xmlElement, KEY_METADATA_CREATIONDATE);
if (creationDate != null) {
Date date = sdf.parse(creationDate);
entity.setCreationDate(date);
}
entity.setHash(getXMLProperty(xmlElement, KEY_METADATA_HASH));
- entity.setParentVersionUuid(getXMLProperty(xmlElement,
- KEY_METADATA_PARENTVERSION_UUID));
- entity.setParentVersionVersion(getXMLProperty(xmlElement,
- KEY_METADATA_PARENTVERSION_VERSION));
+ entity.setParentVersionUuid(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_UUID));
+ entity.setParentVersionVersion(getXMLProperty(xmlElement, KEY_METADATA_PARENTVERSION_VERSION));
Map<String, String> descriptors = new HashMap<String, String>();
- Element descriptorsElement = getXMLElementByTagName(xmlElement,
- KEY_METADATA_DESCRIPTORS);
+ Element descriptorsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_DESCRIPTORS);
if (descriptorsElement != null) {
- Set<Element> descriptorElements = getXMLElementsByTagName(
- descriptorsElement, KEY_METADATA_DESCRIPTOR);
+ Set<Element> descriptorElements = getXMLElementsByTagName(descriptorsElement, KEY_METADATA_DESCRIPTOR);
for (Element descriptorElement : descriptorElements) {
- String name = getXMLProperty(descriptorElement,
- KEY_METADATA_DESCRIPTOR_NAME);
- String value = getXMLProperty(descriptorElement,
- KEY_METADATA_DESCRIPTOR_VALUE);
+ String name = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_NAME);
+ String value = getXMLProperty(descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE);
descriptors.put(name, value);
}
}
@@ -135,26 +123,20 @@
List<Attachment> attachments = new ArrayList<Attachment>();
- Element attachmentsElement = getXMLElementByTagName(xmlElement,
- KEY_METADATA_ATTACHMENTS);
+ Element attachmentsElement = getXMLElementByTagName(xmlElement, KEY_METADATA_ATTACHMENTS);
if (attachmentsElement != null) {
- Set<Element> attachmentElements = getXMLElementsByTagName(
- attachmentsElement, KEY_METADATA_ATTACHMENT);
+ Set<Element> attachmentElements = getXMLElementsByTagName(attachmentsElement, KEY_METADATA_ATTACHMENT);
for (Element attachmentElement : attachmentElements) {
Attachment attachment = new Attachment();
- String name = getXMLProperty(attachmentElement,
- KEY_METADATA_ATTACHMENT_NAME);
+ String name = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_NAME);
attachment.setFileName(name);
- String type = getXMLProperty(attachmentElement,
- KEY_METADATA_ATTACHMENT_TYPE);
- ContentType contentType = ContentTypeFactory
- .getContentTypeInstance(type);
+ String type = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_TYPE);
+ ContentType contentType = ContentTypeFactory.getContentTypeInstance(type);
attachment.setContentType(contentType);
- String dataHash = getXMLProperty(attachmentElement,
- KEY_METADATA_ATTACHMENT_HASH);
+ String dataHash = getXMLProperty(attachmentElement, KEY_METADATA_ATTACHMENT_HASH);
attachment.setDataHash(dataHash);
attachments.add(attachment);
@@ -170,53 +152,36 @@
* @see fr.cemagref.simexplorer.is.factories.BaseEntityFactory#saveElement(org.w3c.dom.Document, org.w3c.dom.Element, fr.cemagref.simexplorer.is.entities.BaseEntity)
*/
@Override
- public void saveElement(Document document, Element xmlElement,
- MetaData element) throws Exception {
+ public void saveElement(Document document, Element xmlElement, MetaData element) throws Exception {
- setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element
- .getUuid());
- setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element
- .getName());
- setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element
- .getType());
- setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element
- .getDescription());
- setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element
- .getVersion().toString());
+ setXMLProperty(document, xmlElement, KEY_METADATA_UUID, element.getUuid());
+ setXMLProperty(document, xmlElement, KEY_METADATA_NAME, element.getName());
+ setXMLProperty(document, xmlElement, KEY_METADATA_TYPE, element.getType());
+ setXMLProperty(document, xmlElement, KEY_METADATA_DESCRIPTION, element.getDescription());
+ setXMLProperty(document, xmlElement, KEY_METADATA_VERSION, element.getVersion().toString());
if (element.isLatest()) {
- setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION,
- "1");
+ setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "1");
} else {
- setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION,
- "0");
+ setXMLProperty(document, xmlElement, KEY_METADATA_LATESTVERSION, "0");
}
if (element.getCreationDate() != null) {
- setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, sdf
- .format(element.getCreationDate()));
+ setXMLProperty(document, xmlElement, KEY_METADATA_CREATIONDATE, sdf.format(element.getCreationDate()));
}
- setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element
- .getHash());
- setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID,
- element.getParentVersionUuid());
- setXMLProperty(document, xmlElement,
- KEY_METADATA_PARENTVERSION_VERSION, element
- .getParentVersionVersion());
+ setXMLProperty(document, xmlElement, KEY_METADATA_HASH, element.getHash());
+ setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_UUID, element.getParentVersionUuid());
+ setXMLProperty(document, xmlElement, KEY_METADATA_PARENTVERSION_VERSION, element.getParentVersionVersion());
Map<String, String> descriptors = element.getDescriptors();
- Element descriptorsElement = document
- .createElement(KEY_METADATA_DESCRIPTORS);
+ Element descriptorsElement = document.createElement(KEY_METADATA_DESCRIPTORS);
for (Map.Entry<String, String> kv : descriptors.entrySet()) {
- Element descriptorElement = document
- .createElement(KEY_METADATA_DESCRIPTOR);
- setXMLProperty(document, descriptorElement,
- KEY_METADATA_DESCRIPTOR_NAME, kv.getKey());
- setXMLProperty(document, descriptorElement,
- KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue());
+ Element descriptorElement = document.createElement(KEY_METADATA_DESCRIPTOR);
+ setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_NAME, kv.getKey());
+ setXMLProperty(document, descriptorElement, KEY_METADATA_DESCRIPTOR_VALUE, kv.getValue());
descriptorsElement.appendChild(descriptorElement);
}
@@ -226,20 +191,15 @@
if (attachments != null) {
- Element attachmentsElement = document
- .createElement(KEY_METADATA_ATTACHMENTS);
+ Element attachmentsElement = document.createElement(KEY_METADATA_ATTACHMENTS);
for (Attachment attachment : attachments) {
- Element attachmentElement = document
- .createElement(KEY_METADATA_ATTACHMENT);
+ Element attachmentElement = document.createElement(KEY_METADATA_ATTACHMENT);
- setXMLProperty(document, attachmentElement,
- KEY_METADATA_ATTACHMENT_NAME, attachment.getFileName());
- setXMLProperty(document, attachmentElement,
- KEY_METADATA_ATTACHMENT_TYPE, attachment
- .getContentType().getClass().getSimpleName());
- setXMLProperty(document, attachmentElement,
- KEY_METADATA_ATTACHMENT_HASH, attachment.getDataHash());
+ setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_NAME, attachment.getFileName());
+ setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_TYPE, attachment.getContentType()
+ .getClass().getSimpleName());
+ setXMLProperty(document, attachmentElement, KEY_METADATA_ATTACHMENT_HASH, attachment.getDataHash());
attachmentsElement.appendChild(attachmentElement);
}
@@ -253,17 +213,14 @@
* As metadata is stored inside an entity, this method loads metadata with parsing stream and retrieve metadata
* node.
*
- * @param xmlStream the xml stream
+ * @param node the node
*
* @return the meta data
*
* @throws Exception the exception
*/
- public MetaData loadElementFromParentXML(InputStream xmlStream)
- throws Exception {
- Document document = getXMLBuilder().parse(xmlStream);
- Element rootElement = (Element) document.getFirstChild();
- Element mdeElement = getXMLElementByTagName(rootElement, KEY_METADATA);
+ public MetaData loadElementFromParentXML(Element node) throws Exception {
+ Element mdeElement = getXMLElementByTagName(node, KEY_METADATA);
MetaData mde;
mde = loadElement(mdeElement);
return mde;
@@ -279,8 +236,7 @@
*
* @throws Exception the exception
*/
- public InputStream replaceElementInParentXML(InputStream xmlStream,
- MetaData newMetadata) throws Exception {
+ public InputStream modifyMedataElementStream(InputStream xmlStream, MetaData newMetadata) throws Exception {
Document document = getXMLBuilder().parse(xmlStream);
Element rootElement = (Element) document.getFirstChild();
@@ -302,6 +258,23 @@
}
/**
+ * Replace element in parent xml.
+ *
+ * @param newMetadata the new metadata
+ * @param document the document
+ * @param xmlNode the xml node
+ *
+ * @throws Exception the exception
+ */
+ public void replaceMetadataInXML(Document document, Element xmlNode, MetaData newMetadata) throws Exception {
+ Element newElement = document.createElement(KEY_METADATA);
+ this.saveElement(document, newElement, newMetadata);
+
+ Element oldElement = getXMLElementByTagName(xmlNode, KEY_METADATA);
+ xmlNode.replaceChild(newElement, oldElement);
+ }
+
+ /**
* Compute hash.
*
* @param xmlStream the xml stream
@@ -310,13 +283,14 @@
*
* @throws Exception the exception
*/
- public String computeHash(InputStream xmlStream) throws Exception {
- Document document = getXMLBuilder().parse(xmlStream);
+ public String computeHash(Element node) throws Exception {
+ Document document = getXMLBuilder().newDocument();
+ document.appendChild(document.importNode(node, true));
+
int removeNodes = removeMetadatas(document);
DigestGenerator digestGenerator = new DigestGenerator();
- byte[] digest = digestGenerator.getDigest(document,
- DigestGenerator.sha1DigestAlgorithm);
+ byte[] digest = digestGenerator.getDigest(document, DigestGenerator.sha1DigestAlgorithm);
return MD5.asHex(digest);
}
@@ -336,8 +310,7 @@
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
- if (child instanceof Element
- && KEY_METADATA.equals(((Element) child).getTagName())) {
+ if (child instanceof Element && KEY_METADATA.equals(((Element) child).getTagName())) {
toRemove.add(child);
}
}
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -30,6 +30,9 @@
/** Field name for id. */
public static final String KEY_UUID = "simexplorer.uuid";
+ /** Field name for id and version. */
+ public static final String KEY_UUID_VERSION = "simexplorer.uuidversion";
+
/** Field name for name. */
public static final String KEY_NAME = "simexplorer.name";
Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-14 19:37:33 UTC (rev 980)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-02-14 20:18:28 UTC (rev 981)
@@ -30,6 +30,8 @@
import java.util.StringTokenizer;
import java.util.Map.Entry;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
@@ -69,9 +71,11 @@
*/
public class LuceneDatabase extends Database {
+ /** The Constant log. */
+ private static final Log log = LogFactory.getLog(Config.class);
+
/** DB folder. */
- private static String dbFolder = Config.getProperties().getProperty(
- "simexplorer.db");
+ private static String dbFolder = Config.getProperties().getProperty("simexplorer.db");
/** Optimize period. */
private static Integer optimizePeriod = new Integer(Config.getProperties()
@@ -118,8 +122,7 @@
*
* @return Searcher
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
private Searcher getSearcher() throws IOException {
synchronized (searcherSynchronizer) {
@@ -137,11 +140,9 @@
/**
* Release searcher, after the end of a query execution.
*
- * @param searcher
- * Searcher to be released
+ * @param searcher Searcher to be released
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
private void releaseSearcher(Searcher searcher) throws IOException {
synchronized (searcherSynchronizer) {
@@ -152,8 +153,7 @@
/**
* Called to invalidate reader.
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
private void resetReader() throws IOException {
synchronized (searcherSynchronizer) {
@@ -225,8 +225,7 @@
/**
* Push commit to db.
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
private void synchedCommit() throws IOException {
synchronized (writerSynchronizer) {
@@ -236,8 +235,7 @@
Date now = new Date();
long elapsed = now.getTime() - lastOptimize.getTime();
// One optimize per period, if readers are closed
- if (elapsed > optimizePeriod * 1000
- && getSearcherPool().allClosed()) {
+ if (elapsed > optimizePeriod * 1000 && getSearcherPool().allClosed()) {
writer.optimize();
lastOptimize = new Date();
}
@@ -263,20 +261,10 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#insertElement(fr.cemagref.simexplorer.is.entities.metadata.MetaData, java.util.List)
*/
@Override
- public void insertElement(MetaData element, List<Reader> readers)
- throws SimExplorerStorageException {
+ public void insertElement(MetaData element, List<Reader> readers) throws SimExplorerStorageException {
// Save element to a Lucene document
Document document = saveLuceneElement(element, readers);
- // Retrieve existing element with same id/version
- MetaData oldElement = getElement(element.getUuid(), element
- .getVersion());
- // Delete element if exists, for update
- if (oldElement != null) {
- // update
- deleteElement(element);
- }
-
try {
synchronized (writerSynchronizer) {
// add document to index
@@ -291,8 +279,7 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#getElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
@Override
- public MetaData getElement(String uuid, Version version)
- throws SimExplorerStorageException {
+ public MetaData getElement(String uuid, Version version) throws SimExplorerStorageException {
MetaData result = null;
try {
@@ -318,20 +305,15 @@
/**
* Gets the hits by id version.
*
- * @param uuid
- * the uuid
- * @param version
- * the version
- * @param searcher
- * the searcher
+ * @param uuid the uuid
+ * @param version the version
+ * @param searcher the searcher
*
* @return the hits by id version
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
- private Hits getHitsByIdVersion(String uuid, Version version,
- Searcher searcher) throws IOException {
+ private Hits getHitsByIdVersion(String uuid, Version version, Searcher searcher) throws IOException {
// Retrieve element with id/version
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
@@ -346,8 +328,7 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#getVersions(java.lang.String)
*/
@Override
- public List<Version> getVersions(String uuid)
- throws SimExplorerStorageException {
+ public List<Version> getVersions(String uuid) throws SimExplorerStorageException {
// Retrieve all document corresponding to id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
@@ -383,8 +364,7 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsById(java.lang.String, boolean)
*/
@Override
- public Set<MetaData> findElementsById(String uuid, boolean onlyLatest)
- throws SimExplorerStorageException {
+ public Set<MetaData> findElementsById(String uuid, boolean onlyLatest) throws SimExplorerStorageException {
// Create hash map with id
Map<String, String> properties = new HashMap<String, String>();
properties.put(KEY_UUID, uuid);
@@ -416,8 +396,7 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsByPropertiesCount(java.util.Map)
*/
@Override
- public int findElementsByPropertiesCount(Map<String, String> properties)
- throws SimExplorerStorageException {
+ public int findElementsByPropertiesCount(Map<String, String> properties) throws SimExplorerStorageException {
int result = 0;
try {
@@ -442,8 +421,7 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsByProperties(java.util.Map, int, int, int)
*/
@Override
- public Set<MetaData> findElementsByProperties(
- Map<String, String> properties, int start, int count, int dateOrder)
+ public Set<MetaData> findElementsByProperties(Map<String, String> properties, int start, int count, int dateOrder)
throws SimExplorerStorageException {
Set<MetaData> result = null;
@@ -469,8 +447,8 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsByContentSearchCount(java.lang.String, boolean)
*/
@Override
- public int findElementsByContentSearchCount(String queryText,
- boolean onlyLatest) throws SimExplorerStorageException {
+ public int findElementsByContentSearchCount(String queryText, boolean onlyLatest)
+ throws SimExplorerStorageException {
Query query;
try {
query = getQueryByContentSearch(queryText, onlyLatest);
@@ -502,9 +480,7 @@
/**
* Retrieve a Lucene Sort for date sorting.
*
- * @param dateOrder
- * sort wanted SORT_DATE_NONE, SORT_DATE_DESCENDING,
- * SORT_DATE_ASCENDING,
+ * @param dateOrder sort wanted SORT_DATE_NONE, SORT_DATE_DESCENDING, SORT_DATE_ASCENDING,
*
* @return null if no sort
*/
@@ -523,9 +499,8 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#findElementsByContentSearch(java.lang.String, boolean, int, int, int)
*/
@Override
- public Set<MetaData> findElementsByContentSearch(String queryText,
- boolean onlyLatest, int start, int count, int dateOrder)
- throws SimExplorerStorageException {
+ public Set<MetaData> findElementsByContentSearch(String queryText, boolean onlyLatest, int start, int count,
+ int dateOrder) throws SimExplorerStorageException {
Query query;
try {
query = getQueryByContentSearch(queryText, onlyLatest);
@@ -557,18 +532,14 @@
/**
* Retrieve a Lucene Query for a full text search.
*
- * @param queryText
- * String to match
- * @param onlyLatest
- * Latest flag
+ * @param queryText String to match
+ * @param onlyLatest Latest flag
*
* @return Query
*
- * @throws ParseException
- * the parse exception
+ * @throws ParseException the parse exception
*/
- private Query getQueryByContentSearch(String queryText, boolean onlyLatest)
- throws ParseException {
+ private Query getQueryByContentSearch(String queryText, boolean onlyLatest) throws ParseException {
Query query;
// Create an analyzer for query parsing
Analyzer analyzer = new SimpleAnalyzer();
@@ -582,9 +553,7 @@
// Boolean search with content and latest field
query = new BooleanQuery();
((BooleanQuery) query).add(searchQuery, BooleanClause.Occur.MUST);
- ((BooleanQuery) query).add(
- new TermQuery(new Term(KEY_LATEST, "1")),
- BooleanClause.Occur.MUST);
+ ((BooleanQuery) query).add(new TermQuery(new Term(KEY_LATEST, "1")), BooleanClause.Occur.MUST);
} else {
// No change
query = searchQuery;
@@ -597,16 +566,14 @@
* @see fr.cemagref.simexplorer.is.storage.database.Database#deleteElement(java.lang.String, fr.cemagref.simexplorer.is.entities.metadata.Version)
*/
@Override
- public void deleteElement(String uuid, Version version)
- throws SimExplorerStorageException {
+ public void deleteElement(String uuid, Version version) throws SimExplorerStorageException {
// Delete element in db with term search
- Term[] terms = new Term[2];
- terms[0] = new Term(KEY_UUID, uuid);
- terms[1] = new Term(KEY_VERSION, version.toString());
+ Term term = new Term(KEY_UUID_VERSION, getUuidVersion(uuid, version));
try {
synchronized (writerSynchronizer) {
- writer.deleteDocuments(terms);
+ //log.info("deleting " + term.toString());
+ writer.deleteDocuments(term);
}
} catch (Exception e) {
throw new SimExplorerStorageException(e);
@@ -616,25 +583,19 @@
/**
* Find all documents matching properties.
*
- * @param properties
- * criteria
- * @param searcher
- * the searcher
- * @param dateOrder
- * the date order
+ * @param properties criteria
+ * @param searcher the searcher
+ * @param dateOrder the date order
*
* @return Documents and search handle
*
- * @throws IOException
- * Signals that an I/O exception has occurred.
+ * @throws IOException Signals that an I/O exception has occurred.
*/
- private Hits findHits(Map<String, String> properties, Searcher searcher,
- int dateOrder) throws IOException {
+ private Hits findHits(Map<String, String> properties, Searcher searcher, int dateOrder) throws IOException {
// Create a query with all parameters
BooleanQuery query = new BooleanQuery();
for (Entry<String, String> kv : properties.entrySet()) {
- query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())),
- BooleanClause.Occur.MUST);
+ query.add(new TermQuery(new Term(kv.getKey(), kv.getValue())), BooleanClause.Occur.MUST);
}
Hits hits = searcher.search(query, getSortDate(dateOrder));
@@ -644,25 +605,19 @@
/**
* Convert Lucene documents to real entities.
*
- * @param hits
- * Document collection
- * @param start
- * Index of first document to return
- * @param count
- * Number of documents to return
+ * @param hits Document collection
+ * @param start Index of first document to return
+ * @param count Number of documents to return
*
* @return Entities list
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
- private Set<MetaData> convertHitsToElements(Hits hits, int start, int count)
- throws Exception {
+ private Set<MetaData> convertHitsToElements(Hits hits, int start, int count) throws Exception {
Set<MetaData> elements = new HashSet<MetaData>();
if (hits != null) {
// For documents in range
- for (int i = start; i < hits.length()
- && (i < start + count || count == -1); i++) {
+ for (int i = start; i < hits.length() && (i < start + count || count == -1); i++) {
Document document = hits.doc(i);
// Convert to element
elements.add(loadLuceneElement(document));
@@ -674,13 +629,11 @@
/**
* Transform a Lucene document into a LoggableElement thanks to a factory.
*
- * @param document
- * The document to transform
+ * @param document The document to transform
*
* @return Instance of element
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
@SuppressWarnings( { "unchecked" })
private MetaData loadLuceneElement(Document document) throws Exception {
@@ -755,16 +708,14 @@
attachment.setDataHash(fieldValue);
}
if (field.equals(KEY_ATTACHMENT_TYPE)) {
- attachment.setContentType(ContentTypeFactory
- .getContentTypeInstance(fieldValue));
+ attachment.setContentType(ContentTypeFactory.getContentTypeInstance(fieldValue));
}
}
}
Map<String, String> finalDescriptors = new HashMap<String, String>();
for (Map.Entry<Integer, KeyValue> entry : descriptors.entrySet()) {
- finalDescriptors.put(entry.getValue().getKey(), entry.getValue()
- .getKey());
+ finalDescriptors.put(entry.getValue().getKey(), entry.getValue().getKey());
}
element.setDescriptors(finalDescriptors);
@@ -775,9 +726,7 @@
element.setAttachments(finalAttachments);
element.setParentVersionUuid(document.get(KEY_PARENTVERSION_UUID));
- element
- .setParentVersionVersion(document
- .get(KEY_PARENTVERSION_VERSION));
+ element.setParentVersionVersion(document.get(KEY_PARENTVERSION_VERSION));
return element;
}
@@ -785,29 +734,29 @@
/**
* Add a field to a document.
*
- * @param document
- * Document to add the field
- * @param name
- * Field name
- * @param value
- * Field value
+ * @param document Document to add the field
+ * @param name Field name
+ * @param value Field value
*/
private void addSimpleField(Document document, String name, String value) {
if (value != null) {
// Create a simple field
- Field f = new Field(name, value, Field.Store.YES,
- Field.Index.UN_TOKENIZED);
+ Field f = new Field(name, value, Field.Store.YES, Field.Index.UN_TOKENIZED);
document.add(f);
}
}
+ private String getUuidVersion(String uuid, Version version) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(uuid).append(".").append(version.toString());
+ return sb.toString();
+ }
+
/**
* Transform an element to a Lucene document thanks to a factory.
*
- * @param readers
- * the readers
- * @param element
- * the element
+ * @param readers the readers
+ * @param element the element
*
* @return the document
*/
@@ -817,13 +766,13 @@
// Store all element properties in Lucene document
addSimpleField(document, KEY_UUID, element.getUuid());
+ addSimpleField(document, KEY_VERSION, element.getVersion().toString());
+
+ addSimpleField(document, KEY_UUID_VERSION, getUuidVersion(element.getUuid(), element.getVersion()));
+
addSimpleField(document, KEY_NAME, element.getName());
addSimpleField(document, KEY_TYPE, element.getType());
addSimpleField(document, KEY_DESCRIPTION, element.getDescription());
- if (element.getVersion() != null) {
- addSimpleField(document, KEY_VERSION, element.getVersion()
- .toString());
- }
if (element.isLatest()) {
addSimpleField(document, KEY_LATEST, "1");
} else {
@@ -831,8 +780,7 @@
}
if (element.getCreationDate() != null) {
- addSimpleField(document, KEY_CREATIONDATE, Long.toString(element
- .getCreationDate().getTime()));
+ addSimpleField(document, KEY_CREATIONDATE, Long.toString(element.getCreationDate().getTime()));
}
addSimpleField(document, KEY_HASH, element.getHash());
@@ -840,10 +788,8 @@
int i = 0;
for (Map.Entry<String, String> entry : descriptors.entrySet()) {
String key = KEY_DESCRIPTOR + DOT + i;
- addSimpleField(document, key + DOT + KEY_DESCRIPTOR_KEY, entry
- .getKey());
- addSimpleField(document, key + DOT + KEY_DESCRIPTOR_VALUE, entry
- .getValue());
+ addSimpleField(document, key + DOT + KEY_DESCRIPTOR_KEY, entry.getKey());
+ addSimpleField(document, key + DOT + KEY_DESCRIPTOR_VALUE, entry.getValue());
i++;
}
@@ -851,19 +797,15 @@
i = 0;
for (Attachment attachment : attachments) {
String key = KEY_ATTACHMENT + DOT + i;
- addSimpleField(document, key + DOT + KEY_ATTACHMENT_FILENAME,
- attachment.getFileName());
- addSimpleField(document, key + DOT + KEY_ATTACHMENT_HASH,
- attachment.getDataHash());
- addSimpleField(document, key + DOT + KEY_ATTACHMENT_TYPE,
- attachment.getContentType().getClass().getSimpleName());
+ addSimpleField(document, key + DOT + KEY_ATTACHMENT_FILENAME, attachment.getFileName());
+ addSimpleField(document, key + DOT + KEY_ATTACHMENT_HASH, attachment.getDataHash());
+ addSimpleField(document, key + DOT + KEY_ATTACHMENT_TYPE, attachment.getContentType().getClass()
+ .getSimpleName());
i++;
}
- addSimpleField(document, KEY_PARENTVERSION_UUID, element
- .getParentVersionUuid());
- addSimpleField(document, KEY_PARENTVERSION_VERSION, element
- .getParentVersionVersion());
+ addSimpleField(document, KEY_PARENTVERSION_UUID, element.getParentVersionUuid());
+ addSimpleField(document, KEY_PARENTVERSION_VERSION, element.getParentVersionVersion());
for (Reader reader : readers) {
document.add(new Field(KEY_SEARCHABLE_CONTENT, reader));
1
0
r980 - trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: tchemit
Date: 2008-02-14 19:37:33 +0000 (Thu, 14 Feb 2008)
New Revision: 980
Modified:
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
Log:
ajout TODO
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java 2008-02-14 19:34:08 UTC (rev 979)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/ElementExport.java 2008-02-14 19:37:33 UTC (rev 980)
@@ -41,6 +41,7 @@
/**
* The Class ElementExport.
+ * TODO la classe ne devrait-elle pas s'appeller ElementDownload ?
*/
public class ElementExport extends ElementPageDetail {
1
0
r979 - trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: tchemit
Date: 2008-02-14 19:34:08 +0000 (Thu, 14 Feb 2008)
New Revision: 979
Modified:
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToLocalAction.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToRemoteAction.java
Log:
mise en place action export depuis onglet synchronise (surcharge de l'action export de base)
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java 2008-02-14 18:54:25 UTC (rev 978)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java 2008-02-14 19:34:08 UTC (rev 979)
@@ -26,6 +26,7 @@
import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractTabAction;
import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel;
import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel;
+import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel;
import jaxx.runtime.builder.TabModel;
import java.awt.event.ActionEvent;
@@ -48,9 +49,10 @@
private static final long serialVersionUID = 7535647131305304738L;
- String uuid;
- Version version;
- StorageService fromService, toService;
+ protected String uuid;
+ protected Version version;
+ protected StorageService fromService, toService;
+ protected Boolean remote = null;
public ExportAction(String name) {
super(name);
@@ -61,10 +63,11 @@
if (!super.beforeAction(e)) {
return false;
}
- Boolean remote = null;
+
MetaData element = null;
// on retrouve l'onglet concerné à partir de son model
TabModel tabModel = getModel();
+
if (tabModel instanceof DetailTabModel) {
DetailTabModel model = (DetailTabModel) tabModel;
element = model.getDetail();
@@ -77,18 +80,19 @@
uuid = element.getUuid();
version = element.getVersion();
remote = model.isRemote();
+ } else if (tabModel instanceof SynchronizeTabModel) {
+ // the real test will be in extends class
+ return true;
}
boolean result;
result = remote != null && version != null && uuid != null && EntitiesAction.EXPORT.accept(element);
- if (result) {
- fromService = StorageServiceHelper.getService(getContext(), remote);
- toService = StorageServiceHelper.getService(getContext(), !remote);
- }
return result;
}
@Override
protected void doAction(ActionEvent e) throws Exception {
+ StorageService fromService = StorageServiceHelper.getService(getContext(), remote);
+ StorageService toService = StorageServiceHelper.getService(getContext(), !remote);
log.info("fromService : " + fromService);
log.info("toService : " + toService);
log.info("uuid - version : " + uuid + " - " + version);
@@ -100,6 +104,7 @@
super.clear();
version = null;
uuid = null;
+ remote = null;
fromService = toService = null;
// l'action est multi-tab, et est stateless!
// on doit recalculer le tab a chaque visite
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToLocalAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToLocalAction.java 2008-02-14 18:54:25 UTC (rev 978)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToLocalAction.java 2008-02-14 19:34:08 UTC (rev 979)
@@ -20,16 +20,9 @@
import fr.cemagref.simexplorer.is.entities.EntitiesAction;
import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException;
-import fr.cemagref.simexplorer.is.ui.swing.JDetailTab;
-import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractTabAction;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
+import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel;
-import javax.swing.JTree;
import java.awt.event.ActionEvent;
-import java.io.File;
/**
* Action pour exporter une application
@@ -45,17 +38,10 @@
mnemonic = 'x',
hideActionText = true
)
-public class ExportToLocalAction extends SimExplorerAbstractTabAction {
+public class ExportToLocalAction extends ExportAction {
private static final long serialVersionUID = 7535647131305304738L;
- JTree tree;
- LoggableElementTreeNode node;
- File file;
- LoggableElement element;
- String uuid;
- Version version;
-
public ExportToLocalAction(String name) {
super(name);
}
@@ -65,32 +51,14 @@
if (!super.beforeAction(e)) {
return false;
}
- JDetailTab ui = (JDetailTab) getUI();
- tree = ui.getNavigationTree();
- node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree);
+ SynchronizeTabModel model = (SynchronizeTabModel) getModel();
+ LoggableElement element = model.getRemoteSelectedNode();
boolean result;
- result = EntitiesAction.EXPORT.accept(node);
- if (result) {
- element = (LoggableElement) node.getUserObject();
+ if (result = EntitiesAction.EXPORT.accept(element)) {
uuid = element.getMetaData().getUuid();
version = element.getMetaData().getVersion();
+ remote = true;
}
return result;
}
-
- @Override
- protected void doAction(ActionEvent e) throws Exception {
- throw new SimExplorerRuntimeException(this + " is not implemented yet!");
- }
-
- @Override
- protected void clear() {
- super.clear();
- tree = null;
- node = null;
- file = null;
- element = null;
- version = null;
- uuid = null;
- }
}
\ No newline at end of file
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToRemoteAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToRemoteAction.java 2008-02-14 18:54:25 UTC (rev 978)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportToRemoteAction.java 2008-02-14 19:34:08 UTC (rev 979)
@@ -18,18 +18,11 @@
* ##% */
package fr.cemagref.simexplorer.is.ui.swing.actions;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
import fr.cemagref.simexplorer.is.entities.EntitiesAction;
-import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractTabAction;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
-import fr.cemagref.simexplorer.is.ui.swing.JDetailTab;
-import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException;
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.ui.swing.model.SynchronizeTabModel;
-import javax.swing.JTree;
import java.awt.event.ActionEvent;
-import java.io.File;
/**
* Action pour exporter une application
@@ -45,17 +38,10 @@
mnemonic = 'x',
hideActionText = true
)
-public class ExportToRemoteAction extends SimExplorerAbstractTabAction {
+public class ExportToRemoteAction extends ExportAction {
private static final long serialVersionUID = 7535647131305304738L;
- JTree tree;
- LoggableElementTreeNode node;
- File file;
- LoggableElement element;
- String uuid;
- Version version;
-
public ExportToRemoteAction(String name) {
super(name);
}
@@ -65,32 +51,14 @@
if (!super.beforeAction(e)) {
return false;
}
- JDetailTab ui = (JDetailTab) getUI();
- tree = ui.getNavigationTree();
- node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree);
+ SynchronizeTabModel model = (SynchronizeTabModel) getModel();
+ LoggableElement element = model.getLocalSelectedNode();
boolean result;
- result = EntitiesAction.EXPORT.accept(node);
- if (result) {
- element = (LoggableElement) node.getUserObject();
+ if (result = EntitiesAction.EXPORT.accept(element)) {
uuid = element.getMetaData().getUuid();
version = element.getMetaData().getVersion();
+ remote = false;
}
return result;
}
-
- @Override
- protected void doAction(ActionEvent e) throws Exception {
- throw new SimExplorerRuntimeException(this+" is not implemented yet!");
- }
-
- @Override
- protected void clear() {
- super.clear();
- tree = null;
- node = null;
- file = null;
- element = null;
- version = null;
- uuid = null;
- }
}
\ No newline at end of file
1
0
r978 - trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: tchemit
Date: 2008-02-14 18:54:25 +0000 (Thu, 14 Feb 2008)
New Revision: 978
Modified:
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java
Log:
mise en place action export depuis onglet liste et detail
TODO faire celles depuis onglet synchronisation
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java 2008-02-14 18:53:32 UTC (rev 977)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/ExportAction.java 2008-02-14 18:54:25 UTC (rev 978)
@@ -18,18 +18,17 @@
* ##% */
package fr.cemagref.simexplorer.is.ui.swing.actions;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.entities.EntitiesAction;
+import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.entities.EntitiesAction;
+import fr.cemagref.simexplorer.is.service.StorageService;
+import fr.cemagref.simexplorer.is.ui.StorageServiceHelper;
import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractTabAction;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeHelper;
-import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementTreeNode;
-import fr.cemagref.simexplorer.is.ui.swing.JDetailTab;
-import fr.cemagref.simexplorer.is.ui.SimExplorerRuntimeException;
+import fr.cemagref.simexplorer.is.ui.swing.model.DetailTabModel;
+import fr.cemagref.simexplorer.is.ui.swing.model.ListTabModel;
+import jaxx.runtime.builder.TabModel;
-import javax.swing.JTree;
import java.awt.event.ActionEvent;
-import java.io.File;
/**
* Action pour exporter une application
@@ -49,12 +48,9 @@
private static final long serialVersionUID = 7535647131305304738L;
- JTree tree;
- LoggableElementTreeNode node;
- File file;
- LoggableElement element;
String uuid;
Version version;
+ StorageService fromService, toService;
public ExportAction(String name) {
super(name);
@@ -65,32 +61,48 @@
if (!super.beforeAction(e)) {
return false;
}
- JDetailTab ui = (JDetailTab) getUI();
- tree = ui.getNavigationTree();
- node = LoggableElementTreeHelper.getSelectedNodeOrRootNode(tree);
+ Boolean remote = null;
+ MetaData element = null;
+ // on retrouve l'onglet concerné à partir de son model
+ TabModel tabModel = getModel();
+ if (tabModel instanceof DetailTabModel) {
+ DetailTabModel model = (DetailTabModel) tabModel;
+ element = model.getDetail();
+ remote = model.isRemote();
+ uuid = element.getUuid();
+ version = model.getSelectedVersion();
+ } else if (tabModel instanceof ListTabModel) {
+ ListTabModel model = (ListTabModel) getModel();
+ element = model.get(model.getSelectedIndex());
+ uuid = element.getUuid();
+ version = element.getVersion();
+ remote = model.isRemote();
+ }
boolean result;
- result = EntitiesAction.EXPORT.accept(node);
+ result = remote != null && version != null && uuid != null && EntitiesAction.EXPORT.accept(element);
if (result) {
- element = (LoggableElement) node.getUserObject();
- uuid = element.getMetaData().getUuid();
- version = element.getMetaData().getVersion();
+ fromService = StorageServiceHelper.getService(getContext(), remote);
+ toService = StorageServiceHelper.getService(getContext(), !remote);
}
return result;
}
@Override
protected void doAction(ActionEvent e) throws Exception {
- throw new SimExplorerRuntimeException(this+" is not implemented yet!");
+ log.info("fromService : " + fromService);
+ log.info("toService : " + toService);
+ log.info("uuid - version : " + uuid + " - " + version);
+ fr.cemagref.simexplorer.is.service.StorageServiceHelper.exportElementTo(getContext().getToken(), fromService, toService, uuid, version.toString());
}
@Override
protected void clear() {
super.clear();
- tree = null;
- node = null;
- file = null;
- element = null;
version = null;
uuid = null;
+ fromService = toService = null;
+ // l'action est multi-tab, et est stateless!
+ // on doit recalculer le tab a chaque visite
+ setTab(null);
}
}
\ No newline at end of file
1
0
r977 - in trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is: service ui
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: tchemit
Date: 2008-02-14 18:53:32 +0000 (Thu, 14 Feb 2008)
New Revision: 977
Modified:
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java
Log:
ajout sur le service de mock de la provenance
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-02-14 18:52:50 UTC (rev 976)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-02-14 18:53:32 UTC (rev 977)
@@ -18,9 +18,15 @@
* ##% */
package fr.cemagref.simexplorer.is.service;
+import com.healthmarketscience.rmiio.SerializableInputStream;
+import fr.cemagref.simexplorer.is.attachment.Attachment;
+import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
+import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
import static fr.cemagref.simexplorer.is.factories.XmlConstants.FILE_DATA_PREFIX;
import static fr.cemagref.simexplorer.is.factories.XmlConstants.FILE_XML;
import static fr.cemagref.simexplorer.is.factories.XmlConstants.FOLDER_SEPARATOR;
+import org.codelutin.util.ZipStreamEncoder;
import java.io.InputStream;
import java.io.PipedInputStream;
@@ -30,15 +36,6 @@
import java.util.Map;
import java.util.SortedMap;
-import org.codelutin.util.ZipStreamEncoder;
-
-import com.healthmarketscience.rmiio.SerializableInputStream;
-
-import fr.cemagref.simexplorer.is.attachment.Attachment;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-
/**
* The Class MockStorageServiceImpl.
*
@@ -50,8 +47,11 @@
private Attachment xmlAttachment;
- public MockStorageServiceImpl() {
+ private boolean remote;
+
+ public MockStorageServiceImpl(boolean remote) {
base = new MockDatabase();
+ this.remote = remote;
}
/**
@@ -103,7 +103,7 @@
* @see fr.cemagref.simexplorer.is.service.StorageService#exportElement(java.lang.String, java.lang.String, java.lang.String)
*/
public InputStream retrieveElementXML(String token, String uuid,
- String version) throws SimExplorerServiceException {
+ String version) throws SimExplorerServiceException {
return (InputStream) checkImplemented();
}
@@ -111,7 +111,7 @@
* @see fr.cemagref.simexplorer.is.service.StorageService#exportFull(java.lang.String, java.lang.String, java.lang.String)
*/
public InputStream retrieveElementFull(String token, String uuid,
- String version) throws SimExplorerServiceException {
+ String version) throws SimExplorerServiceException {
return (InputStream) checkImplemented();
}
@@ -120,7 +120,7 @@
* @see fr.cemagref.simexplorer.is.service.StorageService#retrieveData(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
*/
public InputStream retrieveElementData(String token, String uuid,
- String version, Attachment attachment) throws SimExplorerServiceException {
+ String version, Attachment attachment) throws SimExplorerServiceException {
return null;
}
@@ -164,7 +164,7 @@
ElementGenerator.RandomStream stream = base.generateTextStream();
String md5 = stream.getMd5();
attachment.setDataHash(md5);
- MockDatabase.log.info("setMd5 "+ md5+" for "+element);
+ MockDatabase.log.info("setMd5 " + md5 + " for " + element);
return stream.getStream();
} catch (Exception e) {
throw new SimExplorerServiceException(e);
@@ -246,7 +246,7 @@
public Version[] getVersions(String token, String uuid)
throws SimExplorerServiceException {
MetaData[] datas = base.metadatas.get(uuid);
- if (datas==null) {
+ if (datas == null) {
return new Version[0];
}
Version[] result = new Version[datas.length];
@@ -264,7 +264,7 @@
if (login == null) {
throw new SimExplorerServiceException(new NullPointerException("login can not be null"));
}
- return password == null || password.length()==0 ? null : "abc";
+ return password == null || password.length() == 0 ? null : "abc";
}
/* (non-Javadoc)
@@ -287,6 +287,8 @@
checkImplemented();
}
-
-
+ @Override
+ public String toString() {
+ return super.toString() + " remote:" + remote;
+ }
}
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java 2008-02-14 18:52:50 UTC (rev 976)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/StorageServiceHelper.java 2008-02-14 18:53:32 UTC (rev 977)
@@ -179,7 +179,7 @@
protected static StorageService getLocalStorageService() {
if (storageService == null) {
if (mock) {
- return storageService = new MockStorageServiceImpl();
+ return storageService = new MockStorageServiceImpl(false);
}
try {
storageService = new StorageServiceClient();
@@ -197,7 +197,7 @@
protected static StorageService getRemoteStorageService(SimExplorerContext context) {
if (remoteStorageService == null) {
if (mock) {
- return remoteStorageService = new MockStorageServiceImpl();
+ return remoteStorageService = new MockStorageServiceImpl(true);
}
try {
Properties props = initProperties(context.getConfig().getRemoteURI());
1
0
r976 - trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/util
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
by tchemit@users.labs.libre-entreprise.org 14 Feb '08
14 Feb '08
Author: tchemit
Date: 2008-02-14 18:52:50 +0000 (Thu, 14 Feb 2008)
New Revision: 976
Modified:
trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/util/ErrorDialog.jaxx
Log:
stacktrace en police plus petite
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/util/ErrorDialog.jaxx
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/util/ErrorDialog.jaxx 2008-02-14 16:02:10 UTC (rev 975)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/uimodel/fr/cemagref/simexplorer/is/ui/swing/util/ErrorDialog.jaxx 2008-02-14 18:52:50 UTC (rev 976)
@@ -21,7 +21,7 @@
<row fill='both' weightx='1' weighty='1'>
<cell>
<JScrollPane width='600' height='200'>
- <JTextArea id='errorStack' editable='false'/>
+ <JTextArea id='errorStack' editable='false' font-size='9'/>
</JScrollPane>
</cell>
</row>
1
0