From eb7bbd688f0c64213b526acdb4ec33d377a0eab5 Mon Sep 17 00:00:00 2001 From: Gelli Samson Date: Mon, 20 Jan 2020 17:33:26 +0800 Subject: [PATCH] Remove GeolocationPropertyDao.getInstanceIdLocationIdMap. Remove StudyDataManager.getInstanceIdLocationIdMap. Remove StudyDataManagerImpl.getInstanceIdLocationIdMap. Remove GeolocationPropertyDaoTest.testGetInstanceIdLocationIdMap. Remove StudyDataManagerImplTest.testGetInstanceIdLocationIdMap. IBP-3048-UseStudyInstanceLocation --- .../dao/dms/GeolocationPropertyDao.java | 23 ------------------- .../manager/StudyDataManagerImpl.java | 5 ---- .../manager/api/StudyDataManager.java | 6 ----- .../dao/dms/GeolocationPropertyDaoTest.java | 20 ---------------- .../manager/StudyDataManagerImplTest.java | 16 ------------- 5 files changed, 70 deletions(-) diff --git a/src/main/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDao.java b/src/main/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDao.java index 4a0787739a..ffe310cc66 100644 --- a/src/main/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDao.java +++ b/src/main/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDao.java @@ -132,29 +132,6 @@ public Map getGeolocationPropsAndValuesByGeolocation(final Integ } } - public Map getInstanceIdLocationIdMap(final List instanceIds) { - Map 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 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 getGeoLocationPropertyByVariableId(final Integer datasetId, final Integer instanceDbId) { Preconditions.checkNotNull(datasetId); diff --git a/src/main/java/org/generationcp/middleware/manager/StudyDataManagerImpl.java b/src/main/java/org/generationcp/middleware/manager/StudyDataManagerImpl.java index 97f97ac61d..2e5bf0ff74 100644 --- a/src/main/java/org/generationcp/middleware/manager/StudyDataManagerImpl.java +++ b/src/main/java/org/generationcp/middleware/manager/StudyDataManagerImpl.java @@ -1111,11 +1111,6 @@ public StudyMetadata getStudyMetadataForGeolocationId(final Integer geolocationI return this.getDmsProjectDao().getStudyMetadataForGeolocationId(geolocationId); } - @Override - public Map getInstanceIdLocationIdMap(final List instanceIds) { - return this.getGeolocationPropertyDao().getInstanceIdLocationIdMap(instanceIds); - } - @Override public Map getGeolocationPropsAndValuesByGeolocation(final Integer studyId) { return this.getGeolocationPropertyDao().getGeolocationPropsAndValuesByGeolocation(studyId); diff --git a/src/main/java/org/generationcp/middleware/manager/api/StudyDataManager.java b/src/main/java/org/generationcp/middleware/manager/api/StudyDataManager.java index aa5bd181d3..37f6907fa7 100644 --- a/src/main/java/org/generationcp/middleware/manager/api/StudyDataManager.java +++ b/src/main/java/org/generationcp/middleware/manager/api/StudyDataManager.java @@ -765,10 +765,4 @@ boolean isVariableUsedInStudyOrTrialEnvironmentInOtherPrograms( */ List getUsersForEnvironment(final Integer instanceId); - /** - * Returns the instance id to location id map - * @param instanceIds - * @return - */ - Map getInstanceIdLocationIdMap(final List instanceIds); } diff --git a/src/test/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDaoTest.java b/src/test/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDaoTest.java index 5a93a0400a..b46dd2e41f 100644 --- a/src/test/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDaoTest.java +++ b/src/test/java/org/generationcp/middleware/dao/dms/GeolocationPropertyDaoTest.java @@ -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()); - - 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 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 = diff --git a/src/test/java/org/generationcp/middleware/manager/StudyDataManagerImplTest.java b/src/test/java/org/generationcp/middleware/manager/StudyDataManagerImplTest.java index bc93341f1b..6fa55c460a 100644 --- a/src/test/java/org/generationcp/middleware/manager/StudyDataManagerImplTest.java +++ b/src/test/java/org/generationcp/middleware/manager/StudyDataManagerImplTest.java @@ -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 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