This repository has been archived by the owner on Jan 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from IntegratedBreedingPlatform/BMS-2006-SetUp…
…3.0.8Env BMS-2025 Set temporary GID to 0 to prevent possible override from existing germplasm
- Loading branch information
Showing
4 changed files
with
353 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
.../generationcp/breeding/manager/data/initializer/ImportedGermplasmListDataInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
|
||
package org.generationcp.breeding.manager.data.initializer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.generationcp.breeding.manager.crossingmanager.pojos.GermplasmName; | ||
import org.generationcp.breeding.manager.pojos.ImportedGermplasm; | ||
import org.generationcp.breeding.manager.pojos.ImportedGermplasmList; | ||
import org.generationcp.middleware.data.initializer.GermplasmTestDataInitializer; | ||
import org.generationcp.middleware.domain.inventory.ListEntryLotDetails; | ||
|
||
public class ImportedGermplasmListDataInitializer { | ||
|
||
public static ImportedGermplasmList createImportedGermplasmList(final int noOfEntries) { | ||
final String filename = "SourceList.xls"; | ||
final String name = "Import List 001"; | ||
final String title = "Import List 001 description"; | ||
final String type = "LST"; | ||
final Date date = new Date(); | ||
|
||
final ImportedGermplasmList importedGermplasmList = new ImportedGermplasmList(filename, name, title, type, date); | ||
importedGermplasmList.setImportedGermplasms(createListOfImportedGermplasm(noOfEntries)); | ||
return importedGermplasmList; | ||
} | ||
|
||
public static List<ImportedGermplasm> createListOfImportedGermplasm(final int noOfEntries) { | ||
final List<ImportedGermplasm> importedGermplasmList = new ArrayList<ImportedGermplasm>(); | ||
|
||
for (int i = 1; i <= noOfEntries; i++) { | ||
|
||
importedGermplasmList.add(createImportedGermplasm(i)); | ||
} | ||
|
||
return importedGermplasmList; | ||
} | ||
|
||
public static ImportedGermplasm createImportedGermplasm(final int id) { | ||
final ImportedGermplasm importedGermplasm = new ImportedGermplasm(); | ||
|
||
importedGermplasm.setAttributeVariates(createAttributeVariates(id)); | ||
|
||
return importedGermplasm; | ||
} | ||
|
||
private static Map<String, String> createAttributeVariates(final int id) { | ||
final Map<String, String> attributeVariates = new HashMap<String, String>(); | ||
attributeVariates.put("NOTE", "note value" + id); | ||
return attributeVariates; | ||
} | ||
|
||
public static List<GermplasmName> createGermplasmNameObjects(final int noOfEntries) { | ||
final List<GermplasmName> germplasmNameList = new ArrayList<GermplasmName>(); | ||
|
||
for (int i = 1; i <= noOfEntries; i++) { | ||
|
||
final GermplasmName gName = | ||
new GermplasmName(GermplasmTestDataInitializer.createGermplasm(i), GermplasmTestDataInitializer.createGermplasmName(i)); | ||
|
||
germplasmNameList.add(gName); | ||
} | ||
|
||
return germplasmNameList; | ||
} | ||
|
||
public static List<Integer> createListOfGemplasmIds(final int noOfIds) { | ||
final List<Integer> ids = new ArrayList<Integer>(); | ||
|
||
for (int i = 1; i <= noOfIds; i++) { | ||
ids.add(i); | ||
} | ||
|
||
return ids; | ||
} | ||
|
||
public static Map<ListEntryLotDetails, Double> createReservations(final int noOfEntries) { | ||
final Map<ListEntryLotDetails, Double> reservations = new HashMap<ListEntryLotDetails,Double>(); | ||
for (Integer i = 0; i < noOfEntries; i++) { | ||
reservations.put(ListInventoryDataInitializer.createLotDetail(i, 1), i.doubleValue()); | ||
} | ||
return reservations; | ||
} | ||
|
||
public static List<Map<Integer, String>> createFactorsRowValuesListParserData() { | ||
final List<Map<Integer, String>> testData = new ArrayList<Map<Integer,String>>(); | ||
|
||
final String[][] rawData = | ||
{ {"ENTRY_NO", "Germplasm entry - enumerated (number)", "GERMPLASM ENTRY", "NUMBER", "ENUMERATED"}, | ||
{"GID", "Germplasm identifier - assigned (DBID)", "GERMPLASM ID", "GERMPLASM ID", "ASSIGNED"}, | ||
{"ENTRY_CODE", "Germplasm ID - Assigned (Code)", "GERMPLASM ENTRY", "CODE OF ENTRY_CODE", "ASSIGNED"}, | ||
{"DESIGNATION", "Germplasm identifier - assigned (DBCV)", "GERMPLASM ID", "GERMPLASM NAME", "ASSIGNED"}, | ||
{"CROSS", "The pedigree string of the germplasm", "CROSS HISTORY", "TEXT", "ASSIGNED"}, | ||
{"SEED_SOURCE", "Seed source - Selected (Code)", "SEED SOURCE", "CODE OF SEED_SOURCE", "SELECTED"}}; | ||
|
||
for (final String[] rowValue : rawData) { | ||
final Map<Integer, String> map = new HashMap<Integer,String>(); | ||
for (int i = 0; i < rowValue.length; i++) { | ||
map.put(i, rowValue[i]); | ||
} | ||
|
||
testData.add(map); | ||
} | ||
|
||
return testData; | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
...java/org/generationcp/breeding/manager/data/initializer/ListInventoryDataInitializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
|
||
package org.generationcp.breeding.manager.data.initializer; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.generationcp.middleware.domain.inventory.ListDataInventory; | ||
import org.generationcp.middleware.domain.inventory.ListEntryLotDetails; | ||
import org.generationcp.middleware.domain.oms.Term; | ||
import org.generationcp.middleware.pojos.GermplasmListData; | ||
import org.generationcp.middleware.pojos.Location; | ||
|
||
public class ListInventoryDataInitializer { | ||
|
||
public static final int NO_OF_LISTDATA = 5; | ||
|
||
public static final int NO_OF_LOTS_PER_LISTDATA = 5; | ||
|
||
public static List<GermplasmListData> createGermplasmListDataWithInventoryDetails() { | ||
List<GermplasmListData> inventoryDetails = new ArrayList<GermplasmListData>(); | ||
|
||
for (int i = 0; i < NO_OF_LISTDATA; i++) { | ||
GermplasmListData listData = new GermplasmListData(); | ||
int id = i + 1; | ||
listData.setId(id); | ||
listData.setEntryId(id); | ||
listData.setDesignation("Germplasm" + id); | ||
listData.setGid(id); | ||
listData.setInventoryInfo(createInventoryInfo(id)); | ||
listData.setStatus(0); | ||
inventoryDetails.add(listData); | ||
} | ||
|
||
return inventoryDetails; | ||
} | ||
|
||
public static ListDataInventory createInventoryInfo(int listDataId) { | ||
ListDataInventory inventoryInfo = new ListDataInventory(listDataId, listDataId); | ||
List<ListEntryLotDetails> lotDetails = new ArrayList<ListEntryLotDetails>(); | ||
for (int i = 0; i < NO_OF_LOTS_PER_LISTDATA; i++) { | ||
lotDetails.add(createLotDetail(i, listDataId)); | ||
} | ||
inventoryInfo.setLotRows(lotDetails); | ||
inventoryInfo.setActualInventoryLotCount(1); | ||
inventoryInfo.setReservedLotCount(2); | ||
return inventoryInfo; | ||
} | ||
|
||
public static ListEntryLotDetails createLotDetail(int i, int listDataId) { | ||
ListEntryLotDetails lotDetail = new ListEntryLotDetails(); | ||
int id = (i + 1) * listDataId; | ||
lotDetail.setId(id); | ||
lotDetail.setLotId(id); | ||
lotDetail.setLocationOfLot(createLocation(id)); | ||
lotDetail.setLocId(i); | ||
lotDetail.setScaleOfLot(createScale(id)); | ||
lotDetail.setScaleId(i); | ||
lotDetail.setAvailableLotBalance(100D); | ||
lotDetail.setActualLotBalance(100D); | ||
lotDetail.setReservedTotalForEntry(100D); | ||
lotDetail.setCommentOfLot("Lot Comment" + id); | ||
return lotDetail; | ||
} | ||
|
||
public static Term createScale(int id) { | ||
Term scale = new Term(); | ||
scale.setId(id); | ||
scale.setName("Scale" + id); | ||
return scale; | ||
} | ||
|
||
public static Location createLocation(int id) { | ||
Location location = new Location(); | ||
location.setLocid(id); | ||
location.setLname("Location" + id); | ||
return location; | ||
} | ||
|
||
public static Term createTerm(String name) { | ||
Term term = new Term(); | ||
term.setName(name); | ||
term.setId(0); | ||
return term; | ||
} | ||
|
||
public static Integer getNumberOfEntriesInInventoryView() { | ||
return NO_OF_LISTDATA * NO_OF_LOTS_PER_LISTDATA; | ||
} | ||
|
||
public static Integer getNumberOfEntriesInListView() { | ||
return NO_OF_LISTDATA; | ||
} | ||
} |
108 changes: 108 additions & 0 deletions
108
.../generationcp/breeding/manager/listimport/actions/ProcessImportedGermplasmActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
|
||
package org.generationcp.breeding.manager.listimport.actions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.generationcp.breeding.manager.data.initializer.ImportedGermplasmListDataInitializer; | ||
import org.generationcp.breeding.manager.listimport.GermplasmFieldsComponent; | ||
import org.generationcp.breeding.manager.listimport.SpecifyGermplasmDetailsComponent; | ||
import org.generationcp.breeding.manager.pojos.ImportedGermplasm; | ||
import org.generationcp.middleware.data.initializer.GermplasmTestDataInitializer; | ||
import org.generationcp.middleware.exceptions.MiddlewareQueryException; | ||
import org.generationcp.middleware.manager.Operation; | ||
import org.generationcp.middleware.manager.api.GermplasmDataManager; | ||
import org.generationcp.middleware.pojos.Germplasm; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import com.vaadin.ui.ComboBox; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ProcessImportedGermplasmActionTest { | ||
|
||
@Mock | ||
private SpecifyGermplasmDetailsComponent germplasmDetailsComponent; | ||
|
||
@Mock | ||
private GermplasmFieldsComponent germplasmFieldsComponent; | ||
|
||
@Mock | ||
private GermplasmDataManager germplasmDataManager; | ||
|
||
@InjectMocks | ||
private ProcessImportedGermplasmAction processImportedGermplasmAction; | ||
|
||
final static Integer IBDB_USER_ID = 1; | ||
final static Integer DATE_INT_VALUE = 20151105; | ||
|
||
@Before | ||
public void setUp() { | ||
Mockito.doReturn(this.germplasmFieldsComponent).when(this.germplasmDetailsComponent).getGermplasmFieldsComponent(); | ||
final ComboBox locationComboBox = new ComboBox(); | ||
locationComboBox.addItem("1"); | ||
Mockito.doReturn(locationComboBox).when(this.germplasmFieldsComponent).getLocationComboBox(); | ||
|
||
final ComboBox methodComboBox = new ComboBox(); | ||
methodComboBox.addItem("1"); | ||
Mockito.doReturn(methodComboBox).when(this.germplasmFieldsComponent).getBreedingMethodComboBox(); | ||
|
||
this.processImportedGermplasmAction.setGermplasmDataManager(this.germplasmDataManager); | ||
} | ||
|
||
@Test | ||
public void testUpdateGidWhenGermplasmIdIsExisting() throws MiddlewareQueryException { | ||
final int gid = 100; | ||
final ImportedGermplasm importedGermplasm = ImportedGermplasmListDataInitializer.createImportedGermplasm(gid); | ||
importedGermplasm.setDesig("Name" + gid); | ||
|
||
final int germplasmMatchesCount = 1; | ||
final boolean searchByNameOrNewGermplasmIsNeeded = true; | ||
Germplasm germplasm = GermplasmTestDataInitializer.createGermplasm(0); | ||
|
||
Mockito.doReturn(true).when(this.germplasmDetailsComponent).automaticallyAcceptSingleMatchesCheckbox(); | ||
|
||
final List<Germplasm> germplasms = new ArrayList<Germplasm>(); | ||
germplasms.add(GermplasmTestDataInitializer.createGermplasm(gid)); | ||
|
||
Mockito.doReturn(germplasms).when(this.germplasmDataManager) | ||
.getGermplasmByName(importedGermplasm.getDesig(), 0, 1, Operation.EQUAL); | ||
|
||
germplasm = | ||
this.processImportedGermplasmAction.updateGidForSingleMatch(IBDB_USER_ID, this.DATE_INT_VALUE, importedGermplasm, | ||
germplasmMatchesCount, germplasm, searchByNameOrNewGermplasmIsNeeded); | ||
|
||
Assert.assertEquals("Expecting that the gid set is from the existing germplasm.", gid, germplasm.getGid().intValue()); | ||
} | ||
|
||
@Test | ||
public void testUpdateGidWhenNoGermplasmIdIsExisting() throws MiddlewareQueryException { | ||
final int gid = 0; | ||
final ImportedGermplasm importedGermplasm = ImportedGermplasmListDataInitializer.createImportedGermplasm(gid); | ||
importedGermplasm.setDesig("Name" + gid); | ||
|
||
final int germplasmMatchesCount = 0; | ||
final boolean searchByNameOrNewGermplasmIsNeeded = true; | ||
Germplasm germplasm = GermplasmTestDataInitializer.createGermplasm(0); | ||
|
||
|
||
try { | ||
germplasm = | ||
this.processImportedGermplasmAction.updateGidForSingleMatch(IBDB_USER_ID, this.DATE_INT_VALUE, importedGermplasm, | ||
germplasmMatchesCount, germplasm, searchByNameOrNewGermplasmIsNeeded); | ||
|
||
Mockito.verify(this.germplasmDetailsComponent, Mockito.times(0)).automaticallyAcceptSingleMatchesCheckbox(); | ||
Mockito.verify(this.germplasmDataManager, Mockito.times(0)).getGermplasmByName(importedGermplasm.getDesig(), 0, 1, Operation.EQUAL); | ||
} catch (Exception e) { | ||
Assert.fail(); | ||
} | ||
Assert.assertEquals("Expecting that the gid is set to 0 when there is no existing germplasm.", 0, germplasm.getGid().intValue()); | ||
} | ||
} |