Source:
public void processExperimentalDesign(final Workbook workbook, final String programUUID, final String exptDesignValueFromObsSheet) throws WorkbookParserException { final Optional<MeasurementVariable> exptDesignVarInConditions = this.findMeasurementVariableByTermId(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), workbook.getConditions()); if(exptDesignVarInConditions.isPresent()) { final MeasurementVariable exptDesignVar = exptDesignVarInConditions.get(); if (exptDesignVar.getValue() != null && !exptDesignVar.getValue().isEmpty()) { Term exptDesignValue = this.termDataManager.getTermByName(exptDesignVar.getValue()); if (exptDesignValue != null) { exptDesignVar.setValue(String.valueOf(exptDesignValue.getId())); } else { throw new WorkbookParserException("Invalid value for Experimental Design"); } } else { exptDesignVar.setValue(this.getExperimentalDesignIdValue(exptDesignValueFromObsSheet)); } } final Optional<MeasurementVariable> exptDesignVarInFactors = this.findMeasurementVariableByTermId(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), workbook.getFactors()); if(exptDesignVarInFactors.isPresent()) { final MeasurementVariable exptDesignVar = exptDesignVarInFactors.get(); if(!exptDesignVarInConditions.isPresent()) { exptDesignVar.setValue(this.getExperimentalDesignIdValue(exptDesignValueFromObsSheet)); exptDesignVar.setVariableType(VariableType.ENVIRONMENT_DETAIL); workbook.getConditions().add(exptDesignVar); } workbook.getFactors().remove(exptDesignVarInFactors.get()); } if(!exptDesignVarInConditions.isPresent() && !exptDesignVarInFactors.isPresent()) { final MeasurementVariable exptDesignVar = this.createMeasurementVariable(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), String.valueOf(TermId.EXTERNALLY_GENERATED.getId()), Operation.ADD, PhenotypicType.TRIAL_ENVIRONMENT, programUUID); exptDesignVar.setVariableType(VariableType.ENVIRONMENT_DETAIL); workbook.getConditions().add(exptDesignVar); } }

Target:
public void processExperimentalDesign(final Workbook workbook, final String programUUID, final String exptDesignValueFromObsSheet) throws WorkbookParserException { final Optional<MeasurementVariable> exptDesignVarInConditions = this.findMeasurementVariableByTermId(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), workbook.getConditions()); if(exptDesignVarInConditions.isPresent()) { final MeasurementVariable exptDesignVar = exptDesignVarInConditions.get(); if (exptDesignVar.getValue() != null && !exptDesignVar.getValue().isEmpty()) { exptDesignVar.setValue(this.getExperimentalDesignIdValue(exptDesignVar.getValue())); } else { exptDesignVar.setValue(this.getExperimentalDesignIdValue(exptDesignValueFromObsSheet)); } } final Optional<MeasurementVariable> exptDesignVarInFactors = this.findMeasurementVariableByTermId(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), workbook.getFactors()); if(exptDesignVarInFactors.isPresent()) { final MeasurementVariable exptDesignVar = exptDesignVarInFactors.get(); if(!exptDesignVarInConditions.isPresent()) { exptDesignVar.setValue(this.getExperimentalDesignIdValue(exptDesignValueFromObsSheet)); exptDesignVar.setVariableType(VariableType.ENVIRONMENT_DETAIL); workbook.getConditions().add(exptDesignVar); } workbook.getFactors().remove(exptDesignVarInFactors.get()); } if(!exptDesignVarInConditions.isPresent() && !exptDesignVarInFactors.isPresent()) { final MeasurementVariable exptDesignVar = this.createMeasurementVariable(TermId.EXPERIMENT_DESIGN_FACTOR.getId(), String.valueOf(TermId.EXTERNALLY_GENERATED.getId()), Operation.ADD, PhenotypicType.TRIAL_ENVIRONMENT, programUUID); exptDesignVar.setVariableType(VariableType.ENVIRONMENT_DETAIL); workbook.getConditions().add(exptDesignVar); } }