Search in sources :

Example 1 with SelectionMarker

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);
    }
}
Also used : DAOException(org.jbei.ice.storage.DAOException) HibernateException(org.hibernate.HibernateException) SelectionMarker(org.jbei.ice.storage.model.SelectionMarker)

Example 2 with SelectionMarker

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));
}
Also used : Account(org.jbei.ice.storage.model.Account) EntryCreator(org.jbei.ice.lib.entry.EntryCreator) SelectionMarker(org.jbei.ice.storage.model.SelectionMarker) Strain(org.jbei.ice.storage.model.Strain) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

SelectionMarker (org.jbei.ice.storage.model.SelectionMarker)2 HashSet (java.util.HashSet)1 HibernateException (org.hibernate.HibernateException)1 EntryCreator (org.jbei.ice.lib.entry.EntryCreator)1 DAOException (org.jbei.ice.storage.DAOException)1 Account (org.jbei.ice.storage.model.Account)1 Strain (org.jbei.ice.storage.model.Strain)1 Test (org.junit.Test)1