Skip to content

Commit

Permalink
Merge pull request #736 from IntegratedBreedingPlatform/IBP-3048-UseS…
Browse files Browse the repository at this point in the history
…tudyInstanceLocation

IBP-3048 Apply code cleanup
  • Loading branch information
darla-leafnode authored Jan 21, 2020
2 parents fc3f503 + eb7bbd6 commit 96d35fe
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,29 +132,6 @@ public Map<String, String> getGeolocationPropsAndValuesByGeolocation(final Integ
}
}

public Map<Integer, String> getInstanceIdLocationIdMap(final List<Integer> instanceIds) {
Map<Integer, String> instanceIdLocationIdMap = new HashMap<>();
final StringBuilder sql =
new StringBuilder().append("SELECT ").append(" geo.nd_geolocation_id as instanceId, geo.value as value ").append("FROM ")
.append(" nd_geolocationprop geo ").append("WHERE ").append(" geo.nd_geolocation_id in (:geolocationIds) ")
.append(" AND geo.type_id = :locationVariableId");

try {
final Query query =
this.getSession().createSQLQuery(sql.toString()).addScalar("instanceId").addScalar("value")
.setParameterList("geolocationIds", instanceIds).setParameter("locationVariableId", TermId.LOCATION_ID.getId());
final List<Object> results = query.list();
for (final Object obj : results) {
final Object[] row = (Object[]) obj;
instanceIdLocationIdMap.put((Integer) row[0], (String) row[1]);
}
return instanceIdLocationIdMap;
} catch (final MiddlewareQueryException e) {
final String message = "Error with getInstanceIdLocationIdMap() query from instanceIds: " + instanceIds;
GeolocationPropertyDao.LOG.error(message, e);
throw new MiddlewareQueryException(message, e);
}
}

public Map<Integer, String> getGeoLocationPropertyByVariableId(final Integer datasetId, final Integer instanceDbId) {
Preconditions.checkNotNull(datasetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1111,11 +1111,6 @@ public StudyMetadata getStudyMetadataForGeolocationId(final Integer geolocationI
return this.getDmsProjectDao().getStudyMetadataForGeolocationId(geolocationId);
}

@Override
public Map<Integer, String> getInstanceIdLocationIdMap(final List<Integer> instanceIds) {
return this.getGeolocationPropertyDao().getInstanceIdLocationIdMap(instanceIds);
}

@Override
public Map<String, String> getGeolocationPropsAndValuesByGeolocation(final Integer studyId) {
return this.getGeolocationPropertyDao().getGeolocationPropsAndValuesByGeolocation(studyId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -765,10 +765,4 @@ boolean isVariableUsedInStudyOrTrialEnvironmentInOtherPrograms(
*/
List<UserDto> getUsersForEnvironment(final Integer instanceId);

/**
* Returns the instance id to location id map
* @param instanceIds
* @return
*/
Map<Integer, String> getInstanceIdLocationIdMap(final List<Integer> instanceIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,26 +88,6 @@ public void testGetGeolocationPropsAndValuesByGeolocation() {
Assert.assertNotNull(propertiesMap.get(this.variable2.getDefinition()));
}

@Test
public void testGetInstanceIdLocationIdMap() {
final DmsProject dataset =
this.createDataset(RandomStringUtils.randomAlphabetic(20), DatasetTypeEnum.SUMMARY_DATA.getId(), this.study);
final Integer geolocationId =
this.createEnvironmentData(dataset, new ArrayList<Integer>());

final GeolocationProperty prop = new GeolocationProperty();
prop.setType(TermId.LOCATION_ID.getId());
final Geolocation geolocation = new Geolocation(geolocationId);
prop.setGeolocation(geolocation);
prop.setRank(1);
prop.setValue("1001");
this.geolocationPropDao.save(prop);

final Map<Integer, String> instanceIdLocationIdMap = this.geolocationPropDao.getInstanceIdLocationIdMap(Arrays.asList(geolocationId));
Assert.assertEquals(1, instanceIdLocationIdMap.size());
Assert.assertEquals("1001", instanceIdLocationIdMap.get(geolocationId));
}

@Test
public void testDeleteGeolocationPropertyValueInProject() {
final Integer geolocationIdMain =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,6 @@ public void testSearchStudiesForName() throws Exception {
}
}

@Test
public void testGetInstanceIdLocationIdMap() throws Exception {
final StudyReference newStudy = this.studyTDI.addTestStudy();
final Integer studyId = newStudy.getId();
this.studyTDI.addTestDataset(studyId, DatasetTypeEnum.PLOT_DATA.getId());
final Random random = new Random();
final String locationId = String.valueOf(random.nextInt());
final String season = String.valueOf(random.nextInt());
this.studyTDI.createEnvironmentDataset(this.crop, studyId, locationId, season);

this.manager.getActiveSession().flush();

final Map<Integer, String> instanceIdLocationIdMap = this.manager.getInstanceIdLocationIdMap(Arrays.asList(this.studyTDI.getGeolocationId()));
Assert.assertEquals(locationId, instanceIdLocationIdMap.get(this.studyTDI.getGeolocationId()));
}

@Test
public void testSearchStudiesForStartDate() throws Exception {
// Study search query expect datasets for studies to be returned
Expand Down

0 comments on commit 96d35fe

Please sign in to comment.