Author: blavenier Date: 2013-02-01 10:30:28 +0100 (Fri, 01 Feb 2013) New Revision: 284 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/284 Log: - getProgram return a program with a zone, or a program with a 'null' zone if location is not a zone. Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java Modified: trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java =================================================================== --- trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-01 07:40:14 UTC (rev 283) +++ trunk/tutti-persistence-adagio/src/main/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceImpl.java 2013-02-01 09:30:28 UTC (rev 284) @@ -99,34 +99,30 @@ @Override public Program getProgram(String id) { - Object[] source = queryUnique( + Iterator<Object[]> list = queryList( "program", - "programCode", StringType.INSTANCE, id); + "programCode", StringType.INSTANCE, id, + "locationLevelId", IntegerType.INSTANCE, enumeration.LOCATION_LEVEL_ID_PROGRAM, + "locationClassificationId", IntegerType.INSTANCE, enumeration.LOCATION_CLASSIFICATION_ID_SECTOR); + + if (list.hasNext() == false) return null; - if (source == null) return null; + // Keep only the first row (=the first location, if many found) + Object[] source = list.next(); Program result = new Program(); result.setId((String) source[0]); result.setName((String) source[1]); result.setComment((String) source[2]); - - // get program locations - Iterator<Object[]> list = queryList( - "allProgramLocations", - "programCode", StringType.INSTANCE, id); - - List<Zone> zones = Lists.newArrayList(); - while (list.hasNext()) { - Object[] zoneSource = list.next(); - Zone target = new Zone(); - target.setId(String.valueOf(zoneSource[0])); - target.setLabel((String) zoneSource[1]); - target.setName((String) zoneSource[2]); - zones.add(target); + + if (source[3] != null) { + Zone zone = new Zone(); + zone.setId(String.valueOf(source[3])); + zone.setLabel((String) source[4]); + zone.setName((String) source[5]); + + result.setZone(zone); } - if (!zones.isEmpty()) { - result.setZone(zones.get(0)); - } return result; } @@ -213,9 +209,6 @@ target.setDescription(source.getComment()); } - - - // Zone if (copyIfNull && source.getZone() == null) { // Remove program location classifications : Modified: trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml =================================================================== --- trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-02-01 07:40:14 UTC (rev 283) +++ trunk/tutti-persistence-adagio/src/main/resources/queries-override.hbm.xml 2013-02-01 09:30:28 UTC (rev 284) @@ -65,22 +65,10 @@ <!-- [DAT-03] Get a detail program --> <query name="program"> <![CDATA[ - SELECT + SELECT p.code, p.name, - p.description - FROM - ProgramImpl p - WHERE - p.code = :programCode - ]]> - <query-param name="programCode" type="java.lang.String"/> - </query> - - <!-- [DAT-03-1] Get a program locations --> - <query name="allProgramLocations"> - <![CDATA[ - SELECT + p.description, l.id, l.label, l.name @@ -89,8 +77,17 @@ LEFT OUTER JOIN p.locations l WHERE p.code = :programCode + AND ( + l is null OR ( + l.locationLevel.id = :locationLevelId + AND l.locationClassification.id = :locationClassificationId + ) + ) + ORDER BY l.label ]]> <query-param name="programCode" type="java.lang.String"/> + <query-param name="locationLevelId" type="java.lang.Integer"/> + <query-param name="locationClassificationId" type="java.lang.Integer"/> </query> <!-- [DAT-04] Get a detail cruise --> Modified: trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java =================================================================== --- trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-01 07:40:14 UTC (rev 283) +++ trunk/tutti-persistence-adagio/src/test/java/fr/ifremer/tutti/persistence/service/ProgramPersistenceServiceTest.java 2013-02-01 09:30:28 UTC (rev 284) @@ -78,7 +78,8 @@ Assert.assertNotNull(actual); Assert.assertNotNull(actual.getId()); Assert.assertNotNull(actual.getName()); - Assert.assertNotNull(actual.getZone()); + //comment, because in test database, "CAM-CGFS" could have a location that is not a zone + //Assert.assertNotNull(actual.getZone()); Assert.assertEquals(programCode, actual.getId()); }