r416 - in trunk: simexplorer-is-service simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab
Author: glandais Date: 2008-01-22 15:15:22 +0000 (Tue, 22 Jan 2008) New Revision: 416 Added: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceServerTest.java Removed: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java Modified: trunk/simexplorer-is-service/pom.xml trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowLocalTabAction.java trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowRemoteTabAction.java Log: Secured service Modified: trunk/simexplorer-is-service/pom.xml =================================================================== --- trunk/simexplorer-is-service/pom.xml 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/pom.xml 2008-01-22 15:15:22 UTC (rev 416) @@ -23,6 +23,11 @@ <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> + <groupId>simexplorer-is</groupId> + <artifactId>simexplorer-is-security</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> <groupId>com.healthmarketscience.rmiio</groupId> <artifactId>rmiio</artifactId> <version>2.0.0</version> Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-01-22 15:15:22 UTC (rev 416) @@ -60,39 +60,39 @@ throw new IllegalStateException("not implemented"); } - public MetaDataEntity saveElement(RemoteInputStream zipRemoteStream) throws Exception { + public MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) throws Exception { return (MetaDataEntity) checkImplemented(); } - public MetaDataEntity saveElement(RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) throws Exception { + public MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) throws Exception { return (MetaDataEntity) checkImplemented(); } - public MetaDataEntity getMetadata(String uuid) throws Exception { + public MetaDataEntity getMetadata(String token, String uuid) throws Exception { return mockData().get(uuid); } - public MetaDataEntity getMetadata(String uuid, String version) throws Exception { + public MetaDataEntity getMetadata(String token, String uuid, String version) throws Exception { return mockData().get(uuid); } - public void exportElement(RemoteOutputStream xmlOutputStream, String uuid, String version) throws Exception { + public void exportElement(String token, RemoteOutputStream xmlOutputStream, String uuid, String version) throws Exception { checkImplemented(); } - public int findFullTextCount(String query, boolean onlyLatest) throws Exception { + public int findFullTextCount(String token, String query, boolean onlyLatest) throws Exception { return (Integer) checkImplemented(); } - public MetaDataEntity[] findFullText(String query, boolean onlyLatest, int indexStart, int count, int dateOrder) throws Exception { + public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, int indexStart, int count, int dateOrder) throws Exception { return (MetaDataEntity[]) checkImplemented(); } - public int findApplicationsCount(boolean onlyLatest) throws Exception { + public int findApplicationsCount(String token, boolean onlyLatest) throws Exception { return mockData().size(); } - public MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count, int dateOrder) throws Exception { + public MetaDataEntity[] findApplications(String token, boolean onlyLatest, int start, int count, int dateOrder) throws Exception { int last = start + count; System.out.println("ask data from " + start + " width:" + count); SortedMap<String, MetaDataEntity> map = mockData(); @@ -107,7 +107,11 @@ return result; } - public LoggableElement getElement(String uuid, String version) throws Exception { + public LoggableElement getElement(String token, String uuid, String version) throws Exception { return (LoggableElement) checkImplemented(); } + + public String loginUser(String login, String password) { + return (String) checkImplemented(); + } } Modified: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageService.java 2008-01-22 15:15:22 UTC (rev 416) @@ -27,6 +27,17 @@ void commit() throws Exception; /** + * Login user onto system Not used for local usages + * + * @param login + * Login + * @param password + * Password + * @return Token as logon evidence + */ + String loginUser(String login, String password); + + /** * Save a remote element * * @param zipRemoteStream @@ -34,7 +45,7 @@ * @return Metadata of element imported * @throws Exception */ - MetaDataEntity saveElement(RemoteInputStream zipRemoteStream) + MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) throws Exception; /** @@ -48,7 +59,7 @@ * @return Metadata of element saved * @throws Exception */ - MetaDataEntity saveElement(RemoteInputStream xmlRemoteStream, + MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, Map<String, RemoteInputStream> attachmentsRemoteStream) throws Exception; @@ -59,7 +70,7 @@ * @return * @throws Exception */ - MetaDataEntity getMetadata(String uuid) throws Exception; + MetaDataEntity getMetadata(String token, String uuid) throws Exception; /** * Retrieve metadata @@ -69,7 +80,8 @@ * @return * @throws Exception */ - MetaDataEntity getMetadata(String uuid, String version) throws Exception; + MetaDataEntity getMetadata(String token, String uuid, String version) + throws Exception; /** * Export element to a remote stream @@ -80,8 +92,8 @@ * @param version * @throws Exception */ - void exportElement(RemoteOutputStream xmlOutputStream, String uuid, - String version) throws Exception; + void exportElement(String token, RemoteOutputStream xmlOutputStream, + String uuid, String version) throws Exception; /** * Retrieve number of elements matching query @@ -91,7 +103,8 @@ * @return * @throws Exception */ - int findFullTextCount(String query, boolean onlyLatest) throws Exception; + int findFullTextCount(String token, String query, boolean onlyLatest) + throws Exception; /** * Find elements matching query @@ -104,8 +117,9 @@ * @return * @throws Exception */ - MetaDataEntity[] findFullText(String query, boolean onlyLatest, - int indexStart, int count, int dateOrder) throws Exception; + MetaDataEntity[] findFullText(String token, String query, + boolean onlyLatest, int indexStart, int count, int dateOrder) + throws Exception; /** * Retrieve number of applications @@ -114,7 +128,8 @@ * @return * @throws Exception */ - int findApplicationsCount(boolean onlyLatest) throws Exception; + int findApplicationsCount(String token, boolean onlyLatest) + throws Exception; /** * Get a list of applications @@ -126,8 +141,8 @@ * @return * @throws Exception */ - MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count, - int dateOrder) throws Exception; + MetaDataEntity[] findApplications(String token, boolean onlyLatest, + int start, int count, int dateOrder) throws Exception; /** * Fully load an element @@ -137,7 +152,7 @@ * @return * @throws Exception */ - LoggableElement getElement(String uuid, String version) + LoggableElement getElement(String token, String uuid, String version) throws Exception; } Added: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceClient.java 2008-01-22 15:15:22 UTC (rev 416) @@ -0,0 +1,16 @@ +package fr.cemagref.simexplorer.is.service; + +import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl; + +public class StorageServiceClient extends StorageServiceCommon { + + public StorageServiceClient() { + storageEngine = new StorageEngineImpl(); + super.firstOpen(); + } + + public String loginUser(String login, String password) { + return null; + } + +} Copied: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java (from rev 415, trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java) =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceCommon.java 2008-01-22 15:15:22 UTC (rev 416) @@ -0,0 +1,329 @@ +package fr.cemagref.simexplorer.is.service; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import javax.ejb.Remote; +import javax.ejb.Stateless; + +import org.jboss.annotation.ejb.RemoteBinding; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import com.healthmarketscience.rmiio.RemoteInputStream; +import com.healthmarketscience.rmiio.RemoteInputStreamClient; +import com.healthmarketscience.rmiio.RemoteOutputStream; +import com.healthmarketscience.rmiio.RemoteOutputStreamClient; + +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.factories.BaseEntityFactory; +import fr.cemagref.simexplorer.is.factories.MetaDataEntityFactory; +import fr.cemagref.simexplorer.is.factories.XmlConstants; +import fr.cemagref.simexplorer.is.storage.engine.StorageEngine; +import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl; + +public abstract class StorageServiceCommon implements StorageService, XmlConstants { + + protected StorageEngine storageEngine; + + private static final String KEY_XML = "_xml"; + + protected void firstOpen() { + try { + storageEngine.open(); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + public void open() throws Exception { + storageEngine.open(); + } + + public void close() throws Exception { + storageEngine.close(); + } + + public void commit() throws Exception { + storageEngine.commit(); + } + + public MetaDataEntity saveElement(String token, RemoteInputStream zipRemoteStream) + throws Exception { + InputStream zipStream = RemoteInputStreamClient.wrap(zipRemoteStream); + return saveElement(token, zipStream); + } + + public MetaDataEntity saveElement(String token, RemoteInputStream xmlRemoteStream, + Map<String, RemoteInputStream> attachmentsRemoteStream) + throws Exception { + InputStream xmlStream = RemoteInputStreamClient.wrap(xmlRemoteStream); + Map<String, InputStream> attachmentStreams = new HashMap<String, InputStream>(); + for (Map.Entry<String, RemoteInputStream> entry : attachmentsRemoteStream + .entrySet()) { + InputStream stream = RemoteInputStreamClient.wrap(entry.getValue()); + attachmentStreams.put(entry.getKey(), stream); + } + return saveElement(token, xmlStream, attachmentStreams); + } + + public MetaDataEntity getMetadata(String token, String uuid) throws Exception { + return storageEngine.getMetadata(uuid); + } + + public MetaDataEntity getMetadata(String token, String uuid, String version) + throws Exception { + return storageEngine.getMetadata(uuid, new Version(version)); + } + + public MetaDataEntity[] findFullText(String token, String query, boolean onlyLatest, + int indexStart, int count, int dateOrder) throws Exception { + return storageEngine.findFullText(query, onlyLatest, indexStart, count, + dateOrder); + } + + public int findFullTextCount(String token, String query, boolean onlyLatest) + throws Exception { + return storageEngine.findFullTextCount(query, onlyLatest); + } + + public int findApplicationsCount(String token, boolean onlyLatest) throws Exception { + return storageEngine.findElementsByTypeCount(VALUE_METADATA_TYPE_EA, + onlyLatest); + } + + public MetaDataEntity[] findApplications(String token, boolean onlyLatest, int start, + int count, int dateOrder) throws Exception { + return storageEngine.findElementsByType(VALUE_METADATA_TYPE_EA, + onlyLatest, start, count, dateOrder); + } + + public LoggableElement getElement(String token, String uuid, String version) + throws Exception { + MetaDataEntity mde = getMetadata(uuid, version); + + LoggableElement le = (LoggableElement) BaseEntityFactory.getFactory( + LoggableElement.class.getPackage().getName() + "." + mde.getType()) + .loadElement(storageEngine.retrieveData(mde, KEY_XML)); + + return le; + } + + private MetaDataEntity saveElement(String token, InputStream zipStream) throws Exception { + String xmlFile = null; + Map<String, String> attachments = new HashMap<String, String>(); + + ZipInputStream zis = new ZipInputStream(zipStream); + + ZipEntry entry; + while ((entry = zis.getNextEntry()) != null) { + if (!entry.isDirectory()) { + String entryName = entry.getName(); + if (entryName.equals(FILE_XML)) { + xmlFile = storageEngine.storeTempData(zis); + } else { + if (entryName.startsWith(FILE_DATA_PREFIX)) { + String fileName = entryName.replace(FILE_DATA_PREFIX + + "/", ""); + String idFile = storageEngine.storeTempData(zis); + attachments.put(fileName, idFile); + } + } + } + } + + return saveElement(token, xmlFile, attachments); + } + + public MetaDataEntity saveElement(String token, InputStream xmlFile, + Map<String, InputStream> attachments) throws Exception { + // Store temporary data + String idxml = storageEngine.storeTempData(xmlFile); + Map<String, String> idsattachment = new HashMap<String, String>(); + for (Map.Entry<String, InputStream> entry : attachments.entrySet()) { + String idattachment = storageEngine.storeTempData(entry.getValue()); + idsattachment.put(entry.getKey(), idattachment); + } + return saveElement(token, idxml, idsattachment); + } + + public void exportElement(String token, RemoteOutputStream xmlOutputStream, String uuid, + String version) throws Exception { + MetaDataEntity mde = getMetadata(uuid, version); + InputStream xmlStream = storageEngine.retrieveData(mde, KEY_XML); + OutputStream os = RemoteOutputStreamClient.wrap(xmlOutputStream); + + // Buffer copy stream to stream + BufferedInputStream bin = new BufferedInputStream(xmlStream); + BufferedOutputStream bout = new BufferedOutputStream(os); + while (true) { + int datum = bin.read(); + if (datum == -1) + break; + bout.write(datum); + } + bout.flush(); + + } + + /** + * Real implementation of saveElement + * + * @param idxml + * @param idsattachment + * @return + * @throws Exception + */ + private MetaDataEntity saveElement(String token, String idxml, + Map<String, String> idsattachment) throws Exception { + // Load metadata xml + MetaDataEntityFactory mdeFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + MetaDataEntity metaData = mdeFactory + .loadElementFromParentXML(storageEngine.retrieveTempData(idxml)); + + if (metaData.getType() != null + && VALUE_METADATA_TYPE_EA.equals(metaData.getType())) { + + /* + ExplorationApplication ea = (ExplorationApplication) BaseEntityFactory + .getFactory(ExplorationApplication.class).loadElement( + storageEngine.retrieveTempData(idxml)); + */ + + // If element is an EA, save inner Components and Data + List<String> components = new ArrayList<String>(); + List<String[]> explorationDatas = new ArrayList<String[]>(); + + // Retrieve elements + extractChildren(token, idxml, idsattachment, components, explorationDatas); + + // For each exploration data + for (String[] explorationData : explorationDatas) { + // where is stored xml + String idxmlED = explorationData[0]; + + // where is stored result + Map<String, String> attachmentsED = new HashMap<String, String>(); + if (explorationData.length > 1) { + attachmentsED.put(explorationData[1], idsattachment + .get(explorationData[1])); + } + // recursive save + saveElement(token, idxmlED, attachmentsED); + + } + + // For each component + for (String idComponent : components) { + saveElement(token, idComponent, new HashMap<String, String>()); + } + + } + + // Process version rules + processVersionRules(token, metaData); + + // Prepare saving + Map<String, InputStream> attachments = new HashMap<String, InputStream>(); + + attachments.put(KEY_XML, storageEngine.retrieveTempData(idxml)); + if (metaData.getType() != null + && !VALUE_METADATA_TYPE_EA.equals(metaData.getType())) { + for (Map.Entry<String, String> entry : idsattachment.entrySet()) { + attachments.put(entry.getKey(), storageEngine + .retrieveTempData(entry.getValue())); + } + } + storageEngine.saveElement(metaData, attachments); + storageEngine.commit(); + + return metaData; + } + + private void processVersionRules(String token, MetaDataEntity metaData) throws Exception { + + // Check existing version in storage + MetaDataEntity previousVersion = storageEngine.getMetadata(metaData + .getUuid(), metaData.getVersion()); + /* + * MetaDataEntity parentData = storageEngine.getElementVersion(metaData + * .getParentData().getUuid(), metaData.getParentData() .getVersion()); + * MetaDataEntity parentVersion = + * storageEngine.getElementVersion(metaData + * .getParentVersion().getUuid(), metaData.getParentVersion() + * .getVersion()); + */ + + // Version rules + if (previousVersion != null) { + metaData.setVersion(previousVersion.getVersion().incVersion(0) + .toString()); + } + + } + + private void extractChildren(String token, String idxml, + Map<String, String> idsattachment, List<String> components, + List<String[]> explorationDatas) throws Exception { + + MetaDataEntityFactory<MetaDataEntity> elementFactory = (MetaDataEntityFactory) BaseEntityFactory + .getFactory(MetaDataEntity.class); + + Document document = BaseEntityFactory.getXMLBuilder().parse( + storageEngine.retrieveTempData(idxml)); + + Element rootElement = (Element) document.getFirstChild(); + + // Components + Element componentsElement = elementFactory.getXMLElementByTagName( + rootElement, KEY_EXPLORATIONAPPLICATION_COMPONENTS); + Set<Element> componentElements = elementFactory + .getXMLElementsByTagName(componentsElement, + KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE); + for (Element element : componentElements) { + components.add(storageEngine.storeTempData(elementFactory + .serializeElement(element))); + } + + Element applicationDatasElement = elementFactory + .getXMLElementByTagName(rootElement, + KEY_EXPLORATIONAPPLICATION_DATA); + Set<Element> applicationDataElements = elementFactory + .getXMLElementsByTagName(applicationDatasElement, + KEY_EXPLORATIONAPPLICATION_DATA_NODE); + + for (Element elementAD : applicationDataElements) { + Element element = elementFactory.getXMLElementByTagName(elementAD, + KEY_EXPLORATIONDATA_RESULT); + String result = elementFactory.getXMLProperty(element, + KEY_RESULT_FILE); + + String[] explorationDataArray = null; + if (result != null) { + explorationDataArray = new String[2]; + explorationDataArray[1] = result; + } else { + explorationDataArray = new String[1]; + } + explorationDataArray[0] = storageEngine + .storeTempData(elementFactory.serializeElement(elementAD)); + + explorationDatas.add(explorationDataArray); + } + + } + +} Deleted: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java 2008-01-22 15:15:22 UTC (rev 416) @@ -1,334 +0,0 @@ -package fr.cemagref.simexplorer.is.service; - -import java.io.BufferedInputStream; -import java.io.BufferedOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -import javax.ejb.Remote; -import javax.ejb.Stateless; - -import org.jboss.annotation.ejb.RemoteBinding; -import org.w3c.dom.Document; -import org.w3c.dom.Element; - -import com.healthmarketscience.rmiio.RemoteInputStream; -import com.healthmarketscience.rmiio.RemoteInputStreamClient; -import com.healthmarketscience.rmiio.RemoteOutputStream; -import com.healthmarketscience.rmiio.RemoteOutputStreamClient; - -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; -import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.factories.BaseEntityFactory; -import fr.cemagref.simexplorer.is.factories.MetaDataEntityFactory; -import fr.cemagref.simexplorer.is.factories.XmlConstants; -import fr.cemagref.simexplorer.is.storage.engine.StorageEngine; -import fr.cemagref.simexplorer.is.storage.engine.StorageEngineImpl; - - at Stateless(name = "StorageService") - at Remote(StorageService.class) - at RemoteBinding(jndiBinding = "StorageService") -public class StorageServiceImpl implements StorageService, XmlConstants { - - private StorageEngine storageEngineImpl = null; - - private static final String KEY_XML = "_xml"; - - public StorageServiceImpl() { - super(); - storageEngineImpl = new StorageEngineImpl(); - try { - storageEngineImpl.open(); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - public void open() throws Exception { - storageEngineImpl.open(); - } - - public void close() throws Exception { - storageEngineImpl.close(); - } - - public void commit() throws Exception { - storageEngineImpl.commit(); - } - - public MetaDataEntity saveElement(RemoteInputStream zipRemoteStream) - throws Exception { - InputStream zipStream = RemoteInputStreamClient.wrap(zipRemoteStream); - return saveElement(zipStream); - } - - public MetaDataEntity saveElement(RemoteInputStream xmlRemoteStream, - Map<String, RemoteInputStream> attachmentsRemoteStream) - throws Exception { - InputStream xmlStream = RemoteInputStreamClient.wrap(xmlRemoteStream); - Map<String, InputStream> attachmentStreams = new HashMap<String, InputStream>(); - for (Map.Entry<String, RemoteInputStream> entry : attachmentsRemoteStream - .entrySet()) { - InputStream stream = RemoteInputStreamClient.wrap(entry.getValue()); - attachmentStreams.put(entry.getKey(), stream); - } - return saveElement(xmlStream, attachmentStreams); - } - - public MetaDataEntity getMetadata(String uuid) throws Exception { - return storageEngineImpl.getMetadata(uuid); - } - - public MetaDataEntity getMetadata(String uuid, String version) - throws Exception { - return storageEngineImpl.getMetadata(uuid, new Version(version)); - } - - public MetaDataEntity[] findFullText(String query, boolean onlyLatest, - int indexStart, int count, int dateOrder) throws Exception { - return storageEngineImpl.findFullText(query, onlyLatest, indexStart, count, - dateOrder); - } - - public int findFullTextCount(String query, boolean onlyLatest) - throws Exception { - return storageEngineImpl.findFullTextCount(query, onlyLatest); - } - - public int findApplicationsCount(boolean onlyLatest) throws Exception { - return storageEngineImpl.findElementsByTypeCount(VALUE_METADATA_TYPE_EA, - onlyLatest); - } - - public MetaDataEntity[] findApplications(boolean onlyLatest, int start, - int count, int dateOrder) throws Exception { - return storageEngineImpl.findElementsByType(VALUE_METADATA_TYPE_EA, - onlyLatest, start, count, dateOrder); - } - - public LoggableElement getElement(String uuid, String version) - throws Exception { - MetaDataEntity mde = getMetadata(uuid, version); - - LoggableElement le = (LoggableElement) BaseEntityFactory.getFactory( - LoggableElement.class.getPackage().getName() + "." + mde.getType()) - .loadElement(storageEngineImpl.retrieveData(mde, KEY_XML)); - - return le; - } - - private MetaDataEntity saveElement(InputStream zipStream) throws Exception { - String xmlFile = null; - Map<String, String> attachments = new HashMap<String, String>(); - - ZipInputStream zis = new ZipInputStream(zipStream); - - ZipEntry entry; - while ((entry = zis.getNextEntry()) != null) { - if (!entry.isDirectory()) { - String entryName = entry.getName(); - if (entryName.equals(FILE_XML)) { - xmlFile = storageEngineImpl.storeTempData(zis); - } else { - if (entryName.startsWith(FILE_DATA_PREFIX)) { - String fileName = entryName.replace(FILE_DATA_PREFIX - + "/", ""); - String idFile = storageEngineImpl.storeTempData(zis); - attachments.put(fileName, idFile); - } - } - } - } - - return saveElement(xmlFile, attachments); - } - - public MetaDataEntity saveElement(InputStream xmlFile, - Map<String, InputStream> attachments) throws Exception { - // Store temporary data - String idxml = storageEngineImpl.storeTempData(xmlFile); - Map<String, String> idsattachment = new HashMap<String, String>(); - for (Map.Entry<String, InputStream> entry : attachments.entrySet()) { - String idattachment = storageEngineImpl.storeTempData(entry.getValue()); - idsattachment.put(entry.getKey(), idattachment); - } - return saveElement(idxml, idsattachment); - } - - public void exportElement(RemoteOutputStream xmlOutputStream, String uuid, - String version) throws Exception { - MetaDataEntity mde = getMetadata(uuid, version); - InputStream xmlStream = storageEngineImpl.retrieveData(mde, KEY_XML); - OutputStream os = RemoteOutputStreamClient.wrap(xmlOutputStream); - - // Buffer copy stream to stream - BufferedInputStream bin = new BufferedInputStream(xmlStream); - BufferedOutputStream bout = new BufferedOutputStream(os); - while (true) { - int datum = bin.read(); - if (datum == -1) - break; - bout.write(datum); - } - bout.flush(); - - } - - /** - * Real implementation of saveElement - * - * @param idxml - * @param idsattachment - * @return - * @throws Exception - */ - private MetaDataEntity saveElement(String idxml, - Map<String, String> idsattachment) throws Exception { - // Load metadata xml - MetaDataEntityFactory mdeFactory = (MetaDataEntityFactory) BaseEntityFactory - .getFactory(MetaDataEntity.class); - MetaDataEntity metaData = mdeFactory - .loadElementFromParentXML(storageEngineImpl.retrieveTempData(idxml)); - - if (metaData.getType() != null - && VALUE_METADATA_TYPE_EA.equals(metaData.getType())) { - - /* - ExplorationApplication ea = (ExplorationApplication) BaseEntityFactory - .getFactory(ExplorationApplication.class).loadElement( - storageEngine.retrieveTempData(idxml)); - */ - - // If element is an EA, save inner Components and Data - List<String> components = new ArrayList<String>(); - List<String[]> explorationDatas = new ArrayList<String[]>(); - - // Retrieve elements - extractChildren(idxml, idsattachment, components, explorationDatas); - - // For each exploration data - for (String[] explorationData : explorationDatas) { - // where is stored xml - String idxmlED = explorationData[0]; - - // where is stored result - Map<String, String> attachmentsED = new HashMap<String, String>(); - if (explorationData.length > 1) { - attachmentsED.put(explorationData[1], idsattachment - .get(explorationData[1])); - } - // recursive save - saveElement(idxmlED, attachmentsED); - - } - - // For each component - for (String idComponent : components) { - saveElement(idComponent, new HashMap<String, String>()); - } - - } - - // Process version rules - processVersionRules(metaData); - - // Prepare saving - Map<String, InputStream> attachments = new HashMap<String, InputStream>(); - - attachments.put(KEY_XML, storageEngineImpl.retrieveTempData(idxml)); - if (metaData.getType() != null - && !VALUE_METADATA_TYPE_EA.equals(metaData.getType())) { - for (Map.Entry<String, String> entry : idsattachment.entrySet()) { - attachments.put(entry.getKey(), storageEngineImpl - .retrieveTempData(entry.getValue())); - } - } - storageEngineImpl.saveElement(metaData, attachments); - storageEngineImpl.commit(); - - return metaData; - } - - private void processVersionRules(MetaDataEntity metaData) throws Exception { - - // Check existing version in storage - MetaDataEntity previousVersion = storageEngineImpl.getMetadata(metaData - .getUuid(), metaData.getVersion()); - /* - * MetaDataEntity parentData = storageEngine.getElementVersion(metaData - * .getParentData().getUuid(), metaData.getParentData() .getVersion()); - * MetaDataEntity parentVersion = - * storageEngine.getElementVersion(metaData - * .getParentVersion().getUuid(), metaData.getParentVersion() - * .getVersion()); - */ - - // Version rules - if (previousVersion != null) { - metaData.setVersion(previousVersion.getVersion().incVersion(0) - .toString()); - } - - } - - private void extractChildren(String idxml, - Map<String, String> idsattachment, List<String> components, - List<String[]> explorationDatas) throws Exception { - - MetaDataEntityFactory<MetaDataEntity> elementFactory = (MetaDataEntityFactory) BaseEntityFactory - .getFactory(MetaDataEntity.class); - - Document document = BaseEntityFactory.getXMLBuilder().parse( - storageEngineImpl.retrieveTempData(idxml)); - - Element rootElement = (Element) document.getFirstChild(); - - // Components - Element componentsElement = elementFactory.getXMLElementByTagName( - rootElement, KEY_EXPLORATIONAPPLICATION_COMPONENTS); - Set<Element> componentElements = elementFactory - .getXMLElementsByTagName(componentsElement, - KEY_EXPLORATIONAPPLICATION_COMPONENT_NODE); - for (Element element : componentElements) { - components.add(storageEngineImpl.storeTempData(elementFactory - .serializeElement(element))); - } - - Element applicationDatasElement = elementFactory - .getXMLElementByTagName(rootElement, - KEY_EXPLORATIONAPPLICATION_DATA); - Set<Element> applicationDataElements = elementFactory - .getXMLElementsByTagName(applicationDatasElement, - KEY_EXPLORATIONAPPLICATION_DATA_NODE); - - for (Element elementAD : applicationDataElements) { - Element element = elementFactory.getXMLElementByTagName(elementAD, - KEY_EXPLORATIONDATA_RESULT); - String result = elementFactory.getXMLProperty(element, - KEY_RESULT_FILE); - - String[] explorationDataArray = null; - if (result != null) { - explorationDataArray = new String[2]; - explorationDataArray[1] = result; - } else { - explorationDataArray = new String[1]; - } - explorationDataArray[0] = storageEngineImpl - .storeTempData(elementFactory.serializeElement(elementAD)); - - explorationDatas.add(explorationDataArray); - } - - } - -} Added: trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java =================================================================== --- trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java (rev 0) +++ trunk/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceServer.java 2008-01-22 15:15:22 UTC (rev 416) @@ -0,0 +1,36 @@ +package fr.cemagref.simexplorer.is.service; + +import javax.ejb.EJB; +import javax.ejb.Remote; +import javax.ejb.Stateless; + +import org.jboss.annotation.ejb.RemoteBinding; + +import fr.cemagref.simexplorer.is.security.service.AuthenticationService; +import fr.cemagref.simexplorer.is.storage.engine.StorageEngineSecuImpl; + + at Stateless(name = "StorageService") + at Remote(StorageService.class) + at RemoteBinding(jndiBinding = "StorageService") +public class StorageServiceServer extends StorageServiceCommon { + + @EJB + private AuthenticationService authenticationService; + + public StorageServiceServer() { + storageEngine = new StorageEngineSecuImpl(); + super.firstOpen(); + } + + public String loginUser(String login, String password) { + String token = authenticationService.loginUser(login, password); + if (token != null) { + // FIXME datasource différent pour la secu et les timers = + // impossible de faire des requêtes sur les deux dans la même + // transaction + // authenticationService.closeSessionTimer(token); + } + return token; + } + +} Modified: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java =================================================================== --- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java 2008-01-22 15:15:22 UTC (rev 416) @@ -8,18 +8,19 @@ import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; import fr.cemagref.simexplorer.is.factories.BaseEntityFactory; import fr.cemagref.simexplorer.is.factories.XmlConstants; -import fr.cemagref.simexplorer.is.service.StorageServiceImpl; +import fr.cemagref.simexplorer.is.service.StorageServiceClient; +import fr.cemagref.simexplorer.is.service.StorageServiceCommon; public class StorageServiceMassInsert extends TestCase { - private StorageServiceImpl storageService; + private StorageServiceCommon storageService; private ElementGenerator elementGenerator; protected void setUp() throws Exception { super.setUp(); elementGenerator = new ElementGenerator(); - storageService = new StorageServiceImpl(); + storageService = new StorageServiceClient(); storageService.open(); } @@ -63,7 +64,7 @@ ExplorationApplication.class).saveElement( XmlConstants.VALUE_METADATA_TYPE_EA, ea); - storageService.saveElement(xmlStream, + storageService.saveElement(null, xmlStream, new HashMap<String, InputStream>()); if (i > 0 && i % 100 == 0) { Added: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceServerTest.java =================================================================== --- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceServerTest.java (rev 0) +++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceServerTest.java 2008-01-22 15:15:22 UTC (rev 416) @@ -0,0 +1,34 @@ +package fr.cemagref.simexplorer.is.service.test; + +import java.util.Properties; + +import javax.naming.Context; +import javax.naming.InitialContext; + +import junit.framework.TestCase; +import fr.cemagref.simexplorer.is.service.StorageService; + +public class StorageServiceServerTest extends TestCase { + + private StorageService storageService; + + protected void setUp() throws Exception { + super.setUp(); + + 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"); + + } + + public void testLogin() { + String token = storageService.loginUser("superadmin", "password"); + System.out.println(token); + } + +} Modified: trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java =================================================================== --- trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java 2008-01-22 15:15:22 UTC (rev 416) @@ -15,110 +15,113 @@ import com.healthmarketscience.rmiio.SimpleRemoteInputStream; import fr.cemagref.simexplorer.is.service.StorageService; -import fr.cemagref.simexplorer.is.service.StorageServiceImpl; +import fr.cemagref.simexplorer.is.service.StorageServiceClient; +import fr.cemagref.simexplorer.is.service.StorageServiceCommon; public class StorageServiceTest extends TestCase { - private StorageService storageService; - private Random r = new Random(); + private StorageService storageService; + private Random r = new Random(); - protected void setUp() throws Exception { - super.setUp(); + protected void setUp() throws Exception { + super.setUp(); - storageService = new StorageServiceImpl(); - } + storageService = new StorageServiceClient(); + } - protected void tearDown() throws Exception { - super.tearDown(); - } + protected void tearDown() throws Exception { + super.tearDown(); + } - public void testInsertElementZip() throws Exception { - InputStream zipStream = new FileInputStream( - "./src/ressources/testImport/test.zip"); - RemoteInputStreamServer zipRemoteStream = new SimpleRemoteInputStream( - zipStream); - storageService.saveElement(zipRemoteStream); - storageService.commit(); - assertNotNull(storageService.getMetadata("abcd")); - } + public void testInsertElementZip() throws Exception { + InputStream zipStream = new FileInputStream( + "./src/ressources/testImport/test.zip"); + RemoteInputStreamServer zipRemoteStream = new SimpleRemoteInputStream( + zipStream); + storageService.saveElement(null, zipRemoteStream); + storageService.commit(); + assertNotNull(storageService.getMetadata(null, "abcd")); + } - public void testInsertElementStreams() throws Exception { - String id = UUID.randomUUID().toString(); - String[] randomcontent = new String[2]; - for (int i = 0; i < randomcontent.length; i++) { - randomcontent[i] = Long.toHexString(r.nextLong()); - } + public void testInsertElementStreams() throws Exception { + String id = UUID.randomUUID().toString(); + String[] randomcontent = new String[2]; + for (int i = 0; i < randomcontent.length; i++) { + randomcontent[i] = Long.toHexString(r.nextLong()); + } - StringBuffer xmlString = new StringBuffer( - "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); - xmlString.append("<data>"); - xmlString.append("<metadata>"); - xmlString.append("<uuid>" + id + "</uuid>"); - xmlString.append("<version>1.0</version>"); - xmlString.append("<name>Test element</name>"); - xmlString.append("<type>TEST</type>"); - xmlString.append("<description>Element test</description>"); - xmlString.append("<creationdate>0</creationdate>"); - xmlString.append("<hash>AAAAA</hash>"); - /* - * xmlString.append("<parentdatauuid></parentdatauuid>"); - * xmlString.append("<parentdataversion></parentdataversion>"); - * xmlString.append("<parentversionuuid></parentversionuuid>"); - * xmlString.append("<parentversionversion></parentversionversion>"); - */ - xmlString.append("<descriptors>"); - xmlString - .append("<descriptor><name>a</name><value>1</value></descriptor>"); - xmlString - .append("<descriptor><name>b</name><value>2</value></descriptor>"); - xmlString - .append("<descriptor><name>c</name><value>3</value></descriptor>"); - xmlString.append("</descriptors>"); - xmlString.append("<attachments>"); - for (int i = 0; i < randomcontent.length; i++) { - xmlString.append("<attachment>"); - xmlString.append("<name>content" + i - + "</name><type>RawType</type>"); - xmlString.append("</attachment>"); - } - xmlString.append("</attachments>"); - xmlString.append("</metadata>"); - xmlString.append("</data>"); + StringBuffer xmlString = new StringBuffer( + "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); + xmlString.append("<data>"); + xmlString.append("<metadata>"); + xmlString.append("<uuid>" + id + "</uuid>"); + xmlString.append("<version>1.0</version>"); + xmlString.append("<name>Test element</name>"); + xmlString.append("<type>TEST</type>"); + xmlString.append("<description>Element test</description>"); + xmlString.append("<creationdate>0</creationdate>"); + xmlString.append("<hash>AAAAA</hash>"); + /* + * xmlString.append("<parentdatauuid></parentdatauuid>"); + * xmlString.append("<parentdataversion></parentdataversion>"); + * xmlString.append("<parentversionuuid></parentversionuuid>"); + * xmlString.append("<parentversionversion></parentversionversion>"); + */ + xmlString.append("<descriptors>"); + xmlString + .append("<descriptor><name>a</name><value>1</value></descriptor>"); + xmlString + .append("<descriptor><name>b</name><value>2</value></descriptor>"); + xmlString + .append("<descriptor><name>c</name><value>3</value></descriptor>"); + xmlString.append("</descriptors>"); + xmlString.append("<attachments>"); + for (int i = 0; i < randomcontent.length; i++) { + xmlString.append("<attachment>"); + xmlString.append("<name>content" + i + + "</name><type>RawType</type>"); + xmlString.append("</attachment>"); + } + xmlString.append("</attachments>"); + xmlString.append("</metadata>"); + xmlString.append("</data>"); - InputStream xmlStream = new ByteArrayInputStream(xmlString.toString() - .getBytes()); - RemoteInputStreamServer xmlRemoteStream = new SimpleRemoteInputStream( - xmlStream); + InputStream xmlStream = new ByteArrayInputStream(xmlString.toString() + .getBytes()); + RemoteInputStreamServer xmlRemoteStream = new SimpleRemoteInputStream( + xmlStream); - Map<String, RemoteInputStream> attachmentsRemoteStream = new HashMap<String, RemoteInputStream>(); + Map<String, RemoteInputStream> attachmentsRemoteStream = new HashMap<String, RemoteInputStream>(); - for (int j = 0; j < randomcontent.length; j++) { + for (int j = 0; j < randomcontent.length; j++) { - StringBuffer contentString = new StringBuffer(""); - for (int i = 0; i < 50; i++) { - contentString.append(Long.toHexString(r.nextLong())) - .append(" "); - } - contentString.append(randomcontent[j]).append(" "); - for (int i = 0; i < 100; i++) { - contentString.append(Long.toHexString(r.nextLong())) - .append(" "); - } + StringBuffer contentString = new StringBuffer(""); + for (int i = 0; i < 50; i++) { + contentString.append(Long.toHexString(r.nextLong())) + .append(" "); + } + contentString.append(randomcontent[j]).append(" "); + for (int i = 0; i < 100; i++) { + contentString.append(Long.toHexString(r.nextLong())) + .append(" "); + } - InputStream contentStream = new ByteArrayInputStream(contentString - .toString().getBytes()); - RemoteInputStreamServer contentRemoteStream = new SimpleRemoteInputStream( - contentStream); - attachmentsRemoteStream.put("content" + j, contentRemoteStream); + InputStream contentStream = new ByteArrayInputStream(contentString + .toString().getBytes()); + RemoteInputStreamServer contentRemoteStream = new SimpleRemoteInputStream( + contentStream); + attachmentsRemoteStream.put("content" + j, contentRemoteStream); - } + } - storageService.saveElement(xmlRemoteStream, attachmentsRemoteStream); - storageService.commit(); - assertNotNull(storageService.getMetadata(id)); - for (int i = 0; i < randomcontent.length; i++) { - assertTrue(storageService.findFullTextCount(randomcontent[i], false) > 0); - } - } + storageService.saveElement(null, xmlRemoteStream, + attachmentsRemoteStream); + storageService.commit(); + assertNotNull(storageService.getMetadata(null, id)); + for (int i = 0; i < randomcontent.length; i++) { + assertTrue(storageService.findFullTextCount(null, randomcontent[i], + false) > 0); + } + } } Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/SimExplorerAbstractTabAction.java 2008-01-22 15:15:22 UTC (rev 416) @@ -107,7 +107,7 @@ StorageService service; service = getTab() == SimExplorerTab.local ? SimExplorer.getStorageService() : SimExplorer.getRemoteStorageService(); MetaDataEntity[] data; - data = service.findApplications(onlyLatest, (int) newFirstIndex, width, rowOrder); + data = service.findApplications(null, onlyLatest, (int) newFirstIndex, width, rowOrder); return data; } Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowLocalTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowLocalTabAction.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowLocalTabAction.java 2008-01-22 15:15:22 UTC (rev 416) @@ -76,7 +76,7 @@ if (data == null) { // first local query, build model - long size = SimExplorer.getStorageService().findApplicationsCount(false); + long size = SimExplorer.getStorageService().findApplicationsCount(null, false); // init pagination PaginationModel paginationModel = new PaginationModel(); Modified: trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowRemoteTabAction.java =================================================================== --- trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowRemoteTabAction.java 2008-01-22 14:12:45 UTC (rev 415) +++ trunk/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/action/tab/ShowRemoteTabAction.java 2008-01-22 15:15:22 UTC (rev 416) @@ -75,7 +75,7 @@ if (data == null) { // first local query, build model - long size = SimExplorer.getRemoteStorageService().findApplicationsCount(false); + long size = SimExplorer.getRemoteStorageService().findApplicationsCount(null, false); // init pagination PaginationModel paginationModel = new PaginationModel();
participants (1)
-
glandais@users.labs.libre-entreprise.org