Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #61 from IntegratedBreedingPlatform/BMS-2006-SetUp…
Browse files Browse the repository at this point in the history
…3.0.8Env

BMS-2025 Set temporary GID to 0 to prevent possible override from existing germplasm
  • Loading branch information
jaira committed Nov 27, 2015
2 parents 8252662 + 9d9e405 commit a18d3f1
Show file tree
Hide file tree
Showing 4 changed files with 353 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,19 +253,9 @@ protected void performThirdPedigreeAction() {
germplasm = new Germplasm();
}

if(searchByNameOrNewGermplasmIsNeeded) {
// gid at creation is temporary, will be set properly below
germplasm = createGermplasmObject(i, 0, 0, 0, ibdbUserId, dateIntValue);

if(germplasmMatchesCount==1 && germplasmDetailsComponent.automaticallyAcceptSingleMatchesCheckbox()){
//If a single match is found, multiple matches will be
// handled by SelectGemrplasmWindow and
// then receiveGermplasmFromWindowAndUpdateGermplasmData()
List<Germplasm> foundGermplasm = this.germplasmDataManager.getGermplasmByName(importedGermplasm.getDesig(), 0, 1, Operation.EQUAL);
germplasm.setGid(foundGermplasm.get(0).getGid());
doNotCreateGermplasmsWithId.add(foundGermplasm.get(0).getGid());
}
}
germplasm = updateGidForSingleMatch(ibdbUserId, dateIntValue,
importedGermplasm, germplasmMatchesCount, germplasm,
searchByNameOrNewGermplasmIsNeeded);

Name name = createNameObject(ibdbUserId, dateIntValue, importedGermplasm.getDesig());

Expand All @@ -288,6 +278,39 @@ protected void performThirdPedigreeAction() {
}


/**
* Update GID to the existing germplasm's id. Otherwise, gid is set to 0
*
* @param ibdbUserId
* @param dateIntValue
* @param importedGermplasm
* @param germplasmMatchesCount
* @param germplasm
* @param searchByNameOrNewGermplasmIsNeeded
* @return
*/
Germplasm updateGidForSingleMatch(Integer ibdbUserId,
Integer dateIntValue, ImportedGermplasm importedGermplasm,
int germplasmMatchesCount, Germplasm germplasm,
boolean searchByNameOrNewGermplasmIsNeeded)
throws MiddlewareQueryException {
if(searchByNameOrNewGermplasmIsNeeded) {
// gid at creation is temporary, will be set properly below
germplasm = createGermplasmObject(0, 0, 0, 0, ibdbUserId, dateIntValue);

if(germplasmMatchesCount==1 && germplasmDetailsComponent.automaticallyAcceptSingleMatchesCheckbox()){
//If a single match is found, multiple matches will be
// handled by SelectGemrplasmWindow and
// then receiveGermplasmFromWindowAndUpdateGermplasmData()
List<Germplasm> foundGermplasm = this.germplasmDataManager.getGermplasmByName(importedGermplasm.getDesig(), 0, 1, Operation.EQUAL);
germplasm.setGid(foundGermplasm.get(0).getGid());
doNotCreateGermplasmsWithId.add(foundGermplasm.get(0).getGid());
}
}
return germplasm;
}


protected boolean isNeedToDisplayGermplasmSelectionWindow(int germplasmMatchesCount) {
return (germplasmMatchesCount>1)
|| (germplasmMatchesCount > 0 && !germplasmDetailsComponent.automaticallyAcceptSingleMatchesCheckbox());
Expand Down Expand Up @@ -609,6 +632,13 @@ public void addNameToGermplasm(Name name, Integer gid){
doNotCreateGermplasmsWithId.add(gid);
newDesignationsForExistingGermplasm.add(name);
}


public void setGermplasmDataManager(
GermplasmDataManager germplasmDataManager) {
this.germplasmDataManager = germplasmDataManager;

}



Expand Down
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;
}
}
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;
}
}
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());
}
}

0 comments on commit a18d3f1

Please sign in to comment.