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

Bms 3823 entry type is zero in exported germplasm list #624

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.generationcp.middleware.domain.etl.MeasurementVariable;
import org.generationcp.middleware.domain.etl.Workbook;
import org.generationcp.middleware.domain.gms.GermplasmListType;
import org.generationcp.middleware.domain.gms.SystemDefinedEntryType;
import org.generationcp.middleware.domain.oms.StudyType;
import org.generationcp.middleware.domain.oms.TermId;
import org.generationcp.middleware.exceptions.MiddlewareException;
Expand Down Expand Up @@ -661,19 +662,17 @@ List<Map<String, Object>> generateGermplasmListDataTable(final List<ImportedGerm
dataMap.put(ImportGermplasmListController.DESIG, germplasm.getDesig());
dataMap.put(ImportGermplasmListController.GID, germplasm.getGid());

if (!isNursery) {
if (isDefaultTestCheck || germplasm.getEntryTypeValue() == null
|| "0".equals(germplasm.getEntryTypeValue())) {
germplasm.setEntryTypeValue(defaultTestCheckId);
germplasm.setEntryTypeCategoricalID(Integer.valueOf(defaultTestCheckId));
dataMap.put(ImportGermplasmListController.CHECK, defaultTestCheckId);
} else {
dataMap.put(ImportGermplasmListController.CHECK, germplasm.getEntryTypeCategoricalID());
}

if (isDefaultTestCheck || germplasm.getEntryTypeValue() == null
|| "0".equals(germplasm.getEntryTypeValue())) {
germplasm.setEntryTypeValue(defaultTestCheckId);
germplasm.setEntryTypeCategoricalID(Integer.valueOf(defaultTestCheckId));
dataMap.put(ImportGermplasmListController.CHECK, defaultTestCheckId);
} else {
dataMap.put(ImportGermplasmListController.CHECK, germplasm.getEntryTypeCategoricalID());
}

if (isNursery) {
dataMap.put(ImportGermplasmListController.ENTRY_CODE, germplasm.getEntryCode());
dataMap.put(ImportGermplasmListController.CHECK, "");
}

final List<SettingDetail> factorsList = this.userSelection.getPlotsLevelList();
Expand Down Expand Up @@ -1581,6 +1580,7 @@ protected void addVariablesFromTemporaryWorkbookToWorkbook(final UserSelection u
protected void processChecks(final UserSelection userSelection, final ImportGermplasmListForm form) {

final String[] selectedCheck = form.getSelectedCheck();
final Map<String, ImportedGermplasm> checkGermplasmMap = new HashMap<>();

if (selectedCheck != null && selectedCheck.length != 0) {

Expand All @@ -1591,29 +1591,37 @@ protected void processChecks(final UserSelection userSelection, final ImportGerm
// since for trial, we are using only the original info
importedGermplasmMainInfoToUse = userSelection.getImportedGermplasmMainInfo();
}
if (importedGermplasmMainInfoToUse != null) {
if (importedGermplasmMainInfoToUse != null
&& importedGermplasmMainInfoToUse.getImportedGermplasmList() != null
&& importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms() != null
&& !importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().isEmpty()) {
for (int i = 0; i < selectedCheck.length; i++) {
if (NumberUtils.isNumber(selectedCheck[i])) {
importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().get(i)
.setEntryTypeValue(selectedCheck[i]);
importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().get(i)
.setEntryTypeCategoricalID(Integer.parseInt(selectedCheck[i]));
final ImportedGermplasm importedGermplasm = importedGermplasmMainInfoToUse
.getImportedGermplasmList().getImportedGermplasms().get(i);
importedGermplasm.setEntryTypeValue(SystemDefinedEntryType.CHECK_ENTRY.getEntryTypeValue());
importedGermplasm.setEntryTypeCategoricalID(Integer.parseInt(selectedCheck[i]));
importedGermplasm.setEntryTypeName(SystemDefinedEntryType.CHECK_ENTRY.getEntryTypeName());
checkGermplasmMap.put(importedGermplasm.getGid(), importedGermplasm);
}
}
}
} else {
// we set the check to null
if (userSelection.getImportedGermplasmMainInfo() != null
&& userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() != null
&& userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList()
.getImportedGermplasms() != null) {
}

if (userSelection.getImportedGermplasmMainInfo() != null
&& userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() != null && userSelection
.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms() != null) {

for (final ImportedGermplasm germplasm : userSelection.getImportedGermplasmMainInfo()
.getImportedGermplasmList().getImportedGermplasms()) {

// this is to keep track of the original list before merging
// with the checks
for (final ImportedGermplasm germplasm : userSelection.getImportedGermplasmMainInfo()
.getImportedGermplasmList().getImportedGermplasms()) {
germplasm.setEntryTypeCategoricalID(null);
germplasm.setEntryTypeValue("");
if (checkGermplasmMap.containsKey(germplasm.getGid())) {
germplasm.setEntryTypeCategoricalID(
checkGermplasmMap.get(germplasm.getGid()).getEntryTypeCategoricalID());
germplasm.setEntryTypeValue(checkGermplasmMap.get(germplasm.getGid()).getEntryTypeValue());
} else {
germplasm.setEntryTypeCategoricalID(SystemDefinedEntryType.TEST_ENTRY.getEntryTypeCategoricalId());
germplasm.setEntryTypeValue(SystemDefinedEntryType.TEST_ENTRY.getEntryTypeValue());
}
}
}
Expand All @@ -1625,17 +1633,16 @@ protected void processImportedGermplasmAndChecks(final UserSelection userSelecti
final ImportGermplasmListForm form) {

this.processChecks(userSelection, form);

if (userSelection.getImportedGermplasmMainInfo() != null) {

this.copyImportedGermplasmFromUserSelectionToForm(userSelection, form);

this.mergePrimaryAndCheckGermplasmList(userSelection, form);

final boolean hasCheck = form.getSelectedCheck() != null && form.getSelectedCheck().length != 0;
// This would validate and add CHECK factor if necessary
this.importGermplasmFileService.validataAndAddCheckFactor(form.getImportedGermplasm(),
userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(),
userSelection);
userSelection, hasCheck);

if (userSelection.getStartingEntryNo() == null) {
userSelection.setStartingEntryNo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,37 +24,45 @@

/**
* The Interface ImportGermplasmFileService.
*
*
* @author Daniel Jao
*/
public interface ImportGermplasmFileService {

/**
* Takes in an MultipartFile that was uploaded by the user, and returns the ImportedGermplasmMainInfo for the information needed.
* Takes in an MultipartFile that was uploaded by the user, and returns the
* ImportedGermplasmMainInfo for the information needed.
*
* @param multipartFile the multipart file
* @param multipartFile
* the multipart file
* @return the imported germplasm main info
* @throws IOException Signals that an I/O exception has occurred.
* @throws IOException
* Signals that an I/O exception has occurred.
*/
ImportedGermplasmMainInfo storeImportGermplasmWorkbook(MultipartFile multipartFile) throws IOException;

/**
* Process workbook.
*
* @param mainInfo the main info
* @param mainInfo
* the main info
* @return the imported germplasm main info
*/
ImportedGermplasmMainInfo processWorkbook(ImportedGermplasmMainInfo mainInfo);

/**
* Do process now.
*
* @param workbook the workbook
* @param mainInfo the main info
* @throws Exception the exception
* @param workbook
* the workbook
* @param mainInfo
* the main info
* @throws Exception
* the exception
*/
void doProcessNow(Workbook workbook, ImportedGermplasmMainInfo mainInfo) throws Exception;

void validataAndAddCheckFactor(List<ImportedGermplasm> formImportedGermplasmsm, List<ImportedGermplasm> importedGermplasms,
UserSelection userSelection) throws MiddlewareException;
void validataAndAddCheckFactor(List<ImportedGermplasm> formImportedGermplasmsm,
List<ImportedGermplasm> importedGermplasms, UserSelection userSelection, boolean hasCheck)
throws MiddlewareException;
}
Loading