Commit 4243392e authored by Matija Obreza's avatar Matija Obreza Committed by Matija Obreza
Browse files

Fixed bug in sizeOf

parent 253b4231
......@@ -44,7 +44,7 @@ public interface AccessionListRepository extends JpaRepository<AccessionList, Lo
@Modifying
void addOne(AccessionList acceList, long acceId);
@Query("select count(*) from AccessionList al where al = ?1")
@Query(nativeQuery=true, value="select count(acceid) from accelistitems where listid = ?1")
int sizeOf(AccessionList list);
}
......@@ -30,6 +30,7 @@ import org.genesys2.server.persistence.domain.TraitValueRepository;
import org.genesys2.server.persistence.domain.TraitValueRepositoryImpl;
import org.genesys2.server.service.AccessionListService;
import org.genesys2.server.service.FilterConstants;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilter;
import org.genesys2.server.service.impl.FilterHandler.AppliedFilters;
......@@ -41,6 +42,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
......@@ -79,6 +81,9 @@ public class AccessionListReal {
@Autowired
private GenesysService genesysService;
@Autowired
private GenesysFilterService genesysFilterService;
@Test
public void testAccessionList1() throws NonUniqueAccessionException {
......@@ -99,7 +104,8 @@ public class AccessionListReal {
assertThat("List size of 1", accessionListService.sizeOf(loaded), is(1));
// do a load
accessionListService.getAccessionIds(loaded);
Set<Long> ids = accessionListService.getAccessionIds(loaded);
assertThat("List size of 1", ids.size(), is(1));
// Bye-bye
accessionListService.delete(loaded);
......@@ -124,6 +130,9 @@ public class AccessionListReal {
// Add accessions by their IDs
accessionListService.addToList(loaded, accessionIds);
Set<Long> ids = accessionListService.getAccessionIds(loaded);
assertThat("List size of 100", ids.size(), is(100));
// Bye-bye
accessionListService.delete(loaded);
}
......@@ -145,10 +154,18 @@ public class AccessionListReal {
// 1st pass
accessionListService.addToList(loaded, filters);
int count = accessionListService.sizeOf(loaded);
System.err.println(count);
// 2nd pass (this would throw errors)
accessionListService.addToList(loaded, filters);
assertThat("No change in list size expected", accessionListService.sizeOf(loaded), is(count));
final AppliedFilters filters2 = new AppliedFilters();
filters2.add(new AppliedFilter().setFilterName(FilterConstants.LIST).addFilterValue(new FilterHandler.LiteralValueFilter(loaded.getUuid())));
Page<Accession> res = genesysFilterService.listAccessions(filters2, new PageRequest(0, 50));
assertThat("Page.total must match", res.getTotalElements(), is((long)count));
assertThat("Page.total must match", res.getNumberOfElements(), is(50));
// Remove all traces of us being here
accessionListService.delete(loaded);
......
......@@ -27,21 +27,27 @@ import org.genesys2.server.persistence.domain.GenesysLowlevelRepositoryCustomImp
import org.genesys2.server.service.AclService;
import org.genesys2.server.service.ContentService;
import org.genesys2.server.service.CropService;
import org.genesys2.server.service.GenesysFilterService;
import org.genesys2.server.service.GenesysService;
import org.genesys2.server.service.GeoService;
import org.genesys2.server.service.HtmlSanitizer;
import org.genesys2.server.service.InstituteService;
import org.genesys2.server.service.OrganizationService;
import org.genesys2.server.service.TaxonomyService;
import org.genesys2.server.service.TraitService;
import org.genesys2.server.service.UserService;
import org.genesys2.server.service.audit.SpringSecurityAuditorAware;
import org.genesys2.server.service.impl.AclServiceImpl;
import org.genesys2.server.service.impl.ContentServiceImpl;
import org.genesys2.server.service.impl.CropServiceImpl;
import org.genesys2.server.service.impl.GenesysFilterServiceImpl;
import org.genesys2.server.service.impl.GenesysServiceImpl;
import org.genesys2.server.service.impl.GeoServiceImpl;
import org.genesys2.server.service.impl.InstituteServiceImpl;
import org.genesys2.server.service.impl.OWASPSanitizer;
import org.genesys2.server.service.impl.OrganizationServiceImpl;
import org.genesys2.server.service.impl.TaxonomyServiceImpl;
import org.genesys2.server.service.impl.TraitServiceImpl;
import org.genesys2.server.service.impl.UserServiceImpl;
import org.springframework.cache.CacheManager;
import org.springframework.cache.support.NoOpCacheManager;
......@@ -70,6 +76,21 @@ public class GenesysBeansConfig {
return new GenesysServiceImpl();
}
@Bean
public GenesysFilterService genesysFilterService() {
return new GenesysFilterServiceImpl();
}
@Bean
public TraitService traitService() {
return new TraitServiceImpl();
}
@Bean
public InstituteService instituteService() {
return new InstituteServiceImpl();
}
@Bean
public GenesysLowlevelRepository genesysLowlevelRepository() {
return new GenesysLowlevelRepositoryCustomImpl();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment