You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(17) |
Jul
(13) |
Aug
(17) |
Sep
(25) |
Oct
(19) |
Nov
|
Dec
|
---|
From: <jg...@us...> - 2006-08-07 12:59:26
|
Revision: 41 Author: jgongo Date: 2006-08-07 05:59:18 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=41&view=rev Log Message: ----------- Added methods for code searching Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-08-07 10:11:36 UTC (rev 40) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-08-07 12:59:18 UTC (rev 41) @@ -24,8 +24,10 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -36,6 +38,7 @@ import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; +import javax.persistence.Transient; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; @@ -104,6 +107,10 @@ @JoinColumn(name = "level_id", nullable = false) private List<Item> items = new ArrayList<Item>( ); + /** A mapping of codes to items for the items included in this level. */ + @Transient + private Map<String, Item> codesToItems; + /** Constructor provided for persistence engine. */ private Level( ) {} @@ -330,6 +337,45 @@ throw new IllegalArgumentException( ); } + /** + * Returns the code to item mapping, useful to get the item with the provided code. + * + * @return the code to item mapping. + */ + protected Map<String, Item> getCodeToItemMapping( ) + { + if( this.codesToItems == null ) + { + this.codesToItems = new HashMap<String, Item>( ); + for( Item item : this.getItems( ) ) + this.codesToItems.put( item.getCode( ), item ); + } + + return this.codesToItems; + } + + /** + * Returns <code>true</code> if the provided code is included in this level or levels under this level. Levels under this level + * will only be searched if <code>searchSublevels</code> is true. + * + * @param code the code to search. + * @param searchSublevels whether to search in levels under this level. + * @return <code>true</code> if the provided code is included in this level or levels under this level. + */ + public boolean isIncludedInLevel( String code, boolean searchSublevels ) + { + if( this.getCodeToItemMapping( ).containsKey( code ) ) + return true; + else + { + List<Level> levelsInVersion = this.getVersion( ).getLevels( ); + if( searchSublevels && this.getNumber( ) < levelsInVersion.size( ) ) + return levelsInVersion.get( this.getNumber( ) ).isIncludedInLevel( code, searchSublevels ); + else + return false; + } + } + @Override public boolean equals( Object object ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 10:12:24
|
Revision: 40 Author: jgongo Date: 2006-08-07 03:11:36 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=40&view=rev Log Message: ----------- Suppressed warnings for unused id and lockingVersion variables Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-08-07 10:11:36 UTC (rev 40) @@ -54,12 +54,14 @@ { private static final long serialVersionUID = 4169537105933133532L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; /** A classification is identified by a unique identifier, which may typically be an abbreviation of its title. */ Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-08-07 10:11:36 UTC (rev 40) @@ -53,12 +53,14 @@ { private static final long serialVersionUID = -2041101270919820504L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; /** A classification family is identified by a unique identifier. */ Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-08-07 10:11:36 UTC (rev 40) @@ -58,12 +58,14 @@ { private static final long serialVersionUID = -3965211400312532582L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; /** The level this item belongs to. */ Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-08-07 10:11:36 UTC (rev 40) @@ -53,12 +53,14 @@ { private static final long serialVersionUID = -8542980068158519003L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; /** The version this level belongs to. */ Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-08-07 10:11:36 UTC (rev 40) @@ -64,12 +64,14 @@ { private static final long serialVersionUID = -6949734640328443272L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; /** Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-08-07 10:11:36 UTC (rev 40) @@ -47,13 +47,14 @@ { private static final long serialVersionUID = 4300393468288029803L; - + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java 2006-08-07 10:11:36 UTC (rev 40) @@ -46,13 +46,16 @@ @Entity public class Row implements Serializable { - + private static final long serialVersionUID = 6601926722422919229L; + + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java 2006-08-07 10:11:36 UTC (rev 40) @@ -41,13 +41,14 @@ { private static final long serialVersionUID = 0L; - + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-08-07 10:11:36 UTC (rev 40) @@ -47,12 +47,14 @@ { private static final long serialVersionUID = 0L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-08-07 10:11:36 UTC (rev 40) @@ -45,12 +45,14 @@ { private static final long serialVersionUID = 1661678204467740737L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-08-07 10:11:36 UTC (rev 40) @@ -22,24 +22,15 @@ package org.surveyforge.core.metadata; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; -import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; -import javax.persistence.OneToMany; -import javax.persistence.Transient; import org.hibernate.annotations.GenericGenerator; -import org.hibernate.annotations.IndexColumn; -import org.surveyforge.core.survey.Study; /** * An object variable defines the concept of a variable in connection with a defined statistical object (e.g. the income of a person). @@ -53,13 +44,14 @@ { private static final long serialVersionUID = 4288089682729653747L; - + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-08-07 10:11:36 UTC (rev 40) @@ -54,12 +54,14 @@ { private static final long serialVersionUID = 0L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-08-07 10:11:36 UTC (rev 40) @@ -38,7 +38,6 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; -import org.surveyforge.core.survey.Study; /** * Statistical objects or units may be real world objects (e.g. person, enterprise) or abstract objects like events or states (e.g. @@ -52,13 +51,14 @@ { private static final long serialVersionUID = 3051156955695891963L; - + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java 2006-08-07 10:11:36 UTC (rev 40) @@ -43,12 +43,14 @@ { private static final long serialVersionUID = 0L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-07 10:11:36 UTC (rev 40) @@ -39,12 +39,14 @@ { private static final long serialVersionUID = -83487445078388347L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-08-07 10:11:36 UTC (rev 40) @@ -48,12 +48,14 @@ { private static final long serialVersionUID = 7344092827765295413L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java 2006-08-07 10:11:36 UTC (rev 40) @@ -44,12 +44,14 @@ { private static final long serialVersionUID = -7937801343328085145L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-08-07 10:11:36 UTC (rev 40) @@ -50,12 +50,14 @@ { private static final long serialVersionUID = 0L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-08-07 10:11:36 UTC (rev 40) @@ -54,12 +54,14 @@ { private static final long serialVersionUID = 6844066269698434310L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-08-07 10:11:36 UTC (rev 40) @@ -45,12 +45,14 @@ { private static final long serialVersionUID = 0L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java 2006-08-07 10:11:36 UTC (rev 40) @@ -50,12 +50,14 @@ { private static final long serialVersionUID = -4089931270976596457L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java 2006-08-07 10:11:36 UTC (rev 40) @@ -21,7 +21,6 @@ */ package org.surveyforge.core.survey; -import org.surveyforge.core.metadata.GlobalVariable; import org.testng.Assert; import org.testng.annotations.ExpectedExceptions; import org.testng.annotations.Test; Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-08-07 10:11:36 UTC (rev 40) @@ -23,26 +23,22 @@ import java.lang.reflect.Method; +import org.surveyforge.core.metadata.ConceptualDataElement; +import org.surveyforge.core.metadata.LogicalValueDomain; +import org.surveyforge.core.metadata.RegisterDataElement; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.ExpectedExceptions; import org.testng.annotations.Test; -import org.surveyforge.core.metadata.ConceptualDataElement; -import org.surveyforge.core.metadata.LogicalValueDomain; -import org.surveyforge.core.metadata.Register; -import org.surveyforge.core.metadata.RegisterDataElement; -import org.surveyforge.core.metadata.ValueDomain; /** * @author jsegura */ public class QuestionnaireElementTest { - @DataProvider(name = "dp") public Object[][] createData( Method m ) { - Register register = new Register( "register" ); ConceptualDataElement conceptualDataElement = new ConceptualDataElement( new LogicalValueDomain( ), "conceptualDataElement" ); RegisterDataElement registerDataElement = new RegisterDataElement( conceptualDataElement, "registerDataElement" ); return new Object[][] {new Object[] {registerDataElement}}; Modified: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-08-07 10:01:09 UTC (rev 39) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-08-07 10:11:36 UTC (rev 40) @@ -47,12 +47,14 @@ { private static final long serialVersionUID = 4441883710391359007L; + @SuppressWarnings("unused") @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") private String id; /** Version for optimistic locking. */ + @SuppressWarnings("unused") @javax.persistence.Version private int lockingVersion; @CollectionOfElements This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 10:01:15
|
Revision: 39 Author: jgongo Date: 2006-08-07 03:01:09 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=39&view=rev Log Message: ----------- Minor fixes in relations with ValueDomain Modified Paths: -------------- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java Modified: trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java =================================================================== --- trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-08-07 09:59:51 UTC (rev 38) +++ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java 2006-08-07 10:01:09 UTC (rev 39) @@ -44,8 +44,7 @@ { Register register = new Register( "register" ); ConceptualDataElement conceptualDataElement = new ConceptualDataElement( new LogicalValueDomain( ), "conceptualDataElement" ); - RegisterDataElement registerDataElement = new RegisterDataElement( conceptualDataElement, new ValueDomain( ), - "registerDataElement" ); + RegisterDataElement registerDataElement = new RegisterDataElement( conceptualDataElement, "registerDataElement" ); return new Object[][] {new Object[] {registerDataElement}}; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 09:59:58
|
Revision: 38 Author: jgongo Date: 2006-08-07 02:59:51 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=38&view=rev Log Message: ----------- Cloneable support for ValueDomain, now abstract Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java 2006-08-07 09:58:55 UTC (rev 37) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java 2006-08-07 09:59:51 UTC (rev 38) @@ -21,13 +21,8 @@ */ package org.surveyforge.core.metadata; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; +import java.io.Serializable; -import org.hibernate.annotations.GenericGenerator; - /** * @author jsegura */ @@ -36,18 +31,22 @@ { private static final long serialVersionUID = 2066579378848047283L; -// @Id -// @Column(length = 50) -// @GeneratedValue(generator = "system-uuid") -// @GenericGenerator(name = "system-uuid", strategy = "uuid") -// private String id; -// /** Version for optimistic locking. */ -// @javax.persistence.Version -// private int lockingVersion; + // @Id + // @Column(length = 50) + // @GeneratedValue(generator = "system-uuid") + // @GenericGenerator(name = "system-uuid", strategy = "uuid") + // private String id; + // /** Version for optimistic locking. */ + // @javax.persistence.Version + // private int lockingVersion; - public boolean isValid( Object object ) + public boolean isValid( Serializable object ) { return (Boolean.class.isInstance( object )); } - +// +// public LogicalValueDomain clone( ) +// { +// return (LogicalValueDomain) super.clone( ); +// } } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-07 09:58:55 UTC (rev 37) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-07 09:59:51 UTC (rev 38) @@ -35,7 +35,7 @@ * @author jsegura */ @Entity -public class ValueDomain implements Serializable +public abstract class ValueDomain implements Serializable, Cloneable { private static final long serialVersionUID = -83487445078388347L; @@ -51,10 +51,21 @@ public ValueDomain( ) {} - public boolean isValid( Serializable data ) + public abstract boolean isValid( Serializable data ); + + @Override + public ValueDomain clone( ) { - // TODO Auto-generated method stub - return false; + try + { + ValueDomain copy = (ValueDomain) super.clone( ); + copy.id = null; + copy.lockingVersion = 0; + return copy; + } + catch( CloneNotSupportedException exc ) + { + throw new InternalError( exc.getLocalizedMessage( ) ); + } } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 09:59:04
|
Revision: 37 Author: jgongo Date: 2006-08-07 02:58:55 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=37&view=rev Log Message: ----------- Minor fixes in relations with ValueDomain Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-08-07 09:55:29 UTC (rev 36) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-08-07 09:58:55 UTC (rev 37) @@ -67,7 +67,7 @@ /** */ private int maxResponses = 1; /** */ - @ManyToOne + @ManyToOne(cascade = {CascadeType.ALL}) @JoinColumn(name = "valueDomain_id") private ValueDomain valueDomain; /** */ Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-08-07 09:55:29 UTC (rev 36) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-08-07 09:58:55 UTC (rev 37) @@ -34,6 +34,7 @@ * @author jsegura */ @Entity +// TODO: Improve javadocs public class RegisterDataElement extends DataElement { private static final long serialVersionUID = -8986375207717119033L; @@ -56,13 +57,21 @@ * @throws NullPointerException If the ValueDomain or the identifier or the ConceptualDataElements are <code>null</code> or the * identifier is empty. */ - public RegisterDataElement( ConceptualDataElement conceptualDataElement, ValueDomain valueDomain, String identifier ) + public RegisterDataElement( ConceptualDataElement conceptualDataElement, String identifier ) { - super( valueDomain, identifier ); + super( conceptualDataElement.getValueDomain( ).clone( ), identifier ); this.setConceptualDataElement( conceptualDataElement ); } /** + * Creates a new instance of ConceptualDataElement linked with a {@link ConceptualDataElement}. + */ + public RegisterDataElement( ValueDomain valueDomain, String identifier ) + { + super( valueDomain, identifier ); + } + + /** * Returns the ConceptualDataElement that describes the RegisterDataElement. * * @return Returns the conceptualDataElement. @@ -80,6 +89,10 @@ */ public void setConceptualDataElement( ConceptualDataElement conceptualDataElement ) { + if( conceptualDataElement == null ) + { + this.setValueDomain( conceptualDataElement.getValueDomain( ).clone( ) ); + } this.conceptualDataElement = conceptualDataElement; } @@ -114,5 +127,4 @@ { this.question = question; } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 09:55:46
|
Revision: 36 Author: jgongo Date: 2006-08-07 02:55:29 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=36&view=rev Log Message: ----------- Added copy constructor Modified Paths: -------------- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java Modified: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-08-07 08:15:55 UTC (rev 35) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-08-07 09:55:29 UTC (rev 36) @@ -70,6 +70,12 @@ this.setDefaultLocale( defaultLocale ); } + public InternationalizedString( InternationalizedString otherString ) + { + this.strings = new HashMap<Locale, String>( otherString.strings ); + this.defaultLocale = otherString.defaultLocale; + } + public Locale getDefaultLocale( ) { return this.defaultLocale; Modified: trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java =================================================================== --- trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java 2006-08-07 08:15:55 UTC (rev 35) +++ trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java 2006-08-07 09:55:29 UTC (rev 36) @@ -55,7 +55,7 @@ public void useOfDefaultLocale( ) { Assert.assertEquals( new InternationalizedString( ).getDefaultLocale( ), Locale.getDefault( ) ); - Assert.assertEquals( new InternationalizedString( null ).getDefaultLocale( ), Locale.getDefault( ) ); + Assert.assertEquals( new InternationalizedString( (Locale) null ).getDefaultLocale( ), Locale.getDefault( ) ); } @Test This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 08:16:10
|
Revision: 35 Author: jgongo Date: 2006-08-07 01:15:55 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=35&view=rev Log Message: ----------- Added support for pages and sections Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java Added Paths: ----------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/SectionFeed.java Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java 2006-08-07 08:15:55 UTC (rev 35) @@ -0,0 +1,88 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.survey; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.DiscriminatorColumn; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.GenericGenerator; + +/** + * @author jgonzalez + */ +@Entity +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "feedType") +public class Feed implements Serializable + { + private static final long serialVersionUID = -7937801343328085145L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + @ManyToOne + private QuestionnaireElement firstElement; + + private Feed( ) + { + // TODO Auto-generated constructor stub + } + + public Feed( QuestionnaireElement firstElement ) + { + if( firstElement != null ) + this.firstElement = firstElement; + else + throw new NullPointerException( ); + } + + public QuestionnaireElement getFirstElement( ) + { + return firstElement; + } + + @Override + public boolean equals( Object object ) + { + return this.firstElement.equals( ((Feed) object).firstElement ); + } + + @Override + public int hashCode( ) + { + return this.firstElement.hashCode( ); + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Feed.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-08-07 08:14:05 UTC (rev 34) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-08-07 08:15:55 UTC (rev 35) @@ -23,7 +23,9 @@ import java.io.Serializable; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.List; import javax.persistence.CascadeType; @@ -39,6 +41,7 @@ import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.metadata.Register; +import org.surveyforge.util.InternationalizedString; /** * A questionnaire is a list of {@link Question}s used to recollect the data into a register. The questionnaire is included in almost @@ -76,11 +79,20 @@ @Column(length = 500) private String description = ""; /** A questionnaire consists of a number of questionnaire elements. Each element refers to a question. */ - @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "questionnairesIndex") @JoinColumn(name = "questionnaire_id", nullable = false) private List<QuestionnaireElement> elements = new ArrayList<QuestionnaireElement>( ); + /** A questionnaire may have its content organized in pages. */ + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "pageIndex") + @JoinColumn(name = "questionnaire_id", nullable = false) + private List<Feed> pageFeeds = new ArrayList<Feed>( ); + /** A questionnaire may have its content organized in sections. */ + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "sectionIndex") + @JoinColumn(name = "questionnaire_id", nullable = false) + private List<SectionFeed> sectionFeeds = new ArrayList<SectionFeed>( ); /** A questionnaire corresponds logically to a register, which describes the content of the data collection. */ @OneToOne(fetch = FetchType.LAZY) @@ -203,7 +215,11 @@ public void addElement( QuestionnaireElement element ) { if( element != null ) + { this.elements.add( element ); + if( this.pageFeeds.isEmpty( ) ) this.createPageFeed( element ); + if( this.sectionFeeds.isEmpty( ) ) this.createSectionFeed( element ); + } else throw new NullPointerException( ); } @@ -217,11 +233,156 @@ public void delElement( QuestionnaireElement element ) { if( element != null ) - this.elements.remove( element ); + { + int indexToRemove = this.elements.indexOf( element ); + if( indexToRemove != -1 ) + { + Comparator<Feed> feedComparator = new Questionnaire.FeedComparator( ); + + Feed pageFeedToRemove = new Feed( element ); + Feed[] pageFeeds = this.getPageFeeds( ).toArray( new Feed[] {} ); + int pageFeedPosition = Arrays.binarySearch( pageFeeds, pageFeedToRemove, feedComparator ); + if( pageFeedPosition >= 0 ) + { + this.pageFeeds.remove( pageFeedPosition ); + if( indexToRemove < this.elements.size( ) - 1 ) this.createPageFeed( this.elements.get( indexToRemove + 1 ) ); + } + + SectionFeed sectionFeedToRemove = new SectionFeed( element ); + SectionFeed[] sectionFeeds = this.getSectionFeeds( ).toArray( new SectionFeed[] {} ); + int sectionFeedPosition = Arrays.binarySearch( sectionFeeds, sectionFeedToRemove, feedComparator ); + if( sectionFeedPosition >= 0 ) + { + SectionFeed oldSectionFeed = this.sectionFeeds.remove( sectionFeedPosition ); + if( indexToRemove < this.elements.size( ) - 1 ) + this.createSectionFeed( this.elements.get( indexToRemove + 1 ), oldSectionFeed.getInternationalizedTitle( ) ); + } + + this.elements.remove( element ); + } + } else throw new NullPointerException( ); } + public Feed createPageFeed( QuestionnaireElement firstElement ) + { + if( firstElement != null ) + { + Comparator<Feed> feedComparator = new Questionnaire.FeedComparator( ); + Feed[] pageFeeds = this.getPageFeeds( ).toArray( new Feed[] {} ); + + Feed pageFeed = new Feed( firstElement ); + int insertionPoint = Arrays.binarySearch( pageFeeds, pageFeed, feedComparator ); + if( insertionPoint < 0 ) // there was no page feed at the specified element + { + this.pageFeeds.add( -insertionPoint - 1, pageFeed ); + return pageFeed; + } + else + return this.pageFeeds.get( insertionPoint ); + } + else + throw new NullPointerException( ); + } + + public void removePageFeed( Feed pageFeed ) + { + this.pageFeeds.remove( pageFeed ); + } + + public List<Feed> getPageFeeds( ) + { + return Collections.unmodifiableList( this.pageFeeds ); + } + + public SectionFeed createSectionFeed( QuestionnaireElement firstElement ) + { + return this.createSectionFeed( firstElement, null ); + } + + public SectionFeed createSectionFeed( QuestionnaireElement firstElement, InternationalizedString title ) + { + if( firstElement != null ) + { + Comparator<Feed> feedComparator = new Questionnaire.FeedComparator( ); + Feed[] sectionFeeds = this.getSectionFeeds( ).toArray( new SectionFeed[] {} ); + + SectionFeed sectionFeed = new SectionFeed( firstElement, title ); + int insertionPoint = Arrays.binarySearch( sectionFeeds, sectionFeed, feedComparator ); + if( insertionPoint < 0 ) // there was no section feed at the specified element + { + this.sectionFeeds.add( -insertionPoint - 1, sectionFeed ); + return sectionFeed; + } + else + return this.sectionFeeds.get( insertionPoint ); + } + else + throw new NullPointerException( ); + } + + public void removeSectionFeed( SectionFeed sectionFeed ) + { + this.sectionFeeds.remove( sectionFeed ); + } + + public List<SectionFeed> getSectionFeeds( ) + { + return Collections.unmodifiableList( this.sectionFeeds ); + } + + public List<SectionFeed> getSectionsInPage( Feed pageFeed ) + { + int pageNumber = this.pageFeeds.indexOf( pageFeed ); + if( pageNumber != -1 ) + { + QuestionnaireElement firstElement = pageFeed.getFirstElement( ); + QuestionnaireElement lastElement = null; + if( pageNumber != this.pageFeeds.size( ) - 1 ) // We aren't in the last page + { + lastElement = this.pageFeeds.get( pageNumber + 1 ).getFirstElement( ); + } + + SectionFeed[] sectionFeeds = this.getSectionFeeds( ).toArray( new SectionFeed[] {} ); + Comparator<Feed> sectionFeedComparator = new Questionnaire.FeedComparator( ); + int firstSectionIndex = Arrays.binarySearch( sectionFeeds, new SectionFeed( firstElement ), sectionFeedComparator ); + if( firstSectionIndex < 0 ) firstSectionIndex = -firstSectionIndex - 2; + int lastSectionIndex = this.getSectionFeeds( ).size( ); + if( lastElement != null ) + { + lastSectionIndex = Arrays.binarySearch( sectionFeeds, new SectionFeed( lastElement ), sectionFeedComparator ); + if( lastSectionIndex < 0 ) lastSectionIndex = -lastSectionIndex - 1; + } + + return Collections.unmodifiableList( this.sectionFeeds.subList( firstSectionIndex, lastSectionIndex ) ); + } + else + throw new IllegalArgumentException( ); + } + + public List<QuestionnaireElement> getElementsInPageAndSection( Feed pageFeed, SectionFeed sectionFeed ) + { + if( this.getSectionsInPage( pageFeed ).contains( sectionFeed ) ) + { + int pageNumber = this.pageFeeds.indexOf( pageFeed ); + int sectionNumber = this.sectionFeeds.indexOf( sectionFeed ); + + int firstElementIndex = Math.max( this.elements.indexOf( pageFeed.getFirstElement( ) ), this.elements.indexOf( sectionFeed + .getFirstElement( ) ) ); + + int lastElementInPageIndex = (pageNumber != this.pageFeeds.size( ) - 1) ? this.elements.indexOf( this.pageFeeds.get( + pageNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; + int lastElementInSectionIndex = (sectionNumber != this.sectionFeeds.size( ) - 1) ? this.elements.indexOf( this.sectionFeeds.get( + sectionNumber + 1 ).getFirstElement( ) ) : Integer.MAX_VALUE; + int lastElementIndex = Math.min( Math.min( lastElementInPageIndex, lastElementInSectionIndex ), this.elements.size( ) ); + + return Collections.unmodifiableList( this.elements.subList( firstElementIndex, lastElementIndex ) ); + } + else + throw new IllegalArgumentException( ); + } + /** * Returns the {@link Register} of the questionnaire. * @@ -286,4 +447,16 @@ { return this.getStudy( ).hashCode( ) ^ this.getIdentifier( ).hashCode( ); } + + private class FeedComparator implements Comparator<Feed>, Serializable + { + private static final long serialVersionUID = 4718037652095754746L; + + public int compare( Feed feed1, Feed feed2 ) + { + Integer firstPosition = Questionnaire.this.getElements( ).indexOf( feed1.getFirstElement( ) ); + Integer secondPosition = Questionnaire.this.getElements( ).indexOf( feed2.getFirstElement( ) ); + return firstPosition.compareTo( secondPosition ); + } + } } Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/SectionFeed.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/SectionFeed.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/SectionFeed.java 2006-08-07 08:15:55 UTC (rev 35) @@ -0,0 +1,111 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.survey; + +import java.util.Locale; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + +import org.surveyforge.util.InternationalizedString; + +/** + * @author jgonzalez + */ +@Entity +public class SectionFeed extends Feed + { + private static final long serialVersionUID = 983150580473588830L; + + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString title = new InternationalizedString( ); + + public SectionFeed( QuestionnaireElement firstElement ) + { + this( firstElement, null ); + } + + public SectionFeed( QuestionnaireElement firstElement, InternationalizedString title ) + { + super( firstElement ); + if( title != null ) this.title = new InternationalizedString( title ); + } + + public InternationalizedString getInternationalizedTitle( ) + { + return this.title; + } + + /** + * Returns the title of this section for the default language. + * + * @return the title of this section for the default language. + * @see InternationalizedString#getString() + */ + public String getTitle( ) + { + return this.title.getString( ); + } + + /** + * Returns the title of this section for the given language. + * + * @param locale the language of the title to be returned. + * @return the title of this section for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getTitle( Locale locale ) + { + return this.title.getString( locale ); + } + + /** + * Sets the title of this section. The title must be non <code>null</code>, otherwise a {@link NullPointerException} is thrown. + * + * @param title the title of this section. + * @throws NullPointerException if the title is <code>null</code>. + */ + public void setTitle( String title ) + { + if( title != null ) + this.title.setString( title ); + else + throw new NullPointerException( ); + } + + /** + * Sets the title of this section for the given language. The language and title must be non <code>null</code>, otherwise a + * {@link NullPointerException} is thrown. + * + * @param locale the language of the title to be set. + * @param title the title of this section. + * @throws NullPointerException if the language or title are <code>null</code>. + */ + public void setTitle( Locale locale, String title ) + { + if( title != null ) + this.title.setString( locale, title ); + else + throw new NullPointerException( ); + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/SectionFeed.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 08:14:16
|
Revision: 34 Author: jgongo Date: 2006-08-07 01:14:05 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=34&view=rev Log Message: ----------- Some minor bug fixes Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-08-07 08:13:24 UTC (rev 33) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-08-07 08:14:05 UTC (rev 34) @@ -210,8 +210,8 @@ { if( registerDataElement == null ) throw new NullPointerException( ); - else if( registerData == null || registerData.getRows( ).size( ) > 0 ) - throw new IllegalArgumentException( ); + else if( this.registerData.getRows( ).size( ) > 0 ) + throw new IllegalStateException( ); else { this.registerDataElements.add( registerDataElement ); @@ -223,8 +223,8 @@ { if( registerDataElement == null ) throw new NullPointerException( ); - else if( registerData != null ) - throw new IllegalArgumentException( ); + else if( this.registerData.getRows( ).size( ) > 0 ) + throw new IllegalStateException( ); else { this.registerDataElements.remove( registerDataElement ); @@ -239,10 +239,10 @@ { if( registerDataElements == null ) throw new NullPointerException( ); - else if( registerData != null ) + else if( this.registerData.getRows( ).size( ) > 0 ) + throw new IllegalStateException( ); + else if( this.key != null && !registerDataElements.containsAll( this.key ) ) throw new IllegalArgumentException( ); - else if( key != null && !registerDataElements.containsAll( key ) ) - throw new IllegalArgumentException( ); else { this.registerDataElements = registerDataElements; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 08:13:33
|
Revision: 33 Author: jgongo Date: 2006-08-07 01:13:24 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=33&view=rev Log Message: ----------- Relation with ConceptualDataElement is now optional Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-08-07 08:09:12 UTC (rev 32) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-08-07 08:13:24 UTC (rev 33) @@ -21,16 +21,10 @@ */ package org.surveyforge.core.metadata; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - import javax.persistence.Entity; import javax.persistence.JoinColumn; -import javax.persistence.ManyToMany; import javax.persistence.ManyToOne; -import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.survey.Question; /** @@ -86,10 +80,7 @@ */ public void setConceptualDataElement( ConceptualDataElement conceptualDataElement ) { - if( conceptualDataElement != null ) - this.conceptualDataElement = conceptualDataElement; - else - throw new NullPointerException( ); + this.conceptualDataElement = conceptualDataElement; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-08-07 08:09:23
|
Revision: 32 Author: jgongo Date: 2006-08-07 01:09:12 -0700 (Mon, 07 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=32&view=rev Log Message: ----------- Relation between ConceptualDataElement and ObjectVariable is now unidirectional and mandatory Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java 2006-08-01 10:26:24 UTC (rev 31) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java 2006-08-07 08:09:12 UTC (rev 32) @@ -46,8 +46,7 @@ @JoinColumn(name = "question_id") private Question question; /** */ - @ManyToOne(optional = true) - @JoinColumn(name = "objectVariable_id", insertable = false, updatable = false) + @ManyToOne private ObjectVariable objectVariable; @@ -91,9 +90,10 @@ */ public void setObjectVariable( ObjectVariable objectVariable ) { - if( this.objectVariable != null ) this.objectVariable.removeConceptualDataElement( this ); - this.objectVariable = objectVariable; - if( this.objectVariable != null ) this.objectVariable.addConceptualDataElement( this ); + if( objectVariable != null ) + this.objectVariable = objectVariable; + else + throw new NullPointerException( ); } @Override Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-08-01 10:26:24 UTC (rev 31) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-08-07 08:09:12 UTC (rev 32) @@ -51,49 +51,42 @@ @Entity public class ObjectVariable implements Serializable { - private static final long serialVersionUID = 4288089682729653747L; + private static final long serialVersionUID = 4288089682729653747L; @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** * Unique and language independent identifier for the object variable. The identifier is unique among all object variables. The * identifier should contain identifications for the statistical object and the global variable it is based on. */ @Column(unique = true, length = 50) - private String identifier; + private String identifier; /** The name is the official, language dependent name of the global variable, provided by the owner of the variable. */ @Column(length = 250) - private String name = ""; + private String name = ""; /** Short general multilingual description of the object variable, including its purpose, its main subject areas etc. */ @Column(length = 500) - private String description = ""; + private String description = ""; /** * Each object variable belongs to a statistical object or unit. The object variable exists only in the context of the object * variable. */ @ManyToOne @JoinColumn(name = "statisticalObjectType_id", insertable = false, updatable = false) - private StatisticalObjectType statisticalObjectType; + private StatisticalObjectType statisticalObjectType; /** An object variable should refer to a global variable definition that reflects the general concepts of the object variable. */ @ManyToOne @JoinColumn(name = "globalVariable_id", insertable = false, updatable = false) - private GlobalVariable globalVariable; + private GlobalVariable globalVariable; - /** Based on an object variable a number of data elements may refer to this object variable. */ - @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) - @IndexColumn(name = "dataElementsIndex") - @JoinColumn(name = "objectVariable_id") - private List<ConceptualDataElement> conceptualDataElements = new ArrayList<ConceptualDataElement>( ); - - private ObjectVariable( ) {} @@ -235,36 +228,6 @@ throw new NullPointerException( ); } - /** - * Returns the list of {@link ConceptualDataElement} linked to this ObjectVariable. - * - * @return Returns the list of ConceptualDataElements. - */ - public List<ConceptualDataElement> getConceptualDataElements( ) - { - return Collections.unmodifiableList( conceptualDataElements ); - } - - /** - * Adds a new {@link ConceptualDataElement} to the list. - * - * @param dataElements The conceptualDataElement to add. - */ - protected void addConceptualDataElement( ConceptualDataElement conceptualDataElement ) - { - this.conceptualDataElements.add( conceptualDataElement ); - } - - /** - * Removes a {@link ConceptualDataElement} from the list. - * - * @param dataElements The conceptualDataElement to remove. - */ - protected void removeConceptualDataElement( ConceptualDataElement conceptualDataElement ) - { - this.conceptualDataElements.remove( conceptualDataElement ); - } - @Override public boolean equals( Object object ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-08-01 10:27:23
|
Revision: 31 Author: javism Date: 2006-08-01 03:26:24 -0700 (Tue, 01 Aug 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=31&view=rev Log Message: ----------- Added hibernate annotations. Modified Paths: -------------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/GlobalVariableTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/VariableFamilyTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java Added Paths: ----------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/package-info.java Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-08-01 10:26:24 UTC (rev 31) @@ -26,42 +26,56 @@ import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.metadata.Register; /** * @author jsegura */ +@Entity public class RegisterData implements Serializable { private static final long serialVersionUID = 4300393468288029803L; - private String identifier; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + @OneToOne(optional = true) private Register register; + + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "rowsIndex") + @JoinColumn(name = "registerData_id") private List<Row> rows = new ArrayList<Row>( ); - public RegisterData( Register register, String identifier ) - { - this.setRegister( register ); - this.setIdentifier( identifier ); - } + private RegisterData( ) + {} - /** - * @return Returns the identifier. - */ - public String getIdentifier( ) + public RegisterData( Register register ) { - return this.identifier; - } - - /** - * @param identifier The identifier to set. - */ - public void setIdentifier( String identifier ) - { - if( identifier != null && !identifier.equals( "" ) ) - this.identifier = identifier; + if( register == null ) + throw new NullPointerException( ); + else if( register.getRegisterData( ) != null ) + throw new IllegalArgumentException( ); else - throw new NullPointerException( ); + this.register = register; } /** @@ -72,16 +86,6 @@ return this.register; } - /** - * @param register The register to set. - */ - public void setRegister( Register register ) - { - if( register == null ) - throw new NullPointerException( ); - else if( this.register != null && this.rows.size( ) != 0 ) throw new IllegalArgumentException( ); - this.register = register; - } /** * @return Returns the rows. @@ -94,7 +98,7 @@ /** * @param rows The rows to . */ - protected void addRows( Row row ) + protected void addRow( Row row ) { if( row != null ) { Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,18 +21,48 @@ */ package org.surveyforge.core.data; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.NoSuchElementException; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * @author jsegura */ -public class Row +@Entity +public class Row implements Serializable { + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + @ManyToOne(optional = true) + @JoinColumn(name = "registerData_id", insertable = false, updatable = false) private RegisterData registerData; + + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "rowDatasIndex") + @JoinColumn(name = "row_id", nullable = false) private List<RowData> rowDatas = new ArrayList<RowData>( ); public Row( RegisterData registerData ) @@ -54,7 +84,10 @@ public void setRegisterData( RegisterData registerData ) { if( registerData != null ) + { this.registerData = registerData; + this.registerData.addRow( this ); + } else throw new NullPointerException( ); } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java 2006-08-01 10:26:24 UTC (rev 31) @@ -23,16 +23,44 @@ import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.GenericGenerator; + // TODO: Elaborate on comments /** * @author jsegura */ -public class RowData +@Entity +public class RowData implements Serializable { - private Serializable data; - private boolean answered; - private boolean applicable; + private static final long serialVersionUID = 0L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + @ManyToOne + @JoinColumn(name = "row_id", insertable = false, updatable = false) + private Row row; + // TODO get/set of the row + + private Serializable data; + + private boolean answered; + private boolean applicable; + /** * @return Returns the data. */ Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,6 +21,10 @@ */ package org.surveyforge.core.metadata; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + import org.surveyforge.core.survey.Question; // TODO: Measure unit? @@ -32,13 +36,21 @@ * * @author jsegura */ +@Entity public class ConceptualDataElement extends DataElement { private static final long serialVersionUID = -6880246451318487216L; /** */ + @ManyToOne(optional = true) + @JoinColumn(name = "question_id") private Question question; + /** */ + @ManyToOne(optional = true) + @JoinColumn(name = "objectVariable_id", insertable = false, updatable = false) + private ObjectVariable objectVariable; + /** * Creates a new ConceptualDataElement based on the params of a DataElement * @@ -66,5 +78,34 @@ this.question = question; } + /** + * @return Returns the objectVariable. + */ + public ObjectVariable getObjectVariable( ) + { + return this.objectVariable; + } + /** + * @param objectVariable The objectVariable to set. + */ + public void setObjectVariable( ObjectVariable objectVariable ) + { + if( this.objectVariable != null ) this.objectVariable.removeConceptualDataElement( this ); + this.objectVariable = objectVariable; + if( this.objectVariable != null ) this.objectVariable.addConceptualDataElement( this ); + } + + @Override + public boolean equals( Object object ) + { + ConceptualDataElement other = (ConceptualDataElement) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,34 +21,69 @@ */ package org.surveyforge.core.metadata; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + // TODO Elaborate on comments /** * @author jsegura */ -public class DataElement +@Entity +public class DataElement implements Serializable { + private static final long serialVersionUID = 0L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** * This is a unique and language independent identifier for the data element. The identifier is unique among all other data elements * for an object variable (standard data element) or within the scope of a statistical activity. */ + @Column(unique = true, length = 50) private String identifier; /** */ private boolean multiple = false; /** */ private int maxResponses = 1; /** */ + @ManyToOne + @JoinColumn(name = "valueDomain_id") private ValueDomain valueDomain; /** */ - private ObjectVariable objectVariable; - /** */ + @ManyToOne(cascade = {CascadeType.ALL}) + @JoinColumn(name = "variableStructure_id", insertable = false, updatable = false) private DataElement variableStructure; /** */ + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "componentElementsIndex") + @JoinColumn(name = "variableStructure_id") private List<DataElement> componentElements = new ArrayList<DataElement>( ); + + private DataElement( ) + {} + /** * @param valueDomain * @param identifier @@ -132,25 +167,8 @@ throw new NullPointerException( ); } - /** - * @return Returns the objectVariable. - */ - public ObjectVariable getObjectVariable( ) - { - return this.objectVariable; - } /** - * @param objectVariable The objectVariable to set. - */ - public void setObjectVariable( ObjectVariable objectVariable ) - { - if( this.objectVariable != null ) this.objectVariable.removeDataElement( this ); - this.objectVariable = objectVariable; - if( this.objectVariable != null ) this.objectVariable.addDataElement( this ); - } - - /** * @return Returns the variableStructure. */ public DataElement getVariableStructure( ) @@ -179,7 +197,7 @@ /** * @param componentElements The componentElements to set. */ - protected void addComponentElement( DataElement componentElement ) + private void addComponentElement( DataElement componentElement ) { if( componentElement != null ) this.componentElements.add( componentElement ); @@ -190,7 +208,7 @@ /** * @param componentElements The componentElements to set. */ - protected void removeComponentElement( DataElement componentElement ) + private void removeComponentElement( DataElement componentElement ) { if( componentElement != null ) this.componentElements.remove( componentElement ); @@ -198,5 +216,17 @@ throw new NullPointerException( ); } + @Override + public boolean equals( Object object ) + { + DataElement other = (DataElement) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-08-01 10:26:24 UTC (rev 31) @@ -23,7 +23,16 @@ import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import org.hibernate.annotations.GenericGenerator; + + /** * The global variable defines the general concept of a statistical variable (e.g. income). More special definitions can be provided * when combining a global variable with a statistical object to an {@link ObjectVariable}. Variable families can group global @@ -31,33 +40,66 @@ * * @author jsegura */ +@Entity public class GlobalVariable implements Serializable { private static final long serialVersionUID = 1661678204467740737L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** A global variable is identified by a unique language independent identifier, which may typically be an abbreviation of its name. */ + @Column(unique = true, length = 50) private String identifier; /** The official name of the global variable is provided by the owner of the variable. */ + @Column(length = 250) private String name = ""; /** * Short general multilingual description of the global variable, including its purpose, its main subject areas etc. */ + @Column(length = 500) private String description = ""; /** Family to which the global variable belongs. */ + @ManyToOne + @JoinColumn(name = "variableFamily_id", insertable = false, updatable = false) private VariableFamily variableFamily; + + private GlobalVariable( ) + {} + /** - * Creates a new GlobalVariable identified by the identifier + * Creates a new GlobalVariable identified by the identifier and placed in the variableFamily. * * @param identifier The identifier of the GlobalVariable. + * @param variableFamily The Variable Family where the GlobalVariable will be placed. * @throws NullPointerException If the identifier is <code>null</code> or is empty. */ + public GlobalVariable( VariableFamily variableFamily, String identifier ) + { + this.setIdentifier( identifier ); + this.setVariableFamily( variableFamily ); + } + + /** + * Creates a new GlobalVariable identified by the identifier. + * + * @param identifier The identifier of the GlobalVariable. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ public GlobalVariable( String identifier ) { this.setIdentifier( identifier ); } + /** * Returns the identifier of the Global Variable. * @@ -144,7 +186,6 @@ * Sets the new {@link VariableFamily} of the GlobalVariable. * * @param variableFamily The variableFamily to set. - * @throws NullPointerException If the {@link VariableFamily} is <code>null</code>. */ public void setVariableFamily( VariableFamily variableFamily ) { @@ -153,5 +194,17 @@ if( this.variableFamily != null ) this.variableFamily.addGlobalVariable( this ); } + @Override + public boolean equals( Object object ) + { + GlobalVariable other = (GlobalVariable) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ) && this.getVariableFamily( ).equals( other.getVariableFamily( ) ); + } + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ) ^ (this.getVariableFamily( ) == null ? 0 : this.getVariableFamily( ).hashCode( )); + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,13 +21,30 @@ */ package org.surveyforge.core.metadata; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.annotations.GenericGenerator; + /** * @author jsegura */ + public class LogicalValueDomain extends ValueDomain { private static final long serialVersionUID = 2066579378848047283L; +// @Id +// @Column(length = 50) +// @GeneratedValue(generator = "system-uuid") +// @GenericGenerator(name = "system-uuid", strategy = "uuid") +// private String id; +// /** Version for optimistic locking. */ +// @javax.persistence.Version +// private int lockingVersion; + public boolean isValid( Object object ) { return (Boolean.class.isInstance( object )); Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-08-01 10:26:24 UTC (rev 31) @@ -26,6 +26,21 @@ import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; +import org.surveyforge.core.survey.Study; + /** * An object variable defines the concept of a variable in connection with a defined statistical object (e.g. the income of a person). * The general description of the meaning of the variable is part of the global variable definition, which is linked to the object @@ -33,38 +48,67 @@ * * @author jsegura */ +@Entity public class ObjectVariable implements Serializable { - private static final long serialVersionUID = 4288089682729653747L; + private static final long serialVersionUID = 4288089682729653747L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** * Unique and language independent identifier for the object variable. The identifier is unique among all object variables. The * identifier should contain identifications for the statistical object and the global variable it is based on. */ - private String identifier; + @Column(unique = true, length = 50) + private String identifier; /** The name is the official, language dependent name of the global variable, provided by the owner of the variable. */ - private String name = ""; + @Column(length = 250) + private String name = ""; /** Short general multilingual description of the object variable, including its purpose, its main subject areas etc. */ - private String description = ""; + @Column(length = 500) + private String description = ""; /** * Each object variable belongs to a statistical object or unit. The object variable exists only in the context of the object * variable. */ - private StatisticalObjectType statisticalObjectType; + @ManyToOne + @JoinColumn(name = "statisticalObjectType_id", insertable = false, updatable = false) + private StatisticalObjectType statisticalObjectType; /** An object variable should refer to a global variable definition that reflects the general concepts of the object variable. */ - private GlobalVariable globalVariable; + @ManyToOne + @JoinColumn(name = "globalVariable_id", insertable = false, updatable = false) + private GlobalVariable globalVariable; + /** Based on an object variable a number of data elements may refer to this object variable. */ - private List<DataElement> dataElements = new ArrayList<DataElement>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "dataElementsIndex") + @JoinColumn(name = "objectVariable_id") + private List<ConceptualDataElement> conceptualDataElements = new ArrayList<ConceptualDataElement>( ); + private ObjectVariable( ) + {} + /** * Creates a new instance of ObjectVariable identified by identifier. * + * @param statisticalObjectType + * @param globalVariable * @param identifier The identifier to set. * @throws NullPointerException If the identifier is <code>null</code> or is empty. */ - public ObjectVariable( String identifier ) + public ObjectVariable( StatisticalObjectType statisticalObjectType, GlobalVariable globalVariable, String identifier ) { + this.setStatisticalObjectType( statisticalObjectType ); + this.setGlobalVariable( globalVariable ); this.setIdentifier( identifier ); } @@ -159,7 +203,10 @@ public void setStatisticalObjectType( StatisticalObjectType statisticalObjectType ) { if( statisticalObjectType != null ) + { this.statisticalObjectType = statisticalObjectType; + this.statisticalObjectType.addObjectVariable( this ); + } else throw new NullPointerException( ); } @@ -189,33 +236,45 @@ } /** - * Returns the list of {@link DataElement} linked to this ObjectVariable. + * Returns the list of {@link ConceptualDataElement} linked to this ObjectVariable. * - * @return Returns the list of dataElements. + * @return Returns the list of ConceptualDataElements. */ - public List<DataElement> getDataElements( ) + public List<ConceptualDataElement> getConceptualDataElements( ) { - return Collections.unmodifiableList( dataElements ); + return Collections.unmodifiableList( conceptualDataElements ); } /** - * Adds a new {@link DataElement} to the list. + * Adds a new {@link ConceptualDataElement} to the list. * - * @param dataElements The dataElements to add. + * @param dataElements The conceptualDataElement to add. */ - protected void addDataElement( DataElement dataElement ) + protected void addConceptualDataElement( ConceptualDataElement conceptualDataElement ) { - this.dataElements.add( dataElement ); + this.conceptualDataElements.add( conceptualDataElement ); } /** - * Removes a {@link DataElement} from the list. + * Removes a {@link ConceptualDataElement} from the list. * - * @param dataElements The dataElements to remove. + * @param dataElements The conceptualDataElement to remove. */ - protected void removeDataElement( DataElement dataElement ) + protected void removeConceptualDataElement( ConceptualDataElement conceptualDataElement ) { - this.dataElements.remove( dataElement ); + this.conceptualDataElements.remove( conceptualDataElement ); } + @Override + public boolean equals( Object object ) + { + ObjectVariable other = (ObjectVariable) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,45 +21,108 @@ */ package org.surveyforge.core.metadata; +import java.io.Serializable; import java.util.Collections; -import java.util.LinkedHashMap; +import java.util.HashMap; import java.util.List; import java.util.ArrayList; +import java.util.Map; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; +import org.hibernate.annotations.MapKey; import org.surveyforge.core.data.RegisterData; +import org.surveyforge.core.survey.Questionnaire; // TODO Elaborate on comments /** * @author jsegura */ -public class Register +@Entity +public class Register implements Serializable { + private static final long serialVersionUID = 0L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** * The name of the register is either a systematic name according to the naming conventions in the organisation or a human language * name that reflects the idea or concept of the cube or register. */ - private String identifier; + @Column(unique = true, length = 50) + private String identifier; /** * When defining hierarchical registers the hierarchy is expressed as master/detail relationship. The master register defines the * objects that consist of the details. */ - private Register masterRegister = null; + @ManyToOne + @JoinColumn(name = "masterRegister_id", insertable = false, updatable = false) + private Register masterRegister = null; + /** * When defining hierarchical registers the hierarchy is expressed as master/detail relationship. The detail registers defines the * objects that are owned by the master objects. */ - private List<Register> detailRegisters = new ArrayList<Register>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "detailRegistersIndex") + @JoinColumn(name = "masterRegister_id") + private List<Register> detailRegisters = new ArrayList<Register>( ); /** */ - private LinkedHashMap<String, Integer> indexes; + + @CollectionOfElements + @MapKey(columns = {@Column(name = "elementMapKey", length = 50)}) + @Column(name = "index", length = 10) + private Map<String, Integer> indexes = new HashMap<String, Integer>( ); + /** */ - private List<RegisterDataElement> registerDataElements = new ArrayList<RegisterDataElement>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "registerDataElementsIndex") + @JoinColumn(name = "register_id", nullable = false) + private List<RegisterDataElement> registerDataElements = new ArrayList<RegisterDataElement>( ); + /** */ - private List<RegisterDataElement> key = new ArrayList<RegisterDataElement>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "keyIndex") + @JoinColumn(name = "registerKey_id") + private List<RegisterDataElement> key = new ArrayList<RegisterDataElement>( ); + /** */ - private List<ValidationRule> validationRules = new ArrayList<ValidationRule>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "validationRulesIndex") + @JoinColumn(name = "register_id") + private List<ValidationRule> validationRules = new ArrayList<ValidationRule>( ); + /** */ - private RegisterData registerData; + @OneToOne(optional = false, cascade = {CascadeType.ALL}) + private RegisterData registerData; + /** */ + @OneToOne(mappedBy = "register", fetch = FetchType.LAZY, optional = true) + // @OneToOne(fetch = FetchType.LAZY) + private Questionnaire questionnaire; + + + private Register( ) + {} + /** * @param registerDataElements * @param key @@ -68,6 +131,7 @@ public Register( String identifier ) { this.setIdentifier( identifier ); + this.registerData = new RegisterData( this ); } /** @@ -141,6 +205,33 @@ return Collections.unmodifiableList( this.registerDataElements ); } + + protected void addRegisterDataElement( RegisterDataElement registerDataElement ) + { + if( registerDataElement == null ) + throw new NullPointerException( ); + else if( registerData == null || registerData.getRows( ).size( ) > 0 ) + throw new IllegalArgumentException( ); + else + { + this.registerDataElements.add( registerDataElement ); + // this.updateElements( ); + } + } + + protected void removeRegisterDataElement( RegisterDataElement registerDataElement ) + { + if( registerDataElement == null ) + throw new NullPointerException( ); + else if( registerData != null ) + throw new IllegalArgumentException( ); + else + { + this.registerDataElements.remove( registerDataElement ); + this.updateElements( ); + } + } + /** * @param registerDataElements */ @@ -159,7 +250,6 @@ } } - /** * @return Returns the key. */ @@ -230,23 +320,10 @@ return this.registerData; } - /** - * @param registerData The registerData to set. - */ - public void setRegisterData( RegisterData registerData ) - { - if( registerData != null && this.registerDataElements.isEmpty( ) ) - throw new IllegalArgumentException( ); - else if( registerData == null && !this.registerDataElements.isEmpty( ) ) - throw new NullPointerException( ); - else - this.registerData = registerData; - } - private void updateElements( ) { - LinkedHashMap<String, Integer> fieldIndexes = new LinkedHashMap<String, Integer>( ); + HashMap<String, Integer> fieldIndexes = new HashMap<String, Integer>( ); int index = 0; for( RegisterDataElement currentRegisterDataElement : this.registerDataElements ) { @@ -260,16 +337,11 @@ } else { - // There are duplicated field names - // String errorMessage = RecordMetadata.messages.getString( "message.duplicated.names" ); - // if( RecordMetadata.log.isInfoEnabled( ) ) - // { - // RecordMetadata.log.info( RecordMetadata.messages.getString( "exception.duplicated.names" ) + errorMessage ); - // } throw new IllegalArgumentException( ); } } + // TODO Hardwritted -1 public int getElementIndex( String elementIdentifier ) { Integer index = this.indexes.get( elementIdentifier ); @@ -281,4 +353,29 @@ return new ArrayList<String>( this.indexes.keySet( ) ); } + + public Questionnaire getQuestionnaire( ) + { + return this.questionnaire; + } + + + public void setQuestionnaire( Questionnaire questionnaire ) + { + this.questionnaire = questionnaire; + } + + @Override + public boolean equals( Object object ) + { + Register otherRegister = (Register) object; + return this.getIdentifier( ).equals( otherRegister.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,19 +21,40 @@ */ package org.surveyforge.core.metadata; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.IndexColumn; +import org.surveyforge.core.survey.Question; + /** * Register data elements define data elements for a register. In contrast to an abstract data element a register data element is * defined in the context of a register and carries process information besides conceptual one. * * @author jsegura */ +@Entity public class RegisterDataElement extends DataElement { private static final long serialVersionUID = -8986375207717119033L; /** The context data element describes the basic properties of the register data element. */ + @ManyToOne + @JoinColumn(name = "conceptualDataElement") private ConceptualDataElement conceptualDataElement; + /** */ + private boolean optional; + /** */ + @ManyToOne(optional = true) + private Question question; + /** * Creates a new instance of ConceptualDataElement linked with a {@link ConceptualDataElement}. * @@ -71,5 +92,36 @@ throw new NullPointerException( ); } + /** + * @return the optional + */ + public boolean isOptional( ) + { + return this.optional; + } + /** + * @param optional the optional to set + */ + public void setOptional( boolean optional ) + { + this.optional = optional; + } + + /** + * @return the question + */ + public Question getQuestion( ) + { + return this.question; + } + + /** + * @param question the question to set + */ + public void setQuestion( Question question ) + { + this.question = question; + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-08-01 10:26:24 UTC (rev 31) @@ -26,6 +26,20 @@ import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; +import org.surveyforge.core.survey.Study; + /** * Statistical objects or units may be real world objects (e.g. person, enterprise) or abstract objects like events or states (e.g. * accident, temperature). A statistical object or unit describes the type of object observed in a statistical survey or presented in a @@ -33,26 +47,52 @@ * * @author jsegura */ +@Entity public class StatisticalObjectType implements Serializable { private static final long serialVersionUID = 3051156955695891963L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** * A statistical object is identified by a unique language independent identifier, which may typically be an abbreviation of its * name. */ + @Column(unique = true, length = 50) private String identifier; /** Unique name statistical unit. */ + @Column(length = 250) private String name = ""; /** Short general multilingual description of the statistical object/unit, including its purpose, its main subject areas etc. */ + @Column(length = 500) private String description = ""; /** A super-type is a generalisation of an object type. */ + @ManyToOne + @JoinColumn(name = "superType_id", insertable = false, updatable = false) private StatisticalObjectType superType; /** A sub type describes a specialisation of the type. Sub types are described as "IS A" relationships. */ + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "subTypesIndex") + @JoinColumn(name = "superType_id") private List<StatisticalObjectType> subTypes = new ArrayList<StatisticalObjectType>( ); /** Object variables defined for the statistical object/unit. */ + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "objectVariablesIndex") + @JoinColumn(name = "statisticalObjectType_id", nullable = false) private List<ObjectVariable> objectVariables = new ArrayList<ObjectVariable>( ); + + private StatisticalObjectType( ) + {} + /** * Creates a new {@link StatisticalObjectType} identified by identifier. * @@ -233,4 +273,18 @@ throw new NullPointerException( ); } + // TODO add subtypes to hashcode & equals + @Override + public boolean equals( Object object ) + { + StatisticalObjectType other = (StatisticalObjectType) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,14 +21,44 @@ */ package org.surveyforge.core.metadata; +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +import org.hibernate.annotations.GenericGenerator; + /* - * TODO : implementation of ValidationRule - * TODO: Elaborate on comments + * TODO : implementation of ValidationRule TODO: Elaborate on comments */ /** * @author jsegura */ -public class ValidationRule +@Entity +public class ValidationRule implements Serializable { + private static final long serialVersionUID = 0L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + @ManyToOne + @JoinColumn(name = "register_id", insertable = false, updatable = false) + private Register register; + + public ValidationRule( ) + {} + + // TODO hashcode + equals + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java 2006-08-01 10:26:24 UTC (rev 31) @@ -23,13 +23,38 @@ import java.io.Serializable; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.annotations.GenericGenerator; + // TODO: Elaborate on comments /** * @author jsegura */ -public abstract class ValueDomain implements Serializable +@Entity +public class ValueDomain implements Serializable { - private static final long serialVersionUID = 7936854840394336906L; + private static final long serialVersionUID = -83487445078388347L; - public abstract boolean isValid( Object object ); + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + + public ValueDomain( ) + {} + + public boolean isValid( Serializable data ) + { + // TODO Auto-generated method stub + return false; + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java 2006-08-01 10:26:24 UTC (rev 31) @@ -26,25 +26,55 @@ import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * A variable family groups a number of global variables that refer to a certain theme. * * @author jsegura */ +@Entity public class VariableFamily implements Serializable { private static final long serialVersionUID = 7344092827765295413L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** A VariableFamily is identified by a unique identifier. */ + @Column(unique = true, length = 50) private String identifier; /** * Detailed description of the VariableFamily. The description describes the theme of the {@link GlobalVariable}s included in the * family. */ + @Column(length = 500) private String description = ""; /** The family have the list of all {@link GlobalVariable}s included in the theme. */ + + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "globalVariablesIndex") + @JoinColumn(name = "variableFamily_id", nullable = false) private List<GlobalVariable> globalVariables = new ArrayList<GlobalVariable>( ); + private VariableFamily( ) + {} /** * Creates a new Family identified by the identifier. @@ -142,4 +172,18 @@ else throw new NullPointerException( ); } + + @Override + public boolean equals( Object object ) + { + VariableFamily other = (VariableFamily) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + } Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/package-info.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/package-info.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/package-info.java 2006-08-01 10:26:24 UTC (rev 31) @@ -0,0 +1 @@ +package org.surveyforge.core; \ No newline at end of file Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/package-info.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,32 +21,70 @@ */ package org.surveyforge.core.survey; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * The question contain the text for the question, with the sub questions being used to provide further information about the question. * Alternatively, the question may be empty and only the sub questions used. Each sub element has a reference to its upper question. * * @author jsegura */ -public class Question +@Entity +public class Question implements Serializable { + private static final long serialVersionUID = 0L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** A question has a language independent identifier that identifies the question among all other globally defined questions. */ - private String identifier; + @Column(unique = true, length = 50) + private String identifier; /** * The question contains the exact text of the question that has been asked to collect the data. The question text is language * dependent. */ - private String text = ""; + @Column(length = 250) + private String text = ""; /** The description contains explanatory notes to the question and/or an extended definition of the question's meaning. */ - private String description = ""; + @Column(length = 500) + private String description = ""; /** This is the question that acts as a frame for a number of sub questions. */ - private Question upperQuestion = null; + @ManyToOne + @JoinColumn(name = "upperQuestion_id", insertable = false, updatable = false) + private Question upperQuestion = null; /** A question referring to a complex fact can be divided in a number of sub questions. */ - private List<Question> subQuestions = new ArrayList<Question>( ); + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "subQuestionsIndex") + @JoinColumn(name = "upperQuestion_id", nullable = false) + private List<Question> subQuestions = new ArrayList<Question>( ); + + private Question( ) + {} + /** * Creates a new Question with an identifier. * @@ -168,7 +206,7 @@ * @param subQuestions The subQuestions to add. * @throws NullPointerException If the subquestion is <code>null</code>. */ - protected void addSubQuestion( Question subQuestion ) + private void addSubQuestion( Question subQuestion ) { if( subQuestion != null ) this.subQuestions.add( subQuestion ); @@ -182,11 +220,25 @@ * @param subQuestion the subQuestion to remove. * @throws NullPointerException If the subquestion is <code>null</code>. */ - protected void removeSubQuestion( Question subQuestion ) + private void removeSubQuestion( Question subQuestion ) { if( subQuestion != null ) this.subQuestions.remove( subQuestion ); else throw new NullPointerException( ); } + + @Override + public boolean equals( Object object ) + { + Question other = (Question) object; + return this.getIdentifier( ).equals( other.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,10 +21,23 @@ */ package org.surveyforge.core.survey; +import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.OneToOne; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; import org.surveyforge.core.metadata.Register; /** @@ -33,28 +46,55 @@ * * @author jsegura */ -public class Questionnaire +@Entity +public class Questionnaire implements Serializable { + private static final long serialVersionUID = 6844066269698434310L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** * A questionnaire is identified by an identifier, which is unique in the context of a statistical activity. It may typically be an * abbreviation of its title or a systematic number. */ + @Column(unique = true, nullable = false, length = 50) private String identifier; /** A questionnaire has a title as provided by the owner or maintenance unit. */ - private String title = ""; + @Column(length = 250) + private String title = ""; /** * Detailed description of the questionnaire. The questionnaire description typically describes the underlying concept of the * questionnaire and basic principles. */ - private String description = ""; + @Column(length = 500) + private String description = ""; /** A questionnaire consists of a number of questionnaire elements. Each element refers to a question. */ - private List<QuestionnaireElement> elements = new ArrayList<QuestionnaireElement>( ); + + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @IndexColumn(name = "questionnairesIndex") + @JoinColumn(name = "questionnaire_id", nullable = false) + private List<QuestionnaireElement> elements = new ArrayList<QuestionnaireElement>( ); + /** A questionnaire corresponds logically to a register, which describes the content of the data collection. */ + @OneToOne(fetch = FetchType.LAZY) private Register register; + /** A questionnaire is included in a Study. */ + @ManyToOne + @JoinColumn(name = "study_id", insertable = false, updatable = false) private Study study; + private Questionnaire( ) + {} + /** * Creates a new Questionnaire included in a Study, corresponding to a Register and identified bu identifier. * @@ -225,10 +265,25 @@ public void setStudy( Study study ) { if( study != null ) + { this.study = study; + this.study.addQuestionnaire( this ); + } else throw new NullPointerException( ); } + @Override + public boolean equals( Object object ) + { + Questionnaire otherQuestionnaire = (Questionnaire) object; + return this.getStudy( ).equals( otherQuestionnaire.getStudy( ) ) + && this.getIdentifier( ).equals( otherQuestionnaire.getIdentifier( ) ); + } + @Override + public int hashCode( ) + { + return this.getStudy( ).hashCode( ) ^ this.getIdentifier( ).hashCode( ); + } } Modified: trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-07-26 07:34:35 UTC (rev 30) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java 2006-08-01 10:26:24 UTC (rev 31) @@ -21,6 +21,16 @@ */ package org.surveyforge.core.survey; +import java.io.Serializable; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import org.hibernate.annotations.GenericGenerator; import org.surveyforge.core.metadata.RegisterDataElement; @@ -30,19 +40,42 @@ * * @author jsegura */ -public class QuestionnaireElement +@Entity +public class QuestionnaireElement implements Serializable { + private static final long serialVersionUID = 0L; + + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + /** A questionnaire element is identified by a unique identifier. */ + @Column(unique = true, length = 50) private String identifier; /** Each questionnaire element has a {@link Question} that has the text and the structure of the question. */ + @ManyToOne(optional = true, cascade = {CascadeType.ALL}) + @JoinColumn(name = "question_id", insertable = false, updatable = false) private Question question = null; /** A questionnaire element have a {@link RegisterDataElement} to have the info of the data. */ + @ManyToOne(optional = false) + @JoinColumn(name = "registerDataElement_id", insertable = false, updatable = false) private RegisterDataElement registerDataElement; /** Default answer if the question is not applicable. */ + @Column(nullable = false, length = 50) private String defaultNotApplicable = ""; /** Default answer if the question is not answered. */ + @Column(nullable = false, length = 50) private String defaultNotAnswered = ""; + + private QuestionnaireElement( ) + {} + /** * Creates a new instance of a QuestionnaireElement linked to the registerDataElement and identified by identifier. * @@ -171,4 +204,20 @@ else throw new NullPointerException( ); } + + // TODO : Equals+hashcode + // @Override + // public boolean equals( Object object ) + // { + // Questionnaire otherQuestionnaire = (Questionnaire) object; + // return this.getQuestion( )( ).equals( otherQuestionnaire.getStudy( ) ) + // && this.getIdentifier( ).equals( otherQuestionnaire.getIdentifier( ) ); + // } + // + // @Override + // public int hashCode( ) + // { + // return this.getStudy( ).h... [truncated message content] |
From: <ja...@us...> - 2006-07-26 11:49:17
|
Revision: 30 Author: javism Date: 2006-07-26 00:34:35 -0700 (Wed, 26 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=30&view=rev Log Message: ----------- Fixed the use of tabs instead of spaces Modified Paths: -------------- trunk/surveyforge-core/pom.xml Modified: trunk/surveyforge-core/pom.xml =================================================================== --- trunk/surveyforge-core/pom.xml 2006-07-21 08:56:54 UTC (rev 29) +++ trunk/surveyforge-core/pom.xml 2006-07-26 07:34:35 UTC (rev 30) @@ -8,27 +8,27 @@ <modelVersion>4.0.0</modelVersion> <artifactId>surveyforge-core</artifactId> <name>SurveyForge Core API</name> - <dependencies> - <dependency> - <groupId>org.testng</groupId> - <artifactId>testng</artifactId> - <classifier>jdk15</classifier> - </dependency> - <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - </dependency> - <dependency> - <groupId>org.surveyforge</groupId> - <artifactId>surveyforge-classification</artifactId> - </dependency> - <dependency> - <groupId>javax.persistence</groupId> - <artifactId>persistence-api</artifactId> - </dependency> + <dependencies> <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-classification</artifactId> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + </dependency> + <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-annotations</artifactId> </dependency> - </dependencies> + </dependencies> </project> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-21 08:57:01
|
Revision: 29 Author: jgongo Date: 2006-07-21 01:56:54 -0700 (Fri, 21 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=29&view=rev Log Message: ----------- Uncommented classification classes Modified Paths: -------------- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml Modified: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml =================================================================== --- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-21 06:23:28 UTC (rev 28) +++ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-21 08:56:54 UTC (rev 29) @@ -13,43 +13,37 @@ <property name="show_sql">false</property> <!-- mapping files --> - <!-- + <!-- package org.surveyforge.util --> <mapping class="org.surveyforge.util.InternationalizedString" /> + + <!-- package org.surveyforge.classification --> <mapping class="org.surveyforge.classification.Family" /> <mapping class="org.surveyforge.classification.Classification" /> <mapping class="org.surveyforge.classification.Version" /> <mapping class="org.surveyforge.classification.Level" /> <mapping class="org.surveyforge.classification.Item" /> - --> - <!-- package org.surveyforge.core.survey --> + <!-- package org.surveyforge.core.survey --> <mapping class="org.surveyforge.core.survey.QuestionnaireElement" /> <mapping class="org.surveyforge.core.survey.Study" /> <mapping class="org.surveyforge.core.survey.Questionnaire" /> <mapping class="org.surveyforge.core.survey.Question" /> - <!-- package org.surveyforge.core.metadata --> - <mapping class="org.surveyforge.core.metadata.ValidationRule" /> - <mapping class="org.surveyforge.core.metadata.Register" /> - <mapping class="org.surveyforge.core.metadata.RegisterDataElement" /> - <mapping class="org.surveyforge.core.metadata.ConceptualDataElement" /> - <mapping class="org.surveyforge.core.metadata.DataElement" /> - <mapping class="org.surveyforge.core.metadata.ValueDomain" /> - <mapping class="org.surveyforge.core.metadata.ObjectVariable" /> - <mapping class="org.surveyforge.core.metadata.GlobalVariable" /> - <mapping class="org.surveyforge.core.metadata.VariableFamily" /> - <mapping class="org.surveyforge.core.metadata.StatisticalObjectType" /> + <!-- package org.surveyforge.core.metadata --> + <mapping class="org.surveyforge.core.metadata.ValidationRule" /> + <mapping class="org.surveyforge.core.metadata.Register" /> + <mapping class="org.surveyforge.core.metadata.RegisterDataElement" /> + <mapping class="org.surveyforge.core.metadata.ConceptualDataElement" /> + <mapping class="org.surveyforge.core.metadata.DataElement" /> + <mapping class="org.surveyforge.core.metadata.ValueDomain" /> + <mapping class="org.surveyforge.core.metadata.ObjectVariable" /> + <mapping class="org.surveyforge.core.metadata.GlobalVariable" /> + <mapping class="org.surveyforge.core.metadata.VariableFamily" /> + <mapping class="org.surveyforge.core.metadata.StatisticalObjectType" /> <!-- package org.surveyforge.core.data --> <mapping class="org.surveyforge.core.data.RegisterData" /> <mapping class="org.surveyforge.core.data.Row" /> <mapping class="org.surveyforge.core.data.RowData" /> - - <!-- cache settings --> - <!-- - <class-cache class="org.hibernate.auction.Item" usage="read-write" /> - <class-cache class="org.hibernate.auction.Bid" usage="read-only" /> - <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write" /> - --> </session-factory> </hibernate-configuration> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-07-21 06:23:39
|
Revision: 28 Author: javism Date: 2006-07-20 23:23:28 -0700 (Thu, 20 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=28&view=rev Log Message: ----------- Added Core classes Modified Paths: -------------- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml Modified: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml =================================================================== --- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-20 09:36:23 UTC (rev 27) +++ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-21 06:23:28 UTC (rev 28) @@ -13,11 +13,43 @@ <property name="show_sql">false</property> <!-- mapping files --> + <!-- <mapping class="org.surveyforge.util.InternationalizedString" /> <mapping class="org.surveyforge.classification.Family" /> <mapping class="org.surveyforge.classification.Classification" /> <mapping class="org.surveyforge.classification.Version" /> <mapping class="org.surveyforge.classification.Level" /> <mapping class="org.surveyforge.classification.Item" /> + --> + + <!-- package org.surveyforge.core.survey --> + <mapping class="org.surveyforge.core.survey.QuestionnaireElement" /> + <mapping class="org.surveyforge.core.survey.Study" /> + <mapping class="org.surveyforge.core.survey.Questionnaire" /> + <mapping class="org.surveyforge.core.survey.Question" /> + + <!-- package org.surveyforge.core.metadata --> + <mapping class="org.surveyforge.core.metadata.ValidationRule" /> + <mapping class="org.surveyforge.core.metadata.Register" /> + <mapping class="org.surveyforge.core.metadata.RegisterDataElement" /> + <mapping class="org.surveyforge.core.metadata.ConceptualDataElement" /> + <mapping class="org.surveyforge.core.metadata.DataElement" /> + <mapping class="org.surveyforge.core.metadata.ValueDomain" /> + <mapping class="org.surveyforge.core.metadata.ObjectVariable" /> + <mapping class="org.surveyforge.core.metadata.GlobalVariable" /> + <mapping class="org.surveyforge.core.metadata.VariableFamily" /> + <mapping class="org.surveyforge.core.metadata.StatisticalObjectType" /> + + <!-- package org.surveyforge.core.data --> + <mapping class="org.surveyforge.core.data.RegisterData" /> + <mapping class="org.surveyforge.core.data.Row" /> + <mapping class="org.surveyforge.core.data.RowData" /> + + <!-- cache settings --> + <!-- + <class-cache class="org.hibernate.auction.Item" usage="read-write" /> + <class-cache class="org.hibernate.auction.Bid" usage="read-only" /> + <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write" /> + --> </session-factory> </hibernate-configuration> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-20 09:36:49
|
Revision: 27 Author: jgongo Date: 2006-07-20 02:36:23 -0700 (Thu, 20 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=27&view=rev Log Message: ----------- Creation of profiles and extraction of parameters for database access Modified Paths: -------------- trunk/pom.xml trunk/surveyforge-db/pom.xml trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml Added Paths: ----------- trunk/surveyforge-db/src/main/filters/ trunk/surveyforge-db/src/main/filters/database.properties trunk/surveyforge-db/src/main/filters/script.properties trunk/surveyforge-db/src/test/filters/ trunk/surveyforge-db/src/test/filters/database.properties Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-07-19 11:06:19 UTC (rev 26) +++ trunk/pom.xml 2006-07-20 09:36:23 UTC (rev 27) @@ -101,13 +101,11 @@ <version>1.0-SNAPSHOT</version> <configuration> <hibernate> - <configurationFile>/src/main/resources/hibernate.cfg.xml</configurationFile> + <configurationFile>/target/classes/hibernate.cfg.xml</configurationFile> </hibernate> <outputDirectory> <hbm2ddl>target/hibernate3/sql</hbm2ddl> </outputDirectory> - <!-- <outputFile>target/hibernate3/sql/classification.sql</outputFile> --> - <drop>true</drop> </configuration> </plugin> </plugins> Modified: trunk/surveyforge-db/pom.xml =================================================================== --- trunk/surveyforge-db/pom.xml 2006-07-19 11:06:19 UTC (rev 26) +++ trunk/surveyforge-db/pom.xml 2006-07-20 09:36:23 UTC (rev 27) @@ -9,25 +9,81 @@ <artifactId>surveyforge-db</artifactId> <name>SurveyForge database generation and tests</name> <build> + <!-- Unfortunately it seems this can't be externalized --> + <extensions> + <extension> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>8.1-407.jdbc3</version> + </extension> + </extensions> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + </resource> + </resources> + <testResources> + <testResource> + <directory>src/test/resources</directory> + <filtering>true</filtering> + </testResource> + </testResources> + <filters> + <filter>src/test/filters/database.properties</filter> + </filters> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>hibernate3-maven-plugin</artifactId> - <configuration> - <outputFile>surveyforge.sql</outputFile> - </configuration> </plugin> </plugins> - <!-- - <extensions> - <extension> - <groupId>postgresql</groupId> - <artifactId>postgresql</artifactId> - <version>8.1-407.jdbc3</version> - </extension> - </extensions> - --> </build> + <profiles> + <profile> + <id>script</id> + <activation> + <activeByDefault>true</activeByDefault> + </activation> + <build> + <filters> + <filter>src/main/filters/script.properties</filter> + </filters> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>hibernate3-maven-plugin</artifactId> + <extensions>false</extensions> + <configuration> + <outputFile>surveyforge.sql</outputFile> + </configuration> + </plugin> + </plugins> + </pluginManagement> + </build> + </profile> + <profile> + <id>database</id> + <build> + <filters> + <filter>src/main/filters/database.properties</filter> + </filters> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>hibernate3-maven-plugin</artifactId> + <configuration> + <drop>true</drop> + </configuration> + <extensions>true</extensions> + </plugin> + </plugins> + </pluginManagement> + </build> + </profile> + </profiles> <dependencies> <dependency> <groupId>org.surveyforge</groupId> Added: trunk/surveyforge-db/src/main/filters/database.properties =================================================================== --- trunk/surveyforge-db/src/main/filters/database.properties (rev 0) +++ trunk/surveyforge-db/src/main/filters/database.properties 2006-07-20 09:36:23 UTC (rev 27) @@ -0,0 +1,5 @@ +database.dialect=org.hibernate.dialect.PostgreSQLDialect +database.driver=org.postgresql.Driver +database.url=jdbc:postgresql://localhost/surveyforge +database.username=postgres +database.password=postgres Added: trunk/surveyforge-db/src/main/filters/script.properties =================================================================== --- trunk/surveyforge-db/src/main/filters/script.properties (rev 0) +++ trunk/surveyforge-db/src/main/filters/script.properties 2006-07-20 09:36:23 UTC (rev 27) @@ -0,0 +1 @@ +database.dialect=org.hibernate.dialect.PostgreSQLDialect Modified: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml =================================================================== --- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-19 11:06:19 UTC (rev 26) +++ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-20 09:36:23 UTC (rev 27) @@ -4,21 +4,13 @@ "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> - <!-- a SessionFactory instance listed as /jndi/name --> - <session-factory name="java:hibernate/SessionFactory"> - <!-- properties --> - <!-- <property name="connection.datasource">java:/comp/env/jdbc/MyDB</property> --> - <!-- - <property name="connection.driver_class">org.postgresql.Driver</property> - <property name="connection.url">jdbc:postgresql://server/DATABASE</property> - <property name="connection.username">user</property> - <property name="connection.password">password</property> - <property name="show_sql">false</property> - <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property> - <property name="jta.UserTransaction">java:comp/UserTransaction</property> - <property name="ejb.naming_strategy">org.hibernate.cfg.DefaultComponentSafeNamingStrategy</property> - --> - <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> + <session-factory> + <property name="dialect">${database.dialect}</property> + <property name="connection.driver_class">${database.driver}</property> + <property name="connection.url">${database.url}</property> + <property name="connection.username">${database.username}</property> + <property name="connection.password">${database.password}</property> + <property name="show_sql">false</property> <!-- mapping files --> <mapping class="org.surveyforge.util.InternationalizedString" /> @@ -27,12 +19,5 @@ <mapping class="org.surveyforge.classification.Version" /> <mapping class="org.surveyforge.classification.Level" /> <mapping class="org.surveyforge.classification.Item" /> - - <!-- cache settings --> - <!-- - <class-cache class="org.hibernate.auction.Item" usage="read-write" /> - <class-cache class="org.hibernate.auction.Bid" usage="read-only" /> - <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write" /> - --> </session-factory> </hibernate-configuration> Added: trunk/surveyforge-db/src/test/filters/database.properties =================================================================== --- trunk/surveyforge-db/src/test/filters/database.properties (rev 0) +++ trunk/surveyforge-db/src/test/filters/database.properties 2006-07-20 09:36:23 UTC (rev 27) @@ -0,0 +1,5 @@ +test.database.dialect=org.hibernate.dialect.HSQLDialect +test.database.driver=org.hsqldb.jdbcDriver +test.database.url=jdbc:hsqldb:mem:surveyforge +test.database.username=sa +test.database.password= Modified: trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml 2006-07-19 11:06:19 UTC (rev 26) +++ trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml 2006-07-20 09:36:23 UTC (rev 27) @@ -10,13 +10,11 @@ <class>org.surveyforge.classification.Level</class> <class>org.surveyforge.classification.Item</class> <properties> - <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> - <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> - <property name="hibernate.connection.url" value="jdbc:postgresql://server/DATABASE" /> - <property name="hibernate.connection.username" value="user" /> - <property name="hibernate.connection.password" value="password" /> - <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file --> - <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ --> + <property name="hibernate.dialect" value="${test.database.dialect}" /> + <property name="hibernate.connection.driver_class" value="${test.database.driver}" /> + <property name="hibernate.connection.url" value="${test.database.url}" /> + <property name="hibernate.connection.username" value="${test.database.username}" /> + <property name="hibernate.connection.password" value="${test.database.password}" /> </properties> </persistence-unit> </persistence> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-19 11:06:42
|
Revision: 26 Author: jgongo Date: 2006-07-19 04:06:19 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=26&view=rev Log Message: ----------- Proper modeling of indexed collections, including implementation of equals and hashCode Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-18 12:55:01 UTC (rev 25) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-19 11:06:19 UTC (rev 26) @@ -421,6 +421,19 @@ throw new IllegalArgumentException( ); } + @Override + public boolean equals( Object object ) + { + Classification otherClassification = (Classification) object; + return this.getIdentifier( ).equals( otherClassification.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } + /** * Compares two verions ordering them by release date. * @@ -432,6 +445,5 @@ { return version1.getReleaseDate( ).compareTo( version2.getReleaseDate( ) ); } - } } Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-18 12:55:01 UTC (rev 25) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-19 11:06:19 UTC (rev 26) @@ -174,4 +174,17 @@ else throw new IllegalArgumentException( ); } + + @Override + public boolean equals( Object object ) + { + Family otherFamily = (Family) object; + return this.getIdentifier( ).equals( otherFamily.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } } Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-07-18 12:55:01 UTC (rev 25) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-07-19 11:06:19 UTC (rev 26) @@ -35,6 +35,7 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -66,7 +67,8 @@ @javax.persistence.Version private int lockingVersion; /** The level this item belongs to. */ - @ManyToOne(optional = false) + @ManyToOne + @JoinColumn(name = "level_id", insertable = false, updatable = false) private Level level; // TODO: Should we make any distinction among alphabetical, numericcal and alphanumerical codes? /** @@ -105,14 +107,16 @@ * Rev.1 item 10 is the parent of item 10.1. */ @ManyToOne + @JoinColumn(name = "parentItem_id", insertable = false, updatable = false) private Item parentItem; /** * Each item, which is not at the lowest level of the classification version or variant, might contain one or a number of sub items, * i.e. items at the next lower level of the classification version or variant. Ex.: In NACE Rev.1, the Group level items 10.1, 10.2 * and 10.3 are sub items of the Division level item 10. */ - @OneToMany(mappedBy = "parentItem", fetch = FetchType.LAZY) + @OneToMany(fetch = FetchType.LAZY) @IndexColumn(name = "subItemIndex") + @JoinColumn(name = "parentItem_id") private List<Item> subItems = new ArrayList<Item>( ); // TODO: Linked items @@ -462,4 +466,17 @@ { return Collections.unmodifiableList( this.subItems ); } + + @Override + public boolean equals( Object object ) + { + Item otherItem = (Item) object; + return this.getVersion( ).equals( otherItem.getVersion( ) ) && this.getCode( ).equals( otherItem.getCode( ) ); + } + + @Override + public int hashCode( ) + { + return this.getVersion( ).hashCode( ) ^ this.getCode( ).hashCode( ); + } } Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-18 12:55:01 UTC (rev 25) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-19 11:06:19 UTC (rev 26) @@ -33,6 +33,7 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; @@ -61,7 +62,8 @@ @javax.persistence.Version private int lockingVersion; /** The version this level belongs to. */ - @ManyToOne(optional = false) + @ManyToOne + @JoinColumn(name = "version_id", insertable = false, updatable = false) private Version version; /** The name given to the level. Ex.: Sections, Sub-sections, Divisions, Groups and Classes in NACE Rev.1. */ @Column(length = 50) @@ -95,8 +97,9 @@ @ManyToOne private Level foreignLevel; /** An ordered list of the categories (classification items) that constitute the level. */ - @OneToMany(mappedBy = "level", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "itemIndex") + @JoinColumn(name = "level_id", nullable = false) private List<Item> items = new ArrayList<Item>( ); /** Constructor provided for persistence engine. */ @@ -324,4 +327,17 @@ else throw new IllegalArgumentException( ); } + + @Override + public boolean equals( Object object ) + { + Level otherLevel = (Level) object; + return this.getVersion( ).equals( otherLevel.getVersion( ) ) && this.getName( ) == otherLevel.getName( ); + } + + @Override + public int hashCode( ) + { + return this.getVersion( ).hashCode( ) ^ this.getNumber( ); + } } Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-18 12:55:01 UTC (rev 25) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-19 11:06:19 UTC (rev 26) @@ -30,7 +30,6 @@ import java.util.Locale; import java.util.Set; -import javax.persistence.AttributeOverride; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; @@ -38,6 +37,7 @@ import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import javax.persistence.Temporal; @@ -169,8 +169,9 @@ @ManyToOne private Version derivedFrom; /** The structure of a classification version is defined by its levels. */ - @OneToMany(mappedBy = "version", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) + @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "levelIndex") + @JoinColumn(name = "version_id", nullable = false) private List<Level> levels = new ArrayList<Level>( ); // /** A list of all case laws associated with the classification version. */ @@ -752,4 +753,17 @@ // { // this.caseLaws = caseLaws; // } + + @Override + public boolean equals( Object object ) + { + Version otherVersion = (Version) object; + return this.getIdentifier( ).equals( otherVersion.getIdentifier( ) ); + } + + @Override + public int hashCode( ) + { + return this.getIdentifier( ).hashCode( ); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-18 12:55:16
|
Revision: 25 Author: jgongo Date: 2006-07-18 05:55:01 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=25&view=rev Log Message: ----------- 1. Added missing default private constructors needed by persistence engine 2. Support for internationalized strings in item titles 3. Support for alternative titles in items Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-18 11:06:25 UTC (rev 24) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-18 12:55:01 UTC (rev 25) @@ -116,6 +116,10 @@ @ManyToOne private Version currentVersion; + /** Constructor provided for persistence engine. */ + private Classification( ) + {} + /** * Creates a new classification belonging to a family, with the given identifier. Both parameters must be non null, otherwise this * constructor will throw a {@link NullPointerException}. Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-18 11:06:25 UTC (rev 24) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-18 12:55:01 UTC (rev 25) @@ -66,7 +66,7 @@ @Column(length = 50, nullable = false, unique = true) private String identifier; /** A classification family has a title. */ - @ManyToOne + @ManyToOne(cascade = {CascadeType.ALL}) private InternationalizedString title; /** A classification family refers to a number of classifications. */ @OneToMany(mappedBy = "family", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-07-18 11:06:25 UTC (rev 24) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-07-18 12:55:01 UTC (rev 25) @@ -24,18 +24,25 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Locale; +import java.util.Map; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import javax.persistence.JoinTable; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; import org.hibernate.annotations.GenericGenerator; import org.hibernate.annotations.IndexColumn; +import org.hibernate.annotations.MapKey; +import org.surveyforge.util.InternationalizedString; /** * A classification item represents a category at a certain level within a classification version or variant. It defines the content @@ -48,57 +55,57 @@ // @Table(schema = "classification") public class Item implements Serializable { - private static final long serialVersionUID = -3965211400312532582L; + private static final long serialVersionUID = -3965211400312532582L; @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @GenericGenerator(name = "system-uuid", strategy = "uuid") - private String id; + private String id; /** Version for optimistic locking. */ @javax.persistence.Version - private int lockingVersion; + private int lockingVersion; /** The level this item belongs to. */ @ManyToOne(optional = false) - private Level level; + private Level level; // TODO: Should we make any distinction among alphabetical, numericcal and alphanumerical codes? /** * A classification item is identified by an alphabetical, numerical or alphanumerical code, which is in line with the code structure * of the classification level. The code is unique within the classification version or variant to which the item belongs. */ @Column(length = 50) - private String code; + private String code; /** A classification item has a title as provided by the owner or maintenance unit. The title describes the content of the category. */ - @Column(length = 250) - private String oficialTitle; + @ManyToOne(cascade = {CascadeType.ALL}) + private InternationalizedString oficialTitle; /** * An item can be expressed in terms of one or several alternative titles. Each alternative title is associated with a title type. * Ex.: Short titles; Medium titles; Self-explanatory titles in CN; Titles in plural form (e.g. Men, Women) for dissemination * purposes; gender related titles. */ - // @CollectionOfElements - // @MapKey(columns = {@Column(name = "titleType", length = 100)}) - // @Column(name = "alternativeTitle", length = 250) - // private Map<String, String> alternativeTitles = new HashMap<String, String>( ); + @OneToMany(cascade = {CascadeType.ALL}) + @JoinTable(name = "item_alternativeTitles") + @MapKey(columns = {@Column(name = "titleType", length = 100)}) + private Map<String, InternationalizedString> alternativeTitles = new HashMap<String, InternationalizedString>( ); // TODO: Explanatory notes /** * Indicates whether or not the item has been generated to make the level to which it belongs complete. Ex.: In NACE Rev.1 one may * generate items AA, BB, FF etc. to make the subsection level complete. */ - private boolean generated; + private boolean generated; // TODO: currently valid and validity periods /** Describes the changes, which the item has been subject to from the previous to the actual classification version or variant. */ @Column(length = 2500) - private String changes; + private String changes; /** Describes the changes, which the item has been subject to during the life time of the actual classification version or variant. */ @Column(length = 2500) - private String updates; + private String updates; /** * The item at the next higher level of the classification version or variant of which the actual item is a sub item. Ex.: In NACE * Rev.1 item 10 is the parent of item 10.1. */ @ManyToOne - private Item parentItem; + private Item parentItem; /** * Each item, which is not at the lowest level of the classification version or variant, might contain one or a number of sub items, * i.e. items at the next lower level of the classification version or variant. Ex.: In NACE Rev.1, the Group level items 10.1, 10.2 @@ -106,13 +113,18 @@ */ @OneToMany(mappedBy = "parentItem", fetch = FetchType.LAZY) @IndexColumn(name = "subItemIndex") - private List<Item> subItems = new ArrayList<Item>( ); + private List<Item> subItems = new ArrayList<Item>( ); // TODO: Linked items // TODO: Case laws // TODO: Index entries - // TODO: What about classification translations? + // TODO: Classification translations - Solved for the moment, we should change the way to access the strings to provide proper + // control of languages + /** Constructor provided for persistence engine. */ + private Item( ) + {} + /** * Creates a new item. The item must be included in a level and have a parent item if the level is not the topmost one. Providing a * <code>null</code> level, code or oficial title would cause this constructor to throw a {@link NullPointerException}. This item @@ -134,6 +146,7 @@ this.level = level; this.parentItem = parentItem; this.setCode( code ); + this.oficialTitle = new InternationalizedString( this.getVersion( ).getDefaultLanguage( ) ); this.setOficialTitle( oficialTitle ); // Reverse relations @@ -180,16 +193,29 @@ } /** - * Returns the description of the category represented by this item. + * Returns the description of the category represented by this item for the default language. * - * @return the description of the category represented by this item. + * @return the description of the category represented by this item for the default language. + * @see InternationalizedString#getString() */ public String getOficialTitle( ) { - return this.oficialTitle; + return this.oficialTitle.getString( ); } /** + * Returns the description of the category represented by this item for the given language. + * + * @param locale the language of the oficial title to be returned. + * @return the description of the category represented by this item for the given language. + * @see InternationalizedString#getString(Locale) + */ + public String getOficialTitle( Locale locale ) + { + return this.oficialTitle.getString( locale ); + } + + /** * Sets the description of the category represented by this item. The title must be non <code>null</code>, otherwise a * {@link NullPointerException} is thrown. * @@ -199,52 +225,142 @@ public void setOficialTitle( String oficialTitle ) { if( oficialTitle != null ) - this.oficialTitle = oficialTitle; + this.oficialTitle.setString( oficialTitle ); else throw new NullPointerException( ); } /** - * Returns the alternative description of this category of the requested type. The requested title type must be among the title types - * defined for the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise this method throws a - * {@link IllegalArgumentException}. If no alternative title has been defined for the requested title type this method returns - * <code>null</code>. + * Sets the description of the category represented by this item for the given language. The language and title must be non + * <code>null</code>, otherwise a {@link NullPointerException} is thrown. * + * @param locale the language of the oficial title to be set. + * @param oficialTitle the description of the category represented by this item. + * @throws NullPointerException if the language or title are <code>null</code>. + */ + public void setOficialTitle( Locale locale, String oficialTitle ) + { + if( oficialTitle != null ) + this.oficialTitle.setString( locale, oficialTitle ); + else + throw new NullPointerException( ); + } + + /** + * Returns the alternative description of this category of the requested type for the default language. The requested title type must + * be among the title types defined for the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise + * this method throws a {@link IllegalArgumentException}. If no alternative title has been defined for the requested title type this + * method returns <code>null</code>. + * * @param titleType the type of the requested alternative title. * @return the alternative description of this category of the requested type, <code>null</code> if no alternative title has been * defined for the requested title type. * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item * belongs to. + * @see InternationalizedString#getString() */ - // public String getAlternativeTitle( String titleType ) - // { - // if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) - // { - // return this.alternativeTitles.get( titleType ); - // } - // else - // throw new IllegalArgumentException( ); - // } + public String getAlternativeTitle( String titleType ) + { + if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + { + return this.alternativeTitles.get( titleType ).getString( ); + } + else + throw new IllegalArgumentException( ); + } + /** - * Sets the alternative description of this category of the requested type. The title type must be among the title types defined for - * the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise this method throws a - * {@link IllegalArgumentException}. + * Sets the alternative description of this category of the requested type for the default language. The title type must be among the + * title types defined for the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise this method + * throws a {@link IllegalArgumentException}. * * @param titleType the type of the alternative title to be set. * @param alternativeTitle the alternative description of this category of the requested type. * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item * belongs to. */ - // public void setAlternativeTitle( String titleType, String alternativeTitle ) - // { - // if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) - // { - // this.alternativeTitles.put( titleType, alternativeTitle ); - // } - // else - // throw new IllegalArgumentException( ); - // } + public void setAlternativeTitle( String titleType, String alternativeTitle ) + { + if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + { + InternationalizedString alternativeI15dString; + if( this.alternativeTitles.containsKey( titleType ) ) + alternativeI15dString = this.alternativeTitles.get( titleType ); + else + { + alternativeI15dString = new InternationalizedString( this.getVersion( ).getDefaultLanguage( ) ); + this.alternativeTitles.put( alternativeTitle, alternativeI15dString ); + } + alternativeI15dString.setString( alternativeTitle ); + } + else + throw new IllegalArgumentException( ); + } + /** + * Returns the alternative description of this category of the requested type for the given language. The requested title type must + * be among the title types defined for the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise + * this method throws a {@link IllegalArgumentException}. If no alternative title has been defined for the requested title type this + * method returns <code>null</code>. + * + * @param titleType the type of the requested alternative title. + * @param locale the language of the requested alternative title. + * @return the alternative description of this category of the requested type, <code>null</code> if no alternative title has been + * defined for the requested title type. + * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item + * belongs to. + * @see InternationalizedString#getString(Locale) + */ + public String getAlternativeTitle( String titleType, Locale locale ) + { + if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + { + return this.alternativeTitles.get( titleType ).getString( locale ); + } + else + throw new IllegalArgumentException( ); + } + + /** + * Sets the alternative description of this category of the requested type for the given language. The title type must be among the + * title types defined for the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise this method + * throws a {@link IllegalArgumentException}. + * + * @param titleType the type of the alternative title to be set. + * @param locale the language of the alternative title to be set. + * @param alternativeTitle the alternative description of this category of the requested type. + * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item + * belongs to. + */ + public void setAlternativeTitle( String titleType, Locale locale, String alternativeTitle ) + { + if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + { + InternationalizedString alternativeI15dString; + if( this.alternativeTitles.containsKey( titleType ) ) + alternativeI15dString = this.alternativeTitles.get( titleType ); + else + { + alternativeI15dString = new InternationalizedString( this.getVersion( ).getDefaultLanguage( ) ); + this.alternativeTitles.put( alternativeTitle, alternativeI15dString ); + } + alternativeI15dString.setString( locale, alternativeTitle ); + } + else + throw new IllegalArgumentException( ); + } + + /** + * Removes an alternative title. + * + * @param titleType the title type of the alternative title to be removed. + */ + public void removeAlternativeTitle( String titleType ) + { + this.alternativeTitles.remove( titleType ); + } + + /** * Returns the number of the level to which the item belongs. * * @return the number of the level to which the item belongs. Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-18 11:06:25 UTC (rev 24) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-18 12:55:01 UTC (rev 25) @@ -99,6 +99,10 @@ @IndexColumn(name = "itemIndex") private List<Item> items = new ArrayList<Item>( ); + /** Constructor provided for persistence engine. */ + private Level( ) + {} + /** * Creates a new level belonging to a version, with the given identifier. Both parameters must be non null, otherwise this * constructor will throw a {@link NullPointerException}. Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-18 11:06:25 UTC (rev 24) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-18 12:55:01 UTC (rev 25) @@ -131,10 +131,11 @@ @IndexColumn(name = "titleTypeIndex") @Column(name = "titleType", length = 100) private List<String> titleTypes; + /** Default language to be used when no language is specified. */ + private Locale defaultLanguage = Locale.getDefault( ); /** A classification version can exist in one or several languages. */ @CollectionOfElements - @AttributeOverride(name = "element", column = @Column(name = "language")) - private Set<Locale> availableLanguages = new HashSet<Locale>( ); + private Set<Locale> availableLanguages = Collections.singleton( this.defaultLanguage ); /** * Indicates whether or not updates are allowed within the classification version, i.e. without leading to a new version. Such * updates will usually be changes, which add items to the structure and/or revalidates/invalidates classification items but which do @@ -175,6 +176,10 @@ // /** A list of all case laws associated with the classification version. */ // private List<CaseLaw> caseLaws; + /** Constructor provided for persistence engine. */ + private Version( ) + {} + /** * Creates a new version belonging to a classification, with the given identifier and release date. All the parameters must be non * null, otherwise this constructor will throw a {@link NullPointerException}. @@ -192,6 +197,23 @@ } /** + * Creates a new version belonging to a classification, with the given identifier, release date and default language. All the + * parameters must be non null, otherwise this constructor will throw a {@link NullPointerException}. + * + * @param classification the classification this version will belong to. + * @param identifier the identifier of this version. + * @param releaseDate the date on which this version was released. + * @throws NullPointerException if any parameter is <code>null</code>. + */ + public Version( Classification classification, String identifier, Date releaseDate, Locale defaultLanguage ) + { + this.setIdentifier( identifier ); + this.setClassification( classification ); + this.setReleaseDate( releaseDate ); + this.setAvailableLanguages( defaultLanguage, Collections.singleton( defaultLanguage ) ); + } + + /** * Returns the identifier of this version. * * @return the identifier of this version. @@ -437,25 +459,45 @@ } /** + * Returns the default language to be used when no language is specified. + * + * @return the default language to be used when no language is specified. + */ + public Locale getDefaultLanguage( ) + { + return this.defaultLanguage; + } + + /** * Returns the set of languages this version is available in. * * @return the set of languages this version is available in. */ public Set<Locale> getAvailableLanguages( ) { - return this.availableLanguages; + return Collections.unmodifiableSet( this.availableLanguages ); } /** - * Sets the set of languages this version is available in. This method throws {@link NullPointerException} if the set of languages is - * <code>null</code>. + * Sets the default language of this version and the set of languages this version is available in. This method throws + * {@link NullPointerException} if the set of languages is <code>null</code>. * * @param availableLanguages the set of languages this version is available in. + * @throws NullPointerException if the default language or available languages are null. + * @throws IllegalArgumentException if the available languages set doesn't include the default language. */ - public void setAvailableLanguages( Set<Locale> availableLanguages ) + public void setAvailableLanguages( Locale defaultLanguage, Set<Locale> availableLanguages ) { - if( availableLanguages != null ) - this.availableLanguages = availableLanguages; + if( availableLanguages != null && defaultLanguage != null ) + { + if( availableLanguages.contains( defaultLanguage ) ) + { + this.defaultLanguage = defaultLanguage; + this.availableLanguages = availableLanguages; + } + else + throw new IllegalArgumentException( ); + } else throw new NullPointerException( ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-18 11:06:40
|
Revision: 24 Author: jgongo Date: 2006-07-18 04:06:25 -0700 (Tue, 18 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=24&view=rev Log Message: ----------- Cascade types added Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-14 10:09:55 UTC (rev 23) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-18 11:06:25 UTC (rev 24) @@ -29,6 +29,7 @@ import java.util.List; import java.util.Set; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -106,7 +107,7 @@ * A classification has at least one {@link Version} (classification version). Ex.: ISIC: ISIC Rev.1, ISIC Rev.2, ISIC Rev.3; NACE: * NACE 70, NACE Rev.1. */ - @OneToMany(mappedBy = "classification", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "classification", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) private Set<Version> versions = new HashSet<Version>( ); /** * If there are several versions of a classification, one version is assigned as the currently valid version. Ex.: ISIC Rev. 3; NACE Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-14 10:09:55 UTC (rev 23) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-18 11:06:25 UTC (rev 24) @@ -27,6 +27,7 @@ import java.util.Set; import javax.persistence.Basic; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -68,9 +69,13 @@ @ManyToOne private InternationalizedString title; /** A classification family refers to a number of classifications. */ - @OneToMany(mappedBy = "family", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "family", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) private Set<Classification> classifications = new HashSet<Classification>( ); + /** Constructor provided for persistence engine. */ + private Family( ) + {} + /** * Creates a new family with the given identifier. * Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-14 10:09:55 UTC (rev 23) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-18 11:06:25 UTC (rev 24) @@ -27,6 +27,7 @@ import java.util.Iterator; import java.util.List; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -94,7 +95,7 @@ @ManyToOne private Level foreignLevel; /** An ordered list of the categories (classification items) that constitute the level. */ - @OneToMany(mappedBy = "level", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "level", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "itemIndex") private List<Item> items = new ArrayList<Item>( ); Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-14 10:09:55 UTC (rev 23) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-18 11:06:25 UTC (rev 24) @@ -32,6 +32,7 @@ import javax.persistence.AttributeOverride; import javax.persistence.Basic; +import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; @@ -167,7 +168,7 @@ @ManyToOne private Version derivedFrom; /** The structure of a classification version is defined by its levels. */ - @OneToMany(mappedBy = "version", fetch = FetchType.LAZY) + @OneToMany(mappedBy = "version", fetch = FetchType.LAZY, cascade = {CascadeType.ALL}) @IndexColumn(name = "levelIndex") private List<Level> levels = new ArrayList<Level>( ); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-07-14 10:10:10
|
Revision: 23 Author: javism Date: 2006-07-14 03:09:55 -0700 (Fri, 14 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=23&view=rev Log Message: ----------- Add TestNG support Added Paths: ----------- trunk/surveyforge-core/src/test/resources/ trunk/surveyforge-core/src/test/resources/testng.xml Added: trunk/surveyforge-core/src/test/resources/testng.xml =================================================================== --- trunk/surveyforge-core/src/test/resources/testng.xml (rev 0) +++ trunk/surveyforge-core/src/test/resources/testng.xml 2006-07-14 10:09:55 UTC (rev 23) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> +<suite name="SurveyForge test suite"> + <test name="All"> + <packages> + <package name="org.surveyforge.core.metadata" /> + <package name="org.surveyforge.core.data" /> + <package name="org.surveyforge.core.survey" /> + </packages> + </test> +</suite> Property changes on: trunk/surveyforge-core/src/test/resources/testng.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ja...@us...> - 2006-07-14 09:46:11
|
Revision: 22 Author: javism Date: 2006-07-14 02:44:53 -0700 (Fri, 14 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=22&view=rev Log Message: ----------- First core module version. It need some improvements on comments and tests. Modified Paths: -------------- trunk/surveyforge-core/pom.xml Added Paths: ----------- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValueDomain.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/VariableFamily.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/ trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Question.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Questionnaire.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/QuestionnaireElement.java trunk/surveyforge-core/src/main/java/org/surveyforge/core/survey/Study.java trunk/surveyforge-core/src/test/ trunk/surveyforge-core/src/test/java/ trunk/surveyforge-core/src/test/java/org/ trunk/surveyforge-core/src/test/java/org/surveyforge/ trunk/surveyforge-core/src/test/java/org/surveyforge/core/ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/ trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/GlobalVariableTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/StatisticalObjectTypeTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/metadata/VariableFamilyTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/ trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireElementTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/QuestionnaireTest.java trunk/surveyforge-core/src/test/java/org/surveyforge/core/survey/StudyTest.java Modified: trunk/surveyforge-core/pom.xml =================================================================== --- trunk/surveyforge-core/pom.xml 2006-07-13 09:43:50 UTC (rev 21) +++ trunk/surveyforge-core/pom.xml 2006-07-14 09:44:53 UTC (rev 22) @@ -8,39 +8,27 @@ <modelVersion>4.0.0</modelVersion> <artifactId>surveyforge-core</artifactId> <name>SurveyForge Core API</name> - <dependencies> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-classification</artifactId> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + </dependency> <dependency> - <groupId>commons-logging</groupId> - <artifactId>commons-logging</artifactId> - <scope>compile</scope> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> </dependency> - </dependencies> - <reporting> - <plugins> - <plugin> - <artifactId>maven-javadoc-plugin</artifactId> - <configuration> - <charset>UTF-8</charset> - <docencoding>UTF-8</docencoding> - <encoding>UTF-8</encoding> - <show>private</show> - <links> - <link>http://java.sun.com/j2se/1.5.0/docs/api/</link> - </links> - </configuration> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>changelog-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>jxr-maven-plugin</artifactId> - </plugin> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>taglist-maven-plugin</artifactId> - </plugin> - </plugins> - </reporting> + </dependencies> </project> Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,131 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.data; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import org.surveyforge.core.metadata.Register; + +/** + * @author jsegura + */ +public class RegisterData implements Serializable + { + private static final long serialVersionUID = 4300393468288029803L; + + private String identifier; + private Register register; + private List<Row> rows = new ArrayList<Row>( ); + + public RegisterData( Register register, String identifier ) + { + this.setRegister( register ); + this.setIdentifier( identifier ); + } + + /** + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * @param identifier The identifier to set. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + /** + * @return Returns the register. + */ + public Register getRegister( ) + { + return this.register; + } + + /** + * @param register The register to set. + */ + public void setRegister( Register register ) + { + if( register == null ) + throw new NullPointerException( ); + else if( this.register != null && this.rows.size( ) != 0 ) throw new IllegalArgumentException( ); + this.register = register; + } + + /** + * @return Returns the rows. + */ + public List<Row> getRows( ) + { + return Collections.unmodifiableList( this.rows ); + } + + /** + * @param rows The rows to . + */ + protected void addRows( Row row ) + { + if( row != null ) + { + if( this.register.getKey( ).size( ) == 0 ) throw new IllegalArgumentException( ); + ArrayList<Integer> illegalList = new ArrayList<Integer>( ); + // TODO: Check valiadation rules + + if( this.register.getRegisterDataElements( ).size( ) != row.getRowDatas( ).size( ) ) throw new IllegalArgumentException( ); + int index = 0; + for( RowData rowData : row.getRowDatas( ) ) + { + if( !this.register.getRegisterDataElements( ).get( index ).getValueDomain( ).isValid( rowData.getData( ) ) ) + illegalList.add( index ); // TODO: Elaborate on this Exception + index++; + } + if( illegalList.size( ) == 0 ) this.rows.add( row ); + // TODO: else throw Exception + } + + else + throw new NullPointerException( ); + } + + /** + * @param rows The rows to . + */ + protected void removeRows( Row row ) + { + if( row != null ) + this.rows.remove( row ); + else + throw new NullPointerException( ); + } + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RegisterData.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,85 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.data; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.NoSuchElementException; + +/** + * @author jsegura + */ +public class Row + { + + private RegisterData registerData; + private List<RowData> rowDatas = new ArrayList<RowData>( ); + + public Row( RegisterData registerData ) + { + this.setRegisterData( registerData ); + } + + /** + * @return Returns the registerData. + */ + public RegisterData getRegisterData( ) + { + return this.registerData; + } + + /** + * @param registerData The registerData to set. + */ + public void setRegisterData( RegisterData registerData ) + { + if( registerData != null ) + this.registerData = registerData; + else + throw new NullPointerException( ); + } + + public void setField( String elementIdentifier, RowData rowData ) + { + int fieldIndex = this.registerData.getRegister( ).getElementIndex( elementIdentifier ); + if( fieldIndex != -1 ) + { + this.rowDatas.set( fieldIndex, rowData ); + } + else + { + // String errorMessage = MessageFormat.format( Record.messages.getString( "message.invalid.name" ), fieldName ); + // if( Record.log.isInfoEnabled( ) ) + // { + // Record.log.info( Record.messages.getString( "exception.invalid.name" ) + errorMessage ); + // } + throw new NoSuchElementException( ); + } + } + + public List<RowData> getRowDatas( ) + { + return Collections.unmodifiableList( this.rowDatas ); + } + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/Row.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,85 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.data; + +import java.io.Serializable; + +// TODO: Elaborate on comments +/** + * @author jsegura + */ +public class RowData + { + private Serializable data; + private boolean answered; + private boolean applicable; + + /** + * @return Returns the data. + */ + public Serializable getData( ) + { + return this.data; + } + + /** + * @param data The data to set. + */ + public void setData( Serializable data ) + { + this.data = data; + } + + /** + * @return Returns the answered. + */ + public boolean isAnswered( ) + { + return this.answered; + } + + /** + * @param answered The answered to set. + */ + public void setAnswered( boolean answered ) + { + this.answered = answered; + } + + /** + * @return Returns the applicable. + */ + public boolean isApplicable( ) + { + return this.applicable; + } + + /** + * @param applicable The applicable to set. + */ + public void setApplicable( boolean applicable ) + { + this.applicable = applicable; + } + + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/data/RowData.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,70 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import org.surveyforge.core.survey.Question; + +// TODO: Measure unit? +// TODO: Elaborate on comments +/** + * Conceptual data elements define conceptual standards for data elements. Conceptual data elements have a context independent + * definition and are associated with a value set and a measure unit describing how the values are measured. A standard question used + * for collecting data for those variables can be added. + * + * @author jsegura + */ +public class ConceptualDataElement extends DataElement + { + private static final long serialVersionUID = -6880246451318487216L; + + /** */ + private Question question; + + /** + * Creates a new ConceptualDataElement based on the params of a DataElement + * + * @param valueDomain + * @param identifier + */ + public ConceptualDataElement( ValueDomain valueDomain, String identifier ) + { + super( valueDomain, identifier ); + } + + /** + * @return Returns the question. + */ + public Question getQuestion( ) + { + return this.question; + } + + /** + * @param question The question to set. + */ + public void setQuestion( Question question ) + { + this.question = question; + } + + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ConceptualDataElement.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,202 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +// TODO Elaborate on comments +/** + * @author jsegura + */ +public class DataElement + { + /** + * This is a unique and language independent identifier for the data element. The identifier is unique among all other data elements + * for an object variable (standard data element) or within the scope of a statistical activity. + */ + private String identifier; + /** */ + private boolean multiple = false; + /** */ + private int maxResponses = 1; + /** */ + private ValueDomain valueDomain; + /** */ + private ObjectVariable objectVariable; + /** */ + private DataElement variableStructure; + /** */ + private List<DataElement> componentElements = new ArrayList<DataElement>( ); + + /** + * @param valueDomain + * @param identifier + */ + public DataElement( ValueDomain valueDomain, String identifier ) + { + this.setValueDomain( valueDomain ); + this.setIdentifier( identifier ); + } + + /** + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * @param identifier The identifier to set. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + /** + * @return Returns the multiple. + */ + public boolean isMultiple( ) + { + return this.multiple; + } + + /** + * @param multiple The multiple to set. + */ + public void setMultiple( boolean multiple ) + { + this.multiple = multiple; + } + + /** + * @return Returns the maxResponses. + */ + public int getMaxResponses( ) + { + return this.maxResponses; + } + + /** + * @param maxResponses The maxResponses to set. + */ + public void setMaxResponses( int maxResponses ) + { + if( maxResponses >= 1 ) + this.maxResponses = maxResponses; + else + throw new IllegalArgumentException( ); + } + + /** + * @return Returns the valueDomain. + */ + public ValueDomain getValueDomain( ) + { + return this.valueDomain; + } + + /** + * @param valueDomain The valueDomain to set. + */ + public void setValueDomain( ValueDomain valueDomain ) + { + if( valueDomain != null ) + this.valueDomain = valueDomain; + else + throw new NullPointerException( ); + } + + /** + * @return Returns the objectVariable. + */ + public ObjectVariable getObjectVariable( ) + { + return this.objectVariable; + } + + /** + * @param objectVariable The objectVariable to set. + */ + public void setObjectVariable( ObjectVariable objectVariable ) + { + if( this.objectVariable != null ) this.objectVariable.removeDataElement( this ); + this.objectVariable = objectVariable; + if( this.objectVariable != null ) this.objectVariable.addDataElement( this ); + } + + /** + * @return Returns the variableStructure. + */ + public DataElement getVariableStructure( ) + { + return this.variableStructure; + } + + /** + * @param variableStructure The variableStructure to set. + */ + public void setVariableStructure( DataElement variableStructure ) + { + if( this.variableStructure != null ) this.variableStructure.removeComponentElement( this ); + this.variableStructure = variableStructure; + if( this.variableStructure != null ) this.variableStructure.addComponentElement( this ); + } + + /** + * @return Returns the componentElements. + */ + public List<DataElement> getComponentElements( ) + { + return Collections.unmodifiableList( this.componentElements ); + } + + /** + * @param componentElements The componentElements to set. + */ + protected void addComponentElement( DataElement componentElement ) + { + if( componentElement != null ) + this.componentElements.add( componentElement ); + else + throw new NullPointerException( ); + } + + /** + * @param componentElements The componentElements to set. + */ + protected void removeComponentElement( DataElement componentElement ) + { + if( componentElement != null ) + this.componentElements.remove( componentElement ); + else + throw new NullPointerException( ); + } + + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/DataElement.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,157 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import java.io.Serializable; + + +/** + * The global variable defines the general concept of a statistical variable (e.g. income). More special definitions can be provided + * when combining a global variable with a statistical object to an {@link ObjectVariable}. Variable families can group global + * variables. + * + * @author jsegura + */ +public class GlobalVariable implements Serializable + { + private static final long serialVersionUID = 1661678204467740737L; + + /** A global variable is identified by a unique language independent identifier, which may typically be an abbreviation of its name. */ + private String identifier; + /** The official name of the global variable is provided by the owner of the variable. */ + private String name = ""; + /** + * Short general multilingual description of the global variable, including its purpose, its main subject areas etc. + */ + private String description = ""; + + /** Family to which the global variable belongs. */ + private VariableFamily variableFamily; + + /** + * Creates a new GlobalVariable identified by the identifier + * + * @param identifier The identifier of the GlobalVariable. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ + public GlobalVariable( String identifier ) + { + this.setIdentifier( identifier ); + } + + /** + * Returns the identifier of the Global Variable. + * + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * Sets a new identifier for the GlobalVariable. + * + * @param identifier The identifier to set. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + /** + * Returns the name of the GlobalVariable. + * + * @return Returns the name. + */ + public String getName( ) + { + return this.name; + } + + /** + * Sets a new name to the GlobalVariable. + * + * @param name The name to set. + * @throws NullPointerException If the name is <code>null</code>. + */ + public void setName( String name ) + { + if( name != null ) + this.name = name; + else + throw new NullPointerException( ); + } + + /** + * Returns the description of the GlobalVariable. + * + * @return Returns the description. + */ + public String getDescription( ) + { + return this.description; + } + + /** + * Sets a new description of the GlobalVariable. + * + * @param description The description to set. + * @throws NullPointerException If the description is <code>null</code>. + */ + public void setDescription( String description ) + { + if( description != null ) + this.description = description; + else + throw new NullPointerException( ); + } + + /** + * Returns the {@link VariableFamily} of the GlobalVariable. + * + * @return Returns the variableFamily. + */ + public VariableFamily getVariableFamily( ) + { + return this.variableFamily; + } + + /** + * Sets the new {@link VariableFamily} of the GlobalVariable. + * + * @param variableFamily The variableFamily to set. + * @throws NullPointerException If the {@link VariableFamily} is <code>null</code>. + */ + public void setVariableFamily( VariableFamily variableFamily ) + { + if( this.variableFamily != null ) this.variableFamily.removeGlobalVariable( this ); + this.variableFamily = variableFamily; + if( this.variableFamily != null ) this.variableFamily.addGlobalVariable( this ); + } + + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/GlobalVariable.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,36 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +/** + * @author jsegura + */ +public class LogicalValueDomain extends ValueDomain + { + private static final long serialVersionUID = 2066579378848047283L; + + public boolean isValid( Object object ) + { + return (Boolean.class.isInstance( object )); + } + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/LogicalValueDomain.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,221 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * An object variable defines the concept of a variable in connection with a defined statistical object (e.g. the income of a person). + * The general description of the meaning of the variable is part of the global variable definition, which is linked to the object + * variable. Several object variables can be defined for one global variable to define specific types of object variables. + * + * @author jsegura + */ +public class ObjectVariable implements Serializable + { + private static final long serialVersionUID = 4288089682729653747L; + + /** + * Unique and language independent identifier for the object variable. The identifier is unique among all object variables. The + * identifier should contain identifications for the statistical object and the global variable it is based on. + */ + private String identifier; + /** The name is the official, language dependent name of the global variable, provided by the owner of the variable. */ + private String name = ""; + /** Short general multilingual description of the object variable, including its purpose, its main subject areas etc. */ + private String description = ""; + /** + * Each object variable belongs to a statistical object or unit. The object variable exists only in the context of the object + * variable. + */ + private StatisticalObjectType statisticalObjectType; + /** An object variable should refer to a global variable definition that reflects the general concepts of the object variable. */ + private GlobalVariable globalVariable; + /** Based on an object variable a number of data elements may refer to this object variable. */ + private List<DataElement> dataElements = new ArrayList<DataElement>( ); + + + /** + * Creates a new instance of ObjectVariable identified by identifier. + * + * @param identifier The identifier to set. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ + public ObjectVariable( String identifier ) + { + this.setIdentifier( identifier ); + } + + /** + * Returns the identifier of the ObjectVariable. + * + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * Sets the new identifier of the ObjectVariable. + * + * @param identifier The identifier to set. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + /** + * Returns the name of the ObjectVariable. + * + * @return Returns the name. + */ + public String getName( ) + { + return this.name; + } + + /** + * Sets the name of the ObjectVariable. + * + * @param name The name to set. + * @throws NullPointerException If the name is <code>null</code>. + */ + public void setName( String name ) + { + if( name != null ) + this.name = name; + else + throw new NullPointerException( ); + } + + /** + * Returns the description of the ObjectVariable. + * + * @return Returns the description. + */ + public String getDescription( ) + { + return this.description; + } + + /** + * Sets a new description to the ObjectVariable. + * + * @param description The description to set. + * @throws NullPointerException If the description is <code>null</code>. + */ + public void setDescription( String description ) + { + if( description != null ) + this.description = description; + else + throw new NullPointerException( ); + } + + /** + * Returns the {@link StatisticalObjectType} this ObjectVariable belongs to. + * + * @return Returns the StatisticalObjectType. + */ + public StatisticalObjectType getStatisticalObjectType( ) + { + return this.statisticalObjectType; + } + + /** + * Sets a new {@link StatisticalObjectType} this ObjectVariable belongs to. + * + * @param statisticalObjectType The statisticalObjectType to set. + * @throws NullPointerException If the statisticalObjectType is <code>null</code>. + */ + public void setStatisticalObjectType( StatisticalObjectType statisticalObjectType ) + { + if( statisticalObjectType != null ) + this.statisticalObjectType = statisticalObjectType; + else + throw new NullPointerException( ); + } + + /** + * Returns the {@link GlobalVariable} this ObjectVariable is linked to. + * + * @return Returns the globalVariable. + */ + public GlobalVariable getGlobalVariable( ) + { + return this.globalVariable; + } + + /** + * Returns the new {@link GlobalVariable} this ObjectVariable is linked to. + * + * @param globalVariable The globalVariable to set. + * @throws NullPointerException If the globalVariable is <code>null</code>. + */ + public void setGlobalVariable( GlobalVariable globalVariable ) + { + if( globalVariable != null ) + this.globalVariable = globalVariable; + else + throw new NullPointerException( ); + } + + /** + * Returns the list of {@link DataElement} linked to this ObjectVariable. + * + * @return Returns the list of dataElements. + */ + public List<DataElement> getDataElements( ) + { + return Collections.unmodifiableList( dataElements ); + } + + /** + * Adds a new {@link DataElement} to the list. + * + * @param dataElements The dataElements to add. + */ + protected void addDataElement( DataElement dataElement ) + { + this.dataElements.add( dataElement ); + } + + /** + * Removes a {@link DataElement} from the list. + * + * @param dataElements The dataElements to remove. + */ + protected void removeDataElement( DataElement dataElement ) + { + this.dataElements.remove( dataElement ); + } + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ObjectVariable.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,284 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.ArrayList; + +import org.surveyforge.core.data.RegisterData; + +// TODO Elaborate on comments +/** + * @author jsegura + */ +public class Register + { + /** + * The name of the register is either a systematic name according to the naming conventions in the organisation or a human language + * name that reflects the idea or concept of the cube or register. + */ + private String identifier; + /** + * When defining hierarchical registers the hierarchy is expressed as master/detail relationship. The master register defines the + * objects that consist of the details. + */ + private Register masterRegister = null; + /** + * When defining hierarchical registers the hierarchy is expressed as master/detail relationship. The detail registers defines the + * objects that are owned by the master objects. + */ + private List<Register> detailRegisters = new ArrayList<Register>( ); + /** */ + private LinkedHashMap<String, Integer> indexes; + /** */ + private List<RegisterDataElement> registerDataElements = new ArrayList<RegisterDataElement>( ); + /** */ + private List<RegisterDataElement> key = new ArrayList<RegisterDataElement>( ); + /** */ + private List<ValidationRule> validationRules = new ArrayList<ValidationRule>( ); + /** */ + private RegisterData registerData; + + /** + * @param registerDataElements + * @param key + * @param identifier + */ + public Register( String identifier ) + { + this.setIdentifier( identifier ); + } + + /** + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * @param identifier The identifier to set. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + + /** + * @return Returns the masterRegister. + */ + public Register getMasterRegister( ) + { + return this.masterRegister; + } + + /** + * @param masterRegister The masterRegister to set. + */ + public void setMasterRegister( Register masterRegister ) + { + if( this.masterRegister != null ) this.masterRegister.delDetailRegister( this ); + this.masterRegister = masterRegister; + if( this.masterRegister != null ) this.masterRegister.addDetailRegister( this ); + + } + + /** + * @return Returns the detailRegister. + */ + public List<Register> getDetailRegisters( ) + { + return Collections.unmodifiableList( this.detailRegisters ); + } + + /** + * @param detailRegister The detailRegister to set. + */ + protected void addDetailRegister( Register detailRegister ) + { + if( detailRegister != null ) this.detailRegisters.add( detailRegister ); + } + + /** + * @param detailRegister The detailRegister to set. + */ + protected void delDetailRegister( Register detailRegister ) + { + if( detailRegister != null ) this.detailRegisters.remove( detailRegister ); + } + + /** + * @return Returns the registerDataElements. + */ + public List<RegisterDataElement> getRegisterDataElements( ) + { + return Collections.unmodifiableList( this.registerDataElements ); + } + + /** + * @param registerDataElements + */ + public void setRegisterDataElements( List<RegisterDataElement> registerDataElements ) + { + if( registerDataElements == null ) + throw new NullPointerException( ); + else if( registerData != null ) + throw new IllegalArgumentException( ); + else if( key != null && !registerDataElements.containsAll( key ) ) + throw new IllegalArgumentException( ); + else + { + this.registerDataElements = registerDataElements; + this.updateElements( ); + } + } + + + /** + * @return Returns the key. + */ + public List<RegisterDataElement> getKey( ) + { + return Collections.unmodifiableList( this.key ); + } + + /** + * @param key The key to set. + */ + public void setKey( List<RegisterDataElement> key ) + { + if( key == null ) + throw new NullPointerException( ); + else if( this.registerDataElements.containsAll( key ) ) + this.key = key; + else + throw new IllegalArgumentException( ); + } + + /** + * @return Returns the validationRules. + */ + public List<ValidationRule> getValidationRules( ) + { + return Collections.unmodifiableList( this.validationRules ); + } + + /** + * @param validationRules The validationRules to set. + */ + public void setValidationRules( List<ValidationRule> validationRules ) + { + if( validationRules != null ) + this.validationRules = validationRules; + else + throw new NullPointerException( ); + } + + /** + * @param validationRule + */ + public void addValidationRule( ValidationRule validationRule ) + { + if( validationRule != null ) + this.validationRules.add( validationRule ); + else + throw new NullPointerException( ); + } + + /** + * @param validationRule + */ + public void delValidationRule( ValidationRule validationRule ) + { + if( validationRule != null ) + this.validationRules.remove( validationRule ); + else + throw new NullPointerException( ); + } + + /** + * @return Returns the registerData. + */ + public RegisterData getRegisterData( ) + { + return this.registerData; + } + + /** + * @param registerData The registerData to set. + */ + public void setRegisterData( RegisterData registerData ) + { + if( registerData != null && this.registerDataElements.isEmpty( ) ) + throw new IllegalArgumentException( ); + else if( registerData == null && !this.registerDataElements.isEmpty( ) ) + throw new NullPointerException( ); + else + this.registerData = registerData; + + } + + private void updateElements( ) + { + LinkedHashMap<String, Integer> fieldIndexes = new LinkedHashMap<String, Integer>( ); + int index = 0; + for( RegisterDataElement currentRegisterDataElement : this.registerDataElements ) + { + fieldIndexes.put( currentRegisterDataElement.getIdentifier( ), index ); + index++; + } + + if( this.registerDataElements.size( ) == fieldIndexes.size( ) ) + { + this.indexes = fieldIndexes; + } + else + { + // There are duplicated field names + // String errorMessage = RecordMetadata.messages.getString( "message.duplicated.names" ); + // if( RecordMetadata.log.isInfoEnabled( ) ) + // { + // RecordMetadata.log.info( RecordMetadata.messages.getString( "exception.duplicated.names" ) + errorMessage ); + // } + throw new IllegalArgumentException( ); + } + } + + public int getElementIndex( String elementIdentifier ) + { + Integer index = this.indexes.get( elementIdentifier ); + return (index != null) ? index : -1; + } + + public List<String> getElementIdentifiers( ) + { + return new ArrayList<String>( this.indexes.keySet( ) ); + } + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/Register.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,75 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +/** + * Register data elements define data elements for a register. In contrast to an abstract data element a register data element is + * defined in the context of a register and carries process information besides conceptual one. + * + * @author jsegura + */ +public class RegisterDataElement extends DataElement + { + private static final long serialVersionUID = -8986375207717119033L; + + /** The context data element describes the basic properties of the register data element. */ + private ConceptualDataElement conceptualDataElement; + + /** + * Creates a new instance of ConceptualDataElement linked with a {@link ConceptualDataElement}. + * + * @param conceptualDataElement The conceptualDataElement that describes the {@link RegisterDataElement}. + * @throws NullPointerException If the ValueDomain or the identifier or the ConceptualDataElements are <code>null</code> or the + * identifier is empty. + */ + public RegisterDataElement( ConceptualDataElement conceptualDataElement, ValueDomain valueDomain, String identifier ) + { + super( valueDomain, identifier ); + this.setConceptualDataElement( conceptualDataElement ); + } + + /** + * Returns the ConceptualDataElement that describes the RegisterDataElement. + * + * @return Returns the conceptualDataElement. + */ + public ConceptualDataElement getConceptualDataElement( ) + { + return this.conceptualDataElement; + } + + /** + * Sets the ConceptualDataElement that describes the RegisterDataElement. + * + * @param conceptualDataElement The conceptualDataElements to set. + * @throws NullPointerException If the conceptualDataElement is <code>null</code>. + */ + public void setConceptualDataElement( ConceptualDataElement conceptualDataElement ) + { + if( conceptualDataElement != null ) + this.conceptualDataElement = conceptualDataElement; + else + throw new NullPointerException( ); + } + + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/RegisterDataElement.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,236 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * Statistical objects or units may be real world objects (e.g. person, enterprise) or abstract objects like events or states (e.g. + * accident, temperature). A statistical object or unit describes the type of object observed in a statistical survey or presented in a + * statistical table. It is considered as an abstract set of objects to be observed, measured or estimated. + * + * @author jsegura + */ +public class StatisticalObjectType implements Serializable + { + private static final long serialVersionUID = 3051156955695891963L; + + /** + * A statistical object is identified by a unique language independent identifier, which may typically be an abbreviation of its + * name. + */ + private String identifier; + /** Unique name statistical unit. */ + private String name = ""; + /** Short general multilingual description of the statistical object/unit, including its purpose, its main subject areas etc. */ + private String description = ""; + /** A super-type is a generalisation of an object type. */ + private StatisticalObjectType superType; + /** A sub type describes a specialisation of the type. Sub types are described as "IS A" relationships. */ + private List<StatisticalObjectType> subTypes = new ArrayList<StatisticalObjectType>( ); + /** Object variables defined for the statistical object/unit. */ + private List<ObjectVariable> objectVariables = new ArrayList<ObjectVariable>( ); + + /** + * Creates a new {@link StatisticalObjectType} identified by identifier. + * + * @param identifier The identifier to set. + */ + public StatisticalObjectType( String identifier ) + { + this.setIdentifier( identifier ); + } + + /** + * Returns the identifier of the StatisticalObjectType. + * + * @return Returns the identifier. + */ + public String getIdentifier( ) + { + return this.identifier; + } + + /** + * Sets a new identifier for the StatisticalObjectType. + * + * @param identifier The identifier to set. + * @throws NullPointerException If the identifier is <code>null</code> or is empty. + */ + public void setIdentifier( String identifier ) + { + if( identifier != null && !identifier.equals( "" ) ) + this.identifier = identifier; + else + throw new NullPointerException( ); + } + + /** + * Returns the name of the StatisticalObjectType. + * + * @return Returns the name. + */ + public String getName( ) + { + return this.name; + } + + /** + * Sets a new name to the StatisticalObjectType. + * + * @param name The name to set. + * @throws NullPointerException If the name is <code>null</code>. + */ + public void setName( String name ) + { + if( name != null ) + this.name = name; + else + throw new NullPointerException( ); + } + + /** + * Returns the description of the StatisticalObjectType. + * + * @return Returns the description. + */ + public String getDescription( ) + { + return this.description; + } + + /** + * Sets a new description for the StatisticalObjectType. + * + * @param description The description to set. + * @throws NullPointerException If the name is <code>null</code>. + */ + public void setDescription( String description ) + { + if( description != null ) + this.description = description; + else + throw new NullPointerException( ); + } + + /** + * Return the super type of the StatisticalObjectType. + * + * @return Returns the superType. + */ + public StatisticalObjectType getSuperType( ) + { + return superType; + } + + /** + * Sets the super type of the StatisticalObjectType. + * + * @param superType The superType to set. + */ + public void setSuperType( StatisticalObjectType superType ) + { + if( this.superType != null ) this.superType.removeSubType( this ); + this.superType = superType; + if( this.superType != null ) this.superType.addSubType( this ); + } + + /** + * Returns the list of sub types of the StatisticalObjectType. + * + * @return Returns the list of subtypes. + */ + public List<StatisticalObjectType> getSubTypes( ) + { + return Collections.unmodifiableList( this.subTypes ); + } + + /** + * Adds a new subtype to the list of subtypes for the StatisticalObjectType + * + * @param subtypes The subtypes to add. + * @throws NullPointerException If the subtype is <code>null</code>. + */ + protected void addSubType( StatisticalObjectType subType ) + { + if( subType != null ) + this.subTypes.add( subType ); + else + throw new NullPointerException( ); + } + + /** + * Removes a subtype from the list of subtypes for the StatisticalObjectType + * + * @param subtypes The subtypes to remove. + * @throws NullPointerException If the subtype is <code>null</code>. + */ + protected void removeSubType( StatisticalObjectType subType ) + { + if( subType != null ) + this.subTypes.remove( subType ); + else + throw new NullPointerException( ); + } + + /** + * Returns the list of {@link ObjectVariable}s related to his StatisticalObjectType. + * + * @return Returns the list of ObjectVariables. + */ + public List<ObjectVariable> getObjectVariables( ) + { + return Collections.unmodifiableList( this.objectVariables ); + } + + /** + * Adds an object variable to the list of object variables for the StatisticalObjectType + * + * @param subtypes The object variable to remove. + * @throws NullPointerException If the objectVariable is <code>null</code>. + */ + protected void addObjectVariable( ObjectVariable objectVariable ) + { + if( objectVariable != null ) + this.objectVariables.add( objectVariable ); + else + throw new NullPointerException( ); + } + + /** + * Removes an object variable from the list of object variables for the StatisticalObjectType + * + * @param subtypes The object variable to remove. + * @throws NullPointerException If the objectVariable is <code>null</code>. + */ + protected void removeObjectVariable( ObjectVariable objectVariable ) + { + if( objectVariable != null ) + this.objectVariables.remove( objectVariable ); + else + throw new NullPointerException( ); + } + + } Property changes on: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/StatisticalObjectType.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java =================================================================== --- trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java (rev 0) +++ trunk/surveyforge-core/src/main/java/org/surveyforge/core/metadata/ValidationRule.java 2006-07-14 09:44:53 UTC (rev 22) @@ -0,0 +1,34 @@ +/* + * surveyforge-core - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.core.metadata; + +/*... [truncated message content] |
From: <jg...@us...> - 2006-07-13 09:44:02
|
Revision: 21 Author: jgongo Date: 2006-07-13 02:43:50 -0700 (Thu, 13 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=21&view=rev Log Message: ----------- Version was incorrectly annotated as Transient Modified Paths: -------------- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-13 09:09:22 UTC (rev 20) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-13 09:43:50 UTC (rev 21) @@ -36,7 +36,6 @@ import javax.persistence.Id; import javax.persistence.ManyToOne; import javax.persistence.OneToMany; -import javax.persistence.Transient; import org.hibernate.annotations.CollectionOfElements; import org.hibernate.annotations.GenericGenerator; @@ -113,7 +112,7 @@ * If there are several versions of a classification, one version is assigned as the currently valid version. Ex.: ISIC Rev. 3; NACE * Rev. 1. */ - @Transient + @ManyToOne private Version currentVersion; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-13 09:42:40
|
Revision: 18 Author: jgongo Date: 2006-07-13 01:34:27 -0700 (Thu, 13 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=18&view=rev Log Message: ----------- 1. Support for internationalized text in util module 2. EJB3/Hibernate annotations in classification package 3. Creation of database module Modified Paths: -------------- trunk/pom.xml trunk/surveyforge-classification/pom.xml trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java Added Paths: ----------- trunk/surveyforge-db/ trunk/surveyforge-db/pom.xml trunk/surveyforge-db/src/ trunk/surveyforge-db/src/main/ trunk/surveyforge-db/src/main/resources/ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml trunk/surveyforge-db/src/test/ trunk/surveyforge-db/src/test/java/ trunk/surveyforge-db/src/test/resources/ trunk/surveyforge-db/src/test/resources/META-INF/ trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml trunk/surveyforge-db/src/test/resources/testng.xml trunk/surveyforge-util/ trunk/surveyforge-util/pom.xml trunk/surveyforge-util/src/ trunk/surveyforge-util/src/main/ trunk/surveyforge-util/src/main/java/ trunk/surveyforge-util/src/main/java/org/ trunk/surveyforge-util/src/main/java/org/surveyforge/ trunk/surveyforge-util/src/main/java/org/surveyforge/util/ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java trunk/surveyforge-util/src/test/ trunk/surveyforge-util/src/test/java/ trunk/surveyforge-util/src/test/java/org/ trunk/surveyforge-util/src/test/java/org/surveyforge/ trunk/surveyforge-util/src/test/java/org/surveyforge/util/ trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java trunk/surveyforge-util/src/test/resources/ trunk/surveyforge-util/src/test/resources/testng.xml Modified: trunk/pom.xml =================================================================== --- trunk/pom.xml 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/pom.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -93,6 +93,25 @@ <version>1.0-alpha-6</version> </extension> </extensions> + <pluginManagement> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>hibernate3-maven-plugin</artifactId> + <version>1.0-SNAPSHOT</version> + <configuration> + <hibernate> + <configurationFile>/src/main/resources/hibernate.cfg.xml</configurationFile> + </hibernate> + <outputDirectory> + <hbm2ddl>target/hibernate3/sql</hbm2ddl> + </outputDirectory> + <!-- <outputFile>target/hibernate3/sql/classification.sql</outputFile> --> + <drop>true</drop> + </configuration> + </plugin> + </plugins> + </pluginManagement> <plugins> <plugin> <artifactId>maven-compiler-plugin</artifactId> @@ -120,8 +139,10 @@ </plugins> </build> <modules> + <module>surveyforge-util</module> <module>surveyforge-classification</module> <module>surveyforge-core</module> + <module>surveyforge-db</module> </modules> <repositories> <repository> @@ -207,6 +228,11 @@ <dependencies> <dependency> <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-util</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> <artifactId>surveyforge-classification</artifactId> <version>${project.version}</version> </dependency> @@ -239,6 +265,29 @@ <version>1.0</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + <version>3.2.0.cr1</version> + <exclusions> + <exclusion> + <groupId>javax.persistence</groupId> + <artifactId>ejb</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + <version>3.1beta1</version> + <scope>test</scope> + <exclusions> + <exclusion> + <groupId>javax.persistence</groupId> + <artifactId>ejb</artifactId> + </exclusion> + </exclusions> + </dependency> </dependencies> </dependencyManagement> <distributionManagement> Modified: trunk/surveyforge-classification/pom.xml =================================================================== --- trunk/surveyforge-classification/pom.xml 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/pom.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -7,9 +7,13 @@ </parent> <modelVersion>4.0.0</modelVersion> <artifactId>surveyforge-classification</artifactId> - <name>SurveyForge Classification API</name> + <name>SurveyForge classification API</name> <dependencies> <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-util</artifactId> + </dependency> + <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <classifier>jdk15</classifier> @@ -22,5 +26,9 @@ <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + </dependency> </dependencies> </project> Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Classification.java 2006-07-13 08:34:27 UTC (rev 18) @@ -29,6 +29,18 @@ import java.util.List; import java.util.Set; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Transient; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.GenericGenerator; + /** * A classification describes the ensemble of one or several consecutive classification {@link org.surveyforge.classification.Version}s. * In the context of the classification database, there is no structured list of categories directly associated with the @@ -36,49 +48,72 @@ * * @author jgonzalez */ +@Entity +// @Table(schema = "classification") public class Classification implements Serializable { private static final long serialVersionUID = 4169537105933133532L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; /** A classification is identified by a unique identifier, which may typically be an abbreviation of its title. */ + @Column(unique = true, length = 50) private String identifier; /** A classification has a title as provided by the owner. */ + @Column(unique = true, length = 250) private String title; /** Short general description of the classification, including its purpose, its main subject areas etc. */ + @Column(length = 500) private String description; /** * A classification can be designed in a specific context. Ex.: ISIC: international classification; NACE: EU classification; * NACE-BEL: Belgian classification. */ + @Column(length = 250) private String context; /** * A classification is designed to classify a specific type of object/unit according to a specific attribute. Ex.: Enterprises by * economic activity, products by origin, persons by age. */ + @Column(length = 250) private String objectsClassified; /** Areas of statistics in which the classification is implemented. Ex.: ISCO is used in employment and labour force statistics. */ + @Column(length = 250) private String subjectAreas; /** * The statistical office or other authority, which created and maintains the version(s) of the classification. A classification may * have several owners. Ex.: ISIC is owned by UNSD; ISCO-COM is owned by ILO and Eurostat. */ + @CollectionOfElements + @Column(name = "owner", length = 100) private Set<String> owners = new HashSet<String>( ); /** A classification can be associated with one or a number of keywords. Ex.: For NACE: ”Economic Activity”; ”Industry”; ”Production”. */ + @CollectionOfElements + @Column(name = "keyword", length = 100) private Set<String> keywords = new HashSet<String>( ); /** * Classifications may be grouped into classification {@link Family families}. Shows to which family the classification belongs. * Ex.: ISIC and NACE belong to the family ”Classifications of economic activity”. */ + @ManyToOne(optional = false) private Family family; /** * A classification has at least one {@link Version} (classification version). Ex.: ISIC: ISIC Rev.1, ISIC Rev.2, ISIC Rev.3; NACE: * NACE 70, NACE Rev.1. */ + @OneToMany(mappedBy = "classification", fetch = FetchType.LAZY) private Set<Version> versions = new HashSet<Version>( ); /** * If there are several versions of a classification, one version is assigned as the currently valid version. Ex.: ISIC Rev. 3; NACE * Rev. 1. */ + @Transient private Version currentVersion; /** Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Family.java 2006-07-13 08:34:27 UTC (rev 18) @@ -26,6 +26,18 @@ import java.util.HashSet; import java.util.Set; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.surveyforge.util.InternationalizedString; + /** * A classification family comprises a number of {@link org.surveyforge.classification.Classification}s, which are related from a * certain point of view. The family may be based, for instance, on a common classification variable (e.g. economic activity) or on a @@ -34,16 +46,30 @@ * * @author jgonzalez */ +@Entity +// @Table(schema = "classification") public class Family implements Serializable { - private static final long serialVersionUID = -2041101270919820504L; + private static final long serialVersionUID = -2041101270919820504L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; /** A classification family is identified by a unique identifier. */ - private String identifier; + @Basic(optional = false) + @Column(length = 50, nullable = false, unique = true) + private String identifier; /** A classification family has a title. */ - private String title; + @ManyToOne + private InternationalizedString title; /** A classification family refers to a number of classifications. */ - private Set<Classification> classifications = new HashSet<Classification>( ); + @OneToMany(mappedBy = "family", fetch = FetchType.LAZY) + private Set<Classification> classifications = new HashSet<Classification>( ); /** * Creates a new family with the given identifier. @@ -85,7 +111,7 @@ * * @return the title of this family. */ - public String getTitle( ) + public InternationalizedString getTitle( ) { return title; } @@ -95,7 +121,7 @@ * * @param title the new title of this family. */ - public void setTitle( String title ) + public void setTitle( InternationalizedString title ) { this.title = title; } Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Item.java 2006-07-13 08:34:27 UTC (rev 18) @@ -24,10 +24,19 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * A classification item represents a category at a certain level within a classification version or variant. It defines the content * and the borders of the category. A statistical object/unit can be classified to one and only one item at each level of a @@ -35,48 +44,69 @@ * * @author jgonzalez */ +@Entity +// @Table(schema = "classification") public class Item implements Serializable { - private static final long serialVersionUID = -3965211400312532582L; + private static final long serialVersionUID = -3965211400312532582L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; /** The level this item belongs to. */ - private Level level; + @ManyToOne(optional = false) + private Level level; // TODO: Should we make any distinction among alphabetical, numericcal and alphanumerical codes? /** * A classification item is identified by an alphabetical, numerical or alphanumerical code, which is in line with the code structure * of the classification level. The code is unique within the classification version or variant to which the item belongs. */ - private String code; + @Column(length = 50) + private String code; /** A classification item has a title as provided by the owner or maintenance unit. The title describes the content of the category. */ - private String oficialTitle; + @Column(length = 250) + private String oficialTitle; /** * An item can be expressed in terms of one or several alternative titles. Each alternative title is associated with a title type. * Ex.: Short titles; Medium titles; Self-explanatory titles in CN; Titles in plural form (e.g. Men, Women) for dissemination * purposes; gender related titles. */ - private Map<String, String> alternativeTitles = new HashMap<String, String>( ); + // @CollectionOfElements + // @MapKey(columns = {@Column(name = "titleType", length = 100)}) + // @Column(name = "alternativeTitle", length = 250) + // private Map<String, String> alternativeTitles = new HashMap<String, String>( ); // TODO: Explanatory notes /** * Indicates whether or not the item has been generated to make the level to which it belongs complete. Ex.: In NACE Rev.1 one may * generate items AA, BB, FF etc. to make the subsection level complete. */ - private boolean generated; + private boolean generated; // TODO: currently valid and validity periods /** Describes the changes, which the item has been subject to from the previous to the actual classification version or variant. */ - private String changes; + @Column(length = 2500) + private String changes; /** Describes the changes, which the item has been subject to during the life time of the actual classification version or variant. */ - private String updates; + @Column(length = 2500) + private String updates; /** * The item at the next higher level of the classification version or variant of which the actual item is a sub item. Ex.: In NACE * Rev.1 item 10 is the parent of item 10.1. */ - private Item parentItem; + @ManyToOne + private Item parentItem; /** * Each item, which is not at the lowest level of the classification version or variant, might contain one or a number of sub items, * i.e. items at the next lower level of the classification version or variant. Ex.: In NACE Rev.1, the Group level items 10.1, 10.2 * and 10.3 are sub items of the Division level item 10. */ - private List<Item> subItems = new ArrayList<Item>( ); + @OneToMany(mappedBy = "parentItem", fetch = FetchType.LAZY) + @IndexColumn(name = "subItemIndex") + private List<Item> subItems = new ArrayList<Item>( ); // TODO: Linked items // TODO: Case laws @@ -186,16 +216,15 @@ * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item * belongs to. */ - public String getAlternativeTitle( String titleType ) - { - if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) - { - return this.alternativeTitles.get( titleType ); - } - else - throw new IllegalArgumentException( ); - } - + // public String getAlternativeTitle( String titleType ) + // { + // if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + // { + // return this.alternativeTitles.get( titleType ); + // } + // else + // throw new IllegalArgumentException( ); + // } /** * Sets the alternative description of this category of the requested type. The title type must be among the title types defined for * the classification version this item belongs to ({@see Version#getTitleTypes()}), otherwise this method throws a @@ -206,16 +235,15 @@ * @throws IllegalArgumentException if the requested title type is not among the title types of the classification version this item * belongs to. */ - public void setAlternativeTitle( String titleType, String alternativeTitle ) - { - if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) - { - this.alternativeTitles.put( titleType, alternativeTitle ); - } - else - throw new IllegalArgumentException( ); - } - + // public void setAlternativeTitle( String titleType, String alternativeTitle ) + // { + // if( this.getVersion( ).getTitleTypes( ).contains( titleType ) ) + // { + // this.alternativeTitles.put( titleType, alternativeTitle ); + // } + // else + // throw new IllegalArgumentException( ); + // } /** * Returns the number of the level to which the item belongs. * Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Level.java 2006-07-13 08:34:27 UTC (rev 18) @@ -27,6 +27,17 @@ import java.util.Iterator; import java.util.List; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; + +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * A classification structure (classification version or classification variant) is composed of one or several levels. In a * hierarchical classification the items of each level but the highest (most aggregated) level are aggregated to the nearest higher @@ -34,18 +45,31 @@ * * @author jgonzalez */ +@Entity +// @Table(schema = "classification") public class Level implements Serializable { private static final long serialVersionUID = -8542980068158519003L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; /** The version this level belongs to. */ + @ManyToOne(optional = false) private Version version; /** The name given to the level. Ex.: Sections, Sub-sections, Divisions, Groups and Classes in NACE Rev.1. */ + @Column(length = 50) private String name; /** * Text describing the content and particular purpose of the level. Ex.: NACE sub-sections were introduced to provide more detail at * an aggregate level. */ + @Column(length = 250) private String description; // TODO: Should we make any distinctions here? // /** Indicates whether the item code at the level is alphabetical, numerical or alphanumerical. */ @@ -54,19 +78,24 @@ * Indicates how the code is constructed of numbers, letters and separators. Ex. In NACE Rev.1 the code structure at the Class level * is 99.99 */ + @Column(length = 50) private String codeStructure; /** * Rule for the construction of dummy codes from the codes of the next higher level when an incomplete level is made complete. Ex.: * The NACE Rev.1 subsection dummy codes may be created by doubling the section code letter, i.e. Section code: B, subsection dummy * code: BB */ + @Column(length = 50) private String dummyCode; /** * A foreign level is a level that has been inherited from another classification version and is owned and maintained by the owners * and maintenance unit of that classification version. */ + @ManyToOne private Level foreignLevel; /** An ordered list of the categories (classification items) that constitute the level. */ + @OneToMany(mappedBy = "level", fetch = FetchType.LAZY) + @IndexColumn(name = "itemIndex") private List<Item> items = new ArrayList<Item>( ); /** Modified: trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java =================================================================== --- trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-06-28 09:05:09 UTC (rev 17) +++ trunk/surveyforge-classification/src/main/java/org/surveyforge/classification/Version.java 2006-07-13 08:34:27 UTC (rev 18) @@ -30,6 +30,22 @@ import java.util.Locale; import java.util.Set; +import javax.persistence.AttributeOverride; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.IndexColumn; + /** * A classification version is a list of mutually exclusive categories representing the version-specific values of the classification * variable. If the version is hierarchical, each level in the hierarchy is a set of mutually exclusive categories. A classification @@ -41,36 +57,57 @@ * * @author jgonzalez */ +@Entity +// @Table(schema = "classification") public class Version implements Serializable { private static final long serialVersionUID = -6949734640328443272L; + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; /** * A classification version is identified by a unique identifier, which may typically be an abbreviation of its title. It is often * distinguished from other versions of the same classification by reference to a revision number or to the year of the version's * coming into force. Ex.: NACE Rev.1, CPA 96. */ + @Basic(optional = false) + @Column(nullable = false, unique = true, length = 50) private String identifier; /** * A classification version has a title as provided by the owner or maintenance unit. Ex.: Classification of Products by Activity, * 1996. */ + @Column(unique = true, length = 250) private String title; /** Short general description of the classification version. */ + @Column(length = 500) private String description; /** Date on which the classification version was released. */ + @Basic(optional = false) + @Temporal(TemporalType.DATE) + @Column(nullable = false) private Date releaseDate; /** * The introduction provides a detailed description of the classification version, the background for its creation, the * classification variable and objects/units classified, classification rules etc. */ + @Column(length = 500) private String introduction; /** * The unit or group of persons within the organisation who are responsible for the classification version, i.e. for maintaining, * updating and changing it. */ + @Column(length = 250) private String maintenanceUnit; /** Person(s) who may be contacted for additional information about the classification version. */ + @CollectionOfElements + @Column(name = "contactPerson", length = 100) private Set<String> contactPersons = new HashSet<String>( ); /** * Indicates that the classification version is covered by a legal act or by some other formal agreement. Ex.: The legal base for @@ -78,15 +115,24 @@ * European Communities No. L 293, 24.10.1990) 2. Commission of the European Communities Regulation (EEC) No. 761/93 of 24 March 1993 * (Official Journal of the European Communities No. L 83, 3.4.1993) */ + @Column(length = 500) private String legalBase; /** A list of the publications in which the classification version has been published. */ + @CollectionOfElements + @IndexColumn(name = "publicationIndex") + @Column(name = "publication", length = 100) private List<String> publications = new ArrayList<String>( ); /** * A list of the defined types of alternative item titles available for the version. Each title type refers to a list of alternative * item titles. Ex.: Short titles; Medium titles. */ + @CollectionOfElements + @IndexColumn(name = "titleTypeIndex") + @Column(name = "titleType", length = 100) private List<String> titleTypes; /** A classification version can exist in one or several languages. */ + @CollectionOfElements + @AttributeOverride(name = "element", column = @Column(name = "language")) private Set<Locale> availableLanguages = new HashSet<Locale>( ); /** * Indicates whether or not updates are allowed within the classification version, i.e. without leading to a new version. Such @@ -95,17 +141,21 @@ */ private boolean updatesPossible; /** Verbal summary description of changes which have occurred from the previous classification version to the actual version. */ + @Column(length = 2500) private String changes; /** Verbal summary description of changes which have occurred within the classification version. */ + @Column(length = 2500) private String updates; /** * Classification versions may have restricted copyrights. Such versions might be excluded from downloading and should be displayed * in official publications (e.g. WEB) indicating the copyright owner. */ + @Column(length = 500) private String copyright; /** Indicates whether or not the classification version may be published or disseminated (e.g. on the Web). */ private boolean disseminationAllowed; /** A classification version is a version of one specific classification. Ex.: CPA 96 is a version of CPA. */ + @ManyToOne(optional = false) private Classification classification; /** * A classification version can be derived from one of the classification versions of another classification. The derived version can @@ -114,8 +164,11 @@ * the classification version from which the actual version is derived. Ex.: NACE Rev.1 is derived from ISIC Rev.3; CPA 93 is derived * from the Provisional CPC (1991). */ + @ManyToOne private Version derivedFrom; /** The structure of a classification version is defined by its levels. */ + @OneToMany(mappedBy = "version", fetch = FetchType.LAZY) + @IndexColumn(name = "levelIndex") private List<Level> levels = new ArrayList<Level>( ); // /** A list of all case laws associated with the classification version. */ Added: trunk/surveyforge-db/pom.xml =================================================================== --- trunk/surveyforge-db/pom.xml (rev 0) +++ trunk/surveyforge-db/pom.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,54 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <parent> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge</artifactId> + <version>0.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>surveyforge-db</artifactId> + <name>SurveyForge database generation and tests</name> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>hibernate3-maven-plugin</artifactId> + <configuration> + <outputFile>surveyforge.sql</outputFile> + </configuration> + </plugin> + </plugins> + <!-- + <extensions> + <extension> + <groupId>postgresql</groupId> + <artifactId>postgresql</artifactId> + <version>8.1-407.jdbc3</version> + </extension> + </extensions> + --> + </build> + <dependencies> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-util</artifactId> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-classification</artifactId> + </dependency> + <dependency> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge-core</artifactId> + </dependency> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>hibernate</groupId> + <artifactId>hibernate-entitymanager</artifactId> + </dependency> + </dependencies> +</project> Property changes on: trunk/surveyforge-db/pom.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml =================================================================== --- trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml (rev 0) +++ trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,38 @@ +<?xml version='1.0' encoding='utf-8'?> +<!DOCTYPE hibernate-configuration PUBLIC + "-//Hibernate/Hibernate Configuration DTD//EN" + "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> + +<hibernate-configuration> + <!-- a SessionFactory instance listed as /jndi/name --> + <session-factory name="java:hibernate/SessionFactory"> + <!-- properties --> + <!-- <property name="connection.datasource">java:/comp/env/jdbc/MyDB</property> --> + <!-- + <property name="connection.driver_class">org.postgresql.Driver</property> + <property name="connection.url">jdbc:postgresql://server/DATABASE</property> + <property name="connection.username">user</property> + <property name="connection.password">password</property> + <property name="show_sql">false</property> + <property name="transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property> + <property name="jta.UserTransaction">java:comp/UserTransaction</property> + <property name="ejb.naming_strategy">org.hibernate.cfg.DefaultComponentSafeNamingStrategy</property> + --> + <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> + + <!-- mapping files --> + <mapping class="org.surveyforge.util.InternationalizedString" /> + <mapping class="org.surveyforge.classification.Family" /> + <mapping class="org.surveyforge.classification.Classification" /> + <mapping class="org.surveyforge.classification.Version" /> + <mapping class="org.surveyforge.classification.Level" /> + <mapping class="org.surveyforge.classification.Item" /> + + <!-- cache settings --> + <!-- + <class-cache class="org.hibernate.auction.Item" usage="read-write" /> + <class-cache class="org.hibernate.auction.Bid" usage="read-only" /> + <collection-cache collection="org.hibernate.auction.Item.bids" usage="read-write" /> + --> + </session-factory> +</hibernate-configuration> Property changes on: trunk/surveyforge-db/src/main/resources/hibernate.cfg.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml =================================================================== --- trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml (rev 0) +++ trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" + version="1.0"> + <persistence-unit name="surveyforge"> + <class>org.surveyforge.util.InternationalizedString</class> + <class>org.surveyforge.classification.Family</class> + <class>org.surveyforge.classification.Classification</class> + <class>org.surveyforge.classification.Version</class> + <class>org.surveyforge.classification.Level</class> + <class>org.surveyforge.classification.Item</class> + <properties> + <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" /> + <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" /> + <property name="hibernate.connection.url" value="jdbc:postgresql://server/DATABASE" /> + <property name="hibernate.connection.username" value="user" /> + <property name="hibernate.connection.password" value="password" /> + <!-- alternatively to <class> and <property> declarations, you can use a regular hibernate.cfg.xml file --> + <!-- property name="hibernate.ejb.cfgfile" value="/org/hibernate/ejb/test/hibernate.cfg.xml"/ --> + </properties> + </persistence-unit> +</persistence> \ No newline at end of file Property changes on: trunk/surveyforge-db/src/test/resources/META-INF/persistence.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-db/src/test/resources/testng.xml =================================================================== --- trunk/surveyforge-db/src/test/resources/testng.xml (rev 0) +++ trunk/surveyforge-db/src/test/resources/testng.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> +<suite name="SurveyForge db test suite"> + <test name="database"> + <packages> + <package name="org.surveyforge.util" /> + <package name="org.surveyforge.classification" /> + <package name="org.surveyforge.core" /> + </packages> + </test> +</suite> Property changes on: trunk/surveyforge-db/src/test/resources/testng.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-util/pom.xml =================================================================== --- trunk/surveyforge-util/pom.xml (rev 0) +++ trunk/surveyforge-util/pom.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project> + <parent> + <groupId>org.surveyforge</groupId> + <artifactId>surveyforge</artifactId> + <version>0.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>surveyforge-util</artifactId> + <name>SurveyForge support classes</name> + <dependencies> + <dependency> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>javax.persistence</groupId> + <artifactId>persistence-api</artifactId> + </dependency> + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-annotations</artifactId> + </dependency> + </dependencies> +</project> Property changes on: trunk/surveyforge-util/pom.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java (rev 0) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,109 @@ +/* + * surveyforge-util - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.util; + +import java.util.HashMap; +import java.util.Locale; +import java.util.Map; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import org.hibernate.annotations.CollectionOfElements; +import org.hibernate.annotations.GenericGenerator; +import org.hibernate.annotations.MapKey; + +// TODO: Write javadoc comments +// TODO: This should be modeled as an embeddable object, but we have been unable to find a proper mapping using Hibernate annotations. +/** + * @author jgonzalez + */ +@Entity +public class InternationalizedString + { + @Id + @Column(length = 50) + @GeneratedValue(generator = "system-uuid") + @GenericGenerator(name = "system-uuid", strategy = "uuid") + private String id; + /** Version for optimistic locking. */ + @javax.persistence.Version + private int lockingVersion; + @CollectionOfElements + @MapKey(columns = {@Column(name = "locale", length = 25)}) + @Column(name = "string", length = 2500) + private Map<Locale, String> strings = new HashMap<Locale, String>( ); + @Column(length = 25) + private Locale defaultLocale = Locale.getDefault( ); + + public InternationalizedString( ) + {} + + public InternationalizedString( Locale defaultLocale ) + { + this.setDefaultLocale( defaultLocale ); + } + + public Locale getDefaultLocale( ) + { + return this.defaultLocale; + } + + public void setDefaultLocale( Locale defaultLocale ) + { + if( defaultLocale != null ) + this.defaultLocale = defaultLocale; + else + this.defaultLocale = Locale.getDefault( ); + } + + public String getString( ) + { + if( this.strings.containsKey( this.getDefaultLocale( ) ) ) + return this.strings.get( this.getDefaultLocale( ) ); + else if( this.strings.containsKey( new Locale( this.getDefaultLocale( ).getLanguage( ), this.getDefaultLocale( ).getCountry( ) ) ) ) + return this.strings.get( new Locale( this.getDefaultLocale( ).getLanguage( ), this.getDefaultLocale( ).getCountry( ) ) ); + else if( this.strings.containsKey( new Locale( this.getDefaultLocale( ).getLanguage( ) ) ) ) + return this.strings.get( new Locale( this.getDefaultLocale( ).getLanguage( ) ) ); + else + return null; + } + + public String getString( Locale locale ) + { + if( this.strings.containsKey( locale ) ) + return this.strings.get( locale ); + else if( this.strings.containsKey( new Locale( locale.getLanguage( ), locale.getCountry( ) ) ) ) + return this.strings.get( new Locale( locale.getLanguage( ), locale.getCountry( ) ) ); + else if( this.strings.containsKey( new Locale( locale.getLanguage( ) ) ) ) + return this.strings.get( new Locale( locale.getLanguage( ) ) ); + else + return this.getString( ); + } + + public void setString( Locale locale, String string ) + { + this.strings.put( locale, string ); + } + } Property changes on: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java =================================================================== --- trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java (rev 0) +++ trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,78 @@ +/* + * surveyforge-classification - Copyright (C) 2006 OPEN input - http://www.openinput.com/ + * + * 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 + * + * $Id$ + */ +package org.surveyforge.util; + +import java.util.Locale; + +import org.testng.Assert; +import org.testng.annotations.Configuration; +import org.testng.annotations.Test; + +/** + * Tests related to {@link org.surveyforge.util.InternationalizedString}. + * + * @author jgonzalez + */ +public class InternationalizedStringTest + { + private InternationalizedString i15dString; + private static Locale ES = new Locale( "ES" ); + private static Locale UK_WIN = new Locale( "EN", "UK", "WIN" ); + + private static String ESPAÑOL = "ESPAÑOL"; + private static String ENGLISH = "ENGLISH"; + private static String ENGLISH_UK_WIN = "ENGLISH-UK-WIN"; + + @Configuration(beforeTestClass = true) + public void setupString( ) + { + this.i15dString = new InternationalizedString( InternationalizedStringTest.ES ); + this.i15dString.setString( InternationalizedStringTest.ES, InternationalizedStringTest.ESPAÑOL ); + this.i15dString.setString( Locale.ENGLISH, InternationalizedStringTest.ENGLISH ); + this.i15dString.setString( InternationalizedStringTest.UK_WIN, InternationalizedStringTest.ENGLISH_UK_WIN ); + } + + @Test + public void useOfDefaultLocale( ) + { + Assert.assertEquals( new InternationalizedString( ).getDefaultLocale( ), Locale.getDefault( ) ); + Assert.assertEquals( new InternationalizedString( null ).getDefaultLocale( ), Locale.getDefault( ) ); + } + + @Test + public void lookupStrings( ) + { + Locale ES_es = new Locale( "ES", "es" ); + Locale ES_es_win = new Locale( "ES", "es", "WIN" ); + + Assert.assertEquals( this.i15dString.getString( ), InternationalizedStringTest.ESPAÑOL ); + Assert.assertEquals( this.i15dString.getString( ES_es ), InternationalizedStringTest.ESPAÑOL ); + Assert.assertEquals( this.i15dString.getString( ES_es_win ), InternationalizedStringTest.ESPAÑOL ); + + Assert.assertEquals( this.i15dString.getString( Locale.ENGLISH ), InternationalizedStringTest.ENGLISH ); + Assert.assertEquals( this.i15dString.getString( Locale.UK ), InternationalizedStringTest.ENGLISH ); + Assert.assertEquals( this.i15dString.getString( Locale.US ), InternationalizedStringTest.ENGLISH ); + Assert.assertEquals( this.i15dString.getString( InternationalizedStringTest.UK_WIN ), InternationalizedStringTest.ENGLISH_UK_WIN ); + + Assert.assertEquals( this.i15dString.getString( Locale.FRENCH ), InternationalizedStringTest.ESPAÑOL ); + } + } Property changes on: trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id Added: trunk/surveyforge-util/src/test/resources/testng.xml =================================================================== --- trunk/surveyforge-util/src/test/resources/testng.xml (rev 0) +++ trunk/surveyforge-util/src/test/resources/testng.xml 2006-07-13 08:34:27 UTC (rev 18) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> +<suite name="SurveyForge util test suite"> + <test name="util"> + <packages> + <package name="org.surveyforge.util" /> + </packages> + </test> +</suite> Property changes on: trunk/surveyforge-util/src/test/resources/testng.xml ___________________________________________________________________ Name: svn:keywords + Date Revision Author HeadURL Id This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-13 09:09:41
|
Revision: 20 Author: jgongo Date: 2006-07-13 02:09:22 -0700 (Thu, 13 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=20&view=rev Log Message: ----------- Several improvements to InternationalizedString including Serializable implementation Modified Paths: -------------- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java Modified: trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java =================================================================== --- trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-07-13 09:07:00 UTC (rev 19) +++ trunk/surveyforge-util/src/main/java/org/surveyforge/util/InternationalizedString.java 2006-07-13 09:09:22 UTC (rev 20) @@ -21,9 +21,12 @@ */ package org.surveyforge.util; +import java.io.Serializable; +import java.util.Collections; import java.util.HashMap; import java.util.Locale; import java.util.Map; +import java.util.Set; import javax.persistence.Column; import javax.persistence.Entity; @@ -40,8 +43,10 @@ * @author jgonzalez */ @Entity -public class InternationalizedString +public class InternationalizedString implements Serializable { + private static final long serialVersionUID = 4441883710391359007L; + @Id @Column(length = 50) @GeneratedValue(generator = "system-uuid") @@ -53,9 +58,9 @@ @CollectionOfElements @MapKey(columns = {@Column(name = "locale", length = 25)}) @Column(name = "string", length = 2500) - private Map<Locale, String> strings = new HashMap<Locale, String>( ); + private Map<Locale, String> strings = new HashMap<Locale, String>( ); @Column(length = 25) - private Locale defaultLocale = Locale.getDefault( ); + private Locale defaultLocale = Locale.getDefault( ); public InternationalizedString( ) {} @@ -102,8 +107,31 @@ return this.getString( ); } + public void setString( String string ) + { + this.strings.put( this.getDefaultLocale( ), string ); + } + public void setString( Locale locale, String string ) { - this.strings.put( locale, string ); + if( locale != null ) + { + if( string != null ) + this.strings.put( locale, string ); + else + this.removeString( locale ); + } + else + throw new NullPointerException( ); } + + public void removeString( Locale locale ) + { + this.strings.remove( locale ); + } + + public Set<Locale> getLocales( ) + { + return Collections.unmodifiableSet( this.strings.keySet( ) ); + } } Modified: trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java =================================================================== --- trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java 2006-07-13 09:07:00 UTC (rev 19) +++ trunk/surveyforge-util/src/test/java/org/surveyforge/util/InternationalizedStringTest.java 2006-07-13 09:09:22 UTC (rev 20) @@ -75,4 +75,6 @@ Assert.assertEquals( this.i15dString.getString( Locale.FRENCH ), InternationalizedStringTest.ESPAÑOL ); } + + // TODO: Add tests for setString with null parameters, removeString and getLocales } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-07-13 09:07:17
|
Revision: 19 Author: jgongo Date: 2006-07-13 02:07:00 -0700 (Thu, 13 Jul 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=19&view=rev Log Message: ----------- Missing properties in module folders Property Changed: ---------------- trunk/surveyforge-db/ trunk/surveyforge-style/ trunk/surveyforge-util/ Property changes on: trunk/surveyforge-db ___________________________________________________________________ Name: bugtraq:url + http://sourceforge.net/tracker/index.php?func=detail&aid=%BUGID%&group_id=169885&atid=852142 Name: bugtraq:message + Issue: %BUGID% Name: svn:ignore + target .project .classpath .settings .wtpmodules .springBeans Property changes on: trunk/surveyforge-style ___________________________________________________________________ Name: bugtraq:url + http://sourceforge.net/tracker/index.php?func=detail&aid=%BUGID%&group_id=169885&atid=852142 Name: bugtraq:message + Issue: %BUGID% Name: svn:ignore + target .project .classpath .settings .wtpmodules .springBeans Property changes on: trunk/surveyforge-util ___________________________________________________________________ Name: bugtraq:url + http://sourceforge.net/tracker/index.php?func=detail&aid=%BUGID%&group_id=169885&atid=852142 Name: bugtraq:message + Issue: %BUGID% Name: svn:ignore + target .project .classpath .settings .wtpmodules .springBeans This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <jg...@us...> - 2006-06-28 09:05:18
|
Revision: 17 Author: jgongo Date: 2006-06-28 02:05:09 -0700 (Wed, 28 Jun 2006) ViewCVS: http://svn.sourceforge.net/surveyforge/?rev=17&view=rev Log Message: ----------- Transparent background for Explorer browser Modified Paths: -------------- trunk/src/site/resources/images/surveyforge-logo.png Modified: trunk/src/site/resources/images/surveyforge-logo.png =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |