Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBP-3305 geolocation reengineering #769

Open
wants to merge 169 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
d4f387b
Initial Liquibase scripts for Geolocation Re-engineering
darla-leafnode Jan 20, 2020
f7053ed
Move trial environment builder methods from GeolocationDao to Environ…
darla-leafnode Jan 20, 2020
29fdb61
Move/modify DAO methods used by StudyDataManager to Environment and E…
darla-leafnode Jan 20, 2020
868d6e3
Move the remaining methods from GeolocationDao to EnvironmentDao
darla-leafnode Jan 20, 2020
0abe8df
Remove geolocation property in ExperimentModel and reference to Geolo…
darla-leafnode Jan 21, 2020
a5568a8
Removed reference to GeolocationDao
darla-leafnode Jan 21, 2020
50d572b
Remove unused searcher classes
darla-leafnode Jan 21, 2020
8e398ca
Move Dao methods from GeolocationPropertyDao to EnvironmentPropertyDao
darla-leafnode Jan 21, 2020
297f76b
Delete GeolocationPropertyDao class. Remove unused imports
darla-leafnode Jan 21, 2020
5600656
Merge branch 'master' into IBP-3389-GeolocationReengineeringSpike
darla-leafnode Jan 21, 2020
6bacaa9
Remove references to nd_geolocation and nd_geolocationprop in DmsProj…
darla-leafnode Jan 21, 2020
1cb4365
Remove unused DataSetDao class
darla-leafnode Jan 21, 2020
87b2576
Remove references to nd_geolocation and nd_geolocationprop in DAO que…
darla-leafnode Jan 22, 2020
91a6f43
Update references to geolocation id
darla-leafnode Jan 23, 2020
6373fa3
Remove nd_geolocation reference from ExperimentDao queries
darla-leafnode Jan 24, 2020
c99495d
Remove nd_geolocation reference from ExperimentPropertyDao queries
darla-leafnode Jan 24, 2020
1ddb5ff
Remove nd_geolocation reference from DAO queries
darla-leafnode Jan 27, 2020
b47d7e5
Remove nd_geolocation reference from Measurements query
darla-leafnode Jan 27, 2020
1bd7a1a
Remove or comment out references to GeolocationDao in test classes to…
darla-leafnode Jan 27, 2020
c5b638f
Fix query error in getting study details
darla-leafnode Jan 27, 2020
842fec9
Merge branch 'master' into IBP-3389-GeolocationReengineeringSpike
darla-leafnode Jan 27, 2020
3fe5a35
Remove remaining references to geolocation in ExperimentPropertyDao
darla-leafnode Jan 27, 2020
d884fb8
Fix query error in getting study instances metadata
darla-leafnode Jan 27, 2020
4ea94c3
Fix query to get experiments of dataset
darla-leafnode Jan 27, 2020
37e09f5
Remove unused code
darla-leafnode Jan 28, 2020
74255b5
Set experiment environment ID properly for different dataset and expe…
darla-leafnode Jan 29, 2020
a306cd1
Fix getting of trial instance number to retrieved experiments
darla-leafnode Jan 30, 2020
76aea6e
Merge branch 'master' into IBP-3389-GeolocationReengineeringSpike
darla-leafnode Jan 30, 2020
97b39ca
Move changesets to 14.2 Liquibase file
darla-leafnode Jan 30, 2020
1b0420d
Remove unused code
darla-leafnode Jan 30, 2020
8cc613b
Revise workbook saving logic to not save to nd_geolocation and nd_geo…
darla-leafnode Feb 4, 2020
23cd660
Fix query error in getting study details
darla-leafnode Feb 4, 2020
a35f394
Fix logic for saving environment experiments
darla-leafnode Feb 4, 2020
bdabced
Delete GeolocationSaver class
darla-leafnode Feb 4, 2020
3247a07
Add logic to save environment variable values
darla-leafnode Feb 4, 2020
6a58388
Remove EnvironmentPropertySaver. Consolidate logic to save fieldmap i…
darla-leafnode Feb 5, 2020
ea05d76
Remove ExperimentDestroyer class
darla-leafnode Feb 5, 2020
7071acc
Merge branch 'master' into IBP-3389-GeolocationReengineeringSpike
darla-leafnode Feb 6, 2020
ade8976
Merge branch 'IBP-3389-GeolocationReengineeringSpike' into IBP-3305-G…
darla-leafnode Feb 13, 2020
c9609d9
Rename services and queries using geolocation term and table
darla-leafnode Feb 17, 2020
ab202fa
Modify Liquibase script to delete contents of nd_geolocation and nd_g…
darla-leafnode Feb 17, 2020
5035363
Fix query error in getting study details by environment id
darla-leafnode Feb 17, 2020
9408265
Merge branch 'master' into IBP-3305-GeolocationReengineering
darla-leafnode Feb 17, 2020
e917420
Remove unused code
darla-leafnode Feb 17, 2020
a778ee5
Restore still relevant code removed before
darla-leafnode Feb 17, 2020
6e113ab
Fix logic for adding study environment
darla-leafnode Feb 18, 2020
7212987
Fix delete study instance query
darla-leafnode Feb 18, 2020
f23ac84
Fix creation of trial environment experiments when saving a new study.
abatac Feb 19, 2020
21e7530
Fix syntax error in query.
abatac Feb 19, 2020
688ad3e
Fix type conversion error.
abatac Feb 19, 2020
9d83f64
Get the datasetId by experimentId instead of nd_geolocation_id
Feb 19, 2020
726f76e
Merge branch 'master' into IBP-3305-GeolocationReengineering
darla-leafnode Feb 20, 2020
ddad237
Used "environmentId" instead of "studyDbId" in parameters and method …
Feb 20, 2020
d1e340c
Fix issue with location value being set to null after saving an exist…
abatac Feb 20, 2020
e86fa14
Fix type conversion error.
abatac Feb 20, 2020
9b22b20
Use String.valueOf to avoid cast error.
Feb 24, 2020
2800c31
Fix query error
Feb 24, 2020
cf58643
Fixed query
Feb 24, 2020
d359a98
Removed nd_geolocation and nd_geolocation_prop references
Feb 24, 2020
7cab203
Fix the error in opening a study if it has field map info.
abatac Feb 24, 2020
f3ac36a
Fix type conversion error.
abatac Feb 24, 2020
10c7c18
Fix issue in saving/updating experiment property.
abatac Feb 26, 2020
186362d
Merge branch 'master' into IBP-3305-GeolocationReengineering
Feb 26, 2020
457adb8
Extract back to separate statement to delete phenotype because its FK…
darla-leafnode Feb 26, 2020
33e3d7c
Fix criteria for getting environments for dataset, depending if given…
darla-leafnode Feb 26, 2020
42b1cf2
Fix bug in saving phenotypes for environment when saving summary stat…
darla-leafnode Feb 27, 2020
e828e0b
Fix query to return only the experiments with values that match the b…
abatac Feb 27, 2020
8021af2
Fix bug in saving means dataset experiments
darla-leafnode Feb 27, 2020
90a5c8f
Change logic for counting experiments of given dataset type and envir…
darla-leafnode Feb 27, 2020
c654b5e
Merge branch 'master' into IBP-3305-GeolocationReengineering
abatac Feb 27, 2020
330cd1f
Fix showing of trial instance number for experiments for means dataset
darla-leafnode Feb 28, 2020
b5e3dea
Fix errors on queries for Head to Head comparison tool
darla-leafnode Feb 28, 2020
f57e44a
Fix failing tests in CrossStudyDataManagerImplTest
abatac Feb 28, 2020
400314d
Fix errors in queries for Multi-Trait Query tool
darla-leafnode Feb 28, 2020
afed628
Merge branch 'IBP-3305-GeolocationReengineering' of https://github.co…
darla-leafnode Feb 28, 2020
123fce1
Fix errors in queries for Multi-Trait Query tool
darla-leafnode Feb 28, 2020
d90b503
Merge branch 'IBP-3305-GeolocationReengineering' of https://github.co…
darla-leafnode Feb 28, 2020
17726a5
Include means type experiment when updating its parent_id to environm…
darla-leafnode Feb 28, 2020
415e049
Remove unnecessary setting of query parameter
darla-leafnode Feb 28, 2020
ce023e7
Fix query for getting observations for samples to also work for sub-o…
darla-leafnode Mar 2, 2020
2188c67
Experiment property entries (environment variables) should be created…
abatac Mar 2, 2020
59c1e0d
Fix query syntax.
abatac Mar 2, 2020
f0c149a
Fixed logic checking for existing trial experiments
Mar 2, 2020
b6e8e49
Inner Join sideId(LocationId)
Mar 2, 2020
b51e044
Revert "Inner Join sideId(LocationId)"
Mar 2, 2020
58e0e41
Fixed query in retrieving the study details
Mar 2, 2020
73d8361
Merge branch 'master' into IBP-3305-GeolocationReengineering
abatac Mar 3, 2020
0ce475d
Fix failing unit tests in StudyDataManagerImplTest.
abatac Mar 3, 2020
bd93785
Removed duplicate code
Mar 3, 2020
d2483cd
Merge branch 'master' into IBP-3305-GeolocationReengineering
abatac Mar 4, 2020
21f2df3
Merge branch 'master' into IBP-3305-GeolocationReengineering
Mar 9, 2020
f812eb7
Renamed 'environment' to 'instance'
Mar 10, 2020
b0f4c78
Renamed 'environment' to 'instance'
Mar 10, 2020
8bdc657
Renamed 'environment' to 'instance'
Mar 10, 2020
79bbe2f
Renamed 'environment' to 'instance'
Mar 10, 2020
02d6537
Revert "Renamed 'environment' to 'instance'"
Mar 10, 2020
2cbc85c
Revert "Renamed 'environment' to 'instance'"
Mar 10, 2020
0eb110a
Revert "Renamed 'environment' to 'instance'"
Mar 10, 2020
634e9bc
Revert "Renamed 'environment' to 'instance'"
Mar 10, 2020
d87d69e
Fixed some failing unit tests
Mar 13, 2020
05f7910
Renamed EnvironmentDao to InstanceDao
Mar 13, 2020
7a5714f
Removed unused method
Mar 13, 2020
79f75d7
Used TermId constant for 1020 value
Mar 13, 2020
4a2b55e
Used DatasetTypeEnum for hardcoded dataset_type_id values
Mar 13, 2020
ce7bd83
Optimize query to get phenotypes of environments of germplasm pairs
darla-leafnode Mar 13, 2020
af010bb
Fix query error
darla-leafnode Mar 13, 2020
a7c8c34
Clean up
Mar 16, 2020
1fdfb0d
Merge branch 'IBP-3305-GeolocationReengineering' of https://github.co…
Mar 16, 2020
79dd443
Merge branch 'master' into IBP-3305-GeolocationReengineering
Mar 16, 2020
79958e3
Remove unused code
darla-leafnode Mar 16, 2020
fb59cee
Remove redundant join condition
darla-leafnode Mar 16, 2020
66deb51
Optimize query to get environments where traits are observed
darla-leafnode Mar 16, 2020
83e9455
Merge branch 'IBP-3305-GeolocationReengineering' of https://github.co…
darla-leafnode Mar 16, 2020
5799f12
Optimize queries for getting numeric, character and categorical trait…
darla-leafnode Mar 16, 2020
247f284
Fix compile errors in test classes
darla-leafnode Mar 16, 2020
3a52826
Optimize query for getting observations of selected traits on selecte…
darla-leafnode Mar 16, 2020
594cc7f
Fix select clause to get correct environment ID
darla-leafnode Mar 16, 2020
d81a99a
Adjust query recently merged for BrAPI get and count Studies
darla-leafnode Mar 17, 2020
543f6a5
Fix logic to count stocks of an environment, dataset and trait
darla-leafnode Mar 17, 2020
d7277f5
Fix query error
darla-leafnode Mar 18, 2020
5256083
Merge branch 'master' into IBP-3305-GeolocationReengineering
Mar 18, 2020
a5e06e7
Merge branch 'master' into IBP-3305-GeolocationReengineering
Mar 18, 2020
345897c
Fixed failing tests
Mar 18, 2020
9d7ae67
Fixed failing tests
Mar 18, 2020
40e5c7e
Fixed failing unit test
Mar 18, 2020
6003aba
Fixed unit tests
Mar 18, 2020
237ecb1
Fixed failing unit tests
Mar 19, 2020
43c58be
Fixed failing unit test
Mar 20, 2020
303de14
Removed logging
Mar 20, 2020
426f858
Fixed failing unit tests and removed unused methods
Mar 20, 2020
bbedcd7
Removed unused methods and attributes
Mar 20, 2020
215d85c
Fixed failing unit test
Mar 20, 2020
38a09c8
Fixed failing unit tests
Mar 22, 2020
9cbca59
Fixed failing unit tests
Mar 22, 2020
347b9e5
Fixed failing unit tests
Mar 22, 2020
6f74328
Fixed query
Mar 23, 2020
b70a8fd
Move Geolocation Re-engineering changesets to 14.3 Liquibase file
darla-leafnode Mar 24, 2020
3caccc0
Create index for nd_experiment.parent_id
darla-leafnode Mar 24, 2020
570ac4c
Removed 14_2_0 file from crop_master.xml
Mar 24, 2020
d7a2c48
Make proper join to environment for all dataset types (trial environm…
darla-leafnode Mar 24, 2020
198a303
Merge branch 'IBP-3305-GeolocationReengineering' of https://github.co…
darla-leafnode Mar 24, 2020
3f15d3b
Correct the join to environment experiment when getting experiments o…
darla-leafnode Mar 24, 2020
b08b042
Remove unnecessary joins in the query to improve performance.
abatac Mar 24, 2020
38cceb1
Implement services to check if dataset ID is valid and if a dataset I…
darla-leafnode Mar 24, 2020
9117e55
Fix query to return only the number of instances with observation units.
abatac Mar 25, 2020
7466a5b
Fix issue in sub-observation batch action update.
abatac Mar 25, 2020
4cdf4cf
Corrected query to properly get the phenotype of a specified dataset …
abatac Mar 25, 2020
189fd3b
Added DatasetBasicDTO
Mar 25, 2020
fd14187
Added getDatasetBasicDTOs method
Mar 26, 2020
0c04605
Merge branch 'master' into IBP-3305-GeolocationReengineering
Mar 26, 2020
c4a7745
Merge branch 'master' into IBP-3305-GeolocationReengineering
abatac Mar 27, 2020
f9ee28f
Optimized subquery for getting if environment can be deleted or has m…
darla-leafnode Mar 27, 2020
c126dd6
Optimized query for loading observation units by not joining to envir…
darla-leafnode Mar 27, 2020
7006bab
Fix compile error
darla-leafnode Mar 27, 2020
1ebc665
Fix TRIAL_INSTANCE select clause
darla-leafnode Mar 27, 2020
573e0b7
Fix TRIAL_INSTANCE data type
darla-leafnode Mar 27, 2020
df06354
Merge branch 'master' into IBP-3305-GeolocationReengineering
darla-leafnode Apr 6, 2020
ef55941
Add back the join to environment experiment row to fix the filtering …
darla-leafnode Apr 6, 2020
fa29543
Remove creation of index on nd_experiment.parent_id
darla-leafnode Apr 6, 2020
fcb3b4a
Optimize query for getting dataset instances by only getting environm…
darla-leafnode Apr 8, 2020
82458da
Merge branch 'master' of https://github.com/IntegratedBreedingPlatfor…
darla-leafnode Apr 14, 2020
600a3e3
Optimize the detached criteria for getting environments in dataset
darla-leafnode Apr 14, 2020
a375bd3
Fix query error introduced by recent merge of master code
darla-leafnode Apr 15, 2020
7fea506
Optimize queries for getting/counting observation units by considerin…
darla-leafnode Apr 16, 2020
705aca2
Set flag whether dataset is subobservation dataset to prevent NPE in …
darla-leafnode Apr 16, 2020
fc89053
Fix query error when retrieving environment dataset instances
darla-leafnode Apr 16, 2020
41e6eef
Optimize query for checking if dataset instance has at least 2 germpl…
darla-leafnode Apr 21, 2020
cc870eb
Optimized queries design to work for both plot and sub-obs datasets t…
darla-leafnode Apr 21, 2020
da43b03
Merge branch 'master' into IBP-3305-GeolocationReengineering
darla-leafnode Apr 21, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Removed reference to GeolocationDao
IBP-3389
darla-leafnode committed Jan 21, 2020
commit a5568a8854ad89ebb0a39de2fb768d78f8792de3
Original file line number Diff line number Diff line change
@@ -63,7 +63,6 @@
import org.generationcp.middleware.pojos.Person;
import org.generationcp.middleware.pojos.dms.DmsProject;
import org.generationcp.middleware.pojos.dms.ExperimentModel;
import org.generationcp.middleware.pojos.dms.Geolocation;
import org.generationcp.middleware.pojos.dms.Phenotype;
import org.generationcp.middleware.pojos.dms.PhenotypeOutlier;
import org.generationcp.middleware.pojos.dms.ProjectProperty;
@@ -347,20 +346,6 @@ public void addOrUpdateExperiment(

}

@Override
public int addTrialEnvironment(final VariableList variableList) {

try {

final Geolocation geolocation = this.getGeolocationSaver().saveGeolocation(variableList, null);
return geolocation.getLocationId();

} catch (final Exception e) {

throw new MiddlewareQueryException("error in addTrialEnvironment " + e.getMessage(), e);
}
}

@Override
public int addStock(final VariableList variableList) {

Original file line number Diff line number Diff line change
@@ -250,15 +250,6 @@ void addExperiment(
*/
void addOrUpdateExperiment(final CropType crop, int dataSetId, ExperimentType experimentType, List<ExperimentValues> experimentValues);

/**
* Adds a Trial Environment. Accepts a variable list and sets up the trial environment data in the local database. It will throw an
* exception if the variable in the variable list passed is not recognized for trial environment.
*
* @param variableList the variable list
* @return ID of the trial environment data created.
*/
int addTrialEnvironment(VariableList variableList);

/**
* Adds a Stock entry. Accepts a variable list and sets up the stock data in the local database. It will throw an exception if the
* variable in the variable list is not a stock variable.
Original file line number Diff line number Diff line change
@@ -11,8 +11,6 @@

package org.generationcp.middleware.operation.saver;

import java.util.ArrayList;

import org.generationcp.middleware.domain.dms.PhenotypicType;
import org.generationcp.middleware.domain.dms.Variable;
import org.generationcp.middleware.domain.dms.VariableList;
@@ -28,6 +26,8 @@
import org.generationcp.middleware.pojos.dms.GeolocationProperty;
import org.generationcp.middleware.util.StringUtil;

import java.util.ArrayList;

public class GeolocationSaver {

private DaoFactory daoFactory;
@@ -42,22 +42,18 @@ public GeolocationSaver(final HibernateSessionProvider sessionProvider) {
this.variableListTransformer = new VariableListTransformer(sessionProvider);
}

public Geolocation saveGeolocation(VariableList variableList, MeasurementRow row) {
return this.saveGeolocation(variableList, row, true);
}

public Geolocation saveGeolocation(VariableList variableList, MeasurementRow row, boolean isCreate) {
Integer locationId = null;
if (row != null && !isCreate && row.getLocationId() != 0) {
locationId = (int) row.getLocationId();
}
final Geolocation geolocation = this.createOrUpdate(variableList, row, locationId);
if (geolocation != null) {
if (isCreate) {
this.daoFactory.getGeolocationDao().save(geolocation);
} else {
this.daoFactory.getGeolocationDao().saveOrUpdate(geolocation);
}
// if (isCreate) {
// this.daoFactory.getGeolocationDao().save(geolocation);
// } else {
// this.daoFactory.getGeolocationDao().saveOrUpdate(geolocation);
// }
if (null != geolocation.getVariates()) {
for (final Variable var : geolocation.getVariates().getVariables()) {
if (null == var.getPhenotypeId()) {
@@ -86,10 +82,7 @@ protected Geolocation createOrUpdate(VariableList factors, MeasurementRow row, I
final String value = variable.getValue();
geolocation = this.getGeolocationObject(geolocation, locationId);

if(isInGeolocation(variableId)){
setGeolocation(geolocation, variableId, value);

} else if (PhenotypicType.TRIAL_ENVIRONMENT == role) {
if (PhenotypicType.TRIAL_ENVIRONMENT == role) {
if (TermId.EXPERIMENT_DESIGN_FACTOR.getId() == variableId) {
// Experiment Design saves the id of the category instead of the name
variable.setValue(variable.getIdValue());
@@ -112,17 +105,11 @@ protected Geolocation createOrUpdate(VariableList factors, MeasurementRow row, I
return geolocation;
}

private boolean isInGeolocation(final int termId) {
return TermId.TRIAL_INSTANCE_FACTOR.getId() == termId || TermId.LATITUDE.getId() == termId || TermId.LONGITUDE.getId() == termId
|| TermId.GEODETIC_DATUM.getId() == termId || TermId.ALTITUDE.getId() == termId;
}


private Geolocation getGeolocationObject(Geolocation geolocation, Integer locationId) {
Geolocation finalGeolocation = geolocation;
if (finalGeolocation == null) {
if (locationId != null) {
finalGeolocation = this.getGeolocationById(locationId);
// finalGeolocation = this.getGeolocationById(locationId);
}
if (finalGeolocation == null) {
finalGeolocation = new Geolocation();
@@ -131,10 +118,6 @@ private Geolocation getGeolocationObject(Geolocation geolocation, Integer locati
return finalGeolocation;
}

protected Geolocation getGeolocationById(Integer locationId) {
return this.daoFactory.getGeolocationDao().getById(locationId);
}

private GeolocationProperty createOrUpdateProperty(Variable variable, Geolocation geolocation) {
GeolocationProperty property = this.getGeolocationProperty(variable.getVariableType().getId(), geolocation);

@@ -174,13 +157,6 @@ private void addVariate(Geolocation geolocation, Variable variable) {
geolocation.getVariates().add(variable);
}

public Geolocation createMinimumGeolocation() {
Geolocation geolocation = this.getGeolocationObject(null, null);
geolocation.setDescription("1");
this.daoFactory.getGeolocationDao().save(geolocation);

return geolocation;
}

public Geolocation updateGeolocationInformation(MeasurementRow row, String programUUID) {
VariableTypeList variableTypes = this.variableTypeListTransformer.transform(row.getMeasurementVariables(), programUUID);
@@ -228,7 +204,7 @@ public Geolocation saveGeolocationOrRetrieveIfExisting(String studyName, Variabl
}
geolocation = this.createOrUpdate(variableList, row, locationId);
geolocation.setDescription(trialInstanceNumber);
this.daoFactory.getGeolocationDao().saveOrUpdate(geolocation);
// this.daoFactory.getGeolocationDao().saveOrUpdate(geolocation);
return geolocation;
}
return null;
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
import org.generationcp.middleware.manager.DaoFactory;
import org.generationcp.middleware.manager.Operation;
import org.generationcp.middleware.pojos.dms.DmsProject;
import org.generationcp.middleware.pojos.dms.Geolocation;
import org.generationcp.middleware.pojos.dms.ExperimentModel;
import org.generationcp.middleware.pojos.dms.ProjectProperty;
import org.generationcp.middleware.pojos.oms.CVTerm;
import org.hibernate.Hibernate;
@@ -191,8 +191,8 @@ public void saveProjectProperties(final DmsProject study, final DmsProject trial
int rank = this.getNextRank(study);
final List<Integer> environmentIds = this.daoFactory.getEnvironmentDao().getEnvironmentIds(study.getProjectId());
final Set<Integer> geoIds = new HashSet<>(environmentIds);
final Geolocation geolocation = this.saver.getGeolocationDao().getById(geoIds.iterator().next());
Hibernate.initialize(geolocation.getProperties());
final ExperimentModel environment = this.daoFactory.getEnvironmentDao().getById(geoIds.iterator().next());
Hibernate.initialize(environment.getProperties());

for (final MeasurementVariable variable : variables) {
final Operation operation = variable.getOperation();
@@ -201,14 +201,14 @@ public void saveProjectProperties(final DmsProject study, final DmsProject trial
}
switch (operation) {
case DELETE:
this.deleteVariable(study, trialDataset, measurementDataset, variable.getRole(), variable.getTermId(), geolocation);
this.deleteVariable(study, trialDataset, measurementDataset, variable.getRole(), variable.getTermId());
break;
case ADD:
this.insertVariable(study, trialDataset, measurementDataset, variable, rank, isConstant, geolocation);
this.insertVariable(study, trialDataset, measurementDataset, variable, rank, isConstant, environment);
rank++;
break;
case UPDATE:
this.updateVariable(study, trialDataset, measurementDataset, variable, isConstant, geolocation);
this.updateVariable(study, trialDataset, measurementDataset, variable, isConstant, environment);
break;
default:
break;
@@ -229,13 +229,8 @@ private int getNextRank(final DmsProject project) {
return nextRank;
}

private boolean isInGeolocation(final int termId) {
return TermId.TRIAL_INSTANCE_FACTOR.getId() == termId || TermId.LATITUDE.getId() == termId || TermId.LONGITUDE.getId() == termId
|| TermId.GEODETIC_DATUM.getId() == termId || TermId.ALTITUDE.getId() == termId;
}

private void insertVariable(final DmsProject project, final DmsProject trialDataset, final DmsProject measurementDataset,
final MeasurementVariable variable, final int rank, final boolean isConstant, final Geolocation geolocation) {
final MeasurementVariable variable, final int rank, final boolean isConstant, final ExperimentModel environment) {

if (PhenotypicType.TRIAL_ENVIRONMENT == variable.getRole()) {
final int datasetRank = this.getNextRank(trialDataset);
@@ -247,12 +242,9 @@ private void insertVariable(final DmsProject project, final DmsProject trialData
if (variable.getTermId() == TermId.TRIAL_INSTANCE_FACTOR.getId()) {
this.insertVariable(measurementDataset, variable, measurementRank);
}
if (this.isInGeolocation(variable.getTermId())) {
this.saver.getGeolocationSaver().setGeolocation(geolocation, variable.getTermId(), variable.getValue());
this.saver.getGeolocationDao().saveOrUpdate(geolocation);
} else {
this.saver.getGeolocationPropertySaver().saveOrUpdate(geolocation, variable.getTermId(), variable.getValue());
}

this.saver.getGeolocationPropertySaver().saveOrUpdate(environment, variable.getTermId(), variable.getValue());


} else if (PhenotypicType.VARIATE == variable.getRole()) {

@@ -281,7 +273,7 @@ private void insertVariable(final DmsProject project, final DmsProject trialData

protected void insertVariable(final DmsProject project, final MeasurementVariable variable, final int rank) {
if (project.getProperties() == null) {
project.setProperties(new ArrayList<ProjectProperty>());
project.setProperties(new ArrayList<>());
}
this.saveVariableType(project, this.createVariableType(variable, rank), variable.getValue());
}
@@ -311,20 +303,15 @@ protected DMSVariableType createVariableType(final MeasurementVariable variable,
}

private void updateVariable(final DmsProject project, final DmsProject trialDataset, final DmsProject measurementDataset,
final MeasurementVariable variable, final boolean isConstant, final Geolocation geolocation) {
final MeasurementVariable variable, final boolean isConstant, final ExperimentModel environment) {
if (TermId.TRIAL_INSTANCE_FACTOR.getId() != variable.getTermId()) {

if (PhenotypicType.TRIAL_ENVIRONMENT == variable.getRole()) {
this.updateVariable(project, variable);
this.updateVariable(trialDataset, variable);
this.updateVariable(measurementDataset, variable);

if (this.isInGeolocation(variable.getTermId())) {
this.saver.getGeolocationSaver().setGeolocation(geolocation, variable.getTermId(), variable.getValue());
this.saver.getGeolocationDao().saveOrUpdate(geolocation);
} else {
this.saver.getGeolocationPropertySaver().saveOrUpdate(geolocation, variable.getTermId(), variable.getValue());
}
this.saver.getGeolocationPropertySaver().saveOrUpdate(environment, variable.getTermId(), variable.getValue());

} else if (PhenotypicType.VARIATE == variable.getRole()) {

@@ -367,18 +354,14 @@ private void updateVariable(final DmsProject project, final MeasurementVariable
}

private void deleteVariable(final DmsProject project, final DmsProject trialDataset, final DmsProject measurementDataset,
final PhenotypicType role, final int termId, final Geolocation geolocation) {
final PhenotypicType role, final int termId) {

if (PhenotypicType.TRIAL_ENVIRONMENT == role) {
this.deleteVariable(trialDataset, termId);
this.deleteVariable(measurementDataset, termId);

if (this.isInGeolocation(termId)) {
this.saver.getGeolocationSaver().setGeolocation(geolocation, termId, null);
this.saver.getGeolocationDao().saveOrUpdate(geolocation);
} else {
this.saver.getGeolocationPropertyDao().deletePropertiesInDataset(project.getProjectId(), Collections.singletonList(termId));
}
this.saver.getGeolocationPropertyDao().deletePropertiesInDataset(project.getProjectId(), Collections.singletonList(termId));


} else if (PhenotypicType.VARIATE == role) {
// for constants