r1416 - trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service
Author: glandais Date: 2008-03-20 14:25:29 +0000 (Thu, 20 Mar 2008) New Revision: 1416 Removed: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java Log: Deprecated Deleted: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-20 14:22:26 UTC (rev 1415) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-20 14:25:29 UTC (rev 1416) @@ -1,187 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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.service; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.SortedMap; -import java.util.TreeMap; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -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.entities.metadata.Version; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.storage.ElementGenerator; -import fr.cemagref.simexplorer.is.storage.VersionGenerator; - -/** - * Classe permettant de créer une base fictive - * - * @author chemit - */ - at Deprecated -public class MockDatabase { - - static final int SIZE = 10; - - static protected Log log = LogFactory.getLog(MockDatabase.class); - - /** - * le dictionnaire d'ea indexées par leur uuid. - * Le premier ea est le parent (donc la version la plus petite) - */ - protected SortedMap<String, ExplorationApplication[]> eas; - - /** - * le dictionnaire des loggableElement indexées par leur uuid. - * Le premier LE est le parent (donc la version la plus petite) - */ - protected SortedMap<String, LoggableElement[]> loggableElements; - - /** - * le dictionnaire de meta data indexées par leur uuid. - * Le premier metadata est le parent (donc la version la plus petite) - */ - protected SortedMap<String, MetaData[]> metadatas; - - protected List<String> metadatasIndex; - - Random r; - - VersionGenerator versionGenerator; - - ElementGenerator elementGenerator; - - public MockDatabase() { - try { - init(); - } catch (Exception e) { - throw new SimExplorerRuntimeException(e); - } - } - - /** - * initialise la base fictive - * - * @throws Exception si pb - */ - public void init() throws Exception { - - - elementGenerator = new ElementGenerator(); - - r = new Random(); - - - versionGenerator = VersionGenerator.getInstance(); - - eas = new TreeMap<String, ExplorationApplication[]>(); - loggableElements = new TreeMap<String, LoggableElement[]>(); - metadatas = new TreeMap<String, MetaData[]>(); - metadatasIndex = new ArrayList<String>(); - - for (int i = 0,max=SIZE+r.nextInt(10); i < max; i++) { - int nbSons = 2 + r.nextInt(3); - Version[] versions = versionGenerator.generateVersions(nbSons + 1); - - ExplorationApplication parentEA = elementGenerator.generateRandomEA(); - MetaData parentMetaData = parentEA.getMetaData(); - parentMetaData.setVersion(versions[0].toString()); - String uuid = parentMetaData.getUuid(); - String name = parentMetaData.getName(); - List<ExplorationApplication> listSons = new ArrayList<ExplorationApplication>(nbSons); - listSons.add(parentEA); - for (int j = 0; j < nbSons; j++) { - ExplorationApplication sonEA = elementGenerator.generateRandomEA(); - sonEA.getMetaData().setUuid(uuid); - sonEA.getMetaData().setName(name); - sonEA.getMetaData().setVersion(versions[j + 1].toString()); - listSons.add(sonEA); - } - registerEA(uuid, listSons.toArray(new ExplorationApplication[listSons.size()])); - } - log.info("nb ExplorationApplications/LoggableElement/MetaDatas : "+eas.size()+"/"+loggableElements.size()+"/"+metadatas.size()); - } - - protected void registerEA(String uuid, ExplorationApplication... eas) throws Exception { - this.eas.put(uuid, eas); - registerLoggableElement(uuid, eas); - for (ExplorationApplication ea : eas) { - for (Component component : ea.getComponents()) { - registerLoggableElement(component.getMetaData().getUuid(), component); - for (Library library : component.getLibraries()) { - registerLoggableElement(library.getMetaData().getUuid(), library); - } - } - for (ExplorationData explorationData : ea.getExplorations()) { - registerLoggableElement(explorationData.getMetaData().getUuid(), explorationData); - } - } - } - - protected void registerLoggableElement(String uuid, LoggableElement... loggableElements) throws Exception { - if (loggableElements.length == 1) { - /* - // generate versions for the unique LE given - LoggableElement loggableElement = loggableElements[0]; - loggableElement.getMetaData().setLatest(false); - String name =loggableElement.getMetaData().getName(); - - List<? extends LoggableElement> sons = elementGenerator.generateArray(loggableElement.getClass()); - int nbSons = 1 + sons.size(); - Version[] versions = versionGenerator.generateVersions(nbSons + 1); - loggableElement.getMetaData().setVersion(versions[0].toString()); - List<LoggableElement> listSons = new ArrayList<LoggableElement>(nbSons); - listSons.add(loggableElement); - int j = 0; - for (LoggableElement sonEA : sons) { - sonEA.getMetaData().setUuid(uuid); - sonEA.getMetaData().setName(name); - sonEA.getMetaData().setVersion(versions[++j].toString()); - listSons.add(sonEA); - } - loggableElements = listSons.toArray(new LoggableElement[listSons.size()]); - */ - } - this.loggableElements.put(uuid, loggableElements); - List<MetaData> datas = new ArrayList<MetaData>(); - for (LoggableElement data : loggableElements) { - datas.add(data.getMetaData()); - } - registerMetaData(uuid, datas.toArray(new MetaData[datas.size()])); - } - - public ElementGenerator.RandomStream generateTextStream() throws Exception { - return elementGenerator.generateTextStream(); - } - - protected void registerMetaData(String uuid, MetaData... datas) { - this.metadatas.put(uuid, datas); - this.metadatasIndex.add(uuid); - } - -} \ No newline at end of file Deleted: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-03-20 14:22:26 UTC (rev 1415) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-03-20 14:25:29 UTC (rev 1416) @@ -1,245 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit -* -* 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.service; - -import java.io.InputStream; -import java.util.Map; -import java.util.SortedMap; - -import com.healthmarketscience.rmiio.SerializableInputStream; - -import fr.cemagref.simexplorer.is.entities.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 fr.cemagref.simexplorer.is.exceptions.SimExplorerException; - -/** - * The Class MockStorageServiceImpl. - * - * @author chemit - */ - at Deprecated -public class MockStorageServiceImpl implements StorageService { - - protected MockDatabase base; - - private boolean remote; - - public MockStorageServiceImpl(boolean remote) { - base = new MockDatabase(); - this.remote = remote; - } - - /** - * Check implemented. - * - * @return the object - */ - private Object checkImplemented() { - throw new IllegalStateException("not implemented"); - } - - public LoggableElement saveElement(String token, SerializableInputStream zipRemoteStream) throws SimExplorerException { - return (LoggableElement) checkImplemented(); - } - - public LoggableElement saveElement(String token, SerializableInputStream xmlRemoteStream, - Map<Attachment, SerializableInputStream> attachmentsRemoteStream) throws SimExplorerException { - return (LoggableElement) checkImplemented(); - } - - public MetaData getMetadata(String token, String uuid) throws SimExplorerException { - MetaData[] datas = base.metadatas.get(uuid); - return datas == null ? null : datas[0]; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#getMetadata(java.lang.String, java.lang.String, java.lang.String) - */ - public MetaData getMetadata(String token, String uuid, String version) throws SimExplorerException { - MetaData[] datas = base.metadatas.get(uuid); - if (datas == null) { - return null; - } - Version v = Version.valueOf(version); - for (MetaData data : datas) { - if (data.getVersion().equals(v)) { - return data; - } - } - return null; - } - - /* (non-Javadoc) - * @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 SimExplorerException { - return (InputStream) checkImplemented(); - } - - /* (non-Javadoc) - * @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 SimExplorerException { - return (InputStream) checkImplemented(); - } - - /* (non-Javadoc) - * @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 SimExplorerException { - - return null; - } - - public int findFullTextCount(String token, String query,String queryColumn, boolean onlyLatest) throws SimExplorerException { - // TODO Changer - return findElementsCount(token, "", onlyLatest); - } - - public MetaData[] findFullText(String token, String query, String queryColumn, boolean onlyLatest, int indexStart, int count, - String column, - boolean ascending) throws SimExplorerException { - // TODO Changer - return findElements(token, "", onlyLatest, indexStart, count, column, ascending); - } - - public int findElementsCount(String token, String type, boolean onlyLatest) throws SimExplorerException { - return base.metadatas.size(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#findApplications(java.lang.String, boolean, int, int, int) - */ - public MetaData[] findElements(String token, String type, boolean onlyLatest, int start, int count, String column, - boolean ascending) - throws SimExplorerException { - int last = start + count; - MockDatabase.log.info("ask data from " + start + " width:" + count); - SortedMap<String, MetaData[]> map = base.metadatas; - if (last > map.size()) { - last = map.size(); - } - MetaData[] result = new MetaData[last - start]; - - for (int i = start; i < last; i++) { - result[i - start] = map.get(base.metadatasIndex.get(i))[0]; - } - return result; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#getElement(java.lang.String, java.lang.String, java.lang.String) - */ - public LoggableElement getLoggableElement(String token, String uuid, String version) throws SimExplorerException { - try { - LoggableElement[] eas = base.loggableElements.get(uuid); - if (eas == null) { - return null; - } - Version v = Version.valueOf(version); - for (LoggableElement element : eas) { - if (element.getMetaData().getVersion().equals(v)) { - return element; - } - } - return null; - } catch (Exception e) { - throw new SimExplorerException(e); - } - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#getVersions(java.lang.String, java.lang.String) - */ - public Version[] getVersions(String token, String uuid) throws SimExplorerException { - MetaData[] datas = base.metadatas.get(uuid); - if (datas == null) { - return new Version[0]; - } - Version[] result = new Version[datas.length]; - for (int i = 0; i < datas.length; i++) { - MetaData data = datas[i]; - result[i] = data.getVersion(); - } - return result; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#loginUser(java.lang.String, java.lang.String) - */ - public String loginUser(String login, String password) throws SimExplorerException { - if (login == null) { - throw new SimExplorerException(new NullPointerException("login can not be null")); - } - return password == null || password.length() == 0 ? null : "abc"; - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#deleteElement(java.lang.String, java.lang.String, java.lang.String) - */ - public void deleteElement(String token, String uuid, String version) { - checkImplemented(); - } - - /* (non-Javadoc) - * @see fr.cemagref.simexplorer.is.service.StorageService#deleteElement(java.lang.String, java.lang.String) - */ - public void deleteElement(String token, String uuid) { - checkImplemented(); - } - - @Override - public void update(String token, String oldUuid, Version oldVersion, MetaData newVersion, boolean deleteOldElement) - throws SimExplorerException { - checkImplemented(); - } - - @Override - public String toString() { - return super.toString() + " remote:" + remote; - } - - @Override - public MetaData[] getMetadatasUsedBy(String token, String uuid, String version) throws SimExplorerException { - checkImplemented(); - return null; - } - - @Override - public MetaData[] getMetadatasUsing(String token, String uuid, String version) throws SimExplorerException { - checkImplemented(); - return null; - } - - @Override - public MetaData[] getMetadatasUsedBy(String token, String uuid) throws SimExplorerException { - checkImplemented(); - return null; - } - - @Override - public MetaData[] getMetadatasUsing(String token, String uuid) throws SimExplorerException { - checkImplemented(); - return null; - } - -}
participants (1)
-
glandais@users.labs.libre-entreprise.org