From d3113b749263664c7742d66297fea7fc85ef3409 Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 24 Apr 2018 10:39:44 +0800 Subject: [PATCH 1/7] Get possible values using the method in fieldbookservice class BMS-3823 --- .../impl/ExportGermplasmListServiceImpl.java | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java index 727fff07b7..c0469c3fae 100644 --- a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java +++ b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java @@ -1,10 +1,16 @@ package com.efficio.fieldbook.web.common.service.impl; -import com.efficio.fieldbook.web.common.bean.SettingDetail; -import com.efficio.fieldbook.web.common.bean.UserSelection; -import com.efficio.fieldbook.web.common.controller.ExportGermplasmListController; -import com.efficio.fieldbook.web.common.service.ExportGermplasmListService; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import javax.annotation.Resource; + import org.apache.commons.lang3.math.NumberUtils; import org.generationcp.commons.exceptions.GermplasmListExporterException; import org.generationcp.commons.parsing.pojo.ImportedGermplasm; @@ -33,14 +39,10 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Configurable; -import javax.annotation.Resource; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Objects; +import com.efficio.fieldbook.web.common.bean.SettingDetail; +import com.efficio.fieldbook.web.common.bean.UserSelection; +import com.efficio.fieldbook.web.common.controller.ExportGermplasmListController; +import com.efficio.fieldbook.web.common.service.ExportGermplasmListService; @Configurable public class ExportGermplasmListServiceImpl implements ExportGermplasmListService { @@ -71,6 +73,9 @@ public class ExportGermplasmListServiceImpl implements ExportGermplasmListServic @Resource private InventoryDataManager inventoryDataManager; + @Resource + private com.efficio.fieldbook.service.api.FieldbookService fieldbookService; + public ExportGermplasmListServiceImpl() { } @@ -120,7 +125,7 @@ GermplasmListExportInputValues setUpInput(final String fileNamePath, final int l this.setExportListTypeFromOriginalGermplasm(germplasmList); final List possibleValues = - this.getPossibleValues(this.userSelection.getPlotsLevelList(), TermId.ENTRY_TYPE.getId()); + this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId()); this.processEntryTypeCode(germplasmlistData, possibleValues); input.setGermplasmList(germplasmList); From 8c546c208a4733e59e6374a3c6a0b2f0fff38874 Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 24 Apr 2018 10:41:05 +0800 Subject: [PATCH 2/7] Properly update the Check value and Check ID of Imported Germplasm based on the Selected Checks. If the germplasm is not in the Selected Checks list, the default type should be TEST ENTRY. BMS-3823 --- .../ImportGermplasmListController.java | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java index 175fdea51d..84ec306e3f 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java @@ -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; @@ -661,19 +662,18 @@ List> generateGermplasmListDataTable(final List factorsList = this.userSelection.getPlotsLevelList(); @@ -1581,7 +1581,8 @@ protected void addVariablesFromTemporaryWorkbookToWorkbook(final UserSelection u protected void processChecks(final UserSelection userSelection, final ImportGermplasmListForm form) { final String[] selectedCheck = form.getSelectedCheck(); - + final Map checkGermplasmMap = new HashMap<>(); + if (selectedCheck != null && selectedCheck.length != 0) { ImportedGermplasmMainInfo importedGermplasmMainInfoToUse = userSelection @@ -1591,32 +1592,38 @@ 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) { - - // 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 (userSelection.getImportedGermplasmMainInfo() != null + && userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() != null + && userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms() != null) { + + for (final ImportedGermplasm germplasm : userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() + .getImportedGermplasms()) { + + 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()); + } + } + } // end: section for taking note of the check germplasm } From fbf6d960fd2bac7533f6836bf5b9d2ab5c9251cf Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Thu, 26 Apr 2018 00:07:49 +0800 Subject: [PATCH 3/7] Added logic to display the ENTRY_TYPE name istead of the id BMS-3823 --- .../js/fbk-data-table/fieldbook-datatable.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/webapp/WEB-INF/static/js/fbk-data-table/fieldbook-datatable.js b/src/main/webapp/WEB-INF/static/js/fbk-data-table/fieldbook-datatable.js index 2aac275410..a59ab2b2d5 100644 --- a/src/main/webapp/WEB-INF/static/js/fbk-data-table/fieldbook-datatable.js +++ b/src/main/webapp/WEB-INF/static/js/fbk-data-table/fieldbook-datatable.js @@ -348,6 +348,24 @@ BMS.Fieldbook.GermplasmListDataTable = (function($) { full.gid + '","' + full.desig + '")">' + data + ''; } }); + } else if ($(this).data('col-name') == '8255-key') { + // For check + columnsDef.push({ + targets: columns.length - 1, + data: $(this).data('col-name'), + render: function(data, type, full, meta) { + var count = 0, + actualVal = '         '; + for (count = 0 ; count < full.checkOptions.length ; count++) { + if (full.checkOptions[count].id == full['8255-key']) { + actualVal = full.checkOptions[count].description; + break; + } + } + + return actualVal; + } + }); } }); From b4c346f7bf3f0842e83a2da2729ea515365093a4 Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 1 May 2018 00:57:44 +0800 Subject: [PATCH 4/7] Added logic to properly populate the value of entry type in the expoert csv germplasm list BMS-3823 --- .../impl/ExportGermplasmListServiceImpl.java | 39 +++++++++---------- .../impl/ExportGermplasmListServiceTest.java | 25 ++++-------- 2 files changed, 26 insertions(+), 38 deletions(-) diff --git a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java index c0469c3fae..7e3e96b5e3 100644 --- a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java +++ b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java @@ -298,14 +298,20 @@ protected List> getExportColumnValuesFromTable(f final List factorsList = this.userSelection.getPlotsLevelList(); final List listData = this.getImportedGermplasm(); - + final List possibleValues = + this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId()); for (final ImportedGermplasm data : listData) { final Map row = new HashMap<>(); for (final SettingDetail settingDetail : factorsList) { final Integer termId = settingDetail.getVariable().getCvTermId(); - row.put(termId, new ExportColumnValue(termId, - this.getGermplasmInfo(settingDetail.getVariable().getCvTermId().toString(), data, settingDetail))); + if(termId == TermId.ENTRY_TYPE.getId()) { + row.put(termId, new ExportColumnValue(termId, + this.getEntryTypeValue(data, possibleValues))); + } else { + row.put(termId, new ExportColumnValue(termId, + this.getGermplasmInfo(settingDetail.getVariable().getCvTermId().toString(), data, settingDetail))); + } } exportColumnValues.add(row); @@ -314,6 +320,15 @@ protected List> getExportColumnValuesFromTable(f return exportColumnValues; } + protected String getEntryTypeValue(ImportedGermplasm germplasm, List possibleValues) { + for (final ValueReference possibleValue : possibleValues) { + if (possibleValue.getId().equals(Integer.valueOf(germplasm.getEntryTypeValue()))) { + return possibleValue.getName(); + } + } + return germplasm.getEntryTypeValue(); + } + protected List getImportedGermplasm() { return this.getUserSelection().getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(); } @@ -334,9 +349,6 @@ protected String getGermplasmInfo(final String termId, final ImportedGermplasm g val = germplasm.getCross().toString(); } else if (term.intValue() == TermId.DESIG.getId()) { val = germplasm.getDesig().toString(); - } else if (term.intValue() == TermId.CHECK.getId()) { - // get the code of ENTRY_TYPE - CATEGORICAL FACTOR - val = this.getCategoricalCodeValue(germplasm, settingDetail); } else if (term == TermId.GROUPGID.getId()) { val = germplasm.getMgid().toString(); } else if (term == TermId.STOCKID.getId()) { @@ -346,21 +358,6 @@ protected String getGermplasmInfo(final String termId, final ImportedGermplasm g return val; } - protected String getCategoricalCodeValue(final ImportedGermplasm germplasm, final SettingDetail settingDetail) { - String val = ""; - if (settingDetail.getPossibleValues() != null) { - for (final ValueReference possibleValue : settingDetail.getPossibleValues()) { - if (possibleValue.getId().equals(Integer.valueOf(germplasm.getEntryTypeValue().toString()))) { - val = possibleValue.getName(); - } - } - } else { - val = germplasm.getEntryTypeValue().toString(); - } - - return val; - } - protected void setGermplasmListManager(final GermplasmListManager germplasmListManager) { this.germplasmListManager = germplasmListManager; } diff --git a/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java b/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java index 93d4946762..34a9302d7c 100644 --- a/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java +++ b/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java @@ -20,6 +20,7 @@ import org.generationcp.commons.pojo.GermplasmListExportInputValues; import org.generationcp.commons.service.GermplasmExportService; import org.generationcp.commons.spring.util.ContextUtil; +import org.generationcp.middleware.data.initializer.ValueReferenceTestDataInitializer; import org.generationcp.middleware.domain.dms.StandardVariable; import org.generationcp.middleware.domain.dms.ValueReference; import org.generationcp.middleware.domain.etl.StudyDetails; @@ -128,6 +129,9 @@ public class ExportGermplasmListServiceTest { @Mock InventoryDataManager inventoryDataManager; + + @Mock + private com.efficio.fieldbook.service.api.FieldbookService fieldbookService; @InjectMocks private ExportGermplasmListServiceImpl exportGermplasmListServiceImpl; @@ -176,6 +180,7 @@ public void setUp() throws MiddlewareException { Mockito.when(ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), TermId.STOCKID.getId(), false, false)).thenReturn(this.createVariable(TermId.STOCKID.getId())); Mockito.when(ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), TermId.SEED_AMOUNT_G.getId(), false, false)).thenReturn(this.createVariable(TermId.SEED_AMOUNT_G.getId())); + Mockito.when(this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId())).thenReturn(ValueReferenceTestDataInitializer.createPossibleValues()); } @@ -327,9 +332,7 @@ public void testGetExportColumnValuesFromTableNursery() { } @Test - public void testGetCategoricalCodeValue() { - final SettingDetail settingDetail = this.generateSettingDetail(TermId.CHECK.getId()); - + public void testGetEntryTypeValue() { final List possibleValues = new ArrayList<>(); final ValueReference valReference = new ValueReference(); valReference.setId(Integer.valueOf(ExportGermplasmListServiceTest.CHECK_VALUE)); @@ -337,26 +340,13 @@ public void testGetCategoricalCodeValue() { valReference.setName(ExportGermplasmListServiceTest.CATEG_CODE_VALUE); possibleValues.add(valReference); - settingDetail.setPossibleValues(possibleValues); - final String categValue = - this.exportGermplasmListServiceImpl.getCategoricalCodeValue(this.generateImportedGermplasm(), settingDetail); + this.exportGermplasmListServiceImpl.getEntryTypeValue(this.generateImportedGermplasm(), possibleValues); Assert.assertEquals(ExportGermplasmListServiceTest.CATEG_CODE_VALUE, categValue); } - @Test - public void testGetCategoricalCodeValuePossibleValuesIsNull() { - final SettingDetail settingDetail = this.generateSettingDetail(TermId.CHECK.getId()); - settingDetail.setPossibleValues(null); - - final String categValue = - this.exportGermplasmListServiceImpl.getCategoricalCodeValue(this.generateImportedGermplasm(), settingDetail); - - Assert.assertEquals(ExportGermplasmListServiceTest.CHECK_VALUE, categValue); - } - @Test public void testSetUpForInputWhereGemplasmListTypeIsNursery() { final List listData = Arrays.asList(this.listDataProject); @@ -592,6 +582,7 @@ private List setUpImportedGermplasm() { importedGermplasm.setSource(ExportGermplasmListServiceTest.SOURCE_VALUE); importedGermplasm.setCross(ExportGermplasmListServiceTest.CROSS_VALUE); importedGermplasm.setDesig(ExportGermplasmListServiceTest.DESIG_VALUE); + importedGermplasm.setEntryTypeValue("1"); importedGermplasms.add(importedGermplasm); return importedGermplasms; From 174b70d2af558b3c003f046d736d6d900e69ed0e Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 1 May 2018 02:08:45 +0800 Subject: [PATCH 5/7] Changed the logic in checkimg if the check variable should be added or not BMS-3823 --- .../controller/ImportGermplasmListController.java | 5 ++--- .../nursery/service/ImportGermplasmFileService.java | 2 +- .../service/impl/ImportGermplasmFileServiceImpl.java | 4 +--- .../ImportGermplasmListControllerTest.java | 12 ++++++------ .../impl/ImportGermplasmFileServiceImplTest.java | 10 +++++----- 5 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java index 84ec306e3f..bee3a1466e 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java @@ -1632,17 +1632,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( diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java b/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java index 3359467683..46cb9e70d7 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java @@ -56,5 +56,5 @@ public interface ImportGermplasmFileService { void doProcessNow(Workbook workbook, ImportedGermplasmMainInfo mainInfo) throws Exception; void validataAndAddCheckFactor(List formImportedGermplasmsm, List importedGermplasms, - UserSelection userSelection) throws MiddlewareException; + UserSelection userSelection, boolean hasCheck) throws MiddlewareException; } diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java b/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java index 94fbd76c43..bc51bf43b1 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java @@ -541,16 +541,14 @@ private void showInvalidFileError(String message) { */ @Override public void validataAndAddCheckFactor(List formImportedGermplasmsm, List importedGermplasms, - UserSelection userSelection) throws MiddlewareException { + UserSelection userSelection, boolean hasCheck) throws MiddlewareException { long start = System.currentTimeMillis(); - boolean hasCheck = false; List sessionImportedGermplasmList = importedGermplasms; for (int i = 0; i < formImportedGermplasmsm.size(); i++) { ImportedGermplasm germplasm = formImportedGermplasmsm.get(i); String checkVal = ""; if (germplasm.getEntryTypeValue() != null && !"".equalsIgnoreCase(germplasm.getEntryTypeValue())) { checkVal = germplasm.getEntryTypeValue(); - hasCheck = true; } sessionImportedGermplasmList.get(i).setEntryTypeValue(checkVal); sessionImportedGermplasmList.get(i).setEntryTypeCategoricalID(germplasm.getEntryTypeCategoricalID()); diff --git a/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java b/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java index 417b1d7d44..d80da07aac 100644 --- a/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java +++ b/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java @@ -220,7 +220,7 @@ public void testDisplayGermplasmDetailsOfSelectedListForNursery() throws Middlew Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListControllerTest.ENTRY_NO_FACTOR)); Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.POSITION)); Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.ENTRY_CODE)); - Assert.assertEquals("", map.get(ImportGermplasmListController.CHECK)); + Assert.assertEquals("1", map.get(ImportGermplasmListController.CHECK)); Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.ENTRY)); x++; } @@ -311,7 +311,7 @@ public void testGenerateGermplasmListDataTableForNursery() { map.get(ImportGermplasmListController.POSITION)); Assert.assertEquals("The entry code's value should be " + x, String.valueOf(x), map.get(ImportGermplasmListController.ENTRY_CODE)); - Assert.assertEquals("The check's value should be empty string", "", + Assert.assertEquals("The check's value should be 1", "1", map.get(ImportGermplasmListController.CHECK)); Assert.assertEquals("The entry's value should be " + x, String.valueOf(x), map.get(ImportGermplasmListController.ENTRY)); @@ -354,7 +354,7 @@ public void testDisplayGermplasmDetailsOfCurrentStudyForNursery() throws Middlew for (final Map map : listDataTable) { Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.POSITION)); Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.ENTRY_CODE)); - Assert.assertEquals("", map.get(ImportGermplasmListController.CHECK)); + Assert.assertEquals(1, map.get(ImportGermplasmListController.CHECK)); Assert.assertEquals(String.valueOf(x), map.get(ImportGermplasmListController.ENTRY)); Assert.assertEquals(this.checkList, map.get(ImportGermplasmListController.CHECK_OPTIONS)); Assert.assertEquals("DESIGNATION" + x, map.get(ImportGermplasmListControllerTest.DESIGNATION_FACTOR)); @@ -598,10 +598,10 @@ public void testProcessChecksWithSelectedChecks() { final List importedGermplasmList = this.userSelection.getImportedCheckGermplasmMainInfo() .getImportedGermplasmList().getImportedGermplasms(); - Assert.assertEquals("10180", importedGermplasmList.get(0).getEntryTypeValue()); + Assert.assertEquals("C", importedGermplasmList.get(0).getEntryTypeValue()); Assert.assertEquals(10180, importedGermplasmList.get(0).getEntryTypeCategoricalID().intValue()); - Assert.assertEquals("10180", importedGermplasmList.get(1).getEntryTypeValue()); + Assert.assertEquals("C", importedGermplasmList.get(1).getEntryTypeValue()); Assert.assertEquals(10180, importedGermplasmList.get(1).getEntryTypeCategoricalID().intValue()); } @@ -630,7 +630,7 @@ public void testProcessImportedGermplasmAndChecks() { Mockito.verify(this.importGermplasmFileService) .validataAndAddCheckFactor(form.getImportedGermplasm(), this.userSelection .getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(), - this.userSelection); + this.userSelection, false); Mockito.verify(this.measurementsGeneratorService).generateRealMeasurementRows(this.userSelection); Mockito.verify(this.fieldbookService).manageCheckVariables(this.userSelection, form); diff --git a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java index 2901404782..1c2b10e78e 100644 --- a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java +++ b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java @@ -308,7 +308,7 @@ public void testValidAndAddCheckFactor() throws MiddlewareException { userSelection.getWorkbook().setVariates(new ArrayList()); userSelection.setImportedGermplasmMainInfo(mainInfo); this.realImportGermplasmFileService.validataAndAddCheckFactor(form.getImportedGermplasm(), userSelection - .getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(), userSelection); + .getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(), userSelection, true); // no check factor yet Assert.assertEquals(0, userSelection.getWorkbook().getMeasurementDatasetVariables().size()); // we now need to add check @@ -331,7 +331,7 @@ public void testValidataAndAddCheckFactorNoCheckAndWithCheckFactor() throws Midd List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); List sessionImportedGermplasm = this.generateImportedGermplasm(); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); for (ImportedGermplasm item : sessionImportedGermplasm) { int index = sessionImportedGermplasm.indexOf(item); @@ -354,7 +354,7 @@ public void testValidataAndAddCheckFactorNoCheckAndWithoutCheckFactor() throws M List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); List sessionImportedGermplasm = this.generateImportedGermplasm(); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, false); for (ImportedGermplasm item : sessionImportedGermplasm) { int index = sessionImportedGermplasm.indexOf(item); @@ -379,7 +379,7 @@ public void testValidataAndAddCheckFactorWithNoExistingCheckFactor() throws Midd Mockito.doReturn(this.generateCheckStandardVariable()).when(this.fieldbookMiddlewareService) .getStandardVariable(Matchers.anyInt(), Matchers.anyString()); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); for (ImportedGermplasm item : sessionImportedGermplasm) { int index = sessionImportedGermplasm.indexOf(item); @@ -409,7 +409,7 @@ public void testValidataAndAddCheckFactorWithExistingCheckFactor() throws Middle .getStandardVariableIdByPropertyScaleMethodRole(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), Matchers.any(PhenotypicType.class)); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); for (ImportedGermplasm item : sessionImportedGermplasm) { int index = sessionImportedGermplasm.indexOf(item); From f03eedc8b49feba9f94b2bb47189bfffb8e65883 Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 1 May 2018 02:19:21 +0800 Subject: [PATCH 6/7] Fixed test error BMS-3823 --- .../service/impl/ImportGermplasmFileServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java index 1c2b10e78e..c2717cf241 100644 --- a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java +++ b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java @@ -331,7 +331,7 @@ public void testValidataAndAddCheckFactorNoCheckAndWithCheckFactor() throws Midd List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); List sessionImportedGermplasm = this.generateImportedGermplasm(); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, false); for (ImportedGermplasm item : sessionImportedGermplasm) { int index = sessionImportedGermplasm.indexOf(item); From 1b70857a1f78fbcc8d23eab9ec5bd824e0f53ba3 Mon Sep 17 00:00:00 2001 From: Marc Ulysis De Ramos Date: Tue, 1 May 2018 02:35:55 +0800 Subject: [PATCH 7/7] Applied leafnode clean up BMS-3823 --- .../impl/ExportGermplasmListServiceImpl.java | 117 +++---- .../ImportGermplasmListController.java | 47 +-- .../service/ImportGermplasmFileService.java | 28 +- .../impl/ImportGermplasmFileServiceImpl.java | 292 ++++++++++-------- .../impl/ExportGermplasmListServiceTest.java | 175 ++++++----- .../ImportGermplasmListControllerTest.java | 20 +- .../ImportGermplasmFileServiceImplTest.java | 235 ++++++++------ 7 files changed, 525 insertions(+), 389 deletions(-) diff --git a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java index 7e3e96b5e3..0633a9d3a0 100644 --- a/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java +++ b/src/main/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceImpl.java @@ -81,11 +81,12 @@ public ExportGermplasmListServiceImpl() { } @Override - public void exportGermplasmListXLS(final String fileNamePath, final int listId, final Map visibleColumns, - final Boolean isNursery) throws GermplasmListExporterException { + public void exportGermplasmListXLS(final String fileNamePath, final int listId, + final Map visibleColumns, final Boolean isNursery) throws GermplasmListExporterException { try { - final GermplasmListExportInputValues input = this.setUpInput(fileNamePath, listId, visibleColumns, isNursery); + final GermplasmListExportInputValues input = this.setUpInput(fileNamePath, listId, visibleColumns, + isNursery); this.germplasmExportService.generateGermplasmListExcelFile(input); @@ -95,8 +96,8 @@ public void exportGermplasmListXLS(final String fileNamePath, final int listId, } - GermplasmListExportInputValues setUpInput(final String fileNamePath, final int listId, final Map visibleColumns, - final Boolean isNursery) { + GermplasmListExportInputValues setUpInput(final String fileNamePath, final int listId, + final Map visibleColumns, final Boolean isNursery) { final GermplasmListExportInputValues input = new GermplasmListExportInputValues(); input.setFileName(fileNamePath); GermplasmList germplasmList = this.fieldbookMiddlewareService.getGermplasmListById(listId); @@ -108,24 +109,27 @@ GermplasmListExportInputValues setUpInput(final String fileNamePath, final int l } // retrieval of germplasm list data from snapshot list - final List germplasmLists = this.fieldbookMiddlewareService.getGermplasmListsByProjectId(studyId, germplasmListType); + final List germplasmLists = this.fieldbookMiddlewareService.getGermplasmListsByProjectId(studyId, + germplasmListType); List germplasmlistData = new ArrayList<>(); if (germplasmLists != null && !germplasmLists.isEmpty()) { germplasmList = germplasmLists.get(0); if (germplasmList != null && germplasmList.getListRef() != null) { - // set the ImportedGermplasmListMainInfo to the List reference of the list, so that it still points to the original list + // set the ImportedGermplasmListMainInfo to the List reference + // of the list, so that it still points to the original list this.userSelection.getImportedGermplasmMainInfo().setListId(germplasmList.getListRef()); } - List listDataProjects = this.germplasmListManager.retrieveSnapshotListData(germplasmList.getId()); - FieldbookListUtil.populateStockIdInListDataProject(listDataProjects, inventoryDataManager); + final List listDataProjects = this.germplasmListManager + .retrieveSnapshotListData(germplasmList.getId()); + FieldbookListUtil.populateStockIdInListDataProject(listDataProjects, this.inventoryDataManager); germplasmlistData = listDataProjects; } this.setExportListTypeFromOriginalGermplasm(germplasmList); - final List possibleValues = - this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId()); + final List possibleValues = this.fieldbookService + .getAllPossibleValues(TermId.ENTRY_TYPE.getId()); this.processEntryTypeCode(germplasmlistData, possibleValues); input.setGermplasmList(germplasmList); @@ -142,7 +146,9 @@ GermplasmListExportInputValues setUpInput(final String fileNamePath, final int l // Get the variables that will be put into the Inventory Section input.setInventoryVariableMap(this.extractInventoryVariableMapFromVisibleColumns(visibleColumns)); - // We do not need the inventory variables in visibleColumns anymore so we have to remove them, since variables in Inventory Section will come from + // We do not need the inventory variables in visibleColumns anymore so + // we have to remove them, since variables in Inventory Section will + // come from // GermplasmListExportInputValues.InventoryVariableMap. this.removeInventoryVariableMapFromVisibleColumns(visibleColumns); @@ -156,19 +162,19 @@ GermplasmListExportInputValues setUpInput(final String fileNamePath, final int l * @param visibleColumns * @return */ - Map extractInventoryVariableMapFromVisibleColumns(final Map visibleColumns) { + Map extractInventoryVariableMapFromVisibleColumns(final Map visibleColumns) { - Map inventontoryVariableMap = new HashMap<>(); + final Map inventontoryVariableMap = new HashMap<>(); - Iterator> iterator = visibleColumns.entrySet().iterator(); + final Iterator> iterator = visibleColumns.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - String termId = entry.getKey(); - Boolean isVisible = entry.getValue(); - if (isVisible && isInventoryVariable(termId)) { - addVariableToMap(inventontoryVariableMap, Integer.valueOf(termId)); + final Map.Entry entry = iterator.next(); + final String termId = entry.getKey(); + final Boolean isVisible = entry.getValue(); + if (isVisible && this.isInventoryVariable(termId)) { + this.addVariableToMap(inventontoryVariableMap, Integer.valueOf(termId)); } } return inventontoryVariableMap; @@ -183,13 +189,13 @@ Map extractInventoryVariableMapFromVisibleColumns(final Map visibleColumns) { - Iterator> iterator = visibleColumns.entrySet().iterator(); + final Iterator> iterator = visibleColumns.entrySet().iterator(); while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - String termId = entry.getKey(); - if (isInventoryVariable(termId)) { + final Map.Entry entry = iterator.next(); + final String termId = entry.getKey(); + if (this.isInventoryVariable(termId)) { iterator.remove(); } } @@ -197,20 +203,22 @@ void removeInventoryVariableMapFromVisibleColumns(final Map vis } boolean isInventoryVariable(final String termId) { - return termId.equals(String.valueOf(TermId.STOCKID.getId())) || termId.equals(String.valueOf(TermId.SEED_AMOUNT_G.getId())); + return termId.equals(String.valueOf(TermId.STOCKID.getId())) + || termId.equals(String.valueOf(TermId.SEED_AMOUNT_G.getId())); } void addVariableToMap(final Map variableMap, final int termId) { - final Variable variable = - this.ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), termId, false, false); + final Variable variable = this.ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), + termId, false, false); if (variable != null) { variableMap.put(variable.getId(), variable); } } - private Map generateColumnStandardVariableMap(final Map visibleColumnMap, final Boolean isNursery) { + private Map generateColumnStandardVariableMap(final Map visibleColumnMap, + final Boolean isNursery) { final Map standardVariableMap = new HashMap<>(); @@ -219,14 +227,13 @@ private Map generateColumnStandardVariableMap(final Map getPossibleValues(final List setti } - protected void processEntryTypeCode(final List listData, final List possibleValues) { + protected void processEntryTypeCode(final List listData, + final List possibleValues) { for (final GermplasmExportSource data : listData) { if (possibleValues != null && !possibleValues.isEmpty()) { @@ -258,11 +266,13 @@ protected void processEntryTypeCode(final List } @Override - public void exportGermplasmListCSV(final String fileNamePath, final Map visibleColumns, final Boolean isNursery) - throws GermplasmListExporterException { + public void exportGermplasmListCSV(final String fileNamePath, final Map visibleColumns, + final Boolean isNursery) throws GermplasmListExporterException { - final List> exportColumnValues = this.getExportColumnValuesFromTable(visibleColumns, isNursery); - final List exportColumnHeaders = this.getExportColumnHeadersFromTable(visibleColumns, isNursery); + final List> exportColumnValues = this + .getExportColumnValuesFromTable(visibleColumns, isNursery); + final List exportColumnHeaders = this.getExportColumnHeadersFromTable(visibleColumns, + isNursery); try { @@ -274,7 +284,8 @@ public void exportGermplasmListCSV(final String fileNamePath, final Map getExportColumnHeadersFromTable(final Map visibleColumns, final Boolean isNursery) { + protected List getExportColumnHeadersFromTable(final Map visibleColumns, + final Boolean isNursery) { final List exportColumnHeaders = new ArrayList<>(); @@ -283,34 +294,33 @@ protected List getExportColumnHeadersFromTable(final Map> getExportColumnValuesFromTable(final Map visibleColumns, - final Boolean isNursery) { + protected List> getExportColumnValuesFromTable( + final Map visibleColumns, final Boolean isNursery) { final List> exportColumnValues = new ArrayList<>(); final List factorsList = this.userSelection.getPlotsLevelList(); final List listData = this.getImportedGermplasm(); - final List possibleValues = - this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId()); + final List possibleValues = this.fieldbookService + .getAllPossibleValues(TermId.ENTRY_TYPE.getId()); for (final ImportedGermplasm data : listData) { final Map row = new HashMap<>(); for (final SettingDetail settingDetail : factorsList) { final Integer termId = settingDetail.getVariable().getCvTermId(); - if(termId == TermId.ENTRY_TYPE.getId()) { - row.put(termId, new ExportColumnValue(termId, - this.getEntryTypeValue(data, possibleValues))); + if (termId == TermId.ENTRY_TYPE.getId()) { + row.put(termId, new ExportColumnValue(termId, this.getEntryTypeValue(data, possibleValues))); } else { - row.put(termId, new ExportColumnValue(termId, - this.getGermplasmInfo(settingDetail.getVariable().getCvTermId().toString(), data, settingDetail))); + row.put(termId, new ExportColumnValue(termId, this.getGermplasmInfo( + settingDetail.getVariable().getCvTermId().toString(), data, settingDetail))); } } @@ -320,7 +330,7 @@ protected List> getExportColumnValuesFromTable(f return exportColumnValues; } - protected String getEntryTypeValue(ImportedGermplasm germplasm, List possibleValues) { + protected String getEntryTypeValue(final ImportedGermplasm germplasm, final List possibleValues) { for (final ValueReference possibleValue : possibleValues) { if (possibleValue.getId().equals(Integer.valueOf(germplasm.getEntryTypeValue()))) { return possibleValue.getName(); @@ -330,10 +340,12 @@ protected String getEntryTypeValue(ImportedGermplasm germplasm, List getImportedGermplasm() { - return this.getUserSelection().getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(); + return this.getUserSelection().getImportedGermplasmMainInfo().getImportedGermplasmList() + .getImportedGermplasms(); } - protected String getGermplasmInfo(final String termId, final ImportedGermplasm germplasm, final SettingDetail settingDetail) { + protected String getGermplasmInfo(final String termId, final ImportedGermplasm germplasm, + final SettingDetail settingDetail) { String val = ""; if (termId != null && NumberUtils.isNumber(termId)) { final Integer term = Integer.valueOf(termId); @@ -391,7 +403,8 @@ protected void setExportListTypeFromOriginalGermplasm(final GermplasmList list) final GermplasmList origList = this.fieldbookMiddlewareService.getGermplasmListById(list.getListRef()); if (origList != null) { - if (origList.getStatus() != null && origList.getStatus().intValue() != GermplasmListDAO.STATUS_DELETED.intValue()) { + if (origList.getStatus() != null + && origList.getStatus().intValue() != GermplasmListDAO.STATUS_DELETED.intValue()) { list.setType(origList.getType()); } else { list.setType(ExportGermplasmListController.GERPLASM_TYPE_LST); diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java index bee3a1466e..878f65428c 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListController.java @@ -662,7 +662,6 @@ List> generateGermplasmListDataTable(final List checkGermplasmMap = new HashMap<>(); - + if (selectedCheck != null && selectedCheck.length != 0) { ImportedGermplasmMainInfo importedGermplasmMainInfoToUse = userSelection @@ -1593,12 +1592,13 @@ protected void processChecks(final UserSelection userSelection, final ImportGerm importedGermplasmMainInfoToUse = userSelection.getImportedGermplasmMainInfo(); } if (importedGermplasmMainInfoToUse != null - && importedGermplasmMainInfoToUse.getImportedGermplasmList() != null - && importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms() != null - && !importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().isEmpty()) { + && importedGermplasmMainInfoToUse.getImportedGermplasmList() != null + && importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms() != null + && !importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().isEmpty()) { for (int i = 0; i < selectedCheck.length; i++) { if (NumberUtils.isNumber(selectedCheck[i])) { - final ImportedGermplasm importedGermplasm = importedGermplasmMainInfoToUse.getImportedGermplasmList().getImportedGermplasms().get(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()); @@ -1607,23 +1607,24 @@ protected void processChecks(final UserSelection userSelection, final ImportGerm } } } - + if (userSelection.getImportedGermplasmMainInfo() != null - && userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() != null - && userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms() != null) { - - for (final ImportedGermplasm germplasm : userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() - .getImportedGermplasms()) { - - 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()); - } - } - } + && userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList() != null && userSelection + .getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms() != null) { + + for (final ImportedGermplasm germplasm : userSelection.getImportedGermplasmMainInfo() + .getImportedGermplasmList().getImportedGermplasms()) { + + 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()); + } + } + } // end: section for taking note of the check germplasm } @@ -1637,7 +1638,7 @@ protected void processImportedGermplasmAndChecks(final UserSelection userSelecti this.copyImportedGermplasmFromUserSelectionToForm(userSelection, form); this.mergePrimaryAndCheckGermplasmList(userSelection, form); - final boolean hasCheck = form.getSelectedCheck() != null && form.getSelectedCheck().length !=0; + 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(), diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java b/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java index 46cb9e70d7..9656d7cef8 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/service/ImportGermplasmFileService.java @@ -24,24 +24,28 @@ /** * 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); @@ -49,12 +53,16 @@ public interface ImportGermplasmFileService { /** * 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 formImportedGermplasmsm, List importedGermplasms, - UserSelection userSelection, boolean hasCheck) throws MiddlewareException; + void validataAndAddCheckFactor(List formImportedGermplasmsm, + List importedGermplasms, UserSelection userSelection, boolean hasCheck) + throws MiddlewareException; } diff --git a/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java b/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java index bc51bf43b1..97b021e61a 100644 --- a/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java +++ b/src/main/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImpl.java @@ -1,12 +1,12 @@ /******************************************************************************* * Copyright (c) 2013, All Rights Reserved. - * + * * Generation Challenge Programme (GCP) - * - * + * + * * This software is licensed for use under the terms of the GNU General Public License (http://bit.ly/8Ztv8M) and the provisions of Part F * of the Generation Challenge Programme Amended Consortium Agreement (http://bit.ly/KQX1nL) - * + * *******************************************************************************/ package com.efficio.fieldbook.web.nursery.service.impl; @@ -52,8 +52,9 @@ /** * The Class ImportGermplasmFileServiceImpl. - * - * @author Daniel Jao This should parse the import file from the user. Can handle basic and advance file format + * + * @author Daniel Jao This should parse the import file from the user. Can + * handle basic and advance file format */ @SuppressWarnings("unused") public class ImportGermplasmFileServiceImpl implements ImportGermplasmFileService { @@ -118,16 +119,18 @@ public class ImportGermplasmFileServiceImpl implements ImportGermplasmFileServic /* * (non-Javadoc) - * + * * @see - * com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService#storeImportGermplasmWorkbook(org.springframework.web.multipart + * com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService# + * storeImportGermplasmWorkbook(org.springframework.web.multipart * .MultipartFile) */ @Override - public ImportedGermplasmMainInfo storeImportGermplasmWorkbook(MultipartFile multipartFile) throws IOException { - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + public ImportedGermplasmMainInfo storeImportGermplasmWorkbook(final MultipartFile multipartFile) + throws IOException { + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); - String filename = this.getFileService().saveTemporaryFile(multipartFile.getInputStream()); + final String filename = this.getFileService().saveTemporaryFile(multipartFile.getInputStream()); mainInfo.setServerFilename(filename); mainInfo.setOriginalFilename(multipartFile.getOriginalFilename()); @@ -137,7 +140,7 @@ public ImportedGermplasmMainInfo storeImportGermplasmWorkbook(MultipartFile mult /** * Gets the file service. - * + * * @return the file service */ public FileService getFileService() { @@ -146,18 +149,20 @@ public FileService getFileService() { /* * (non-Javadoc) - * - * @see com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService#processWorkbook(org.generationcp.commons.parsing.pojo. + * + * @see + * com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService# + * processWorkbook(org.generationcp.commons.parsing.pojo. * ImportedGermplasmMainInfo) */ @Override - public ImportedGermplasmMainInfo processWorkbook(ImportedGermplasmMainInfo mainInfo) { + public ImportedGermplasmMainInfo processWorkbook(final ImportedGermplasmMainInfo mainInfo) { try { this.wb = this.getFileService().retrieveWorkbook(mainInfo.getServerFilename()); this.doProcessNow(this.wb, mainInfo); - } catch (FileNotFoundException e) { + } catch (final FileNotFoundException e) { ImportGermplasmFileServiceImpl.LOG.error("File not found", e); } catch (InvalidFormatException | IOException e) { ImportGermplasmFileServiceImpl.LOG.error(e.getMessage(), e); @@ -173,13 +178,16 @@ public ImportedGermplasmMainInfo processWorkbook(ImportedGermplasmMainInfo mainI /** * Do process now. This would be used for the junit testing - * - * @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 */ @Override - public void doProcessNow(Workbook workbook, ImportedGermplasmMainInfo mainInfo) { + public void doProcessNow(final Workbook workbook, final ImportedGermplasmMainInfo mainInfo) { this.wb = workbook; this.currentSheet = 0; this.currentRow = 0; @@ -234,22 +242,23 @@ private void readSheet2() { // Check if columns ENTRY and DESIG is present if (this.importedGermplasmList.getImportedFactors() != null) { for (int col = 0; col < this.importedGermplasmList.getImportedFactors().size(); col++) { - if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase(AppConstants.ENTRY.getString())) { + if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.ENTRY.getString())) { entryColumnIsPresent = true; - } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase( - AppConstants.DESIGNATION.getString())) { + } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.DESIGNATION.getString())) { desigColumnIsPresent = true; - } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase( - AppConstants.GID.getString())) { + } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.GID.getString())) { desigGidIsPresent = true; - } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase( - AppConstants.CROSS.getString())) { + } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.CROSS.getString())) { desigCrossIsPresent = true; - } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase( - AppConstants.SOURCE.getString())) { + } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.SOURCE.getString())) { desigSourcePresent = true; - } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true).equalsIgnoreCase( - AppConstants.ENTRY_CODE.getString())) { + } else if (this.getCellStringValue(this.currentSheet, this.currentRow, col, true) + .equalsIgnoreCase(AppConstants.ENTRY_CODE.getString())) { desigEntryCodePresent = true; } } @@ -266,7 +275,8 @@ private void readSheet2() { } else if (!desigGidIsPresent && !desigCrossIsPresent && !desigSourcePresent && !desigEntryCodePresent) { // do nothing } else { - this.showInvalidFileError("CROSS or SOURCE or GID or ENTRY CODE column missing " + "from Observation sheet."); + this.showInvalidFileError( + "CROSS or SOURCE or GID or ENTRY CODE column missing " + "from Observation sheet."); ImportGermplasmFileServiceImpl.LOG.debug("Invalid file on missing ENTRY or DESIG on readSheet2"); } } @@ -280,27 +290,32 @@ private void readSheet2() { for (int col = 0; col < this.importedGermplasmList.getImportedFactors().size(); col++) { if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.ENTRY.getString())) { - importedGermplasm - .setEntryId(Integer.valueOf(this.getCellStringValue(this.currentSheet, this.currentRow, col, true))); + importedGermplasm.setEntryId(Integer + .valueOf(this.getCellStringValue(this.currentSheet, this.currentRow, col, true))); } else if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.DESIGNATION.getString())) { - importedGermplasm.setDesig(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); + importedGermplasm + .setDesig(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); } else if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.GID.getString())) { - importedGermplasm.setGid(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); + importedGermplasm + .setGid(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); } else if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.CROSS.getString())) { - importedGermplasm.setCross(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); + importedGermplasm + .setCross(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); } else if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.SOURCE.getString())) { - importedGermplasm.setSource(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); + importedGermplasm + .setSource(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); } else if (this.importedGermplasmList.getImportedFactors().get(col).getFactor() .equalsIgnoreCase(AppConstants.ENTRY_CODE.getString())) { - importedGermplasm.setEntryCode(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); + importedGermplasm + .setEntryCode(this.getCellStringValue(this.currentSheet, this.currentRow, col, true)); } else { ImportGermplasmFileServiceImpl.LOG.debug("Unhandled Column - " - + this.importedGermplasmList.getImportedFactors().get(col).getFactor().toUpperCase() + ":" - + this.getCellStringValue(this.currentSheet, this.currentRow, col)); + + this.importedGermplasmList.getImportedFactors().get(col).getFactor().toUpperCase() + + ":" + this.getCellStringValue(this.currentSheet, this.currentRow, col)); } } this.importedGermplasmList.addImportedGermplasm(importedGermplasm); @@ -317,19 +332,21 @@ private void readGermplasmListFileInfo() { this.listName = this.getCellStringValue(0, 0, 1, true); this.listTitle = this.getCellStringValue(0, 1, 1, true); - String labelIdentifier = this.getCellStringValue(0, 2, 0, true); + final String labelIdentifier = this.getCellStringValue(0, 2, 0, true); if (AppConstants.LIST_DATE.getString().equalsIgnoreCase(labelIdentifier)) { - this.listDate = DateUtil.parseDate(this.getCellStringValue(0, 2, 1, true), DateUtil.DATE_AS_NUMBER_FORMAT); + this.listDate = DateUtil.parseDate(this.getCellStringValue(0, 2, 1, true), + DateUtil.DATE_AS_NUMBER_FORMAT); this.listType = this.getCellStringValue(0, 3, 1, true); } else if (AppConstants.LIST_TYPE.getString().equalsIgnoreCase(labelIdentifier)) { this.listType = this.getCellStringValue(0, 2, 1, true); - this.listDate = DateUtil.parseDate(this.getCellStringValue(0, 3, 1, true), DateUtil.DATE_AS_NUMBER_FORMAT); + this.listDate = DateUtil.parseDate(this.getCellStringValue(0, 3, 1, true), + DateUtil.DATE_AS_NUMBER_FORMAT); } - this.importedGermplasmList = - new ImportedGermplasmList(this.originalFilename, this.listName, this.listTitle, this.listType, this.listDate); - } catch (ParseException e) { + this.importedGermplasmList = new ImportedGermplasmList(this.originalFilename, this.listName, this.listTitle, + this.listType, this.listDate); + } catch (final ParseException e) { ImportGermplasmFileServiceImpl.LOG.error(e.getMessage(), e); } @@ -349,20 +366,25 @@ private void readConditions() { this.currentRow++; // Check if headers are correct - if (!this.getCellStringValue(this.currentSheet, this.currentRow, 0, true).equalsIgnoreCase(AppConstants.CONDITION.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 1, true).equalsIgnoreCase( - AppConstants.DESCRIPTION.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 6, true).equalsIgnoreCase(AppConstants.VALUE.getString())) { + if (!this.getCellStringValue(this.currentSheet, this.currentRow, 0, true) + .equalsIgnoreCase(AppConstants.CONDITION.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 1, true) + .equalsIgnoreCase(AppConstants.DESCRIPTION.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 6, true) + .equalsIgnoreCase(AppConstants.VALUE.getString())) { // for now we dont flag as an error // Skip row from file info this.currentRow++; return; } - if (!this.getCellStringValue(this.currentSheet, this.currentRow, 2, true).equalsIgnoreCase(AppConstants.PROPERTY.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 3, true).equalsIgnoreCase(AppConstants.SCALE.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 4, true).equalsIgnoreCase(AppConstants.METHOD.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 5, true).equalsIgnoreCase( - AppConstants.DATA_TYPE.getString())) { + if (!this.getCellStringValue(this.currentSheet, this.currentRow, 2, true) + .equalsIgnoreCase(AppConstants.PROPERTY.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 3, true) + .equalsIgnoreCase(AppConstants.SCALE.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 4, true) + .equalsIgnoreCase(AppConstants.METHOD.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 5, true) + .equalsIgnoreCase(AppConstants.DATA_TYPE.getString())) { // for now we dont flag as an error // Skip row from file info this.currentRow++; @@ -373,13 +395,14 @@ private void readConditions() { ImportedCondition importedCondition; this.currentRow++; while (!this.rowIsEmpty()) { - importedCondition = - new ImportedCondition(this.getCellStringValue(this.currentSheet, this.currentRow, 0, true), - this.getCellStringValue(this.currentSheet, this.currentRow, 1, true), this.getCellStringValue( - this.currentSheet, this.currentRow, 2, true), this.getCellStringValue(this.currentSheet, - this.currentRow, 3, true), this.getCellStringValue(this.currentSheet, this.currentRow, 4, true), - this.getCellStringValue(this.currentSheet, this.currentRow, 5, true), this.getCellStringValue( - this.currentSheet, this.currentRow, 6, true), ""); + importedCondition = new ImportedCondition( + this.getCellStringValue(this.currentSheet, this.currentRow, 0, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 1, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 2, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 3, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 4, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 5, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 6, true), ""); this.importedGermplasmList.addImportedCondition(importedCondition); this.currentRow++; } @@ -395,17 +418,21 @@ private void readFactors() { Boolean desigColumnIsPresent = false; // Check if headers are correct - if (!this.getCellStringValue(this.currentSheet, this.currentRow, 0, true).equalsIgnoreCase(AppConstants.FACTOR.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 1, true).equalsIgnoreCase( - AppConstants.DESCRIPTION.getString())) { + if (!this.getCellStringValue(this.currentSheet, this.currentRow, 0, true) + .equalsIgnoreCase(AppConstants.FACTOR.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 1, true) + .equalsIgnoreCase(AppConstants.DESCRIPTION.getString())) { this.showInvalidFileError("Incorrect headers for factors."); ImportGermplasmFileServiceImpl.LOG.debug("Invalid file on readFactors header"); } - if (!this.getCellStringValue(this.currentSheet, this.currentRow, 2, true).equalsIgnoreCase(AppConstants.PROPERTY.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 3, true).equalsIgnoreCase(AppConstants.SCALE.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 4, true).equalsIgnoreCase(AppConstants.METHOD.getString()) - || !this.getCellStringValue(this.currentSheet, this.currentRow, 5, true).equalsIgnoreCase( - AppConstants.DATA_TYPE.getString())) { + if (!this.getCellStringValue(this.currentSheet, this.currentRow, 2, true) + .equalsIgnoreCase(AppConstants.PROPERTY.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 3, true) + .equalsIgnoreCase(AppConstants.SCALE.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 4, true) + .equalsIgnoreCase(AppConstants.METHOD.getString()) + || !this.getCellStringValue(this.currentSheet, this.currentRow, 5, true) + .equalsIgnoreCase(AppConstants.DATA_TYPE.getString())) { this.showInvalidFileError("Incorrect headers for factors."); ImportGermplasmFileServiceImpl.LOG.debug("Invalid file on readFactors header"); } @@ -415,12 +442,13 @@ private void readFactors() { // skip header this.currentRow++; while (!this.rowIsEmpty()) { - importedFactor = - new ImportedFactor(this.getCellStringValue(this.currentSheet, this.currentRow, 0, true), this.getCellStringValue( - this.currentSheet, this.currentRow, 1, true), this.getCellStringValue(this.currentSheet, this.currentRow, - 2, true), this.getCellStringValue(this.currentSheet, this.currentRow, 3, true), this.getCellStringValue( - this.currentSheet, this.currentRow, 4, true), this.getCellStringValue(this.currentSheet, this.currentRow, - 5, true), ""); + importedFactor = new ImportedFactor( + this.getCellStringValue(this.currentSheet, this.currentRow, 0, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 1, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 2, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 3, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 4, true), + this.getCellStringValue(this.currentSheet, this.currentRow, 5, true), ""); this.importedGermplasmList.addImportedFactor(importedFactor); // Check if the current factor is ENTRY or DESIG @@ -443,7 +471,7 @@ private void readFactors() { /** * Row is empty. - * + * * @return the boolean */ private Boolean rowIsEmpty() { @@ -452,24 +480,28 @@ private Boolean rowIsEmpty() { /** * Row is empty. - * - * @param row the row + * + * @param row + * the row * @return the boolean */ - private Boolean rowIsEmpty(Integer row) { + private Boolean rowIsEmpty(final Integer row) { return this.rowIsEmpty(this.currentSheet, row); } /** * Row is empty. - * - * @param sheet the sheet - * @param row the row + * + * @param sheet + * the sheet + * @param row + * the row * @return the boolean */ - private Boolean rowIsEmpty(Integer sheet, Integer row) { + private Boolean rowIsEmpty(final Integer sheet, final Integer row) { for (int col = 0; col < 8; col++) { - if (this.getCellStringValue(sheet, row, col) != null && !"".equalsIgnoreCase(this.getCellStringValue(sheet, row, col))) { + if (this.getCellStringValue(sheet, row, col) != null + && !"".equalsIgnoreCase(this.getCellStringValue(sheet, row, col))) { return false; } } @@ -478,23 +510,30 @@ private Boolean rowIsEmpty(Integer sheet, Integer row) { /** * Gets the cell string value. - * - * @param sheetNumber the sheet number - * @param rowNumber the row number - * @param columnNumber the column number + * + * @param sheetNumber + * the sheet number + * @param rowNumber + * the row number + * @param columnNumber + * the column number * @return the cell string value */ - private String getCellStringValue(Integer sheetNumber, Integer rowNumber, Integer columnNumber) { + private String getCellStringValue(final Integer sheetNumber, final Integer rowNumber, final Integer columnNumber) { return this.getCellStringValue(sheetNumber, rowNumber, columnNumber, false); } /** * Gets the cell string value. - * - * @param sheetNumber the sheet number - * @param rowNumber the row number - * @param columnNumber the column number - * @param followThisPosition the follow this position + * + * @param sheetNumber + * the sheet number + * @param rowNumber + * the row number + * @param columnNumber + * the column number + * @param followThisPosition + * the follow this position * @return the cell string value */ private String getCellStringValue(final Integer sheetNumber, final Integer rowNumber, final Integer columnNumber, @@ -523,10 +562,11 @@ private String getCellStringValue(final Integer sheetNumber, final Integer rowNu /** * Show invalid file error. - * - * @param message the message + * + * @param message + * the message */ - private void showInvalidFileError(String message) { + private void showInvalidFileError(final String message) { if (this.fileIsValid) { this.errorMessages.add(ImportGermplasmFileServiceImpl.FILE_INVALID); this.fileIsValid = false; @@ -535,17 +575,20 @@ private void showInvalidFileError(String message) { /* * (non-Javadoc) - * - * @see com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService#validataAndAddCheckFactor(java.util.List, + * + * @see + * com.efficio.fieldbook.web.nursery.service.ImportGermplasmFileService# + * validataAndAddCheckFactor(java.util.List, * com.efficio.fieldbook.web.nursery.bean.UserSelection) */ @Override - public void validataAndAddCheckFactor(List formImportedGermplasmsm, List importedGermplasms, - UserSelection userSelection, boolean hasCheck) throws MiddlewareException { - long start = System.currentTimeMillis(); - List sessionImportedGermplasmList = importedGermplasms; + public void validataAndAddCheckFactor(final List formImportedGermplasmsm, + final List importedGermplasms, final UserSelection userSelection, final boolean hasCheck) + throws MiddlewareException { + final long start = System.currentTimeMillis(); + final List sessionImportedGermplasmList = importedGermplasms; for (int i = 0; i < formImportedGermplasmsm.size(); i++) { - ImportedGermplasm germplasm = formImportedGermplasmsm.get(i); + final ImportedGermplasm germplasm = formImportedGermplasmsm.get(i); String checkVal = ""; if (germplasm.getEntryTypeValue() != null && !"".equalsIgnoreCase(germplasm.getEntryTypeValue())) { checkVal = germplasm.getEntryTypeValue(); @@ -557,22 +600,22 @@ public void validataAndAddCheckFactor(List formImportedGermpl if (hasCheck) { // we need to add the CHECK factor if its not existing - List measurementVariables = userSelection.getWorkbook().getFactors(); - - Integer checkVariableTermId = TermId.CHECK.getId(); - StandardVariable stdvar = - this.fieldbookMiddlewareService.getStandardVariable(checkVariableTermId, this.contextUtil.getCurrentProgramUUID()); - MeasurementVariable checkVariable = - new MeasurementVariable(checkVariableTermId, "CHECK", stdvar.getDescription(), stdvar.getScale().getName(), stdvar - .getMethod().getName(), stdvar.getProperty().getName(), stdvar.getDataType().getName(), "", - AppConstants.ENTRY.getString()); + final List measurementVariables = userSelection.getWorkbook().getFactors(); + + final Integer checkVariableTermId = TermId.CHECK.getId(); + final StandardVariable stdvar = this.fieldbookMiddlewareService.getStandardVariable(checkVariableTermId, + this.contextUtil.getCurrentProgramUUID()); + final MeasurementVariable checkVariable = new MeasurementVariable(checkVariableTermId, "CHECK", + stdvar.getDescription(), stdvar.getScale().getName(), stdvar.getMethod().getName(), + stdvar.getProperty().getName(), stdvar.getDataType().getName(), "", AppConstants.ENTRY.getString()); checkVariable.setRole(PhenotypicType.GERMPLASM); boolean checkFactorExisting = false; - for (MeasurementVariable var : measurementVariables) { - Integer termId = - this.fieldbookMiddlewareService.getStandardVariableIdByPropertyScaleMethodRole(var.getProperty(), var.getScale(), - var.getMethod(), PhenotypicType.getPhenotypicTypeForLabel(var.getLabel())); - if (termId != null && checkVariableTermId != null && termId.intValue() == checkVariableTermId.intValue()) { + for (final MeasurementVariable var : measurementVariables) { + final Integer termId = this.fieldbookMiddlewareService.getStandardVariableIdByPropertyScaleMethodRole( + var.getProperty(), var.getScale(), var.getMethod(), + PhenotypicType.getPhenotypicTypeForLabel(var.getLabel())); + if (termId != null && checkVariableTermId != null + && termId.intValue() == checkVariableTermId.intValue()) { checkFactorExisting = true; break; } @@ -588,15 +631,16 @@ public void validataAndAddCheckFactor(List formImportedGermpl if (userSelection.getWorkbook().isCheckFactorAddedOnly()) { // we need to remove it userSelection.getWorkbook().reset(); - List factors = userSelection.getWorkbook().getFactors(); + final List factors = userSelection.getWorkbook().getFactors(); factors.remove(factors.size() - 1); userSelection.getWorkbook().setFactors(factors); } } - ImportGermplasmFileServiceImpl.LOG.info("validataAndAddCheckFactor Time duration: " + (System.currentTimeMillis() - start)); + ImportGermplasmFileServiceImpl.LOG + .info("validataAndAddCheckFactor Time duration: " + (System.currentTimeMillis() - start)); } - public void setContextUtil(ContextUtil contextUtil) { + public void setContextUtil(final ContextUtil contextUtil) { this.contextUtil = contextUtil; } diff --git a/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java b/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java index 34a9302d7c..90342054fa 100644 --- a/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java +++ b/src/test/java/com/efficio/fieldbook/web/common/service/impl/ExportGermplasmListServiceTest.java @@ -5,7 +5,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -129,7 +128,7 @@ public class ExportGermplasmListServiceTest { @Mock InventoryDataManager inventoryDataManager; - + @Mock private com.efficio.fieldbook.service.api.FieldbookService fieldbookService; @@ -146,23 +145,32 @@ public void setUp() throws MiddlewareException { Mockito.doReturn(ExportGermplasmListServiceTest.CURRENT_USER_ID).when(this.contextUtil).getCurrentUserLocalId(); - Mockito.when(this.ontologyService.getStandardVariable(TermId.ENTRY_NO.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.ENTRY_NO.getId(), ExportGermplasmListServiceTest.ENTRY_NO)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.DESIG.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.DESIG.getId(), ExportGermplasmListServiceTest.DESIGNATION)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.GID.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.GID.getId(), ExportGermplasmListServiceTest.GID)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.CROSS.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.CROSS.getId(), ExportGermplasmListServiceTest.PARENTAGE)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.SEED_SOURCE.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.SEED_SOURCE.getId(), ExportGermplasmListServiceTest.SEED_SOURCE)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.ENTRY_CODE.getId(), this.contextUtil.getCurrentProgramUUID())) - .thenReturn(this.createStandardVariable(TermId.ENTRY_CODE.getId(), ExportGermplasmListServiceTest.ENTRY_CODE)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.ENTRY_NO.getId(), + this.contextUtil.getCurrentProgramUUID())).thenReturn( + this.createStandardVariable(TermId.ENTRY_NO.getId(), ExportGermplasmListServiceTest.ENTRY_NO)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.DESIG.getId(), + this.contextUtil.getCurrentProgramUUID())).thenReturn( + this.createStandardVariable(TermId.DESIG.getId(), ExportGermplasmListServiceTest.DESIGNATION)); Mockito.when( - this.ontologyService.getStandardVariable(TermId.ENTRY_NUMBER_STORAGE.getId(), this.contextUtil.getCurrentProgramUUID())) + this.ontologyService.getStandardVariable(TermId.GID.getId(), this.contextUtil.getCurrentProgramUUID())) + .thenReturn(this.createStandardVariable(TermId.GID.getId(), ExportGermplasmListServiceTest.GID)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.CROSS.getId(), + this.contextUtil.getCurrentProgramUUID())).thenReturn( + this.createStandardVariable(TermId.CROSS.getId(), ExportGermplasmListServiceTest.PARENTAGE)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.SEED_SOURCE.getId(), + this.contextUtil.getCurrentProgramUUID())) + .thenReturn(this.createStandardVariable(TermId.SEED_SOURCE.getId(), + ExportGermplasmListServiceTest.SEED_SOURCE)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.ENTRY_CODE.getId(), + this.contextUtil.getCurrentProgramUUID())) + .thenReturn(this.createStandardVariable(TermId.ENTRY_CODE.getId(), + ExportGermplasmListServiceTest.ENTRY_CODE)); + Mockito.when(this.ontologyService.getStandardVariable(TermId.ENTRY_NUMBER_STORAGE.getId(), + this.contextUtil.getCurrentProgramUUID())) .thenReturn(this.createStandardVariable(TermId.ENTRY_NUMBER_STORAGE.getId(), ExportGermplasmListServiceTest.ENTRY_NUMBER_STORAGE)); - Mockito.when(this.ontologyService.getStandardVariable(TermId.CHECK.getId(), this.contextUtil.getCurrentProgramUUID())) + Mockito.when(this.ontologyService.getStandardVariable(TermId.CHECK.getId(), + this.contextUtil.getCurrentProgramUUID())) .thenReturn(this.createStandardVariable(TermId.CHECK.getId(), ExportGermplasmListServiceTest.CHECK)); Mockito.when(this.userSelection.getWorkbook()).thenReturn(this.workbook); Mockito.when(this.workbook.getStudyDetails()).thenReturn(this.studyDetails); @@ -178,9 +186,13 @@ public void setUp() throws MiddlewareException { .getOwnerListName(ExportGermplasmListServiceTest.CURRENT_USER_ID); Mockito.doReturn("1010").when(this.fieldbookMiddlewareService).getOwnerListName(Matchers.anyInt()); - Mockito.when(ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), TermId.STOCKID.getId(), false, false)).thenReturn(this.createVariable(TermId.STOCKID.getId())); - Mockito.when(ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), TermId.SEED_AMOUNT_G.getId(), false, false)).thenReturn(this.createVariable(TermId.SEED_AMOUNT_G.getId())); - Mockito.when(this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId())).thenReturn(ValueReferenceTestDataInitializer.createPossibleValues()); + Mockito.when(this.ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), + TermId.STOCKID.getId(), false, false)).thenReturn(this.createVariable(TermId.STOCKID.getId())); + Mockito.when(this.ontologyVariableDataManager.getVariable(this.contextUtil.getCurrentProgramUUID(), + TermId.SEED_AMOUNT_G.getId(), false, false)) + .thenReturn(this.createVariable(TermId.SEED_AMOUNT_G.getId())); + Mockito.when(this.fieldbookService.getAllPossibleValues(TermId.ENTRY_TYPE.getId())) + .thenReturn(ValueReferenceTestDataInitializer.createPossibleValues()); } @@ -188,7 +200,8 @@ public void setUp() throws MiddlewareException { public void testExportGermplasmListXLSForTrialManager() { try { - this.exportGermplasmListServiceImpl.exportGermplasmListXLS(this.testFileName, 1, this.getVisibleColumnMap(), false); + this.exportGermplasmListServiceImpl.exportGermplasmListXLS(this.testFileName, 1, this.getVisibleColumnMap(), + false); Mockito.verify(this.germplasmExportService, Mockito.times(1)) .generateGermplasmListExcelFile(Matchers.any(GermplasmListExportInputValues.class)); } catch (final GermplasmListExporterException e) { @@ -201,7 +214,8 @@ public void testExportGermplasmListXLSForTrialManager() { public void testExportGermplasmListXLSForNurseryManager() { try { - this.exportGermplasmListServiceImpl.exportGermplasmListXLS(this.testFileName, 1, this.getVisibleColumnMap(), true); + this.exportGermplasmListServiceImpl.exportGermplasmListXLS(this.testFileName, 1, this.getVisibleColumnMap(), + true); Mockito.verify(this.germplasmExportService, Mockito.times(1)) .generateGermplasmListExcelFile(Matchers.any(GermplasmListExportInputValues.class)); } catch (final GermplasmListExporterException e) { @@ -214,9 +228,10 @@ public void testExportGermplasmListXLSForNurseryManager() { public void testExportGermplasmListCSVForTrialManager() { try { - this.exportGermplasmListServiceImpl.exportGermplasmListCSV(this.testFileName, this.getVisibleColumnMap(), false); - Mockito.verify(this.germplasmExportService, Mockito.times(1)).generateCSVFile(Matchers.any(List.class), Matchers.any(List.class), - Matchers.anyString()); + this.exportGermplasmListServiceImpl.exportGermplasmListCSV(this.testFileName, this.getVisibleColumnMap(), + false); + Mockito.verify(this.germplasmExportService, Mockito.times(1)).generateCSVFile(Matchers.any(List.class), + Matchers.any(List.class), Matchers.anyString()); } catch (final GermplasmListExporterException e) { Assert.fail(); @@ -230,9 +245,10 @@ public void testExportGermplasmListCSVForTrialManager() { public void testExportGermplasmListCSVForNurseryManager() { try { - this.exportGermplasmListServiceImpl.exportGermplasmListCSV(this.testFileName, this.getVisibleColumnMap(), true); - Mockito.verify(this.germplasmExportService, Mockito.times(1)).generateCSVFile(Matchers.any(List.class), Matchers.any(List.class), - Matchers.anyString()); + this.exportGermplasmListServiceImpl.exportGermplasmListCSV(this.testFileName, this.getVisibleColumnMap(), + true); + Mockito.verify(this.germplasmExportService, Mockito.times(1)).generateCSVFile(Matchers.any(List.class), + Matchers.any(List.class), Matchers.anyString()); } catch (final GermplasmListExporterException e) { Assert.fail(); } catch (final IOException e) { @@ -250,8 +266,8 @@ public void tearDown() { @Test public void testGetExportColumnHeadersFromTableTrial() { - final List exportColumnHeaders = - this.exportGermplasmListServiceImpl.getExportColumnHeadersFromTable(this.getVisibleColumnMap(), false); + final List exportColumnHeaders = this.exportGermplasmListServiceImpl + .getExportColumnHeadersFromTable(this.getVisibleColumnMap(), false); Assert.assertEquals(6, exportColumnHeaders.size()); Assert.assertTrue(exportColumnHeaders.get(0).isDisplay()); @@ -273,8 +289,8 @@ public void testGetExportColumnHeadersFromTableTrial() { @Test public void testGetExportColumnHeadersFromTableNursery() { - final List exportColumnHeaders = - this.exportGermplasmListServiceImpl.getExportColumnHeadersFromTable(this.getVisibleColumnMap(), true); + final List exportColumnHeaders = this.exportGermplasmListServiceImpl + .getExportColumnHeadersFromTable(this.getVisibleColumnMap(), true); Assert.assertEquals(6, exportColumnHeaders.size()); Assert.assertTrue(exportColumnHeaders.get(0).isDisplay()); @@ -296,16 +312,18 @@ public void testGetExportColumnHeadersFromTableNursery() { @Test public void testGetExportColumnValuesFromTableTrial() { - final List> exportColumnValues = - this.exportGermplasmListServiceImpl.getExportColumnValuesFromTable(this.getVisibleColumnMap(), false); + final List> exportColumnValues = this.exportGermplasmListServiceImpl + .getExportColumnValuesFromTable(this.getVisibleColumnMap(), false); Assert.assertEquals(1, exportColumnValues.size()); final Map row = exportColumnValues.get(0); Assert.assertEquals(ExportGermplasmListServiceTest.DESIG_VALUE, row.get(TermId.DESIG.getId()).getValue()); - Assert.assertEquals(ExportGermplasmListServiceTest.SOURCE_VALUE, row.get(TermId.SEED_SOURCE.getId()).getValue()); - Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_CODE_VALUE, row.get(TermId.ENTRY_CODE.getId()).getValue()); + Assert.assertEquals(ExportGermplasmListServiceTest.SOURCE_VALUE, + row.get(TermId.SEED_SOURCE.getId()).getValue()); + Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_CODE_VALUE, + row.get(TermId.ENTRY_CODE.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.CROSS_VALUE, row.get(TermId.CROSS.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_NO_VALUE, row.get(TermId.ENTRY_NO.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.GID_VALUE, row.get(TermId.GID.getId()).getValue()); @@ -315,16 +333,18 @@ public void testGetExportColumnValuesFromTableTrial() { @Test public void testGetExportColumnValuesFromTableNursery() { - final List> exportColumnValues = - this.exportGermplasmListServiceImpl.getExportColumnValuesFromTable(this.getVisibleColumnMap(), false); + final List> exportColumnValues = this.exportGermplasmListServiceImpl + .getExportColumnValuesFromTable(this.getVisibleColumnMap(), false); Assert.assertEquals(1, exportColumnValues.size()); final Map row = exportColumnValues.get(0); Assert.assertEquals(ExportGermplasmListServiceTest.DESIG_VALUE, row.get(TermId.DESIG.getId()).getValue()); - Assert.assertEquals(ExportGermplasmListServiceTest.SOURCE_VALUE, row.get(TermId.SEED_SOURCE.getId()).getValue()); - Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_CODE_VALUE, row.get(TermId.ENTRY_CODE.getId()).getValue()); + Assert.assertEquals(ExportGermplasmListServiceTest.SOURCE_VALUE, + row.get(TermId.SEED_SOURCE.getId()).getValue()); + Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_CODE_VALUE, + row.get(TermId.ENTRY_CODE.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.CROSS_VALUE, row.get(TermId.CROSS.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.ENTRY_NO_VALUE, row.get(TermId.ENTRY_NO.getId()).getValue()); Assert.assertEquals(ExportGermplasmListServiceTest.GID_VALUE, row.get(TermId.GID.getId()).getValue()); @@ -340,8 +360,8 @@ public void testGetEntryTypeValue() { valReference.setName(ExportGermplasmListServiceTest.CATEG_CODE_VALUE); possibleValues.add(valReference); - final String categValue = - this.exportGermplasmListServiceImpl.getEntryTypeValue(this.generateImportedGermplasm(), possibleValues); + final String categValue = this.exportGermplasmListServiceImpl + .getEntryTypeValue(this.generateImportedGermplasm(), possibleValues); Assert.assertEquals(ExportGermplasmListServiceTest.CATEG_CODE_VALUE, categValue); @@ -353,21 +373,22 @@ public void testSetUpForInputWhereGemplasmListTypeIsNursery() { final List germplasmLists = Arrays.asList(this.germplasmList); Mockito.when(this.germplasmListManager.retrieveSnapshotListData(Matchers.anyInt())).thenReturn(listData); - Mockito.when( - this.fieldbookMiddlewareService.getGermplasmListsByProjectId(Matchers.anyInt(), Matchers.eq(GermplasmListType.NURSERY))) - .thenReturn(germplasmLists); - Mockito.when(this.fieldbookMiddlewareService.getGermplasmListById(Matchers.anyInt())).thenReturn(this.germplasmList); + Mockito.when(this.fieldbookMiddlewareService.getGermplasmListsByProjectId(Matchers.anyInt(), + Matchers.eq(GermplasmListType.NURSERY))).thenReturn(germplasmLists); + Mockito.when(this.fieldbookMiddlewareService.getGermplasmListById(Matchers.anyInt())) + .thenReturn(this.germplasmList); - Map mockData = Maps.newHashMap(); + final Map mockData = Maps.newHashMap(); mockData.put(0, "StockID101, StockID102"); - Mockito.when(this.inventoryDataManager.retrieveStockIds(Mockito.anyList())).thenReturn(mockData); + Mockito.when(this.inventoryDataManager.retrieveStockIds(Matchers.anyList())).thenReturn(mockData); // Assert - final GermplasmListExportInputValues input = - this.exportGermplasmListServiceImpl.setUpInput(this.testFileName, 80, this.getVisibleColumnMap(), true); + final GermplasmListExportInputValues input = this.exportGermplasmListServiceImpl.setUpInput(this.testFileName, + 80, this.getVisibleColumnMap(), true); Assert.assertEquals("The visible colum maps should be" + this.getVisibleColumnMap(), this.getVisibleColumnMap(), input.getVisibleColumnMap()); - Assert.assertEquals("The germplasm list should be " + this.germplasmList, this.germplasmList, input.getGermplasmList()); + Assert.assertEquals("The germplasm list should be " + this.germplasmList, this.germplasmList, + input.getGermplasmList()); Assert.assertEquals("The germplasm list data should be " + listData, listData, input.getListData()); } @@ -377,33 +398,38 @@ public void testSetUpForInputWhereGemplasmListTypeIsTrial() { final List germplasmLists = Arrays.asList(this.germplasmList); Mockito.when(this.germplasmListManager.retrieveSnapshotListData(Matchers.anyInt())).thenReturn(listData); - Mockito.when(this.fieldbookMiddlewareService.getGermplasmListsByProjectId(Matchers.anyInt(), Matchers.eq(GermplasmListType.TRIAL))) - .thenReturn(germplasmLists); - Mockito.when(this.fieldbookMiddlewareService.getGermplasmListById(Matchers.anyInt())).thenReturn(this.germplasmList); + Mockito.when(this.fieldbookMiddlewareService.getGermplasmListsByProjectId(Matchers.anyInt(), + Matchers.eq(GermplasmListType.TRIAL))).thenReturn(germplasmLists); + Mockito.when(this.fieldbookMiddlewareService.getGermplasmListById(Matchers.anyInt())) + .thenReturn(this.germplasmList); - Map mockData = Maps.newHashMap(); + final Map mockData = Maps.newHashMap(); mockData.put(0, "StockID101, StockID102"); - Mockito.when(this.inventoryDataManager.retrieveStockIds(Mockito.anyList())).thenReturn(mockData); + Mockito.when(this.inventoryDataManager.retrieveStockIds(Matchers.anyList())).thenReturn(mockData); // Assert - final GermplasmListExportInputValues input = - this.exportGermplasmListServiceImpl.setUpInput(this.testFileName, 80, this.getVisibleColumnMap(), false); + final GermplasmListExportInputValues input = this.exportGermplasmListServiceImpl.setUpInput(this.testFileName, + 80, this.getVisibleColumnMap(), false); Assert.assertEquals("The visible colum maps should be" + this.getVisibleColumnMap(), this.getVisibleColumnMap(), input.getVisibleColumnMap()); - Assert.assertEquals("The germplasm list should be " + this.germplasmList, this.germplasmList, input.getGermplasmList()); + Assert.assertEquals("The germplasm list should be " + this.germplasmList, this.germplasmList, + input.getGermplasmList()); Assert.assertEquals("The germplasm list data should be " + listData, listData, input.getListData()); } @Test public void testExtractInventoryVariableMapFromVisibleColumnsInventoryVariablesAreVisible() { - Map visibleColumnsMap = this.getVisibleColumnMap(); + final Map visibleColumnsMap = this.getVisibleColumnMap(); visibleColumnsMap.put(String.valueOf(TermId.STOCKID.getId()), true); visibleColumnsMap.put(String.valueOf(TermId.SEED_AMOUNT_G.getId()), true); - Map result = exportGermplasmListServiceImpl.extractInventoryVariableMapFromVisibleColumns(visibleColumnsMap); + final Map result = this.exportGermplasmListServiceImpl + .extractInventoryVariableMapFromVisibleColumns(visibleColumnsMap); - Assert.assertEquals("There are 2 inventory variables in visibleColumnsMap so the size of InventoryVariableMap should be 2.", 2, result.size()); + Assert.assertEquals( + "There are 2 inventory variables in visibleColumnsMap so the size of InventoryVariableMap should be 2.", + 2, result.size()); Assert.assertTrue(result.containsKey(TermId.STOCKID.getId())); Assert.assertTrue(result.containsKey(TermId.SEED_AMOUNT_G.getId())); @@ -412,13 +438,16 @@ public void testExtractInventoryVariableMapFromVisibleColumnsInventoryVariablesA @Test public void testExtractInventoryVariableMapFromVisibleColumnsInventoryVariablesAreNotVisible() { - Map visibleColumnsMap = this.getVisibleColumnMap(); + final Map visibleColumnsMap = this.getVisibleColumnMap(); visibleColumnsMap.put(String.valueOf(TermId.STOCKID.getId()), false); visibleColumnsMap.put(String.valueOf(TermId.SEED_AMOUNT_G.getId()), false); - Map result = exportGermplasmListServiceImpl.extractInventoryVariableMapFromVisibleColumns(visibleColumnsMap); + final Map result = this.exportGermplasmListServiceImpl + .extractInventoryVariableMapFromVisibleColumns(visibleColumnsMap); - Assert.assertTrue("There are 2 inventory variables in visibleColumnsMap but they are not visible so the size of InventoryVariableMap should be empty", result.isEmpty()); + Assert.assertTrue( + "There are 2 inventory variables in visibleColumnsMap but they are not visible so the size of InventoryVariableMap should be empty", + result.isEmpty()); Assert.assertFalse(result.containsKey(TermId.STOCKID.getId())); Assert.assertFalse(result.containsKey(TermId.SEED_AMOUNT_G.getId())); @@ -427,28 +456,30 @@ public void testExtractInventoryVariableMapFromVisibleColumnsInventoryVariablesA @Test public void testRemoveInventoryVariableMapFromVisibleColumns() { - Map visibleColumnsMap = this.getVisibleColumnMap(); + final Map visibleColumnsMap = this.getVisibleColumnMap(); - // Get the size of visibleColumnsMap before adding the inventory variables so that - // we can compare the size of visibleColumnsMap after removing the inventory variables. - int visibleColumnsMapVariableCount = visibleColumnsMap.size(); + // Get the size of visibleColumnsMap before adding the inventory + // variables so that + // we can compare the size of visibleColumnsMap after removing the + // inventory variables. + final int visibleColumnsMapVariableCount = visibleColumnsMap.size(); // Add inventory variables in visibleColumnsmap visibleColumnsMap.put(String.valueOf(TermId.STOCKID.getId()), true); visibleColumnsMap.put(String.valueOf(TermId.SEED_AMOUNT_G.getId()), true); - exportGermplasmListServiceImpl.removeInventoryVariableMapFromVisibleColumns(visibleColumnsMap); + this.exportGermplasmListServiceImpl.removeInventoryVariableMapFromVisibleColumns(visibleColumnsMap); - Assert.assertEquals("Expecting " + visibleColumnsMapVariableCount + " variables in visibleColumnsMap", visibleColumnsMapVariableCount, visibleColumnsMap.size()); + Assert.assertEquals("Expecting " + visibleColumnsMapVariableCount + " variables in visibleColumnsMap", + visibleColumnsMapVariableCount, visibleColumnsMap.size()); Assert.assertFalse(visibleColumnsMap.containsKey(TermId.STOCKID.getId())); Assert.assertFalse(visibleColumnsMap.containsKey(TermId.SEED_AMOUNT_G.getId())); } - private Variable createVariable(final int termid) { - Variable variable = new Variable(); + final Variable variable = new Variable(); variable.setId(termid); return variable; diff --git a/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java b/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java index d80da07aac..ebe39c2419 100644 --- a/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java +++ b/src/test/java/com/efficio/fieldbook/web/nursery/controller/ImportGermplasmListControllerTest.java @@ -311,8 +311,7 @@ public void testGenerateGermplasmListDataTableForNursery() { map.get(ImportGermplasmListController.POSITION)); Assert.assertEquals("The entry code's value should be " + x, String.valueOf(x), map.get(ImportGermplasmListController.ENTRY_CODE)); - Assert.assertEquals("The check's value should be 1", "1", - map.get(ImportGermplasmListController.CHECK)); + Assert.assertEquals("The check's value should be 1", "1", map.get(ImportGermplasmListController.CHECK)); Assert.assertEquals("The entry's value should be " + x, String.valueOf(x), map.get(ImportGermplasmListController.ENTRY)); Assert.assertEquals("The check option's value should be " + this.checkList, this.checkList, @@ -394,11 +393,14 @@ public void testInitializeObjectsForGermplasmDetailsView() { Assert.assertEquals("The starting plot no should be " + ImportGermplasmListController.STARTING_PLOT_NO, ImportGermplasmListController.STARTING_PLOT_NO, form.getStartingPlotNo()); Assert.assertEquals("The starting entry no should be 1", "1", form.getStartingEntryNo()); - Assert.assertEquals("The main info should be" + mainInfo, mainInfo, this.userSelection.getImportedGermplasmMainInfo()); - Assert.assertNotNull("The imported germplasm list should not be null", this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList()); - Assert.assertEquals("The imported germplasm should be " + list, list, this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms()); + Assert.assertEquals("The main info should be" + mainInfo, mainInfo, + this.userSelection.getImportedGermplasmMainInfo()); + Assert.assertNotNull("The imported germplasm list should not be null", + this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList()); + Assert.assertEquals("The imported germplasm should be " + list, list, + this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms()); } - + @Test public void testInitializeObjectsForGermplasmDetailsViewWhereListIsEmpty() { final ImportGermplasmListForm form = new ImportGermplasmListForm(); @@ -427,8 +429,10 @@ public void testInitializeObjectsForGermplasmDetailsViewWhereListIsEmpty() { Assert.assertEquals("The starting plot no should be " + ImportGermplasmListController.STARTING_PLOT_NO, ImportGermplasmListController.STARTING_PLOT_NO, form.getStartingPlotNo()); Assert.assertNull("The starting entry no should be null", form.getStartingEntryNo()); - Assert.assertEquals("The main info should be" + mainInfo, mainInfo, this.userSelection.getImportedGermplasmMainInfo()); - Assert.assertNull("The imported germplasm list should be null", this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList()); + Assert.assertEquals("The main info should be" + mainInfo, mainInfo, + this.userSelection.getImportedGermplasmMainInfo()); + Assert.assertNull("The imported germplasm list should be null", + this.userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList()); } @Test diff --git a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java index c2717cf241..614e78af7b 100644 --- a/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java +++ b/src/test/java/com/efficio/fieldbook/web/nursery/service/impl/ImportGermplasmFileServiceImplTest.java @@ -73,14 +73,16 @@ public void initialize() { try { - InputStream inp = this.getClass().getClassLoader().getResourceAsStream("GermplasmImportTemplate-Basic-rev4b-with_data.xls"); + InputStream inp = this.getClass().getClassLoader() + .getResourceAsStream("GermplasmImportTemplate-Basic-rev4b-with_data.xls"); this.workbookBasic = WorkbookFactory.create(inp); inp = this.getClass().getClassLoader().getResourceAsStream("GermplasmImportTemplate-Advanced-rev4.xls"); this.workbookAdvance = WorkbookFactory.create(inp); - inp = this.getClass().getClassLoader().getResourceAsStream("GermplasmImportTemplate-Basic-rev4b-with_data.xlsx"); + inp = this.getClass().getClassLoader() + .getResourceAsStream("GermplasmImportTemplate-Basic-rev4b-with_data.xlsx"); this.workbookBasicXlsx = WorkbookFactory.create(inp); @@ -93,7 +95,7 @@ public void initialize() { Mockito.when(this.contextUtil.getCurrentProgramUUID()).thenReturn(""); this.importGermplasmFileService.setContextUtil(this.contextUtil); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail("Failed to load the template files for testing."); } } @@ -101,14 +103,14 @@ public void initialize() { /** * Test valid basic parse import gerplasm. */ - @Ignore + @Ignore @Test public void testValidBasicParseImportGerplasm() { - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookBasic, mainInfo); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } @@ -122,25 +124,29 @@ public void testValidBasicParseImportGerplasm() { Assert.assertFalse(mainInfo.isAdvanceImportType()); Assert.assertTrue(mainInfo.getFileIsValid()); // we check the parse data here - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), "IR 68835-58-1-1-B"); - - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getEntryId(), Integer.valueOf(20)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getDesig(), "IR 67632-14-2-5-1-2-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), + Integer.valueOf(1)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), + "IR 68835-58-1-1-B"); + + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getEntryId(), + Integer.valueOf(20)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getDesig(), + "IR 67632-14-2-5-1-2-B"); } /** * Test valid advance parse import gerplasm. */ - @Ignore + @Ignore @Test public void testValidAdvanceParseImportGerplasm() { - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookAdvance, mainInfo); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } @@ -157,15 +163,19 @@ public void testValidAdvanceParseImportGerplasm() { Assert.assertTrue(mainInfo.isAdvanceImportType()); Assert.assertTrue(mainInfo.getFileIsValid()); // test the parsing - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), "IR 68201-21-2-B-4-B-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), + Integer.valueOf(1)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), + "IR 68201-21-2-B-4-B-B"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getGid(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getCross(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getSource(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryCode(), "1"); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getEntryId(), Integer.valueOf(2)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getDesig(), "IR 67632-14-2-5-1-2-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getEntryId(), + Integer.valueOf(2)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getDesig(), + "IR 67632-14-2-5-1-2-B"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getGid(), "2"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getCross(), "2"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getSource(), "2"); @@ -175,14 +185,14 @@ public void testValidAdvanceParseImportGerplasm() { /** * Test valid basic parse import gerplasm xlsx. */ - @Ignore + @Ignore @Test public void testValidBasicParseImportGerplasmXlsx() { - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookBasicXlsx, mainInfo); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } @@ -196,23 +206,27 @@ public void testValidBasicParseImportGerplasmXlsx() { Assert.assertFalse(mainInfo.isAdvanceImportType()); Assert.assertTrue(mainInfo.getFileIsValid()); // we check the parse data here - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), "IR 68835-58-1-1-B"); - - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getEntryId(), Integer.valueOf(20)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getDesig(), "IR 67632-14-2-5-1-2-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), + Integer.valueOf(1)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), + "IR 68835-58-1-1-B"); + + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getEntryId(), + Integer.valueOf(20)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(19).getDesig(), + "IR 67632-14-2-5-1-2-B"); } /** * Test valid advance parse import gerplasm xlsx. */ - @Ignore + @Ignore @Test public void testValidAdvanceParseImportGerplasmXlsx() { - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookAdvanceXlsx, mainInfo); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } @@ -229,15 +243,19 @@ public void testValidAdvanceParseImportGerplasmXlsx() { Assert.assertTrue(mainInfo.isAdvanceImportType()); Assert.assertTrue(mainInfo.getFileIsValid()); // test the parsing - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), "IR 68201-21-2-B-4-B-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryId(), + Integer.valueOf(1)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getDesig(), + "IR 68201-21-2-B-4-B-B"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getGid(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getCross(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getSource(), "1"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(0).getEntryCode(), "1"); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getEntryId(), Integer.valueOf(2)); - Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getDesig(), "IR 67632-14-2-5-1-2-B"); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getEntryId(), + Integer.valueOf(2)); + Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getDesig(), + "IR 67632-14-2-5-1-2-B"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getGid(), "2"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getCross(), "2"); Assert.assertEquals(mainInfo.getImportedGermplasmList().getImportedGermplasms().get(1).getSource(), "2"); @@ -247,73 +265,83 @@ public void testValidAdvanceParseImportGerplasmXlsx() { /** * Test valid basic parse import gerplasm xls pagination. */ - @Ignore + @Ignore @Test public void testValidBasicParseImportGerplasmXlsPagination() { // testing when doing pagination, we simulate the pagination - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); - ImportGermplasmListForm form = new ImportGermplasmListForm(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportGermplasmListForm form = new ImportGermplasmListForm(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookBasic, mainInfo); form.setImportedGermplasmMainInfo(mainInfo); form.setImportedGermplasm(mainInfo.getImportedGermplasmList().getImportedGermplasms()); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } form.changePage(1); Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getDesig(), "IR 68835-58-1-1-B"); // we check the parse data here + Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getDesig(), "IR 68835-58-1-1-B"); // we + // check + // the + // parse + // data + // here } /** * Test valid advance parse import gerplasm xls pagination. */ - @Ignore + @Ignore @Test public void testValidAdvanceParseImportGerplasmXlsPagination() { // testing when doing pagination, we simulate the pagination - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); - ImportGermplasmListForm form = new ImportGermplasmListForm(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportGermplasmListForm form = new ImportGermplasmListForm(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookAdvance, mainInfo); form.setImportedGermplasmMainInfo(mainInfo); form.setImportedGermplasm(mainInfo.getImportedGermplasmList().getImportedGermplasms()); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } form.changePage(1); Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getEntryId(), Integer.valueOf(1)); - Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getDesig(), "IR 68201-21-2-B-4-B-B"); // we check the parse data + Assert.assertEquals(form.getPaginatedImportedGermplasm().get(0).getDesig(), "IR 68201-21-2-B-4-B-B"); // we + // check + // the + // parse + // data // here } - @Ignore + @Ignore @Test - public void testValidAndAddCheckFactor() throws MiddlewareException { + public void testValidAndAddCheckFactor() throws MiddlewareException { // testing when doing pagination, we simulate the pagination - ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); - ImportGermplasmListForm form = new ImportGermplasmListForm(); + final ImportedGermplasmMainInfo mainInfo = new ImportedGermplasmMainInfo(); + final ImportGermplasmListForm form = new ImportGermplasmListForm(); try { this.realImportGermplasmFileService.doProcessNow(this.workbookAdvance, mainInfo); form.setImportedGermplasmMainInfo(mainInfo); form.setImportedGermplasm(mainInfo.getImportedGermplasmList().getImportedGermplasms()); - } catch (Exception e) { + } catch (final Exception e) { Assert.fail(); } - UserSelection userSelection = new UserSelection(); + final UserSelection userSelection = new UserSelection(); userSelection.setWorkbook(new org.generationcp.middleware.domain.etl.Workbook()); - List factors = new ArrayList(); + final List factors = new ArrayList(); userSelection.getWorkbook().setFactors(factors); userSelection.getWorkbook().setVariates(new ArrayList()); userSelection.setImportedGermplasmMainInfo(mainInfo); - this.realImportGermplasmFileService.validataAndAddCheckFactor(form.getImportedGermplasm(), userSelection - .getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(), userSelection, true); + this.realImportGermplasmFileService.validataAndAddCheckFactor(form.getImportedGermplasm(), + userSelection.getImportedGermplasmMainInfo().getImportedGermplasmList().getImportedGermplasms(), + userSelection, true); // no check factor yet Assert.assertEquals(0, userSelection.getWorkbook().getMeasurementDatasetVariables().size()); // we now need to add check - MeasurementVariable checkVariable = - new MeasurementVariable("CHECK", "TYPE OF ENTRY", "CODE", "ASSIGNED", "CHECK", "C", "", "ENTRY"); + final MeasurementVariable checkVariable = new MeasurementVariable("CHECK", "TYPE OF ENTRY", "CODE", "ASSIGNED", + "CHECK", "C", "", "ENTRY"); factors.add(checkVariable); userSelection.getWorkbook().reset(); userSelection.getWorkbook().setFactors(factors); @@ -324,20 +352,22 @@ public void testValidAndAddCheckFactor() throws MiddlewareException { @Test public void testValidataAndAddCheckFactorNoCheckAndWithCheckFactor() throws MiddlewareException { - Workbook workbook = this.generateWorkbookWithCheckFactor(); + final Workbook workbook = this.generateWorkbookWithCheckFactor(); workbook.setCheckFactorAddedOnly(true); Mockito.doReturn(workbook).when(this.userSelection).getWorkbook(); - List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); - List sessionImportedGermplasm = this.generateImportedGermplasm(); + final List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); + final List sessionImportedGermplasm = this.generateImportedGermplasm(); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, false); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, + this.userSelection, false); - for (ImportedGermplasm item : sessionImportedGermplasm) { - int index = sessionImportedGermplasm.indexOf(item); + for (final ImportedGermplasm item : sessionImportedGermplasm) { + final int index = sessionImportedGermplasm.indexOf(item); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeName(), item.getEntryTypeName()); Assert.assertEquals("", item.getEntryTypeValue()); - Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), item.getEntryTypeCategoricalID()); + Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), + item.getEntryTypeCategoricalID()); } Assert.assertEquals(4, workbook.getFactors().size()); @@ -347,20 +377,22 @@ public void testValidataAndAddCheckFactorNoCheckAndWithCheckFactor() throws Midd @Test public void testValidataAndAddCheckFactorNoCheckAndWithoutCheckFactor() throws MiddlewareException { - Workbook workbook = this.generateWorkbook(); + final Workbook workbook = this.generateWorkbook(); workbook.setCheckFactorAddedOnly(false); Mockito.doReturn(workbook).when(this.userSelection).getWorkbook(); - List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); - List sessionImportedGermplasm = this.generateImportedGermplasm(); + final List formImportedGermplasm = this.generateFormImportedGermplasmNoCheck(); + final List sessionImportedGermplasm = this.generateImportedGermplasm(); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, false); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, + this.userSelection, false); - for (ImportedGermplasm item : sessionImportedGermplasm) { - int index = sessionImportedGermplasm.indexOf(item); + for (final ImportedGermplasm item : sessionImportedGermplasm) { + final int index = sessionImportedGermplasm.indexOf(item); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeName(), item.getEntryTypeName()); Assert.assertEquals("", item.getEntryTypeValue()); - Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), item.getEntryTypeCategoricalID()); + Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), + item.getEntryTypeCategoricalID()); } Assert.assertEquals(4, workbook.getFactors().size()); @@ -370,22 +402,24 @@ public void testValidataAndAddCheckFactorNoCheckAndWithoutCheckFactor() throws M @Test public void testValidataAndAddCheckFactorWithNoExistingCheckFactor() throws MiddlewareException { - Workbook workbook = this.generateWorkbook(); + final Workbook workbook = this.generateWorkbook(); - List formImportedGermplasm = this.generateFormImportedGermplasm(); - List sessionImportedGermplasm = this.generateImportedGermplasm(); + final List formImportedGermplasm = this.generateFormImportedGermplasm(); + final List sessionImportedGermplasm = this.generateImportedGermplasm(); Mockito.doReturn(workbook).when(this.userSelection).getWorkbook(); Mockito.doReturn(this.generateCheckStandardVariable()).when(this.fieldbookMiddlewareService) .getStandardVariable(Matchers.anyInt(), Matchers.anyString()); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, + this.userSelection, true); - for (ImportedGermplasm item : sessionImportedGermplasm) { - int index = sessionImportedGermplasm.indexOf(item); + for (final ImportedGermplasm item : sessionImportedGermplasm) { + final int index = sessionImportedGermplasm.indexOf(item); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeName(), item.getEntryTypeName()); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeValue(), item.getEntryTypeValue()); - Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), item.getEntryTypeCategoricalID()); + Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), + item.getEntryTypeCategoricalID()); } Assert.assertEquals("CHECK", workbook.getFactors().get(4).getName()); @@ -395,27 +429,28 @@ public void testValidataAndAddCheckFactorWithNoExistingCheckFactor() throws Midd @Test public void testValidataAndAddCheckFactorWithExistingCheckFactor() throws MiddlewareException { - Workbook workbook = this.generateWorkbook(); - StandardVariable checkStandardVariable = this.generateCheckStandardVariable(); + final Workbook workbook = this.generateWorkbook(); + final StandardVariable checkStandardVariable = this.generateCheckStandardVariable(); - List formImportedGermplasm = this.generateFormImportedGermplasm(); - List sessionImportedGermplasm = this.generateImportedGermplasm(); + final List formImportedGermplasm = this.generateFormImportedGermplasm(); + final List sessionImportedGermplasm = this.generateImportedGermplasm(); Mockito.doReturn(this.generateWorkbookWithCheckFactor()).when(this.userSelection).getWorkbook(); Mockito.doReturn(checkStandardVariable).when(this.fieldbookMiddlewareService) .getStandardVariable(Matchers.anyInt(), Matchers.anyString()); - Mockito.doReturn(TermId.CHECK.getId()) - .when(this.fieldbookMiddlewareService) - .getStandardVariableIdByPropertyScaleMethodRole(Matchers.anyString(), Matchers.anyString(), Matchers.anyString(), - Matchers.any(PhenotypicType.class)); + Mockito.doReturn(TermId.CHECK.getId()).when(this.fieldbookMiddlewareService) + .getStandardVariableIdByPropertyScaleMethodRole(Matchers.anyString(), Matchers.anyString(), + Matchers.anyString(), Matchers.any(PhenotypicType.class)); - this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, this.userSelection, true); + this.importGermplasmFileService.validataAndAddCheckFactor(formImportedGermplasm, sessionImportedGermplasm, + this.userSelection, true); - for (ImportedGermplasm item : sessionImportedGermplasm) { - int index = sessionImportedGermplasm.indexOf(item); + for (final ImportedGermplasm item : sessionImportedGermplasm) { + final int index = sessionImportedGermplasm.indexOf(item); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeName(), item.getEntryTypeName()); Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeValue(), item.getEntryTypeValue()); - Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), item.getEntryTypeCategoricalID()); + Assert.assertEquals(formImportedGermplasm.get(index).getEntryTypeCategoricalID(), + item.getEntryTypeCategoricalID()); } Assert.assertEquals(4, workbook.getFactors().size()); @@ -423,11 +458,11 @@ public void testValidataAndAddCheckFactorWithExistingCheckFactor() throws Middle } private List generateFormImportedGermplasm() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); for (int x = 0; x < 10; x++) { - ImportedGermplasm importedGermplasm = new ImportedGermplasm(); + final ImportedGermplasm importedGermplasm = new ImportedGermplasm(); importedGermplasm.setIndex(x); importedGermplasm.setBreedingMethodId(1); @@ -444,11 +479,11 @@ private List generateFormImportedGermplasm() { } private List generateFormImportedGermplasmNoCheck() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); for (int x = 0; x < 10; x++) { - ImportedGermplasm importedGermplasm = new ImportedGermplasm(); + final ImportedGermplasm importedGermplasm = new ImportedGermplasm(); importedGermplasm.setIndex(x); importedGermplasm.setBreedingMethodId(1); @@ -463,11 +498,11 @@ private List generateFormImportedGermplasmNoCheck() { private List generateImportedGermplasm() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); for (int x = 0; x < 10; x++) { - ImportedGermplasm importedGermplasm = new ImportedGermplasm(); + final ImportedGermplasm importedGermplasm = new ImportedGermplasm(); importedGermplasm.setIndex(x); importedGermplasm.setBreedingMethodId(1); importedGermplasm.setDesig("DESIG" + x); @@ -481,7 +516,7 @@ private List generateImportedGermplasm() { private StandardVariable generateCheckStandardVariable() { - StandardVariable stdVar = new StandardVariable(); + final StandardVariable stdVar = new StandardVariable(); stdVar.setId(TermId.CHECK.getId()); stdVar.setName("ENTRY_TYPE"); stdVar.setProperty(new Term(2209, "Entry type", "Entry type")); @@ -494,21 +529,21 @@ private StandardVariable generateCheckStandardVariable() { } private Workbook generateWorkbook() { - Workbook wb = new Workbook(); + final Workbook wb = new Workbook(); wb.setFactors(this.generateFactors()); return wb; } private Workbook generateWorkbookWithCheckFactor() { - Workbook wb = new Workbook(); - List factors = this.generateFactors(); + final Workbook wb = new Workbook(); + final List factors = this.generateFactors(); factors.add(this.createMeasurementVariable("ENTRY_TYPE")); wb.setFactors(factors); return wb; } private List generateFactors() { - List list = new ArrayList<>(); + final List list = new ArrayList<>(); list.add(this.createMeasurementVariable("TRIAL_INSTANCE")); list.add(this.createMeasurementVariable("ENTRY_NO")); list.add(this.createMeasurementVariable("PLOT_NO")); @@ -517,8 +552,8 @@ private List generateFactors() { } - private MeasurementVariable createMeasurementVariable(String name) { - MeasurementVariable mv = new MeasurementVariable(); + private MeasurementVariable createMeasurementVariable(final String name) { + final MeasurementVariable mv = new MeasurementVariable(); mv.setName(name); return mv; }