r1414 - in trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service: . random
Author: glandais Date: 2008-03-20 14:21:56 +0000 (Thu, 20 Mar 2008) New Revision: 1414 Added: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java Removed: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java Log: Will contain element generators Deleted: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java 2008-03-20 14:19:27 UTC (rev 1413) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java 2008-03-20 14:21:56 UTC (rev 1414) @@ -1,156 +0,0 @@ -package fr.cemagref.simexplorer.is.service; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Random; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import com.healthmarketscience.rmiio.SerializableInputStream; - -import fr.cemagref.simexplorer.is.entities.attachment.Attachment; -import fr.cemagref.simexplorer.is.entities.data.Code; -import fr.cemagref.simexplorer.is.entities.data.Component; -import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.MetaData; -import fr.cemagref.simexplorer.is.factories.LoggableElementFactory; -import fr.cemagref.simexplorer.is.storage.ElementGenerator; -import fr.cemagref.simexplorer.is.storage.VersionGenerator; -import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream; - -/** - * The Class StorageServiceGenerator. Aimed to generate random elements for a service. - */ -public class StorageServiceGenerator { - - /** The Constant log. */ - private static final Log log = LogFactory.getLog(StorageServiceGenerator.class); - - /** The element generator. */ - private static ElementGenerator elementGenerator = new ElementGenerator(); - - /** - * Save ea. - * - * @param ea - * the ea - * @param computeAttachments - * the compute attachments - * - * @return the meta data - * - * @throws Exception - * the exception - */ - private LoggableElement saveEa(StorageService storageService, String token, ExplorationApplication ea, - boolean computeAttachments, Map<Attachment, ElementGenerator.RandomStream> attachments) throws Exception { - - if (computeAttachments) { - List<Attachment> attachmentsKeys = new ArrayList<Attachment>(); - - attachmentsKeys.addAll(ea.getAttachments()); - List<LoggableElement> children = ea.getLEChildren(); - for (LoggableElement child : children) { - attachmentsKeys.addAll(child.getAttachments()); - } - - for (Attachment attachment : attachmentsKeys) { - RandomStream randomStream = elementGenerator.generateTextStream(); - attachment.setDataHash(randomStream.getMd5()); - attachments.put(attachment, randomStream); - } - } - - SerializableInputStream xmlStream = new SerializableInputStream(LoggableElementFactory.getStream(ea)); - - Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>(); - for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) { - realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream())); - } - - return storageService.saveElement(token, xmlStream, realAttachments); - } - - /** - * Test version update. - * - * @param firstVersion - * the first version - * @param secondVersion - * the second version - * @param different - * the different - * @param versions - * the versions - * - * @return the string - * - * @throws Exception - * the exception - */ - public String generateTwoExplorationApplications(StorageService storageService, String token, String firstVersion, - String secondVersion, boolean different) throws Exception { - log.info("-----------------------------"); - - ExplorationApplication ea; - - Map<Attachment, ElementGenerator.RandomStream> attachments = new HashMap<Attachment, RandomStream>(); - - ea = elementGenerator.generateRandomEA(); - - StringBuffer task = new StringBuffer(); - task.append(firstVersion).append("A + ").append(secondVersion); - if (different) { - task.append("B"); - } else { - task.append("A"); - } - - log.info(task.toString()); - - log.info("UUID : " + ea.getMetaData().getUuid()); - log.info("Name : " + ea.getMetaData().getName()); - - ea.getMetaData().setVersion(firstVersion); - - log.info("Saving " + firstVersion + "A"); - LoggableElement le1 = saveEa(storageService, token, ea, true, attachments); - - ea.getMetaData().setVersion(secondVersion); - - if (different) { - Component component = ea.getComponents().iterator().next(); - Code code = new Code(); - code.setCode("regreg"); - code.setLanguage("regreg"); - component.getCodes().add(code); - } - - if (different) { - log.info("Saving " + secondVersion + "B"); - } else { - log.info("Saving " + secondVersion + "A"); - } - LoggableElement le2 = saveEa(storageService, token, ea, false, attachments); - - log.info("A : " + le1.getMetaData().getHash()); - if (different) { - log.info("B : " + le2.getMetaData().getHash()); - } - - return ea.getMetaData().getUuid(); - } - - public void generateLotsExplorationApplication(StorageService storageService, String token, int c) throws Exception { - Random r = new Random(); - for (int i = 0; i < c; i++) { - generateTwoExplorationApplications(storageService, token, VersionGenerator.getInstance().generateVersion().toString(), - VersionGenerator.getInstance().generateVersion().toString(), r.nextBoolean()); - } - } - -} Copied: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java (from rev 1413, trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/StorageServiceGenerator.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java 2008-03-20 14:21:56 UTC (rev 1414) @@ -0,0 +1,156 @@ +package fr.cemagref.simexplorer.is.service; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Random; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import com.healthmarketscience.rmiio.SerializableInputStream; + +import fr.cemagref.simexplorer.is.entities.attachment.Attachment; +import fr.cemagref.simexplorer.is.entities.data.Code; +import fr.cemagref.simexplorer.is.entities.data.Component; +import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication; +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.MetaData; +import fr.cemagref.simexplorer.is.factories.LoggableElementFactory; +import fr.cemagref.simexplorer.is.storage.ElementGenerator; +import fr.cemagref.simexplorer.is.storage.VersionGenerator; +import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream; + +/** + * The Class StorageServiceGenerator. Aimed to generate random elements for a service. + */ +public class StorageServiceGenerator { + + /** The Constant log. */ + private static final Log log = LogFactory.getLog(StorageServiceGenerator.class); + + /** The element generator. */ + private static ElementGenerator elementGenerator = new ElementGenerator(); + + /** + * Save ea. + * + * @param ea + * the ea + * @param computeAttachments + * the compute attachments + * + * @return the meta data + * + * @throws Exception + * the exception + */ + private LoggableElement saveEa(StorageService storageService, String token, ExplorationApplication ea, + boolean computeAttachments, Map<Attachment, ElementGenerator.RandomStream> attachments) throws Exception { + + if (computeAttachments) { + List<Attachment> attachmentsKeys = new ArrayList<Attachment>(); + + attachmentsKeys.addAll(ea.getAttachments()); + List<LoggableElement> children = ea.getLEChildren(); + for (LoggableElement child : children) { + attachmentsKeys.addAll(child.getAttachments()); + } + + for (Attachment attachment : attachmentsKeys) { + RandomStream randomStream = elementGenerator.generateTextStream(); + attachment.setDataHash(randomStream.getMd5()); + attachments.put(attachment, randomStream); + } + } + + SerializableInputStream xmlStream = new SerializableInputStream(LoggableElementFactory.getStream(ea)); + + Map<Attachment, SerializableInputStream> realAttachments = new HashMap<Attachment, SerializableInputStream>(); + for (Map.Entry<Attachment, ElementGenerator.RandomStream> element : attachments.entrySet()) { + realAttachments.put(element.getKey(), new SerializableInputStream(element.getValue().getStream())); + } + + return storageService.saveElement(token, xmlStream, realAttachments); + } + + /** + * Test version update. + * + * @param firstVersion + * the first version + * @param secondVersion + * the second version + * @param different + * the different + * @param versions + * the versions + * + * @return the string + * + * @throws Exception + * the exception + */ + public String generateTwoExplorationApplications(StorageService storageService, String token, String firstVersion, + String secondVersion, boolean different) throws Exception { + log.info("-----------------------------"); + + ExplorationApplication ea; + + Map<Attachment, ElementGenerator.RandomStream> attachments = new HashMap<Attachment, RandomStream>(); + + ea = elementGenerator.generateRandomEA(); + + StringBuffer task = new StringBuffer(); + task.append(firstVersion).append("A + ").append(secondVersion); + if (different) { + task.append("B"); + } else { + task.append("A"); + } + + log.info(task.toString()); + + log.info("UUID : " + ea.getMetaData().getUuid()); + log.info("Name : " + ea.getMetaData().getName()); + + ea.getMetaData().setVersion(firstVersion); + + log.info("Saving " + firstVersion + "A"); + LoggableElement le1 = saveEa(storageService, token, ea, true, attachments); + + ea.getMetaData().setVersion(secondVersion); + + if (different) { + Component component = ea.getComponents().iterator().next(); + Code code = new Code(); + code.setCode("regreg"); + code.setLanguage("regreg"); + component.getCodes().add(code); + } + + if (different) { + log.info("Saving " + secondVersion + "B"); + } else { + log.info("Saving " + secondVersion + "A"); + } + LoggableElement le2 = saveEa(storageService, token, ea, false, attachments); + + log.info("A : " + le1.getMetaData().getHash()); + if (different) { + log.info("B : " + le2.getMetaData().getHash()); + } + + return ea.getMetaData().getUuid(); + } + + public void generateLotsExplorationApplication(StorageService storageService, String token, int c) throws Exception { + Random r = new Random(); + for (int i = 0; i < c; i++) { + generateTwoExplorationApplications(storageService, token, VersionGenerator.getInstance().generateVersion().toString(), + VersionGenerator.getInstance().generateVersion().toString(), r.nextBoolean()); + } + } + +}
participants (1)
-
glandais@users.labs.libre-entreprise.org