Skip to content

Commit 865d682

Browse files
committed
- Deep change to data structures. Inclusion of the ExperimentContext. All the domain, administration and repository classes where refactored
- The importing of excel files is now complete with all the available information - Database operations where put into transactions - Add total of records to results page - Some libraries were updated in the build.gradle file - Sql initialization files have now an initial version of the compendium
1 parent 9e4231f commit 865d682

File tree

62 files changed

+79024
-3441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+79024
-3441
lines changed

build.gradle

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ buildscript {
1313
// Spring boot integration with gradle
1414
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.3.RELEASE")
1515
// Plugin to reload changed classes with out restarting
16-
classpath("org.springframework:springloaded:1.2.1.RELEASE")
16+
classpath("org.springframework:springloaded:1.2.3.RELEASE")
1717
// Plugin to include optional dependencies
1818
classpath("org.springframework.build.gradle:propdeps-plugin:0.0.7")
1919
// Plugin to deploy the war file to a remote Tomcat
@@ -48,7 +48,6 @@ bootRun {
4848
repositories {
4949
//mavenLocal()
5050
mavenCentral()
51-
maven { url "http://lightadmin.org/nexus/content/repositories/snapshots" }
5251
maven { url "http://repository.primefaces.org" }
5352
}
5453

@@ -60,7 +59,7 @@ repositories {
6059
*/
6160
dependencies {
6261

63-
def springBootVersion = "1.2.3.RELEASE"
62+
def springBootVersion = "1.2.4.RELEASE"
6463
def springVersion = "4.1.6.RELEASE"
6564

6665
compile "org.springframework.boot:spring-boot-starter:$springBootVersion"
@@ -72,8 +71,8 @@ dependencies {
7271
compile "org.springframework:spring-orm:$springVersion"
7372

7473
// Includes tomcat-embed-core, tomcat-embed-el, ecj
75-
providedCompile "org.apache.tomcat.embed:tomcat-embed-jasper:8.0.22"
76-
providedCompile "org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.22"
74+
providedCompile "org.apache.tomcat.embed:tomcat-embed-jasper:8.0.23"
75+
providedCompile "org.apache.tomcat.embed:tomcat-embed-logging-juli:8.0.23"
7776

7877
compile("org.springframework.data:spring-data-jpa:1.7.2.RELEASE") {
7978
// Requests an older version with different name
@@ -108,7 +107,7 @@ dependencies {
108107
compile "com.fasterxml.jackson.core:jackson-databind:2.5.1"
109108

110109
// For backend administration. Excludes some apache tiles extras
111-
compile ("org.lightadmin:lightadmin:1.2.0.BUILD-SNAPSHOT") {
110+
compile ("org.lightadmin:lightadmin:1.2.0.RC1") {
112111
exclude module: "tiles-freemarker"
113112
exclude module: "tiles-request-mustache"
114113
exclude module: "tiles-velocity"

src/main/java/org/cgiar/ccafs/csa/domain/AbstractInformationEntity.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
package org.cgiar.ccafs.csa.domain;
22

3+
import com.google.common.base.Joiner;
4+
35
import javax.persistence.Column;
4-
import javax.persistence.Lob;
56
import javax.persistence.MappedSuperclass;
67
import java.io.Serializable;
8+
import java.util.Objects;
79

810
/**
911
* Super class for those entities that have four basic translatable fields
1012
*/
1113
@MappedSuperclass
1214
public abstract class AbstractInformationEntity implements Serializable {
15+
16+
protected static final Joiner joiner = Joiner.on(";").skipNulls();
17+
1318
private static final long serialVersionUID = 1L;
1419

1520
private String code;
1621

1722
private String name;
1823

19-
@Column(length=100000)
24+
@Column(length = 100000)
2025
private String description;
2126

22-
@Column(length=100000)
27+
@Column(length = 100000)
2328
private String documentation;
2429

2530
public abstract Integer getId();
@@ -56,4 +61,18 @@ public void setDocumentation(String documentation) {
5661
this.documentation = documentation;
5762
}
5863

64+
@Override
65+
public boolean equals(Object o) {
66+
if (this == o) return true;
67+
if (o == null || !(o instanceof AbstractInformationEntity)) return false;
68+
AbstractInformationEntity that = (AbstractInformationEntity) o;
69+
return Objects.equals(this.code, that.code) && Objects.equals(this.name, that.name);
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
int result = code != null ? code.hashCode() : super.hashCode();
75+
result = 31 * result + (name != null ? name.hashCode() : 0);
76+
return result;
77+
}
5978
}

src/main/java/org/cgiar/ccafs/csa/domain/ContextValue.java

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.cgiar.ccafs.csa.domain;
22

33
import javax.persistence.*;
4+
import java.util.ArrayList;
5+
import java.util.List;
46

57
/**
68
* The persistent class for the context_filters database table.
@@ -18,6 +20,9 @@ public class ContextValue extends AbstractInformationEntity {
1820
@JoinColumn(name = "context_variable_id")
1921
private ContextVariable contextVariable;
2022

23+
@ManyToMany(mappedBy="contextValues")
24+
private List<ExperimentArticle> experimentArticles = new ArrayList<>();
25+
2126
@Override
2227
public Integer getId() {
2328
return this.id;
@@ -30,4 +35,8 @@ public ContextVariable getContextVariable() {
3035
public void setContextVariable(ContextVariable contextVariable) {
3136
this.contextVariable = contextVariable;
3237
}
38+
39+
public List<ExperimentArticle> getExperimentArticles() {
40+
return experimentArticles;
41+
}
3342
}

src/main/java/org/cgiar/ccafs/csa/domain/ContextVariable.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@ public class ContextVariable extends AbstractInformationEntity {
2525

2626
@Override
2727
public boolean equals(Object o) {
28-
if (this == o) return true;
29-
if (!(o instanceof ContextVariable)) return false;
30-
31-
ContextVariable that = (ContextVariable) o;
32-
33-
return id.equals(that.id);
34-
28+
return super.equals(o) && o instanceof ContextVariable && id.equals(((ContextVariable) o).getId());
3529
}
3630

3731
@Override
3832
public int hashCode() {
39-
return id.hashCode();
33+
return id * super.hashCode();
4034
}
4135

4236
@Override
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.cgiar.ccafs.csa.domain;
22

3-
import org.apache.commons.lang3.StringUtils;
43
import org.joda.time.LocalDate;
54
import org.springframework.format.annotation.DateTimeFormat;
65

@@ -11,6 +10,7 @@
1110
import java.util.Date;
1211
import java.util.List;
1312

13+
import static org.cgiar.ccafs.csa.domain.AbstractInformationEntity.joiner;
1414
import static org.springframework.format.annotation.DateTimeFormat.ISO.DATE;
1515

1616

@@ -31,27 +31,23 @@ public class ExperimentArticle implements Serializable {
3131

3232
private String code;
3333

34-
@Column(length=100000)
34+
@Column(length = 100000)
3535
private String title;
3636

37-
@Column(length=100000)
37+
@Column(length = 100000)
3838
private String outline;
3939

4040
private String link;
4141

4242
private Integer rating;
4343

44-
@ManyToOne
45-
@JoinColumn(name = "farming_system_id")
46-
private FarmingSystem farmingSystem;
47-
48-
@Column(length=100000)
44+
@Column(length = 100000)
4945
private String authors;
5046

5147
@Transient
5248
private List<String> authorsList = new ArrayList<>();
5349

54-
@Column(length=100000)
50+
@Column(length = 100000)
5551
private String contacts;
5652

5753
@Transient
@@ -68,14 +64,7 @@ public class ExperimentArticle implements Serializable {
6864

6965
@ManyToOne
7066
@JoinColumn(name = "theme_id")
71-
private PracticeTheme practiceTheme;
72-
73-
@ManyToOne
74-
@JoinColumn(name = "location_id")
75-
private Location location;
76-
77-
@OneToMany(mappedBy = "experimentArticle", fetch = FetchType.EAGER)
78-
private List<InitialCondition> initialConditions = new ArrayList<>();
67+
private PracticeTheme theme;
7968

8069
@ManyToMany(fetch = FetchType.EAGER)
8170
@JoinTable(
@@ -89,8 +78,8 @@ public class ExperimentArticle implements Serializable {
8978
)
9079
private List<ContextValue> contextValues = new ArrayList<>();
9180

92-
@OneToMany(mappedBy = "experimentArticle", fetch = FetchType.EAGER)
93-
private List<Treatment> treatments;
81+
@OneToMany(mappedBy = "experiment", fetch = FetchType.EAGER)
82+
private List<ExperimentContext> contexts = new ArrayList<>();
9483

9584
// Methods //
9685

@@ -122,43 +111,20 @@ public void setOutline(String outline) {
122111
this.outline = outline;
123112
}
124113

125-
public Integer getRating() {
126-
return this.rating;
127-
}
128-
129-
public void setRating(Integer rating) {
130-
this.rating = rating;
131-
}
132-
133-
public FarmingSystem getFarmingSystem() {
134-
return farmingSystem;
135-
}
136-
137-
public void setFarmingSystem(FarmingSystem farmingSystem) {
138-
this.farmingSystem = farmingSystem;
114+
public String getLink() {
115+
return link;
139116
}
140117

141-
public List<Treatment> getTreatments() {
142-
if (treatments == null) {
143-
treatments = new ArrayList<>();
144-
}
145-
return treatments;
118+
public void setLink(String link) {
119+
this.link = link;
146120
}
147121

148-
public void setTreatments(List<Treatment> treatments) {
149-
this.treatments = treatments;
150-
}
151-
152-
public Treatment addTreatment(Treatment treatment) {
153-
getTreatments().add(treatment);
154-
treatment.setExperiment(this);
155-
return treatment;
122+
public Integer getRating() {
123+
return this.rating;
156124
}
157125

158-
public Treatment removeTreatment(Treatment treatment) {
159-
getTreatments().remove(treatment);
160-
treatment.setExperiment(null);
161-
return treatment;
126+
public void setRating(Integer rating) {
127+
this.rating = rating;
162128
}
163129

164130
public List<String> getAuthorsList() {
@@ -173,30 +139,38 @@ public List<String> getContactsList() {
173139
return this.contactsList;
174140
}
175141

176-
public void addContact(String author) {
177-
getContactsList().add(author);
142+
public void addContact(String contactEmail) {
143+
getContactsList().add(contactEmail);
178144
}
179145

180146
@PrePersist
181147
@PreUpdate
182148
protected void recordSaved() {
183-
authors = StringUtils.join(getAuthorsList(), ";");
184-
contacts = StringUtils.join(getAuthorsList(), ";");
149+
authors = joiner.join(getAuthorsList());
150+
contacts = joiner.join(getContactsList());
185151
}
186152

187153
@PostLoad
188154
protected void recordLoaded() {
189-
if (authors != null && authors.trim().length() == 0) {
155+
if (authors != null && authors.trim().length() != 0) {
190156
String[] data = authors.split(";");
191157
authorsList = Arrays.asList(data);
192158
}
193159

194-
if (contacts != null && contacts.trim().length() == 0) {
160+
if (contacts != null && contacts.trim().length() != 0) {
195161
String[] data = contacts.split(";");
196162
contactsList = Arrays.asList(data);
197163
}
198164
}
199165

166+
public Language getLanguage() {
167+
return language;
168+
}
169+
170+
public void setLanguage(Language language) {
171+
this.language = language;
172+
}
173+
200174
public LocalDate getPublicationDate() {
201175
return new LocalDate(this.publicationDate);
202176
}
@@ -205,40 +179,40 @@ public void setPublicationDate(LocalDate publicationDate) {
205179
this.publicationDate = publicationDate.toDate();
206180
}
207181

208-
public PracticeTheme getPracticeTheme() {
209-
return practiceTheme;
182+
public PracticeTheme getTheme() {
183+
return theme;
210184
}
211185

212-
public void setPracticeTheme(PracticeTheme practiceTheme) {
213-
this.practiceTheme = practiceTheme;
186+
public void setTheme(PracticeTheme theme) {
187+
this.theme = theme;
214188
}
215189

216-
public Location getLocation() {
217-
return this.location;
190+
public List<ContextValue> getContextValues() {
191+
return this.contextValues;
218192
}
219193

220-
public void setLocation(Location location) {
221-
this.location = location;
194+
public ContextValue setContextVariable(ContextValue contextValue) {
195+
if (contextValue != null) getContextValues().add(contextValue);
196+
return contextValue;
222197
}
223198

224-
public List<ContextValue> getContextValues() {
225-
return this.contextValues;
199+
public boolean unsetContextVariable(ContextValue contextValue) {
200+
return getContextValues().remove(contextValue);
226201
}
227202

228-
public List<InitialCondition> getInitialConditions() {
229-
return this.initialConditions;
203+
public List<ExperimentContext> getContexts() {
204+
return contexts;
230205
}
231206

232-
public InitialCondition addInitialCondition(InitialCondition initialCondition) {
233-
getInitialConditions().add(initialCondition);
234-
initialCondition.setExperiment(this);
235-
return initialCondition;
207+
public ExperimentContext addContext(ExperimentContext context) {
208+
getContexts().add(context);
209+
context.setExperiment(this);
210+
return context;
236211
}
237212

238-
public InitialCondition removeInitialCondition(InitialCondition initialCondition) {
239-
getInitialConditions().remove(initialCondition);
240-
initialCondition.setExperiment(null);
241-
return initialCondition;
213+
public ExperimentContext removeExperimentContext(ExperimentContext context) {
214+
getContexts().remove(context);
215+
context.setExperiment(null);
216+
return context;
242217
}
243-
244218
}

0 commit comments

Comments
 (0)