Author: tchemit Date: 2008-03-14 23:22:45 +0000 (Fri, 14 Mar 2008) New Revision: 1336 Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java Log: deprecated Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java 2008-03-14 23:22:32 UTC (rev 1335) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java 2008-03-14 23:22:45 UTC (rev 1336) @@ -1,187 +0,0 @@ -/* -* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin, -* Tony Chemit, 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.swing; - -import com.healthmarketscience.rmiio.SerializableInputStream; -import fr.cemagref.simexplorer.is.entities.EntityTypeEnum; -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; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.exceptions.UnreachableServiceException; -import fr.cemagref.simexplorer.is.service.StorageService; -import fr.cemagref.simexplorer.is.storage.SortColumn; -import fr.cemagref.simexplorer.is.ui.swing.LoggableElementCache; - -import java.io.BufferedInputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; - -/** - * Une classe pour encapsuler les appels aux services Storage et leur initialisation. - * - * @author chemit - * @deprecated use directly service from context - */ -public class StorageServiceHelper { - - /** - * @param context le context de l'application - * @param remote flag pour indiquer le type de service recherché (local ou remote) - * @return le service instancié et initialisé - * @throws UnreachableServiceException si service non joignable - */ - private static StorageService getService(SimExplorerContext context, boolean remote) throws UnreachableServiceException { - StorageService service; - service = context.getStorageService(remote); - return service; - } - - private static String loginUser(SimExplorerContext context, boolean remote, String login, String hashPassword) throws UnreachableServiceException { - StorageService service = getService(context, remote); - try { - String token; - token = service.loginUser(login, hashPassword); - return token; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - private static int getCount(SimExplorerContext context, boolean remote, String query, boolean onlyLatest) { - StorageService service = getService(context, remote); - String token = context.getToken(); - int size; - try { - if (query == null || query.isEmpty()) { - size = service.findElementsCount(token, EntityTypeEnum.ExplorationApplication.toString(), onlyLatest); - } else { - size = service.findFullTextCount(token, query, "", onlyLatest); - } - return size; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - private static MetaData[] getData(SimExplorerContext context, boolean remote, boolean onlyLatest, String query, long newFirstIndex, int width, SortColumn column, boolean ascending) { - StorageService service = getService(context, remote); - String token = context.getToken(); - try { - MetaData[] data; - if (query == null || query.isEmpty()) { - data = service.findElements(token, EntityTypeEnum.ExplorationApplication.toString(), onlyLatest, (int) newFirstIndex, width, column.name(), ascending); - } else { - data = service.findFullText(token, query, "", onlyLatest, (int) newFirstIndex, width, column.name(), ascending); - //data = service.findFullText(token, query, SearchColumn.AllFields.name(), onlyLatest, (int) newFirstIndex, width, column.name(), ascending); - } - return data; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - private static MetaData getMetaData(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - MetaData metas; - metas = getService(context, remote).getMetadata(context.getToken(), uuid, version); - return metas; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - /** - * @param context the application context - * @param remote flag tosay local or remote - * @param uuid uuid of LoggableElement required - * @param version version of LoggableElement required - * @return the LoggableElement from service - * @deprecated prefer use {@link LoggableElementCache} - */ - private static LoggableElement getElement(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - LoggableElement data; - data = getService(context, remote).getLoggableElement(context.getToken(), uuid, version); - return data; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - private static void deleteElement(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - getService(context, remote).deleteElement(context.getToken(), uuid, version); - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - - private static BufferedInputStream retrieveElementFull(SimExplorerContext context, boolean remote, String uuid, String version) { - try { - InputStream stream = getService(context, remote).retrieveElementFull(context.getToken(), uuid, version); - BufferedInputStream bis; - bis = new BufferedInputStream(stream); - return bis; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - private static BufferedInputStream retrieveElementData(SimExplorerContext context, boolean remote, String uuid, String version, Attachment attachment) { - try { - InputStream stream = getService(context, remote).retrieveElementData(context.getToken(), uuid, version, attachment); - BufferedInputStream bis; - bis = new BufferedInputStream(stream); - return bis; - } catch (SimExplorerException e1) { - throw new SimExplorerRuntimeException(e1); - } - } - - private static MetaData importElement(SimExplorerContext context, boolean remote, File file) { - try { - SerializableInputStream zipStream; - zipStream = new SerializableInputStream(new FileInputStream(file)); - MetaData result; - result = getService(context, remote).saveElement(context.getToken(), zipStream).getMetaData(); - return result; - } catch (Exception e) { - throw new SimExplorerRuntimeException(e); - } - } - - private static Version[] getVersions(SimExplorerContext context, boolean remote, String uuid) { - try { - Version[] result; - result = getService(context, remote).getVersions(context.getToken(), uuid); - return result; - } catch (SimExplorerException e) { - throw new SimExplorerRuntimeException(e); - } - } - - protected StorageServiceHelper() { - // no instance - } -}
participants (1)
-
tchemit@users.labs.libre-entreprise.org