use of org.jbei.ice.storage.model.SelectionMarker in project ice by JBEI.
the class SelectionMarkerDAO method getMatchingSelectionMarkers.
public List<String> getMatchingSelectionMarkers(String token, int limit) {
try {
CriteriaQuery<String> query = getBuilder().createQuery(String.class);
Root<SelectionMarker> from = query.from(SelectionMarker.class);
query.where(getBuilder().like(getBuilder().lower(from.get("name")), "%" + token.toLowerCase() + "%"));
query.select(from.get("name")).distinct(true);
return currentSession().createQuery(query).setMaxResults(limit).list();
// return currentSession().createCriteria(SelectionMarker.class)
// .add(Restrictions.ilike("name", token, MatchMode.ANYWHERE))
// .setMaxResults(limit)
// .setProjection(Projections.distinct(Projections.property("name")))
// .list();
} catch (HibernateException he) {
Logger.error(he);
throw new DAOException(he);
}
}
use of org.jbei.ice.storage.model.SelectionMarker in project ice by JBEI.
the class SelectionMarkerDAOTest method testGetMatchingSelectionMarkers.
@Test
public void testGetMatchingSelectionMarkers() throws Exception {
String email = "testGetMatchingSelectionMarkers";
Account account = AccountCreator.createTestAccount(email, false);
Assert.assertNotNull(account);
Strain strain = new Strain();
strain.setName("sTrain");
strain.setBioSafetyLevel(BioSafetyOption.LEVEL_ONE.ordinal());
strain.setShortDescription("test strain");
SelectionMarker marker = new SelectionMarker();
marker.setName("xkcd");
SelectionMarker marker2 = new SelectionMarker();
marker2.setName("test");
Set<SelectionMarker> markerSet = new HashSet<>();
markerSet.add(marker);
markerSet.add(marker2);
strain.setSelectionMarkers(markerSet);
EntryCreator creator = new EntryCreator();
strain = (Strain) creator.createEntry(account, strain, null);
Assert.assertNotNull(strain);
Assert.assertEquals(2, strain.getSelectionMarkers().size());
List<String> results = dao.getMatchingSelectionMarkers("xkcd", 5);
Assert.assertEquals(1, results.size());
List<String> res = dao.getMatchingSelectionMarkers("tes", 5);
Assert.assertEquals(1, res.size());
Assert.assertEquals("test", res.get(0));
}
Aggregations