r104 - in trunk/simexplorer-is-service: . .settings src src/main src/main/java src/main/java/META-INF src/main/java/fr src/main/java/fr/cemagref src/main/java/fr/cemagref/simexplorer src/main/java/fr/cemagref/simexplorer/is src/main/java/fr/cemagref/simexplorer/is/service src/test src/test/java src/test/java/fr src/test/java/fr/cemagref src/test/java/fr/cemagref/simexplorer src/test/java/fr/cemagref/simexplorer/is src/test/java/fr/cemagref/simexplorer/is/service src/test/java/fr/cem
Author: glandais Date: 2008-01-09 14:11:23 +0000 (Wed, 09 Jan 2008) New Revision: 104 Added: trunk/simexplorer-is-service/.classpath trunk/simexplorer-is-service/.project trunk/simexplorer-is-service/.settings/ trunk/simexplorer-is-service/.settings/org.eclipse.jdt.core.prefs trunk/simexplorer-is-service/.settings/org.eclipse.jst.common.project.facet.core.prefs trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.component trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.project.facet.core.xml trunk/simexplorer-is-service/.settings/org.eclipse.wst.validation.prefs trunk/simexplorer-is-service/pom.xml trunk/simexplorer-is-service/src/ trunk/simexplorer-is-service/src/main/ trunk/simexplorer-is-service/src/main/java/ trunk/simexplorer-is-service/src/main/java/META-INF/ trunk/simexplorer-is-service/src/main/java/META-INF/MANIFEST.MF trunk/simexplorer-is-service/src/main/java/fr/ trunk/simexplorer-is-service/src/main/java/fr/cemagref/ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageService.java trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java trunk/simexplorer-is-service/src/test/ trunk/simexplorer-is-service/src/test/java/ trunk/simexplorer-is-service/src/test/java/fr/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/ElementGenerator.java trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java Log: Service split Added: trunk/simexplorer-is-service/.classpath =================================================================== --- trunk/simexplorer-is-service/.classpath (rev 0) +++ trunk/simexplorer-is-service/.classpath 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER/noworkspace"/> + <classpathentry kind="src" path="src/main/java"/> + <classpathentry kind="src" path="src/test/java"/> + <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/java-6-sun-1.6.0.03"/> + <classpathentry kind="lib" path="/home/glandais/dev/tools/jboss-4.2.2.GA/client/jboss-annotations-ejb3.jar"/> + <classpathentry kind="output" path="target/classes"/> +</classpath> Added: trunk/simexplorer-is-service/.project =================================================================== --- trunk/simexplorer-is-service/.project (rev 0) +++ trunk/simexplorer-is-service/.project 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,36 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>simexplorer-is-service</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.maven.ide.eclipse.maven2Builder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.wst.common.project.facet.core.builder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.wst.validation.validationbuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + <nature>org.maven.ide.eclipse.maven2Nature</nature> + <nature>org.eclipse.wst.common.project.facet.core.nature</nature> + <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature> + <nature>org.eclipse.jem.workbench.JavaEMFNature</nature> + </natures> +</projectDescription> Added: trunk/simexplorer-is-service/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/simexplorer-is-service/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/simexplorer-is-service/.settings/org.eclipse.jdt.core.prefs 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,7 @@ +#Tue Jan 08 14:35:19 CET 2008 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 Added: trunk/simexplorer-is-service/.settings/org.eclipse.jst.common.project.facet.core.prefs =================================================================== --- trunk/simexplorer-is-service/.settings/org.eclipse.jst.common.project.facet.core.prefs (rev 0) +++ trunk/simexplorer-is-service/.settings/org.eclipse.jst.common.project.facet.core.prefs 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,4 @@ +#Wed Jan 09 10:45:48 CET 2008 +classpath.helper/org.eclipse.jdt.launching.JRE_CONTAINER\:\:org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType\:\:java-6-sun-1.6.0.03/owners=jst.java\:6.0 +classpath.helper/org.jboss.ide.eclipse.as.classpath.core.runtime.ProjectRuntimeInitializer\:\:JBoss\ 4.2\ Runtime/owners=jst.ejb\:3.0 +eclipse.preferences.version=1 Added: trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.component =================================================================== --- trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.component (rev 0) +++ trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.component 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project-modules id="moduleCoreId" project-version="1.5.0"> + <wb-module deploy-name="simexplorer-is-service"> + <wb-resource deploy-path="/" source-path="/src/main/java"/> + <wb-resource deploy-path="/" source-path="/src/test/java"/> + <property name="java-output-path" value="build/classes"/> + </wb-module> +</project-modules> Added: trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.project.facet.core.xml =================================================================== --- trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.project.facet.core.xml (rev 0) +++ trunk/simexplorer-is-service/.settings/org.eclipse.wst.common.project.facet.core.xml 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<faceted-project> + <runtime name="JBoss 4.2 Runtime"/> + <fixed facet="jst.java"/> + <fixed facet="jst.ejb"/> + <installed facet="jst.java" version="6.0"/> + <installed facet="jst.ejb" version="3.0"/> +</faceted-project> Added: trunk/simexplorer-is-service/.settings/org.eclipse.wst.validation.prefs =================================================================== --- trunk/simexplorer-is-service/.settings/org.eclipse.wst.validation.prefs (rev 0) +++ trunk/simexplorer-is-service/.settings/org.eclipse.wst.validation.prefs 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,6 @@ +#Wed Jan 09 10:19:58 CET 2008 +DELEGATES_PREFERENCE=delegateValidatorListorg.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator\=org.eclipse.wst.xsd.core.internal.validation.eclipse.Validator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator\=org.eclipse.wst.wsdl.validation.internal.eclipse.Validator; +USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.jsp.core.internal.validation.JSPContentValidator;org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsf.validation.internal.JSPSemanticsValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator; +USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.jsp.core.internal.validation.JSPContentValidator;org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator;org.eclipse.wst.common.componentcore.internal.ModuleCoreValidator;org.eclipse.wst.wsi.ui.internal.WSIMessageValidator;org.eclipse.wst.wsdl.validation.internal.eclipse.WSDLDelegatingValidator;org.eclipse.jst.jsp.core.internal.validation.JSPBatchValidator;org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;org.eclipse.wst.xsd.core.internal.validation.eclipse.XSDDelegatingValidator;org.eclipse.jst.jsf.validation.internal.JSPSemanticsValidator;org.eclipse.wst.dtd.core.internal.validation.eclipse.Validator;org.eclipse.wst.html.internal.validation.HTMLValidator;org.eclipse.jst.jsf.validation.internal.appconfig.AppConfigValidator; +USER_PREFERENCE=overrideGlobalPreferencesfalse +eclipse.preferences.version=1 Added: trunk/simexplorer-is-service/pom.xml =================================================================== --- trunk/simexplorer-is-service/pom.xml (rev 0) +++ trunk/simexplorer-is-service/pom.xml 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,53 @@ +<?xml version="1.0" encoding="UTF-8"?><project> + <modelVersion>4.0.0</modelVersion> + <groupId>simexplorer-is</groupId> + <artifactId>simexplorer-is-service</artifactId> + <version>0.0.1-SNAPSHOT</version> + <description></description> + <build> + <plugins> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <skip>true</skip> + </configuration> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <version>5.1</version> + <classifier>jdk15</classifier> + <scope>test</scope> + </dependency> + <dependency> + <groupId>simexplorer-is</groupId> + <artifactId>simexplorer-is-entities</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>simexplorer-is</groupId> + <artifactId>simexplorer-is-storage</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> + <dependency> + <groupId>com.healthmarketscience.rmiio</groupId> + <artifactId>rmiio</artifactId> + <version>2.0.0</version> + </dependency> + <dependency> + <groupId>jboss</groupId> + <artifactId>jboss-ejb3x</artifactId> + <version>4.2.2.GA</version> + </dependency> + </dependencies> +</project> \ No newline at end of file Added: trunk/simexplorer-is-service/src/main/java/META-INF/MANIFEST.MF =================================================================== --- trunk/simexplorer-is-service/src/main/java/META-INF/MANIFEST.MF (rev 0) +++ trunk/simexplorer-is-service/src/main/java/META-INF/MANIFEST.MF 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: simexplorer-is-entities.jar simexplorer-is-service.jar simexplorer-is-storage.jar + Added: trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageService.java =================================================================== --- trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageService.java (rev 0) +++ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageService.java 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,157 @@ +package fr.cemagref.simexplorer.is.service; + +import java.util.Map; + +import javax.ejb.Remote; + +import com.healthmarketscience.rmiio.RemoteInputStream; +import com.healthmarketscience.rmiio.RemoteOutputStream; + +import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; + +/** + * Service interface + * + * @author glandais + * + */ + at Remote +public interface StorageService { + + /** + * Open storage + * + * @throws Exception + */ + void open() throws Exception; + + /** + * Close storage + * + * @throws Exception + */ + void close() throws Exception; + + /** + * Commit in storage + * + * @throws Exception + */ + void commit() throws Exception; + + /** + * Save a remote element + * + * @param zipRemoteStream + * RIIO stream containing data inside a zip + * @return Metadata of element imported + * @throws Exception + */ + MetaDataEntity saveElement(RemoteInputStream zipRemoteStream) + throws Exception; + + /** + * Save a remote element + * + * @param xmlRemoteStream + * RIIO stream containing XML Stream + * @param attachmentsRemoteStream + * RIIO stream containing attached data. Key matches metadata + * attachment keys + * @return Metadata of element saved + * @throws Exception + */ + MetaDataEntity saveElement(RemoteInputStream xmlRemoteStream, + Map<String, RemoteInputStream> attachmentsRemoteStream) + throws Exception; + + /** + * Retrieve metadata (latest version) + * + * @param uuid + * @return + * @throws Exception + */ + MetaDataEntity getMetadata(String uuid) throws Exception; + + /** + * Retrieve metadata + * + * @param uuid + * @param version + * @return + * @throws Exception + */ + MetaDataEntity getMetadata(String uuid, String version) throws Exception; + + /** + * Export element to a remote stream + * + * @param xmlOutputStream + * RMIIO stream where to save data + * @param uuid + * @param version + * @throws Exception + */ + void exportElement(RemoteOutputStream xmlOutputStream, String uuid, + String version) throws Exception; + + /** + * Retrieve number of elements matching query + * + * @param query + * @param onlyLatest + * @return + * @throws Exception + */ + int findFullTextCount(String query, boolean onlyLatest) throws Exception; + + /** + * Find elements matching query + * + * @param query + * @param onlyLatest + * @param indexStart + * @param count + * @param dateOrder + * @return + * @throws Exception + */ + MetaDataEntity[] findFullText(String query, boolean onlyLatest, + int indexStart, int count, int dateOrder) throws Exception; + + /** + * Retrieve number of applications + * + * @param onlyLatest + * @return + * @throws Exception + */ + int findApplicationsCount(boolean onlyLatest) throws Exception; + + /** + * Get a list of applications + * + * @param onlyLatest + * @param start + * @param count + * @param dateOrder + * @return + * @throws Exception + */ + MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count, + int dateOrder) throws Exception; + + /** + * Fully load an exploration application + * + * @param uuid + * @param version + * @return + * @throws Exception + */ + ExplorationApplication getExplorationApplication(String uuid, String version) + throws Exception; + +} Added: trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java =================================================================== --- trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java (rev 0) +++ trunk/simexplorer-is-service/src/main/java/fr/cemagref/simexplorer/is/service/StorageServiceImpl.java 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,325 @@ +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.ExplorationApplication; +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; + + at Stateless(name = "StorageService") + at Remote(StorageService.class) + at RemoteBinding(jndiBinding = "StorageService") +public class StorageServiceImpl implements StorageService, XmlConstants { + + private StorageEngine storageEngine = null; + + private static final String KEY_XML = "_xml"; + + public StorageServiceImpl() { + super(); + storageEngine = new StorageEngine(); + } + + public void open() throws Exception { + storageEngine.open(); + } + + public void close() throws Exception { + storageEngine.close(); + } + + public void commit() throws Exception { + storageEngine.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 storageEngine.getMetadata(uuid); + } + + public MetaDataEntity getMetadata(String uuid, String version) + throws Exception { + return storageEngine.getMetadata(uuid, new Version(version)); + } + + public MetaDataEntity[] findFullText(String query, boolean onlyLatest, + int indexStart, int count, int dateOrder) throws Exception { + return storageEngine.findFullText(query, onlyLatest, indexStart, count, + dateOrder); + } + + public int findFullTextCount(String query, boolean onlyLatest) + throws Exception { + return storageEngine.findFullTextCount(query, onlyLatest); + } + + public int findApplicationsCount(boolean onlyLatest) throws Exception { + return storageEngine.findElementsByTypeCount( + VALUE_METADATA_TYPE_EA, onlyLatest); + } + + public MetaDataEntity[] findApplications(boolean onlyLatest, int start, + int count, int dateOrder) throws Exception { + return storageEngine.findElementsByType(VALUE_METADATA_TYPE_EA, + onlyLatest, start, count, dateOrder); + } + + public ExplorationApplication getExplorationApplication(String uuid, + String version) throws Exception { + MetaDataEntity mde = getMetadata(uuid, version); + ExplorationApplication ea = (ExplorationApplication) BaseEntityFactory + .getFactory(ExplorationApplication.class).loadElement( + storageEngine.retrieveData(mde, KEY_XML)); + return ea; + } + + 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 = 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(xmlFile, attachments); + } + + public MetaDataEntity saveElement(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(idxml, idsattachment); + } + + public void exportElement(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 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(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, 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(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 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); + } + + } + +} Added: trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/ElementGenerator.java =================================================================== --- trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/ElementGenerator.java (rev 0) +++ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/ElementGenerator.java 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,153 @@ +package fr.cemagref.simexplorer.is.service.test; + +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Random; +import java.util.Set; +import java.util.UUID; + +import fr.cemagref.simexplorer.is.entities.data.Code; +import fr.cemagref.simexplorer.is.entities.data.Component; +import fr.cemagref.simexplorer.is.entities.data.Constant; +import fr.cemagref.simexplorer.is.entities.data.ConstantValue; +import fr.cemagref.simexplorer.is.entities.data.DataEntity; +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.data.Result; +import fr.cemagref.simexplorer.is.entities.data.Structure; +import fr.cemagref.simexplorer.is.entities.metadata.MetaDataEntity; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.factories.BaseEntityFactory; + +public class ElementGenerator { + + private Random r = new Random(); + + private String shortString() { + return Long.toHexString(r.nextLong()); + } + + private String longString() { + return UUID.randomUUID().toString(); + } + + private void update(LoggableElement element) throws Exception { + MetaDataEntity metaData = new MetaDataEntity(); + metaData.setUuid(shortString()); + metaData.setName(longString()); + metaData.setType(element.getClass().getSimpleName()); + metaData.setDescription("test"); + Version v = new Version("0"); + int c = 2 + r.nextInt(2); + for (int i = 0; i < c; i++) { + v.setVersion(i, r.nextInt(5)); + } + metaData.setVersion(v.toString()); + metaData.setCreationDate(new Date()); + metaData.setHash(shortString()); + metaData.setLatest(true); + + Map<String, String> descriptors = new HashMap<String, String>(); + int i = 5 + r.nextInt(10); + for (int j = 0; j < i; j++) { + descriptors.put(Integer.toString(j), shortString()); + } + metaData.setDescriptors(descriptors); + + element.setMetaData(metaData); + } + + private <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 = (T) BaseEntityFactory.getFactory(clazz) + .createInstance(); + if (element instanceof LoggableElement) { + update((LoggableElement) element); + } + elements.add(element); + } + return elements; + } + + public ExplorationApplication generateRandomEA() throws Exception { + ExplorationApplication ea = new ExplorationApplication(); + update(ea); + Set<ExplorationData> datas = generateArray(ExplorationData.class); + for (ExplorationData object : datas) { + processExplorationData(object); + } + ea.setExplorations(datas); + Set<Component> components = generateArray(Component.class); + for (Component object : components) { + processComponent(object); + } + ea.setComponents(components); + return ea; + } + + private void processComponent(Component component) throws Exception { + Set<Constant> constants = generateArray(Constant.class); + for (Constant constant : constants) { + processConstant(constant); + } + component.setConstants(constants); + + component.setStructures(new HashSet<Structure>()); + + Set<Code> codes = generateArray(Code.class); + for (Code code : codes) { + processCode(code); + } + component.setCodes(codes); + + Set<Library> libraries = generateArray(Library.class); + for (Library library : libraries) { + processLibrary(library); + } + component.setLibraries(libraries); + + } + + private void processLibrary(Library library) { + } + + private void processCode(Code code) { + code.setCode(shortString()); + code.setLanguage(shortString()); + } + + private void processConstant(Constant constant) { + constant.setName(shortString()); + constant.setType(String.class); + } + + private void processExplorationData(ExplorationData explorationData) + throws Exception { + Result result = new Result(); + explorationData.setResult(result); + + Set<ConstantValue> constantValues = generateArray(ConstantValue.class); + for (ConstantValue constantValue : constantValues) { + processConstantValue(constantValue); + } + explorationData.setValuesMap(constantValues); + + } + + private void processConstantValue(ConstantValue constantValue) { + Constant constant = new Constant(); + constant.setName(shortString()); + constant.setType(Integer.class); + + constantValue.setConstant(constant); + constantValue.setValue(Integer.toString(r.nextInt())); + } + +} Added: trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java =================================================================== --- trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java (rev 0) +++ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceMassInsert.java 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,83 @@ +package fr.cemagref.simexplorer.is.service.test; + +import java.io.InputStream; +import java.util.Date; +import java.util.HashMap; + +import junit.framework.TestCase; +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; + +public class StorageServiceMassInsert extends TestCase { + + private StorageServiceImpl storageService; + private ElementGenerator elementGenerator; + + protected void setUp() throws Exception { + super.setUp(); + elementGenerator = new ElementGenerator(); + + storageService = new StorageServiceImpl(); + storageService.open(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + storageService.close(); + } + + /* + public void testExportXML() throws Exception { + ExplorationApplication ea = elementGenerator.generateRandomEA(); + InputStream xmlStream = BaseEntityFactory.getFactory( + ExplorationApplication.class).saveElement(ea); + + FileOutputStream os = new FileOutputStream( + "/var/local/simexplorer/test.xml"); + + // 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(); + } + */ + + public void testMassInsert() throws Exception { + int c = 350; + + Date begin = new Date(); + + ExplorationApplication ea = null; + for (int i = 0; i < c; i++) { + ea = elementGenerator.generateRandomEA(); + InputStream xmlStream = BaseEntityFactory.getFactory( + ExplorationApplication.class).saveElement( + XmlConstants.VALUE_METADATA_TYPE_EA, ea); + + storageService.saveElement(xmlStream, + new HashMap<String, InputStream>()); + + if (i > 0 && i % 100 == 0) { + Date end = new Date(); + long time = end.getTime() - begin.getTime(); + System.out.println("Insert " + i + " : Time taken : " + time + + "ms"); + double timePerElement = time / i; + System.out.println("Insert " + i + + " : Time taken per element : " + timePerElement + + "ms"); + } + + } + } + +} Added: trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java =================================================================== --- trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java (rev 0) +++ trunk/simexplorer-is-service/src/test/java/fr/cemagref/simexplorer/is/service/test/StorageServiceTest.java 2008-01-09 14:11:23 UTC (rev 104) @@ -0,0 +1,126 @@ +package fr.cemagref.simexplorer.is.service.test; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.UUID; + +import junit.framework.TestCase; + +import com.healthmarketscience.rmiio.RemoteInputStream; +import com.healthmarketscience.rmiio.RemoteInputStreamServer; +import com.healthmarketscience.rmiio.SimpleRemoteInputStream; + +import fr.cemagref.simexplorer.is.service.StorageService; +import fr.cemagref.simexplorer.is.service.StorageServiceImpl; + +public class StorageServiceTest extends TestCase { + + private StorageService storageService; + private Random r = new Random(); + + protected void setUp() throws Exception { + super.setUp(); + + storageService = new StorageServiceImpl(); + storageService.open(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + storageService.close(); + } + + 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 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>"); + + InputStream xmlStream = new ByteArrayInputStream(xmlString.toString() + .getBytes()); + RemoteInputStreamServer xmlRemoteStream = new SimpleRemoteInputStream( + xmlStream); + + Map<String, RemoteInputStream> attachmentsRemoteStream = new HashMap<String, RemoteInputStream>(); + + 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(" "); + } + + 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); + } + } + +}
participants (1)
-
glandais@users.labs.libre-entreprise.org