Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class StandardVariableBuilder extends Builder {

public StandardVariableBuilder(final HibernateSessionProvider sessionProviderForLocal) {
super(sessionProviderForLocal);
daoFactory = new DaoFactory(sessionProviderForLocal);
this.daoFactory = new DaoFactory(sessionProviderForLocal);
}

public StandardVariable create(final int standardVariableId, final String programUUID) {
Expand Down Expand Up @@ -127,7 +127,7 @@ private void specialProcessing(final List<StandardVariableSummary> summaries) {
// Now this relationship is linked to the "Property" of the standard variable. (facepalm).
if (summary.getProperty() != null) {
final List<CVTermRelationship> propertyCvTermRelationships =
daoFactory.getCvTermRelationshipDao().getBySubject(summary.getProperty().getId());
this.daoFactory.getCvTermRelationshipDao().getBySubject(summary.getProperty().getId());
final Term isAOfProperty = this.createTerm(propertyCvTermRelationships, TermId.IS_A);
if (isAOfProperty != null) {
summary.setIsA(new TermSummary(isAOfProperty.getId(), isAOfProperty.getName(), isAOfProperty.getDefinition()));
Expand All @@ -150,7 +150,7 @@ public String getCropOntologyId(final Term term) {
}

final CVTermProperty property =
daoFactory.getCvTermPropertyDao().getOneByCvTermAndType(term.getId(), TermId.CROP_ONTOLOGY_ID.getId());
this.daoFactory.getCvTermPropertyDao().getOneByCvTermAndType(term.getId(), TermId.CROP_ONTOLOGY_ID.getId());
if (property != null) {
cropOntologyId = property.getValue();
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public List<TermProperty> createTermProperties(final int cvTermId) {
}

private CVTerm getCvTerm(final int id) {
return daoFactory.getCvTermDao().getById(id);
return this.daoFactory.getCvTermDao().getById(id);
}

public StandardVariable findOrSave(
Expand Down Expand Up @@ -287,7 +287,7 @@ public VariableType mapPhenotypicTypeToDefaultVariableType(final PhenotypicType
}

public StandardVariable getByName(final String name, final String programUUID) {
final CVTerm cvTerm = daoFactory.getCvTermDao().getByNameAndCvId(name, CvId.VARIABLES.getId());
final CVTerm cvTerm = this.daoFactory.getCvTermDao().getByNameAndCvId(name, CvId.VARIABLES.getId());
if (cvTerm != null && cvTerm.getCvTermId() != null) {
return this.getStandardVariableBuilder().create(cvTerm.getCvTermId(), programUUID);
}
Expand Down Expand Up @@ -319,8 +319,7 @@ public StandardVariable getByPropertyScaleMethodRole(
}

public Integer getIdByPropertyScaleMethod(final Integer propertyId, final Integer scaleId, final Integer methodId) {
Integer stdVariableId = null;
stdVariableId = daoFactory.getCvTermDao().getStandadardVariableIdByPropertyScaleMethod(propertyId, scaleId, methodId, "DESC");
final Integer stdVariableId = this.daoFactory.getCvTermDao().getStandadardVariableIdByPropertyScaleMethod(propertyId, scaleId, methodId, "DESC");
return stdVariableId;
}

Expand All @@ -333,7 +332,7 @@ public Map<String, List<StandardVariable>> getStandardVariablesInProjects(final
// Trim all header names
final List<String> headerNamesTrimmed = new ArrayList<>(Lists.transform(headerNames, new Function<String, String>() {

public String apply(String s) {
public String apply(final String s) {
// Transform header names to uppercase; header names can be in lowercase or combination when defined in file
return s.toUpperCase().trim();
}
Expand Down Expand Up @@ -407,7 +406,11 @@ private void removeHeaderNamesWithMatch(
protected void setRoleOfVariables(final List<StandardVariable> variables, final Map<Integer, VariableType> varIdsWithType) {
for (final StandardVariable standardVariable : variables) {
final VariableType type = varIdsWithType.get(standardVariable.getId());
if (type != null) {
// Experimental Design Variables will have Trial_Environment phenotypic type
final int standardVarialbeId = standardVariable.getId();
if (WorkbookBuilder.EXPERIMENTAL_DESIGN_VARIABLES.contains(standardVarialbeId)) {
standardVariable.setPhenotypicType(PhenotypicType.TRIAL_ENVIRONMENT);
} else if(type != null) {
standardVariable.setPhenotypicType(type.getRole());
}
}
Expand Down Expand Up @@ -435,39 +438,37 @@ public Map<String, Map<Integer, VariableType>> getStandardVariableIdsWithTypeByA

public Map<String, Map<Integer, VariableType>> getStandardVariableIdsWithTypeForTerms(final List<String> termNames) {
if (!termNames.isEmpty()) {
return daoFactory.getCvTermDao().getTermIdsWithTypeByNameOrSynonyms(termNames, CvId.VARIABLES.getId());
return this.daoFactory.getCvTermDao().getTermIdsWithTypeByNameOrSynonyms(termNames, CvId.VARIABLES.getId());
}
return new HashMap<>();
}

public Map<String, Map<Integer, VariableType>> getStandardVariableIdsForTraits(final List<String> traitNames) {
if (!traitNames.isEmpty()) {
return daoFactory.getCvTermDao().getStandardVariableIdsWithTypeByProperties(traitNames);
return this.daoFactory.getCvTermDao().getStandardVariableIdsWithTypeByProperties(traitNames);
}
return new HashMap<>();
}

public Integer getIdByTermId(final int cvTermId, final TermId termId) {
Integer stdVariableId = null;
stdVariableId = daoFactory.getCvTermDao().getStandardVariableIdByTermId(cvTermId, termId);
final Integer stdVariableId = this.daoFactory.getCvTermDao().getStandardVariableIdByTermId(cvTermId, termId);
return stdVariableId;
}

public CVTerm getCvTerm(final String name, final int cvId) {
return daoFactory.getCvTermDao().getByNameAndCvId(name, cvId);
return this.daoFactory.getCvTermDao().getByNameAndCvId(name, cvId);
}

public Integer getIdByPropertyScaleMethodRole(
final Integer propertyId, final Integer scaleId, final Integer methodId,
final PhenotypicType role) {
Integer stdVariableId = null;
stdVariableId = daoFactory.getCvTermDao().getStandadardVariableIdByPropertyScaleMethodRole(propertyId, scaleId, methodId, role);
final Integer stdVariableId = this.daoFactory.getCvTermDao().getStandadardVariableIdByPropertyScaleMethodRole(propertyId, scaleId, methodId, role);
return stdVariableId;
}

public boolean validateEnumerationUsage(final int standardVariableId, final int enumerationId) {
final Integer storedInId =
daoFactory.getCvTermRelationshipDao().getObjectIdByTypeAndSubject(TermId.STORED_IN.getId(), standardVariableId).get(0);
this.daoFactory.getCvTermRelationshipDao().getObjectIdByTypeAndSubject(TermId.STORED_IN.getId(), standardVariableId).get(0);
final String value = String.valueOf(enumerationId);
if (storedInId == TermId.STUDY_INFO_STORAGE.getId() || storedInId == TermId.DATASET_INFO_STORAGE.getId()) {
return !this.isExistsPropertyByTypeAndValue(standardVariableId, value);
Expand Down Expand Up @@ -512,6 +513,6 @@ private boolean isExistsPhenotypeByTypeAndValue(final Integer variateId, final S
}

public List<StandardVariableReference> findAllByProperty(final int propertyId) {
return new ArrayList<>(daoFactory.getCvTermDao().getStandardVariablesOfProperty(propertyId));
return new ArrayList<>(this.daoFactory.getCvTermDao().getStandardVariablesOfProperty(propertyId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ public Workbook createStudyVariableSettings(final int id) {
if (PhenotypicType.TRIAL_ENVIRONMENT == varType.getRole()) {
value = projectProperty.getValue();
if (value == null) {
value = StringUtils.EMPTY;
// During import of study, experiment design values are not set in ProjectProperty so we resolve them from GeolocationProperty
if (VariableType.ENVIRONMENT_DETAIL.equals(varType)) {
final GeolocationPropertyDao geolocationPropertyDao = this.daoFactory.getGeolocationPropertyDao();
value = geolocationPropertyDao.getGeolocationPropValue(stdVariable.getId(), id);
} else {
value = StringUtils.EMPTY;
}
}
} else if (PhenotypicType.VARIATE == varType.getRole()) {// TODO traits
// constants, no need to retrieve the value if it's a trial study
Expand Down Expand Up @@ -735,6 +741,7 @@ private List<MeasurementVariable> removeConstantsFromVariates(
for (final MeasurementVariable constant : constants) {
if (variate.getTermId() == constant.getTermId()) {
found = true;
break;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.commons.lang3.StringUtils;
import org.generationcp.middleware.dao.LocationDAO;
import org.generationcp.middleware.domain.dms.*;
import org.generationcp.middleware.domain.dms.Enumeration;
import org.generationcp.middleware.domain.etl.MeasurementData;
import org.generationcp.middleware.domain.etl.MeasurementRow;
import org.generationcp.middleware.domain.etl.MeasurementVariable;
Expand All @@ -25,6 +26,7 @@
import org.generationcp.middleware.hibernate.HibernateSessionProvider;
import org.generationcp.middleware.manager.DaoFactory;
import org.generationcp.middleware.manager.Operation;
import org.generationcp.middleware.manager.api.OntologyDataManager;
import org.generationcp.middleware.manager.api.StudyDataManager;
import org.generationcp.middleware.operation.builder.WorkbookBuilder;
import org.generationcp.middleware.operation.transformer.etl.ExperimentValuesTransformer;
Expand Down Expand Up @@ -76,6 +78,9 @@ public class WorkbookSaver extends Saver {
@Resource
private StudyDataManager studyDataManager;

@Resource
private OntologyDataManager ontologyDataManager;

public WorkbookSaver() {

}
Expand Down Expand Up @@ -136,6 +141,8 @@ public Map saveVariables(final Workbook workbook, final String programUUID) {
variableTypeMap.put(WorkbookSaver.TRIALVARIABLES, trialVariables);
variableTypeMap.put(WorkbookSaver.EFFECTVARIABLE, effectVariables);
// -- measurementVariables

this.setRMAPValueIfNecessary(trialMV, programUUID);
measurementVariableMap.put(WorkbookSaver.TRIALMV, trialMV);

final List<MeasurementVariable> effectMV = workbook.getMeasurementDatasetVariables();
Expand Down Expand Up @@ -520,6 +527,10 @@ private int createLocationsAndSetToObservations(
if (geolocationId == 0) {
// if geolocationId does not exist, create the geolocation
// and set to row.locationId

//Set RMAP Value if Necessary
this.setRMAPValueObservationIfNecessary(row.getDataList(), programUUID);

final TimerWatch watch = new TimerWatch("transformTrialEnvironment in createLocationsAndSetToObservations");
final VariableList geolocation =
this.getVariableListTransformer().transformTrialEnvironment(row, trialFactors, trialHeaders);
Expand Down Expand Up @@ -1346,5 +1357,42 @@ private void createMeansExperiments(
}
}

private void setRMAPValueIfNecessary(final List<MeasurementVariable> mvarList, final String programUUID) {
final List<MeasurementVariable> catVar = mvarList.stream().filter(variable -> variable.getTermId() == TermId.REPLICATIONS_MAP
.getId()).collect(Collectors.toList());
if (catVar != null) {
for (final MeasurementVariable mVar : catVar) {
final StandardVariable strdVariable = this.ontologyDataManager.findStandardVariableByTraitScaleMethodNames(mVar.getProperty(), mVar.getScale(), mVar.getMethod(), programUUID);
if (strdVariable != null && strdVariable.getEnumerations() !=null) {
final List<Enumeration> possibleValues = strdVariable.getEnumerations().stream().filter(enumeration -> enumeration.getName().equals(mVar.getValue())).collect(
Collectors.toList());
if (possibleValues != null && possibleValues.size() > 0) {
mVar.setValue(String.valueOf(possibleValues.get(0).getId()));
}
}
}
}
}

private void setRMAPValueObservationIfNecessary(final List<MeasurementData> mvarList, final String programUUID) {
final List<MeasurementData> catVar = mvarList.stream().filter(variable -> variable.getMeasurementVariable() != null && variable.getMeasurementVariable().getTermId() == TermId.REPLICATIONS_MAP
.getId()).collect(Collectors.toList());
if (catVar != null) {
for (final MeasurementData mData : catVar) {
final MeasurementVariable mVar = mData.getMeasurementVariable();
final StandardVariable strdVariable;
strdVariable =
this.ontologyDataManager.findStandardVariableByTraitScaleMethodNames(mVar.getProperty(), mVar.getScale(), mVar.getMethod(), programUUID);
if (strdVariable != null && strdVariable.getEnumerations() !=null) {
final List<Enumeration> possibleValues = strdVariable.getEnumerations().stream().filter(enumeration -> enumeration.getName().equals(mData.getValue())).collect(
Collectors.toList());
if (possibleValues != null && possibleValues.size() > 0) {
mVar.setValue(String.valueOf(possibleValues.get(0).getId()));
mData.setValue(String.valueOf(possibleValues.get(0).getId()));
}
}
}
}
}

}
Loading