Simexplorer-si-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
March 2008
- 2 participants
- 198 discussions
r1423 - trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 16:38:10 +0000 (Thu, 20 Mar 2008)
New Revision: 1423
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
Log:
canWrite => canRead
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-20 16:37:13 UTC (rev 1422)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/dao/DaoPermissionImpl.java 2008-03-20 16:38:10 UTC (rev 1423)
@@ -134,8 +134,8 @@
@Override
public List<String> getBusinessIdsVisibleBy(Collection<Actor> actors) {
StringBuffer query = new StringBuffer();
- query.append("select p.businessId from Permission p").append(
- " where (p.canRead = true or p.canAdmin = true or p.isOwner = true)").append(
+ query.append("select distinct p.businessId from Permission p").append(
+ " where (p.canRead = true or p.canWrite = true or p.canAdmin = true or p.isOwner = true)").append(
" and p.actor in (:actors)");
List<String> businessIds = CollectionUtil.toGenericList(em.createQuery(query.toString()).setParameter("actors",
actors).getResultList(), String.class);
1
0
r1422 - trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 16:37:13 +0000 (Thu, 20 Mar 2008)
New Revision: 1422
Modified:
trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
Log:
Permission rules
Modified: trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-20 16:36:31 UTC (rev 1421)
+++ trunk/simexplorer-is/simexplorer-is-security/src/java/fr/cemagref/simexplorer/is/security/credentials/CredentialManagerImpl.java 2008-03-20 16:37:13 UTC (rev 1422)
@@ -96,14 +96,26 @@
if (user.isSuperAdmin()) {
p = new Permission();
p.setOwner(true);
+ p.setCanAdmin(true);
+ p.setCanRead(true);
+ p.setCanWrite(true);
} else {
p = new Permission();
- p.setOwner(false);
- p.setCanAdmin(false);
- p.setCanRead(false);
- p.setCanWrite(false);
List<Permission> permissions = daoPermission.getPermissions(businessId);
+
+ if (permissions.size() == 0) {
+ p.setOwner(true);
+ p.setCanAdmin(true);
+ p.setCanRead(true);
+ p.setCanWrite(true);
+ } else {
+ p.setOwner(false);
+ p.setCanAdmin(false);
+ p.setCanRead(false);
+ p.setCanWrite(false);
+ }
+
for (Permission permission : permissions) {
boolean appliesTo = appliesTo(user, permission.getActor());
if (appliesTo) {
@@ -113,12 +125,19 @@
p.setCanWrite(p.isCanWrite() || permission.isCanWrite());
}
}
- }
- if (p.isOwner()) {
- p.setCanAdmin(true);
- p.setCanRead(true);
- p.setCanWrite(true);
+ if (p.isCanWrite()) {
+ p.setCanRead(true);
+ }
+ if (p.isCanAdmin()) {
+ p.setCanRead(true);
+ p.setCanWrite(true);
+ }
+ if (p.isOwner()) {
+ p.setCanAdmin(true);
+ p.setCanRead(true);
+ p.setCanWrite(true);
+ }
}
return p;
1
0
r1421 - trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 16:36:31 +0000 (Thu, 20 Mar 2008)
New Revision: 1421
Modified:
trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
Log:
hashCode and equals for tests
Modified: trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-20 14:34:47 UTC (rev 1420)
+++ trunk/simexplorer-is/simexplorer-is-entities/src/java/fr/cemagref/simexplorer/is/entities/metadata/MetaData.java 2008-03-20 16:36:31 UTC (rev 1421)
@@ -315,4 +315,86 @@
return getEntityType().getLibelle();
}
+ /* (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode());
+ result = prime * result + ((description == null) ? 0 : description.hashCode());
+ result = prime * result + ((elementClass == null) ? 0 : elementClass.hashCode());
+ result = prime * result + ((hash == null) ? 0 : hash.hashCode());
+ result = prime * result + (latest ? 1231 : 1237);
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((parentUuid == null) ? 0 : parentUuid.hashCode());
+ result = prime * result + ((parentVersion == null) ? 0 : parentVersion.hashCode());
+ result = prime * result + ((uuid == null) ? 0 : uuid.hashCode());
+ result = prime * result + ((version == null) ? 0 : version.hashCode());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final MetaData other = (MetaData) obj;
+ if (creationDate == null) {
+ if (other.creationDate != null)
+ return false;
+ } else if (!creationDate.equals(other.creationDate))
+ return false;
+ if (description == null) {
+ if (other.description != null)
+ return false;
+ } else if (!description.equals(other.description))
+ return false;
+ if (elementClass == null) {
+ if (other.elementClass != null)
+ return false;
+ } else if (!elementClass.equals(other.elementClass))
+ return false;
+ if (hash == null) {
+ if (other.hash != null)
+ return false;
+ } else if (!hash.equals(other.hash))
+ return false;
+ if (latest != other.latest)
+ return false;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ if (parentUuid == null) {
+ if (other.parentUuid != null)
+ return false;
+ } else if (!parentUuid.equals(other.parentUuid))
+ return false;
+ if (parentVersion == null) {
+ if (other.parentVersion != null)
+ return false;
+ } else if (!parentVersion.equals(other.parentVersion))
+ return false;
+ if (uuid == null) {
+ if (other.uuid != null)
+ return false;
+ } else if (!uuid.equals(other.uuid))
+ return false;
+ if (version == null) {
+ if (other.version != null)
+ return false;
+ } else if (!version.equals(other.version))
+ return false;
+ return true;
+ }
+
}
\ No newline at end of file
1
0
r1420 - trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:34:47 +0000 (Thu, 20 Mar 2008)
New Revision: 1420
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java
Log:
Generation update
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java 2008-03-20 14:34:04 UTC (rev 1419)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java 2008-03-20 14:34:47 UTC (rev 1420)
@@ -386,4 +386,18 @@
return rs;
}
+
+ /**
+ * Generate version.
+ *
+ * @return the version
+ */
+ public Version generateVersion() {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0, size = 1+r.nextInt(3); i < size; i++) {
+ sb.append('.').append(r.nextInt(20));
+ }
+ return Version.valueOf(sb.substring(1));
+ }
+
}
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java 2008-03-20 14:34:04 UTC (rev 1419)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java 2008-03-20 14:34:47 UTC (rev 1420)
@@ -19,7 +19,6 @@
import fr.cemagref.simexplorer.is.factories.LoggableElementFactory;
import fr.cemagref.simexplorer.is.service.StorageService;
import fr.cemagref.simexplorer.is.service.random.ElementGenerator.RandomStream;
-import fr.cemagref.simexplorer.is.storage.VersionGenerator;
/**
* The Class StorageServiceGenerator. Aimed to generate random elements for a service.
@@ -35,15 +34,15 @@
/**
* Save ea.
*
- * @param ea
- * the ea
- * @param computeAttachments
- * the compute attachments
+ * @param ea the ea
+ * @param computeAttachments the compute attachments
+ * @param storageService the storage service
+ * @param token the token
+ * @param attachments the attachments
*
* @return the meta data
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
private LoggableElement saveEa(StorageService storageService, String token, ExplorationApplication ea,
boolean computeAttachments, Map<Attachment, ElementGenerator.RandomStream> attachments) throws Exception {
@@ -77,19 +76,15 @@
/**
* Test version update.
*
- * @param firstVersion
- * the first version
- * @param secondVersion
- * the second version
- * @param different
- * the different
- * @param versions
- * the versions
+ * @param firstVersion the first version
+ * @param secondVersion the second version
+ * @param different the different
+ * @param storageService the storage service
+ * @param token the token
*
* @return the string
*
- * @throws Exception
- * the exception
+ * @throws Exception the exception
*/
public String generateTwoExplorationApplications(StorageService storageService, String token, String firstVersion,
String secondVersion, boolean different) throws Exception {
@@ -144,11 +139,20 @@
return ea.getMetaData().getUuid();
}
+ /**
+ * Generate lots exploration application.
+ *
+ * @param storageService the storage service
+ * @param token the token
+ * @param c the c
+ *
+ * @throws Exception the exception
+ */
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());
+ generateTwoExplorationApplications(storageService, token, elementGenerator.generateVersion().toString(),
+ elementGenerator.generateVersion().toString(), r.nextBoolean());
}
}
1
0
r1419 - in trunk/simexplorer-is/simexplorer-is-storage/src: java/fr/cemagref/simexplorer/is/storage test/fr/cemagref/simexplorer/is/storage
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:34:04 +0000 (Thu, 20 Mar 2008)
New Revision: 1419
Added:
trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java
Removed:
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java
Log:
Moving to test
Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:28:16 UTC (rev 1418)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:34:04 UTC (rev 1419)
@@ -1,162 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais, Tony Chemit
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.storage;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-
-/**
- * A Version generator.
- *
- * @author chemit
- */
-public class VersionGenerator {
-
- /** la taille maximum d'une version generée. */
- static final int MAX_SIZE = 5;
-
- /** la valeur maximum d'un numero de version a generer. */
- static final int MAX_VERSION_NUMBER = 10;
-
- /**
- * le nombre maximum de versions generees dans la methode
- * {@link #generateVersions()}.
- */
- static final int MAX_NB_VERSIONS = 20;
-
- /** instance statique partagee. */
- protected static VersionGenerator instance;
-
- /**
- * Gets the single instance of VersionGenerator.
- *
- * @return single instance of VersionGenerator
- */
- public static VersionGenerator getInstance() {
- if (instance == null) {
- instance = new VersionGenerator();
- }
- return instance;
- }
-
- /** The r. */
- protected Random r;
-
- /**
- * Generate version.
- *
- * @return the version
- */
- public Version generateVersion() {
- StringBuilder sb = new StringBuilder();
- for (int i = 0, size = generateNotNullAbsInt(MAX_SIZE); i < size; i++) {
- sb.append('.').append(generateAbsInt(MAX_VERSION_NUMBER));
- }
- return Version.valueOf(sb.substring(1));
- }
-
- /**
- * Generate versions.
- *
- * @return the version[]
- */
- public Version[] generateVersions() {
- int nb = generateNotNullAbsInt(MAX_NB_VERSIONS);
- return generateVersions(nb);
- }
-
- /**
- * Generate versions.
- *
- * @param mandatory
- * the mandatory
- *
- * @return the version[]
- */
- public Version[] generateVersions(Version mandatory) {
- int nb = generateNotNullAbsInt(MAX_NB_VERSIONS);
- Version[] versions = generateVersions(nb);
- List<Version> list = new ArrayList<Version>(Arrays.asList(versions));
- if (!list.contains(mandatory)) {
- list.add(mandatory);
- Collections.sort(list);
- }
- return list.toArray(new Version[list.size()]);
- }
-
- /**
- * Generate versions.
- *
- * @param nb
- * the nb
- *
- * @return the version[]
- */
- public Version[] generateVersions(int nb) {
- Version[] result = new Version[nb];
- result[0] = generateVersion();
- // System.out.println("nb versions :" + nb);
- // System.out.println("version 0 :" + result[0]);
- for (int i = 1; i < nb; i++) {
- result[i] = result[i - 1].incVersion(generateAbsInt(MAX_SIZE));
- // System.out.println("version " + i + " :" + result[i]);
- }
- return result;
- }
-
- /**
- * Generate abs int.
- *
- * @param max
- * the max
- *
- * @return the int
- */
- protected int generateAbsInt(int max) {
- return Math.abs(r.nextInt()) % max;
- }
-
- /**
- * Generate not null abs int.
- *
- * @param max
- * the max
- *
- * @return the int
- */
- protected int generateNotNullAbsInt(int max) {
- int nb = 0;
- while (nb == 0) {
- nb = generateAbsInt(max);
- }
- return nb;
- }
-
- /**
- * Instantiates a new version generator.
- */
- protected VersionGenerator() {
- this.r = new Random();
- }
-
-}
\ No newline at end of file
Copied: trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java (from rev 1418, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/VersionGenerator.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/VersionGenerator.java 2008-03-20 14:34:04 UTC (rev 1419)
@@ -0,0 +1,162 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais, Tony Chemit
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.storage;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Random;
+
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
+
+/**
+ * A Version generator.
+ *
+ * @author chemit
+ */
+public class VersionGenerator {
+
+ /** la taille maximum d'une version generée. */
+ static final int MAX_SIZE = 5;
+
+ /** la valeur maximum d'un numero de version a generer. */
+ static final int MAX_VERSION_NUMBER = 10;
+
+ /**
+ * le nombre maximum de versions generees dans la methode
+ * {@link #generateVersions()}.
+ */
+ static final int MAX_NB_VERSIONS = 20;
+
+ /** instance statique partagee. */
+ protected static VersionGenerator instance;
+
+ /**
+ * Gets the single instance of VersionGenerator.
+ *
+ * @return single instance of VersionGenerator
+ */
+ public static VersionGenerator getInstance() {
+ if (instance == null) {
+ instance = new VersionGenerator();
+ }
+ return instance;
+ }
+
+ /** The r. */
+ protected Random r;
+
+ /**
+ * Generate version.
+ *
+ * @return the version
+ */
+ public Version generateVersion() {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0, size = generateNotNullAbsInt(MAX_SIZE); i < size; i++) {
+ sb.append('.').append(generateAbsInt(MAX_VERSION_NUMBER));
+ }
+ return Version.valueOf(sb.substring(1));
+ }
+
+ /**
+ * Generate versions.
+ *
+ * @return the version[]
+ */
+ public Version[] generateVersions() {
+ int nb = generateNotNullAbsInt(MAX_NB_VERSIONS);
+ return generateVersions(nb);
+ }
+
+ /**
+ * Generate versions.
+ *
+ * @param mandatory
+ * the mandatory
+ *
+ * @return the version[]
+ */
+ public Version[] generateVersions(Version mandatory) {
+ int nb = generateNotNullAbsInt(MAX_NB_VERSIONS);
+ Version[] versions = generateVersions(nb);
+ List<Version> list = new ArrayList<Version>(Arrays.asList(versions));
+ if (!list.contains(mandatory)) {
+ list.add(mandatory);
+ Collections.sort(list);
+ }
+ return list.toArray(new Version[list.size()]);
+ }
+
+ /**
+ * Generate versions.
+ *
+ * @param nb
+ * the nb
+ *
+ * @return the version[]
+ */
+ public Version[] generateVersions(int nb) {
+ Version[] result = new Version[nb];
+ result[0] = generateVersion();
+ // System.out.println("nb versions :" + nb);
+ // System.out.println("version 0 :" + result[0]);
+ for (int i = 1; i < nb; i++) {
+ result[i] = result[i - 1].incVersion(generateAbsInt(MAX_SIZE));
+ // System.out.println("version " + i + " :" + result[i]);
+ }
+ return result;
+ }
+
+ /**
+ * Generate abs int.
+ *
+ * @param max
+ * the max
+ *
+ * @return the int
+ */
+ protected int generateAbsInt(int max) {
+ return Math.abs(r.nextInt()) % max;
+ }
+
+ /**
+ * Generate not null abs int.
+ *
+ * @param max
+ * the max
+ *
+ * @return the int
+ */
+ protected int generateNotNullAbsInt(int max) {
+ int nb = 0;
+ while (nb == 0) {
+ nb = generateAbsInt(max);
+ }
+ return nb;
+ }
+
+ /**
+ * Instantiates a new version generator.
+ */
+ protected VersionGenerator() {
+ this.r = new Random();
+ }
+
+}
\ No newline at end of file
1
0
r1418 - in trunk/simexplorer-is/simexplorer-is-storage/src: java/fr/cemagref/simexplorer/is/storage test/fr/cemagref/simexplorer/is/storage
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:28:16 +0000 (Thu, 20 Mar 2008)
New Revision: 1418
Added:
trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java
Removed:
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java
Log:
Moving to test
Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java 2008-03-20 14:25:53 UTC (rev 1417)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java 2008-03-20 14:28:16 UTC (rev 1418)
@@ -1,172 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.storage;
-
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-
-/**
- * The Class MetaDataGenerator.
- */
-public class MetaDataGenerator {
-
- /** The r. */
- java.util.Random r = new java.util.Random();
-
- /*
- * private static boolean descriptorFieldsInit = false; private static
- * String[] descriptorFields;
- *
- * private static void generateDescriptors() { descriptorFields = new
- * String[10]; for (int i = 0; i < descriptorFields.length; i++) {
- * descriptorFields[i] = "descriptor" + i; } }
- */
-
- /**
- * Generate meta data entity.
- *
- * @param uuid the uuid
- * @param version the version
- * @param parentVersion the parent version
- *
- * @return the meta data
- */
- public MetaData generateMetaDataEntity(String uuid, Version version, MetaData parentVersion) {
- MetaData me = generateMetaDataEntity(uuid, version);
-
- if (parentVersion != null) {
- me.setParentUuid(parentVersion.getUuid());
- me.setParentVersion(parentVersion.getVersion());
- parentVersion.setLatest(false);
- }
- me.setLatest(true);
-
- return me;
- }
-
- /**
- * Generate meta data entity.
- *
- * @param uuid the uuid
- * @param version the version
- *
- * @return the meta data
- */
- public MetaData generateMetaDataEntity(String uuid, Version version) {
- MetaData me = new MetaData();
-
- me.setUuid(uuid);
- me.setName(uuid);
- me.setElementClass(MetaData.class);
- me.setDescription(uuid + " " + version.toString());
- me.setVersion(version.toString());
- me.setLatest(true);
- me.setCreationDate(new Date());
- me.setHash(UUID.randomUUID().toString());
-
- Map<String, String> descriptors = new HashMap<String, String>();
- descriptors.put("overallId", uuid);
- int i = 5 + r.nextInt(10);
- for (int j = 0; j < i; j++) {
- descriptors.put("descriptor" + j, UUID.randomUUID().toString());
- }
- me.setParentUuid(null);
- me.setParentVersion((Version) null);
-
- return me;
- }
-
- /**
- * Generate meta data entity.
- *
- * @return the meta data
- */
- public MetaData generateMetaDataEntity() {
- return generateMetaDataEntity(UUID.randomUUID().toString(), Version.valueOf("1.0"));
- }
-
- /**
- * Generate versionned meta data entity.
- *
- * @return the meta data[]
- */
- public MetaData[] generateVersionnedMetaDataEntity() {
-
- Version[] versions = VersionGenerator.getInstance().generateVersions();
- String uuid = UUID.randomUUID().toString();
-
- int nb = versions.length;
- MetaData[] mes = new MetaData[nb];
-
- mes[0] = generateMetaDataEntity(uuid, versions[0]);
- for (int i = 1; i < nb; i++) {
- mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
- }
- return mes;
- }
-
- /**
- * Generate versionned meta data entity.
- *
- * @param nbMax the nb max
- *
- * @return the meta data[]
- */
- public MetaData[] generateVersionnedMetaDataEntity(int nbMax) {
-
- Version[] versions = VersionGenerator.getInstance().generateVersions(nbMax);
- String uuid = UUID.randomUUID().toString();
-
- int nb = versions.length;
- MetaData[] mes = new MetaData[nb];
-
- mes[0] = generateMetaDataEntity(uuid, versions[0]);
- for (int i = 1; i < nb; i++) {
- mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
- }
- return mes;
- }
-
- /**
- * Generate versionned meta data.
- *
- * @param mandatory the mandatory
- *
- * @return the meta data[]
- */
- public MetaData[] generateVersionnedMetaData(Version mandatory) {
-
- Version[] versions = VersionGenerator.getInstance().generateVersions(mandatory);
- String uuid = UUID.randomUUID().toString();
-
- int nb = versions.length;
- MetaData[] mes = new MetaData[nb];
-
- mes[0] = generateMetaDataEntity(uuid, versions[0]);
- for (int i = 1; i < nb; i++) {
- mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
- }
- return mes;
- }
-
-}
Copied: trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java (from rev 1417, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/test/fr/cemagref/simexplorer/is/storage/MetaDataGenerator.java 2008-03-20 14:28:16 UTC (rev 1418)
@@ -0,0 +1,172 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.storage;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
+
+/**
+ * The Class MetaDataGenerator.
+ */
+public class MetaDataGenerator {
+
+ /** The r. */
+ java.util.Random r = new java.util.Random();
+
+ /*
+ * private static boolean descriptorFieldsInit = false; private static
+ * String[] descriptorFields;
+ *
+ * private static void generateDescriptors() { descriptorFields = new
+ * String[10]; for (int i = 0; i < descriptorFields.length; i++) {
+ * descriptorFields[i] = "descriptor" + i; } }
+ */
+
+ /**
+ * Generate meta data entity.
+ *
+ * @param uuid the uuid
+ * @param version the version
+ * @param parentVersion the parent version
+ *
+ * @return the meta data
+ */
+ public MetaData generateMetaDataEntity(String uuid, Version version, MetaData parentVersion) {
+ MetaData me = generateMetaDataEntity(uuid, version);
+
+ if (parentVersion != null) {
+ me.setParentUuid(parentVersion.getUuid());
+ me.setParentVersion(parentVersion.getVersion());
+ parentVersion.setLatest(false);
+ }
+ me.setLatest(true);
+
+ return me;
+ }
+
+ /**
+ * Generate meta data entity.
+ *
+ * @param uuid the uuid
+ * @param version the version
+ *
+ * @return the meta data
+ */
+ public MetaData generateMetaDataEntity(String uuid, Version version) {
+ MetaData me = new MetaData();
+
+ me.setUuid(uuid);
+ me.setName(uuid);
+ me.setElementClass(MetaData.class);
+ me.setDescription(uuid + " " + version.toString());
+ me.setVersion(version.toString());
+ me.setLatest(true);
+ me.setCreationDate(new Date());
+ me.setHash(UUID.randomUUID().toString());
+
+ Map<String, String> descriptors = new HashMap<String, String>();
+ descriptors.put("overallId", uuid);
+ int i = 5 + r.nextInt(10);
+ for (int j = 0; j < i; j++) {
+ descriptors.put("descriptor" + j, UUID.randomUUID().toString());
+ }
+ me.setParentUuid(null);
+ me.setParentVersion((Version) null);
+
+ return me;
+ }
+
+ /**
+ * Generate meta data entity.
+ *
+ * @return the meta data
+ */
+ public MetaData generateMetaDataEntity() {
+ return generateMetaDataEntity(UUID.randomUUID().toString(), Version.valueOf("1.0"));
+ }
+
+ /**
+ * Generate versionned meta data entity.
+ *
+ * @return the meta data[]
+ */
+ public MetaData[] generateVersionnedMetaDataEntity() {
+
+ Version[] versions = VersionGenerator.getInstance().generateVersions();
+ String uuid = UUID.randomUUID().toString();
+
+ int nb = versions.length;
+ MetaData[] mes = new MetaData[nb];
+
+ mes[0] = generateMetaDataEntity(uuid, versions[0]);
+ for (int i = 1; i < nb; i++) {
+ mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
+ }
+ return mes;
+ }
+
+ /**
+ * Generate versionned meta data entity.
+ *
+ * @param nbMax the nb max
+ *
+ * @return the meta data[]
+ */
+ public MetaData[] generateVersionnedMetaDataEntity(int nbMax) {
+
+ Version[] versions = VersionGenerator.getInstance().generateVersions(nbMax);
+ String uuid = UUID.randomUUID().toString();
+
+ int nb = versions.length;
+ MetaData[] mes = new MetaData[nb];
+
+ mes[0] = generateMetaDataEntity(uuid, versions[0]);
+ for (int i = 1; i < nb; i++) {
+ mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
+ }
+ return mes;
+ }
+
+ /**
+ * Generate versionned meta data.
+ *
+ * @param mandatory the mandatory
+ *
+ * @return the meta data[]
+ */
+ public MetaData[] generateVersionnedMetaData(Version mandatory) {
+
+ Version[] versions = VersionGenerator.getInstance().generateVersions(mandatory);
+ String uuid = UUID.randomUUID().toString();
+
+ int nb = versions.length;
+ MetaData[] mes = new MetaData[nb];
+
+ mes[0] = generateMetaDataEntity(uuid, versions[0]);
+ for (int i = 1; i < nb; i++) {
+ mes[i] = generateMetaDataEntity(uuid, versions[i], mes[i - 1]);
+ }
+ return mes;
+ }
+
+}
1
0
r1417 - in trunk/simexplorer-is: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:25:53 +0000 (Thu, 20 Mar 2008)
New Revision: 1417
Modified:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java
trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java
trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/GenerateDataAction.java
trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/Install.java
Log:
Element generators moving
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
* ##% */
-package fr.cemagref.simexplorer.is.storage;
+package fr.cemagref.simexplorer.is.service.random;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
Modified: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/StorageServiceGenerator.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -1,4 +1,4 @@
-package fr.cemagref.simexplorer.is.service;
+package fr.cemagref.simexplorer.is.service.random;
import java.util.ArrayList;
import java.util.HashMap;
@@ -16,11 +16,10 @@
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.service.StorageService;
+import fr.cemagref.simexplorer.is.service.random.ElementGenerator.RandomStream;
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.
Modified: trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-service/src/test/fr/cemagref/simexplorer/is/service/StorageServiceVersionsTestCase.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -18,29 +18,17 @@
package fr.cemagref.simexplorer.is.service;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import junit.framework.TestCase;
import org.codelutin.util.ArrayUtil;
-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.entities.metadata.Version;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
-import fr.cemagref.simexplorer.is.factories.LoggableElementFactory;
-import fr.cemagref.simexplorer.is.storage.ElementGenerator;
-import fr.cemagref.simexplorer.is.storage.ElementGenerator.RandomStream;
+import fr.cemagref.simexplorer.is.service.random.StorageServiceGenerator;
/**
* The Class StorageServiceVersionsTestCase.
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -18,6 +18,9 @@
* ##% */
package fr.cemagref.simexplorer.is.ui.swing;
+import org.codelutin.i18n.I18n;
+import org.codelutin.option.ParserFailedException;
+
import fr.cemagref.simexplorer.is.entities.EntityTypeEnum;
import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
@@ -25,15 +28,12 @@
import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException;
import fr.cemagref.simexplorer.is.exceptions.UnreachableServiceException;
-import fr.cemagref.simexplorer.is.service.MockStorageServiceImpl;
import fr.cemagref.simexplorer.is.service.StorageService;
import fr.cemagref.simexplorer.is.service.StorageServiceClient;
import fr.cemagref.simexplorer.is.service.remote.RemoteService;
import fr.cemagref.simexplorer.is.service.remote.RemoteStorageService;
import fr.cemagref.simexplorer.is.storage.SortColumn;
import fr.cemagref.simexplorer.is.ui.swing.commandline.SimExplorerAbstractContext;
-import org.codelutin.i18n.I18n;
-import org.codelutin.option.ParserFailedException;
/**
* Le context de l'application, implanté en singleton.
@@ -46,8 +46,6 @@
*/
public class SimExplorerContext extends SimExplorerAbstractContext {
- private final static boolean mock = false;
-
/** le token pour la connexion au serveur distant */
protected String token;
@@ -198,14 +196,10 @@
/** @return le service de storage locale */
protected StorageService getLocalStorageService() {
if (localService == null) {
- if (mock) {
- localService = new MockStorageServiceImpl(false);
- } else {
- try {
- localService = new StorageServiceClient(this.getSource().toString(), "local.");
- } catch (Exception e) {
- throw new SimExplorerRuntimeException(e);
- }
+ try {
+ localService = new StorageServiceClient(this.getSource().toString(), "local.");
+ } catch (Exception e) {
+ throw new SimExplorerRuntimeException(e);
}
// init the cache
localCache = new LoggableElementCache(this, localService);
@@ -216,19 +210,14 @@
/** @return le service de storage distant */
protected StorageService getRemoteStorageService() {
if (remoteService == null) {
- if (mock) {
- remoteService = new MockStorageServiceImpl(true);
- } else {
+ RemoteService.setUri(getRemoteConfig().getURI().toString());
- RemoteService.setUri(getRemoteConfig().getURI().toString());
+ try {
+ remoteService = RemoteStorageService.getStorageService();
- try {
- remoteService = RemoteStorageService.getStorageService();
-
- } catch (Exception e) {
- // no remote service available
- remoteService = null;
- }
+ } catch (Exception e) {
+ // no remote service available
+ remoteService = null;
}
if (remoteService != null) {
// init the cache
Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/GenerateDataAction.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/GenerateDataAction.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/GenerateDataAction.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -2,7 +2,7 @@
import java.awt.event.ActionEvent;
-import fr.cemagref.simexplorer.is.service.StorageServiceGenerator;
+import fr.cemagref.simexplorer.is.service.random.StorageServiceGenerator;
import fr.cemagref.simexplorer.is.ui.swing.actions.util.SimExplorerAbstractAction;
@jaxx.runtime.builder.ActionConfig(
Modified: trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/Install.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/Install.java 2008-03-20 14:25:29 UTC (rev 1416)
+++ trunk/simexplorer-is/simexplorer-is-web/src/java/fr/cemagref/simexplorer/is/ui/web/pages/Install.java 2008-03-20 14:25:53 UTC (rev 1417)
@@ -19,7 +19,7 @@
import org.apache.tapestry.annotations.InjectPage;
-import fr.cemagref.simexplorer.is.service.StorageServiceGenerator;
+import fr.cemagref.simexplorer.is.service.random.StorageServiceGenerator;
import fr.cemagref.simexplorer.is.service.remote.RemoteStorageService;
import fr.cemagref.simexplorer.is.ui.web.pages.security.SuperAdminPage;
1
0
r1416 - trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:25:29 +0000 (Thu, 20 Mar 2008)
New Revision: 1416
Removed:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java
Log:
Deprecated
Deleted: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-20 14:22:26 UTC (rev 1415)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockDatabase.java 2008-03-20 14:25:29 UTC (rev 1416)
@@ -1,187 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin,
-* Tony Chemit
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.service;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import fr.cemagref.simexplorer.is.entities.data.Component;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationApplication;
-import fr.cemagref.simexplorer.is.entities.data.ExplorationData;
-import fr.cemagref.simexplorer.is.entities.data.Library;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException;
-import fr.cemagref.simexplorer.is.storage.ElementGenerator;
-import fr.cemagref.simexplorer.is.storage.VersionGenerator;
-
-/**
- * Classe permettant de créer une base fictive
- *
- * @author chemit
- */
- at Deprecated
-public class MockDatabase {
-
- static final int SIZE = 10;
-
- static protected Log log = LogFactory.getLog(MockDatabase.class);
-
- /**
- * le dictionnaire d'ea indexées par leur uuid.
- * Le premier ea est le parent (donc la version la plus petite)
- */
- protected SortedMap<String, ExplorationApplication[]> eas;
-
- /**
- * le dictionnaire des loggableElement indexées par leur uuid.
- * Le premier LE est le parent (donc la version la plus petite)
- */
- protected SortedMap<String, LoggableElement[]> loggableElements;
-
- /**
- * le dictionnaire de meta data indexées par leur uuid.
- * Le premier metadata est le parent (donc la version la plus petite)
- */
- protected SortedMap<String, MetaData[]> metadatas;
-
- protected List<String> metadatasIndex;
-
- Random r;
-
- VersionGenerator versionGenerator;
-
- ElementGenerator elementGenerator;
-
- public MockDatabase() {
- try {
- init();
- } catch (Exception e) {
- throw new SimExplorerRuntimeException(e);
- }
- }
-
- /**
- * initialise la base fictive
- *
- * @throws Exception si pb
- */
- public void init() throws Exception {
-
-
- elementGenerator = new ElementGenerator();
-
- r = new Random();
-
-
- versionGenerator = VersionGenerator.getInstance();
-
- eas = new TreeMap<String, ExplorationApplication[]>();
- loggableElements = new TreeMap<String, LoggableElement[]>();
- metadatas = new TreeMap<String, MetaData[]>();
- metadatasIndex = new ArrayList<String>();
-
- for (int i = 0,max=SIZE+r.nextInt(10); i < max; i++) {
- int nbSons = 2 + r.nextInt(3);
- Version[] versions = versionGenerator.generateVersions(nbSons + 1);
-
- ExplorationApplication parentEA = elementGenerator.generateRandomEA();
- MetaData parentMetaData = parentEA.getMetaData();
- parentMetaData.setVersion(versions[0].toString());
- String uuid = parentMetaData.getUuid();
- String name = parentMetaData.getName();
- List<ExplorationApplication> listSons = new ArrayList<ExplorationApplication>(nbSons);
- listSons.add(parentEA);
- for (int j = 0; j < nbSons; j++) {
- ExplorationApplication sonEA = elementGenerator.generateRandomEA();
- sonEA.getMetaData().setUuid(uuid);
- sonEA.getMetaData().setName(name);
- sonEA.getMetaData().setVersion(versions[j + 1].toString());
- listSons.add(sonEA);
- }
- registerEA(uuid, listSons.toArray(new ExplorationApplication[listSons.size()]));
- }
- log.info("nb ExplorationApplications/LoggableElement/MetaDatas : "+eas.size()+"/"+loggableElements.size()+"/"+metadatas.size());
- }
-
- protected void registerEA(String uuid, ExplorationApplication... eas) throws Exception {
- this.eas.put(uuid, eas);
- registerLoggableElement(uuid, eas);
- for (ExplorationApplication ea : eas) {
- for (Component component : ea.getComponents()) {
- registerLoggableElement(component.getMetaData().getUuid(), component);
- for (Library library : component.getLibraries()) {
- registerLoggableElement(library.getMetaData().getUuid(), library);
- }
- }
- for (ExplorationData explorationData : ea.getExplorations()) {
- registerLoggableElement(explorationData.getMetaData().getUuid(), explorationData);
- }
- }
- }
-
- protected void registerLoggableElement(String uuid, LoggableElement... loggableElements) throws Exception {
- if (loggableElements.length == 1) {
- /*
- // generate versions for the unique LE given
- LoggableElement loggableElement = loggableElements[0];
- loggableElement.getMetaData().setLatest(false);
- String name =loggableElement.getMetaData().getName();
-
- List<? extends LoggableElement> sons = elementGenerator.generateArray(loggableElement.getClass());
- int nbSons = 1 + sons.size();
- Version[] versions = versionGenerator.generateVersions(nbSons + 1);
- loggableElement.getMetaData().setVersion(versions[0].toString());
- List<LoggableElement> listSons = new ArrayList<LoggableElement>(nbSons);
- listSons.add(loggableElement);
- int j = 0;
- for (LoggableElement sonEA : sons) {
- sonEA.getMetaData().setUuid(uuid);
- sonEA.getMetaData().setName(name);
- sonEA.getMetaData().setVersion(versions[++j].toString());
- listSons.add(sonEA);
- }
- loggableElements = listSons.toArray(new LoggableElement[listSons.size()]);
- */
- }
- this.loggableElements.put(uuid, loggableElements);
- List<MetaData> datas = new ArrayList<MetaData>();
- for (LoggableElement data : loggableElements) {
- datas.add(data.getMetaData());
- }
- registerMetaData(uuid, datas.toArray(new MetaData[datas.size()]));
- }
-
- public ElementGenerator.RandomStream generateTextStream() throws Exception {
- return elementGenerator.generateTextStream();
- }
-
- protected void registerMetaData(String uuid, MetaData... datas) {
- this.metadatas.put(uuid, datas);
- this.metadatasIndex.add(uuid);
- }
-
-}
\ No newline at end of file
Deleted: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-03-20 14:22:26 UTC (rev 1415)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/MockStorageServiceImpl.java 2008-03-20 14:25:29 UTC (rev 1416)
@@ -1,245 +0,0 @@
-/*
-* ##% Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Code Lutin,
-* Tony Chemit
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.service;
-
-import java.io.InputStream;
-import java.util.Map;
-import java.util.SortedMap;
-
-import com.healthmarketscience.rmiio.SerializableInputStream;
-
-import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
-import fr.cemagref.simexplorer.is.entities.data.LoggableElement;
-import fr.cemagref.simexplorer.is.entities.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.exceptions.SimExplorerException;
-
-/**
- * The Class MockStorageServiceImpl.
- *
- * @author chemit
- */
- at Deprecated
-public class MockStorageServiceImpl implements StorageService {
-
- protected MockDatabase base;
-
- private boolean remote;
-
- public MockStorageServiceImpl(boolean remote) {
- base = new MockDatabase();
- this.remote = remote;
- }
-
- /**
- * Check implemented.
- *
- * @return the object
- */
- private Object checkImplemented() {
- throw new IllegalStateException("not implemented");
- }
-
- public LoggableElement saveElement(String token, SerializableInputStream zipRemoteStream) throws SimExplorerException {
- return (LoggableElement) checkImplemented();
- }
-
- public LoggableElement saveElement(String token, SerializableInputStream xmlRemoteStream,
- Map<Attachment, SerializableInputStream> attachmentsRemoteStream) throws SimExplorerException {
- return (LoggableElement) checkImplemented();
- }
-
- public MetaData getMetadata(String token, String uuid) throws SimExplorerException {
- MetaData[] datas = base.metadatas.get(uuid);
- return datas == null ? null : datas[0];
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#getMetadata(java.lang.String, java.lang.String, java.lang.String)
- */
- public MetaData getMetadata(String token, String uuid, String version) throws SimExplorerException {
- MetaData[] datas = base.metadatas.get(uuid);
- if (datas == null) {
- return null;
- }
- Version v = Version.valueOf(version);
- for (MetaData data : datas) {
- if (data.getVersion().equals(v)) {
- return data;
- }
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#exportElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public InputStream retrieveElementXML(String token, String uuid, String version) throws SimExplorerException {
- return (InputStream) checkImplemented();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#exportFull(java.lang.String, java.lang.String, java.lang.String)
- */
- public InputStream retrieveElementFull(String token, String uuid, String version) throws SimExplorerException {
- return (InputStream) checkImplemented();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#retrieveData(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
- */
- public InputStream retrieveElementData(String token, String uuid, String version, Attachment attachment)
- throws SimExplorerException {
-
- return null;
- }
-
- public int findFullTextCount(String token, String query,String queryColumn, boolean onlyLatest) throws SimExplorerException {
- // TODO Changer
- return findElementsCount(token, "", onlyLatest);
- }
-
- public MetaData[] findFullText(String token, String query, String queryColumn, boolean onlyLatest, int indexStart, int count,
- String column,
- boolean ascending) throws SimExplorerException {
- // TODO Changer
- return findElements(token, "", onlyLatest, indexStart, count, column, ascending);
- }
-
- public int findElementsCount(String token, String type, boolean onlyLatest) throws SimExplorerException {
- return base.metadatas.size();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#findApplications(java.lang.String, boolean, int, int, int)
- */
- public MetaData[] findElements(String token, String type, boolean onlyLatest, int start, int count, String column,
- boolean ascending)
- throws SimExplorerException {
- int last = start + count;
- MockDatabase.log.info("ask data from " + start + " width:" + count);
- SortedMap<String, MetaData[]> map = base.metadatas;
- if (last > map.size()) {
- last = map.size();
- }
- MetaData[] result = new MetaData[last - start];
-
- for (int i = start; i < last; i++) {
- result[i - start] = map.get(base.metadatasIndex.get(i))[0];
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#getElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public LoggableElement getLoggableElement(String token, String uuid, String version) throws SimExplorerException {
- try {
- LoggableElement[] eas = base.loggableElements.get(uuid);
- if (eas == null) {
- return null;
- }
- Version v = Version.valueOf(version);
- for (LoggableElement element : eas) {
- if (element.getMetaData().getVersion().equals(v)) {
- return element;
- }
- }
- return null;
- } catch (Exception e) {
- throw new SimExplorerException(e);
- }
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#getVersions(java.lang.String, java.lang.String)
- */
- public Version[] getVersions(String token, String uuid) throws SimExplorerException {
- MetaData[] datas = base.metadatas.get(uuid);
- if (datas == null) {
- return new Version[0];
- }
- Version[] result = new Version[datas.length];
- for (int i = 0; i < datas.length; i++) {
- MetaData data = datas[i];
- result[i] = data.getVersion();
- }
- return result;
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#loginUser(java.lang.String, java.lang.String)
- */
- public String loginUser(String login, String password) throws SimExplorerException {
- if (login == null) {
- throw new SimExplorerException(new NullPointerException("login can not be null"));
- }
- return password == null || password.length() == 0 ? null : "abc";
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#deleteElement(java.lang.String, java.lang.String, java.lang.String)
- */
- public void deleteElement(String token, String uuid, String version) {
- checkImplemented();
- }
-
- /* (non-Javadoc)
- * @see fr.cemagref.simexplorer.is.service.StorageService#deleteElement(java.lang.String, java.lang.String)
- */
- public void deleteElement(String token, String uuid) {
- checkImplemented();
- }
-
- @Override
- public void update(String token, String oldUuid, Version oldVersion, MetaData newVersion, boolean deleteOldElement)
- throws SimExplorerException {
- checkImplemented();
- }
-
- @Override
- public String toString() {
- return super.toString() + " remote:" + remote;
- }
-
- @Override
- public MetaData[] getMetadatasUsedBy(String token, String uuid, String version) throws SimExplorerException {
- checkImplemented();
- return null;
- }
-
- @Override
- public MetaData[] getMetadatasUsing(String token, String uuid, String version) throws SimExplorerException {
- checkImplemented();
- return null;
- }
-
- @Override
- public MetaData[] getMetadatasUsedBy(String token, String uuid) throws SimExplorerException {
- checkImplemented();
- return null;
- }
-
- @Override
- public MetaData[] getMetadatasUsing(String token, String uuid) throws SimExplorerException {
- checkImplemented();
- return null;
- }
-
-}
1
0
r1415 - in trunk/simexplorer-is: simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
Author: glandais
Date: 2008-03-20 14:22:26 +0000 (Thu, 20 Mar 2008)
New Revision: 1415
Added:
trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java
Removed:
trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java
Log:
Will contain element generators
Copied: trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java (from rev 1414, trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java)
===================================================================
--- trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java (rev 0)
+++ trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service/random/ElementGenerator.java 2008-03-20 14:22:26 UTC (rev 1415)
@@ -0,0 +1,389 @@
+/*
+* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software
+* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+* ##% */
+package fr.cemagref.simexplorer.is.storage;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Date;
+import java.util.Random;
+import java.util.UUID;
+
+import org.apache.commons.lang.RandomStringUtils;
+import org.codelutin.util.MD5;
+
+import fr.cemagref.simexplorer.is.entities.Entity;
+import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
+import fr.cemagref.simexplorer.is.entities.composite.Codes;
+import fr.cemagref.simexplorer.is.entities.composite.Components;
+import fr.cemagref.simexplorer.is.entities.composite.ConstantValues;
+import fr.cemagref.simexplorer.is.entities.composite.Constants;
+import fr.cemagref.simexplorer.is.entities.composite.Descriptors;
+import fr.cemagref.simexplorer.is.entities.composite.ExplorationDatas;
+import fr.cemagref.simexplorer.is.entities.composite.Libraries;
+import fr.cemagref.simexplorer.is.entities.composite.SimpleComposite;
+import fr.cemagref.simexplorer.is.entities.composite.Structures;
+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.Descriptor;
+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.metadata.MetaData;
+import fr.cemagref.simexplorer.is.entities.metadata.Version;
+import fr.cemagref.simexplorer.is.factories.ContentTypeFactory;
+
+/**
+ * The Class ElementGenerator.
+ */
+public class ElementGenerator {
+
+ /**
+ * The Class RandomStream.
+ */
+ public class RandomStream {
+
+ /** The md5. */
+ private String md5;
+
+ /** The data. */
+ private byte[] data;
+
+ /**
+ * Gets the stream.
+ *
+ * @return the stream
+ */
+ public InputStream getStream() {
+ InputStream is;
+ is = new ByteArrayInputStream(data);
+ return is;
+ }
+
+ /**
+ * Gets the md5.
+ *
+ * @return the md5
+ */
+ public String getMd5() {
+ return md5;
+ }
+
+ /**
+ * Sets the md5.
+ *
+ * @param md5 the new md5
+ */
+ public void setMd5(String md5) {
+ this.md5 = md5;
+ }
+
+ /**
+ * Sets the data.
+ *
+ * @param bytes the new data
+ */
+ public void setData(byte[] bytes) {
+ data = bytes;
+ }
+
+ }
+
+ /** The r. */
+ private Random r = new Random();
+
+ /** Number of words. */
+ private static int cs;
+
+ /** The counter. */
+ private static int counter = 0;
+
+ /** The randomstrings. */
+ private static String[] randomstrings;
+
+ /**
+ * Instantiates a new element generator.
+ */
+ public ElementGenerator() {
+ super();
+ initializeStrings();
+ }
+
+ /**
+ * Short string.
+ *
+ * @return the string
+ */
+ private String shortString() {
+ return RandomStringUtils.randomAlphabetic(r.nextInt(5) + 5);
+ }
+
+ /**
+ * Hash.
+ *
+ * @return the string
+ */
+ private String hash() {
+ return RandomStringUtils.randomAlphanumeric(32);
+ }
+
+ /**
+ * Initialize strings.
+ */
+ private void initializeStrings() {
+ cs = 150000;
+ randomstrings = new String[cs];
+ for (int i = 0; i < randomstrings.length; i++) {
+ randomstrings[i] = shortString();
+ }
+ }
+
+ /**
+ * Update.
+ *
+ * @param element the element
+ *
+ * @throws Exception the exception
+ */
+ private void update(LoggableElement element) throws Exception {
+ MetaData metaData = new MetaData();
+ metaData.setUuid(UUID.randomUUID().toString());
+ element.setName(element.getClass().getSimpleName() + "-" + counter++);
+
+ StringBuffer sb = new StringBuffer("");
+
+ for (int i = 0, max = 3 + r.nextInt(5); i < max; i++) {
+ sb.append(randomstrings[r.nextInt(cs)]).append(" ");
+ }
+ element.setDescription(sb.toString());
+
+ Version v = new Version("0");
+
+ for (int i = 0, max = 2 + r.nextInt(2); i < max; i++) {
+ v.setVersion(i, r.nextInt(5));
+ }
+ metaData.setVersion(v.toString());
+ metaData.setCreationDate(new Date());
+ metaData.setHash(shortString());
+ metaData.setLatest(true);
+
+ Descriptors descriptors = new Descriptors();
+ for (int i = 0, max = 1 + r.nextInt(12); i < max; i++) {
+ descriptors.add(new Descriptor(shortString(), shortString()));
+ }
+ element.setDescriptors(descriptors);
+
+ if (element instanceof Library || element instanceof ExplorationData) {
+ // generate attachments
+ for (int i = 0, max = r.nextInt(15); i < max; i++) {
+ element.getAttachments().add(generateAttachment());
+ }
+ }
+
+ element.setMetaData(metaData);
+ }
+
+ /**
+ * Generate composite.
+ *
+ * @param <SC> Simple composite wanted
+ * @param <T> Class of simple composite children
+ *
+ * @param compositeClass the composite class
+ *
+ * @return the sC
+ *
+ * @throws Exception the exception
+ */
+ public <T extends Entity, SC extends SimpleComposite<T>> SC generateComposite(Class<SC> compositeClass) throws Exception {
+ SC elements = compositeClass.newInstance();
+ Class<T> elementClass = elements.getChildrenClass();
+ int i = 3 + r.nextInt(2);
+ for (int j = 0; j < i; j++) {
+ T element = elementClass.newInstance();
+ if (element instanceof LoggableElement) {
+ update((LoggableElement) element);
+ }
+ elements.add(element);
+ }
+ return elements;
+ }
+
+ /**
+ * Generate random ea.
+ *
+ * @return the exploration application
+ *
+ * @throws Exception the exception
+ */
+ public ExplorationApplication generateRandomEA() throws Exception {
+ ExplorationApplication ea = new ExplorationApplication();
+ update(ea);
+
+ ExplorationDatas explorationDatas = generateComposite(ExplorationDatas.class);
+ for (ExplorationData object : explorationDatas) {
+ processExplorationData(object);
+ }
+ ea.setExplorations(explorationDatas);
+
+ Components components = generateComposite(Components.class);
+ for (Component object : components) {
+ processComponent(object);
+ }
+ ea.setComponents(components);
+ return ea;
+ }
+
+ /**
+ * Process component.
+ *
+ * @param component the component
+ *
+ * @throws Exception the exception
+ */
+ private void processComponent(Component component) throws Exception {
+ Constants constants = generateComposite(Constants.class);
+ for (Constant constant : constants) {
+ processConstant(constant);
+ }
+ component.setConstants(constants);
+
+ component.setStructures(new Structures());
+
+ Codes codes = generateComposite(Codes.class);
+ for (Code code : codes) {
+ processCode(code);
+ }
+ component.setCodes(codes);
+
+ Libraries libraries = generateComposite(Libraries.class);
+ for (Library library : libraries) {
+ processLibrary(library);
+ }
+ component.setLibraries(libraries);
+
+ }
+
+ /**
+ * Generate attachment.
+ *
+ * @return the attachment
+ *
+ * @throws Exception the exception
+ */
+ private Attachment generateAttachment() throws Exception {
+ Attachment attachment = new Attachment();
+ attachment.setContentType(ContentTypeFactory.getContentTypeInstance("RawType"));
+ attachment.setDataHash(hash());
+ attachment.setFileName(shortString() + ".txt");
+ return attachment;
+ }
+
+ /**
+ * Process library.
+ *
+ * @param library the library
+ *
+ * @throws Exception the exception
+ */
+ private void processLibrary(Library library) throws Exception {
+ // library.getMetaData().getAttachments().add(generateAttachment());
+ }
+
+ /**
+ * Process code.
+ *
+ * @param code the code
+ */
+ private void processCode(Code code) {
+ code.setCode(shortString());
+ code.setLanguage(shortString());
+ }
+
+ /**
+ * Process constant.
+ *
+ * @param constant the constant
+ */
+ private void processConstant(Constant constant) {
+ constant.setName(shortString());
+ constant.setType(String.class);
+ }
+
+ /**
+ * Process exploration data.
+ *
+ * @param explorationData the exploration data
+ *
+ * @throws Exception the exception
+ */
+ private void processExplorationData(ExplorationData explorationData) throws Exception {
+ Result result = new Result();
+ explorationData.setResult(result);
+ // explorationData.getMetaData().getAttachments().add(generateAttachment());
+
+ ConstantValues constantValues = generateComposite(ConstantValues.class);
+ for (ConstantValue constantValue : constantValues) {
+ processConstantValue(constantValue);
+ }
+ explorationData.setConstantValues(constantValues);
+
+ }
+
+ /**
+ * Process constant value.
+ *
+ * @param constantValue the constant value
+ */
+ 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()));
+ }
+
+ /**
+ * Generate text stream.
+ *
+ * @return the input stream
+ *
+ * @throws Exception the exception
+ */
+ public RandomStream generateTextStream() throws Exception {
+ RandomStream rs = new RandomStream();
+
+ int wordcount = 300 + r.nextInt(300);
+ StringBuffer sb = new StringBuffer();
+ for (int i = 0; i < wordcount; i++) {
+ sb.append(randomstrings[r.nextInt(cs)]).append(" ");
+ }
+
+ MD5 md5 = new MD5();
+ md5.Update(sb.toString().getBytes());
+ rs.setMd5(md5.asHex());
+
+ rs.setData(sb.toString().getBytes());
+
+ return rs;
+ }
+}
Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java
===================================================================
--- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-03-20 14:21:56 UTC (rev 1414)
+++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/ElementGenerator.java 2008-03-20 14:22:26 UTC (rev 1415)
@@ -1,389 +0,0 @@
-/*
-* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais
-*
-* This program is free software; you can redistribute it and/or
-* modify it under the terms of the GNU General Public License
-* as published by the Free Software Foundation; either version 2
-* of the License, or (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-* ##% */
-package fr.cemagref.simexplorer.is.storage;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.util.Date;
-import java.util.Random;
-import java.util.UUID;
-
-import org.apache.commons.lang.RandomStringUtils;
-import org.codelutin.util.MD5;
-
-import fr.cemagref.simexplorer.is.entities.Entity;
-import fr.cemagref.simexplorer.is.entities.attachment.Attachment;
-import fr.cemagref.simexplorer.is.entities.composite.Codes;
-import fr.cemagref.simexplorer.is.entities.composite.Components;
-import fr.cemagref.simexplorer.is.entities.composite.ConstantValues;
-import fr.cemagref.simexplorer.is.entities.composite.Constants;
-import fr.cemagref.simexplorer.is.entities.composite.Descriptors;
-import fr.cemagref.simexplorer.is.entities.composite.ExplorationDatas;
-import fr.cemagref.simexplorer.is.entities.composite.Libraries;
-import fr.cemagref.simexplorer.is.entities.composite.SimpleComposite;
-import fr.cemagref.simexplorer.is.entities.composite.Structures;
-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.Descriptor;
-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.metadata.MetaData;
-import fr.cemagref.simexplorer.is.entities.metadata.Version;
-import fr.cemagref.simexplorer.is.factories.ContentTypeFactory;
-
-/**
- * The Class ElementGenerator.
- */
-public class ElementGenerator {
-
- /**
- * The Class RandomStream.
- */
- public class RandomStream {
-
- /** The md5. */
- private String md5;
-
- /** The data. */
- private byte[] data;
-
- /**
- * Gets the stream.
- *
- * @return the stream
- */
- public InputStream getStream() {
- InputStream is;
- is = new ByteArrayInputStream(data);
- return is;
- }
-
- /**
- * Gets the md5.
- *
- * @return the md5
- */
- public String getMd5() {
- return md5;
- }
-
- /**
- * Sets the md5.
- *
- * @param md5 the new md5
- */
- public void setMd5(String md5) {
- this.md5 = md5;
- }
-
- /**
- * Sets the data.
- *
- * @param bytes the new data
- */
- public void setData(byte[] bytes) {
- data = bytes;
- }
-
- }
-
- /** The r. */
- private Random r = new Random();
-
- /** Number of words. */
- private static int cs;
-
- /** The counter. */
- private static int counter = 0;
-
- /** The randomstrings. */
- private static String[] randomstrings;
-
- /**
- * Instantiates a new element generator.
- */
- public ElementGenerator() {
- super();
- initializeStrings();
- }
-
- /**
- * Short string.
- *
- * @return the string
- */
- private String shortString() {
- return RandomStringUtils.randomAlphabetic(r.nextInt(5) + 5);
- }
-
- /**
- * Hash.
- *
- * @return the string
- */
- private String hash() {
- return RandomStringUtils.randomAlphanumeric(32);
- }
-
- /**
- * Initialize strings.
- */
- private void initializeStrings() {
- cs = 150000;
- randomstrings = new String[cs];
- for (int i = 0; i < randomstrings.length; i++) {
- randomstrings[i] = shortString();
- }
- }
-
- /**
- * Update.
- *
- * @param element the element
- *
- * @throws Exception the exception
- */
- private void update(LoggableElement element) throws Exception {
- MetaData metaData = new MetaData();
- metaData.setUuid(UUID.randomUUID().toString());
- element.setName(element.getClass().getSimpleName() + "-" + counter++);
-
- StringBuffer sb = new StringBuffer("");
-
- for (int i = 0, max = 3 + r.nextInt(5); i < max; i++) {
- sb.append(randomstrings[r.nextInt(cs)]).append(" ");
- }
- element.setDescription(sb.toString());
-
- Version v = new Version("0");
-
- for (int i = 0, max = 2 + r.nextInt(2); i < max; i++) {
- v.setVersion(i, r.nextInt(5));
- }
- metaData.setVersion(v.toString());
- metaData.setCreationDate(new Date());
- metaData.setHash(shortString());
- metaData.setLatest(true);
-
- Descriptors descriptors = new Descriptors();
- for (int i = 0, max = 1 + r.nextInt(12); i < max; i++) {
- descriptors.add(new Descriptor(shortString(), shortString()));
- }
- element.setDescriptors(descriptors);
-
- if (element instanceof Library || element instanceof ExplorationData) {
- // generate attachments
- for (int i = 0, max = r.nextInt(15); i < max; i++) {
- element.getAttachments().add(generateAttachment());
- }
- }
-
- element.setMetaData(metaData);
- }
-
- /**
- * Generate composite.
- *
- * @param <SC> Simple composite wanted
- * @param <T> Class of simple composite children
- *
- * @param compositeClass the composite class
- *
- * @return the sC
- *
- * @throws Exception the exception
- */
- public <T extends Entity, SC extends SimpleComposite<T>> SC generateComposite(Class<SC> compositeClass) throws Exception {
- SC elements = compositeClass.newInstance();
- Class<T> elementClass = elements.getChildrenClass();
- int i = 3 + r.nextInt(2);
- for (int j = 0; j < i; j++) {
- T element = elementClass.newInstance();
- if (element instanceof LoggableElement) {
- update((LoggableElement) element);
- }
- elements.add(element);
- }
- return elements;
- }
-
- /**
- * Generate random ea.
- *
- * @return the exploration application
- *
- * @throws Exception the exception
- */
- public ExplorationApplication generateRandomEA() throws Exception {
- ExplorationApplication ea = new ExplorationApplication();
- update(ea);
-
- ExplorationDatas explorationDatas = generateComposite(ExplorationDatas.class);
- for (ExplorationData object : explorationDatas) {
- processExplorationData(object);
- }
- ea.setExplorations(explorationDatas);
-
- Components components = generateComposite(Components.class);
- for (Component object : components) {
- processComponent(object);
- }
- ea.setComponents(components);
- return ea;
- }
-
- /**
- * Process component.
- *
- * @param component the component
- *
- * @throws Exception the exception
- */
- private void processComponent(Component component) throws Exception {
- Constants constants = generateComposite(Constants.class);
- for (Constant constant : constants) {
- processConstant(constant);
- }
- component.setConstants(constants);
-
- component.setStructures(new Structures());
-
- Codes codes = generateComposite(Codes.class);
- for (Code code : codes) {
- processCode(code);
- }
- component.setCodes(codes);
-
- Libraries libraries = generateComposite(Libraries.class);
- for (Library library : libraries) {
- processLibrary(library);
- }
- component.setLibraries(libraries);
-
- }
-
- /**
- * Generate attachment.
- *
- * @return the attachment
- *
- * @throws Exception the exception
- */
- private Attachment generateAttachment() throws Exception {
- Attachment attachment = new Attachment();
- attachment.setContentType(ContentTypeFactory.getContentTypeInstance("RawType"));
- attachment.setDataHash(hash());
- attachment.setFileName(shortString() + ".txt");
- return attachment;
- }
-
- /**
- * Process library.
- *
- * @param library the library
- *
- * @throws Exception the exception
- */
- private void processLibrary(Library library) throws Exception {
- // library.getMetaData().getAttachments().add(generateAttachment());
- }
-
- /**
- * Process code.
- *
- * @param code the code
- */
- private void processCode(Code code) {
- code.setCode(shortString());
- code.setLanguage(shortString());
- }
-
- /**
- * Process constant.
- *
- * @param constant the constant
- */
- private void processConstant(Constant constant) {
- constant.setName(shortString());
- constant.setType(String.class);
- }
-
- /**
- * Process exploration data.
- *
- * @param explorationData the exploration data
- *
- * @throws Exception the exception
- */
- private void processExplorationData(ExplorationData explorationData) throws Exception {
- Result result = new Result();
- explorationData.setResult(result);
- // explorationData.getMetaData().getAttachments().add(generateAttachment());
-
- ConstantValues constantValues = generateComposite(ConstantValues.class);
- for (ConstantValue constantValue : constantValues) {
- processConstantValue(constantValue);
- }
- explorationData.setConstantValues(constantValues);
-
- }
-
- /**
- * Process constant value.
- *
- * @param constantValue the constant value
- */
- 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()));
- }
-
- /**
- * Generate text stream.
- *
- * @return the input stream
- *
- * @throws Exception the exception
- */
- public RandomStream generateTextStream() throws Exception {
- RandomStream rs = new RandomStream();
-
- int wordcount = 300 + r.nextInt(300);
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < wordcount; i++) {
- sb.append(randomstrings[r.nextInt(cs)]).append(" ");
- }
-
- MD5 md5 = new MD5();
- md5.Update(sb.toString().getBytes());
- rs.setMd5(md5.asHex());
-
- rs.setData(sb.toString().getBytes());
-
- return rs;
- }
-}
1
0
r1414 - in trunk/simexplorer-is/simexplorer-is-service/src/java/fr/cemagref/simexplorer/is/service: . random
by glandais@users.labs.libre-entreprise.org 20 Mar '08
by glandais@users.labs.libre-entreprise.org 20 Mar '08
20 Mar '08
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());
+ }
+ }
+
+}
1
0