Working on removing portal filtering code NIHVIVO-2320 and moving processRdfForm2.jsp to java
This commit is contained in:
parent
8cc8247513
commit
835ffa3481
10 changed files with 607 additions and 906 deletions
|
@ -18,10 +18,10 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement;
|
|||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectProperty;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.BaseFiltering;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.tabFactory.TabEntityFactoryFiltering;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||
|
||||
public class VitroFiltersFactoryTest {
|
||||
|
@ -35,7 +35,7 @@ public class VitroFiltersFactoryTest {
|
|||
DateTime easyDate = new org.joda.time.DateTime(2005,1,1,0,0,0,0); //2005-01-01
|
||||
Date givenDate = easyDate.toDate();
|
||||
|
||||
VitroFilters vf = VitroFilterUtils.getSunsetWindowFilter(givenDate);
|
||||
VitroFilters vf = FiltersForTabs.getSunsetWindowFilter(givenDate);
|
||||
Assert.assertNotNull(vf);
|
||||
checkFilterForNull(vf);
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class VitroFiltersFactoryTest {
|
|||
DateTime easyDate = new org.joda.time.DateTime(2005,1,1,0,0,0,0); //2005-01-01
|
||||
Date givenDate = easyDate.toDate();
|
||||
|
||||
VitroFilters vf = VitroFilterUtils.getSunsetWindowFilter(givenDate);
|
||||
VitroFilters vf = FiltersForTabs.getSunsetWindowFilter(givenDate);
|
||||
Assert.assertNotNull(vf);
|
||||
checkFilterForNull(vf);
|
||||
|
||||
|
@ -196,39 +196,7 @@ public class VitroFiltersFactoryTest {
|
|||
|
||||
private int portalId2Numeric(long i) {
|
||||
return (int)FlagMathUtils.portalId2Numeric( i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalsFilter(){
|
||||
VitroFilters vf = VitroFilterUtils.getCalsPortalFilter();
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
|
||||
ind.setFlag1Numeric(0);
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(1) );
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(2));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(3));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(4));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(5));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(6));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
ind.setFlag1Numeric( portalId2Numeric(7));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == REJECT);
|
||||
|
||||
ind.setFlag1Numeric( portalId2Numeric(2) + portalId2Numeric(1));
|
||||
Assert.assertTrue(vf.getIndividualFilter().fn(ind) == ACCEPT);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void checkFilterForNull(VitroFilters vf){
|
||||
Assert.assertNotNull("filter was null", vf);
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.dao.filtering.filters;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.flags.PortalFlag;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WebappDaoFilteringPortalTest {
|
||||
String[][] entsDef = {
|
||||
// entity name flag 1 numeric
|
||||
{"0", "only in portal 1", Long.toString( portalId2Numeric(1) )},
|
||||
{"1", "In portal 1 and 2", Long.toString( portalId2Numeric(1) + portalId2Numeric(2) )},
|
||||
{"2", "in portal 3", Long.toString( portalId2Numeric(3) )},
|
||||
{"3", "checked into no portal", "0"},
|
||||
{"4", "checked into portal 4", Long.toString( portalId2Numeric(4) )},
|
||||
{"5", "checked into 1 and 4", Long.toString( portalId2Numeric(1) + portalId2Numeric(4) )},
|
||||
{"6", "checked into 4", Long.toString( portalId2Numeric(4) )},
|
||||
{"7", "checked into 5", Long.toString( portalId2Numeric(5) )},
|
||||
|
||||
};
|
||||
|
||||
List <Individual> ents = new ArrayList (10);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
//we need something that makes classes
|
||||
for(String entA[] : entsDef){
|
||||
Individual ent = new IndividualImpl();
|
||||
ent.setName("Item " + entA[0] + ": " + entA[1]);
|
||||
ent.setFlag1Numeric( Integer.parseInt(entA[2]) );
|
||||
ents.add(ent);
|
||||
}
|
||||
}
|
||||
|
||||
private long portalId2Numeric(long i) {
|
||||
return FlagMathUtils.portalId2Numeric( i);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPortal(){
|
||||
//Is it in portal 2 (aka numeric portal 4, in vivo 'life sci' ) ?
|
||||
PortalFlag f = new PortalFlag( 2 );
|
||||
VitroFilters vf = VitroFilterUtils.getFilterFromPortalFlag(f);
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
|
||||
//Is it in portal 1 (aka numeric portal 2, in vivo 'vivo portal' ) ?
|
||||
f = new PortalFlag(1);
|
||||
vf = VitroFilterUtils.getFilterFromPortalFlag(f);
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllPorta(){
|
||||
VitroFilters vf = VitroFilterUtils.getCalsPortalFilter();
|
||||
Assert.assertNotNull( vf );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(0) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(1) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(2) ) );
|
||||
Assert.assertFalse( vf.getIndividualFilter().fn( ents.get(3) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(4) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(5) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(6) ) );
|
||||
Assert.assertTrue( vf.getIndividualFilter().fn( ents.get(7) ) );
|
||||
}
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.utils;
|
||||
|
||||
import net.sf.jga.fn.UnaryFunctor;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Individual;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||
import edu.cornell.mannlib.vitro.webapp.beans.Tab;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FiltersForTabs;
|
||||
|
||||
/**
|
||||
* User: bdc34
|
||||
* Date: Dec 13, 2007
|
||||
* Time: 2:47:03 PM
|
||||
*/
|
||||
public class FiltersForTabsTest {
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTabCollegeFiltering(){
|
||||
String flags [] = {"CALS","BOAK","FUNGORK","MACAWI"};
|
||||
UnaryFunctor<Individual,Boolean> testFn =
|
||||
FiltersForTabs.getCollegeFilter(flags);
|
||||
Assert.assertTrue ( testFn!=null);
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("BOAK");
|
||||
Assert.assertTrue( testFn.fn(ind) == true);
|
||||
|
||||
ind.setFlag2Set("");
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("CALS,BOAK,FUNGORK");
|
||||
Assert.assertTrue(testFn.fn(ind) == true);
|
||||
|
||||
ind.setFlag2Set("FINKLY,HAPTO,FOOTOP");
|
||||
Assert.assertTrue(testFn.fn(ind) == false);
|
||||
|
||||
ind.setFlag2Set("FINKLY,HAPTO,FOOTOP,CALS");
|
||||
Assert.assertTrue(testFn.fn(ind) == true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCollegeFilterCreation(){
|
||||
Tab tab = new Tab();
|
||||
tab.setFlag2Set("CALS,BOAK,FUNGORK");
|
||||
tab.setPortalId(7);
|
||||
|
||||
UnaryFunctor<Individual,Boolean> testFn =
|
||||
FiltersForTabs.getFilterForTab(tab, new Portal(), false);
|
||||
Assert.assertTrue ( testFn!=null);
|
||||
|
||||
|
||||
IndividualImpl ind = new IndividualImpl();
|
||||
Assert.assertFalse( testFn.fn( ind) );
|
||||
|
||||
ind.setFlag2Set("CALS");
|
||||
ind.setFlag1Numeric((int)FlagMathUtils.portalId2Numeric( tab.getPortalId() ));
|
||||
|
||||
DateTime dt = new DateTime();
|
||||
ind.setSunrise(dt.minusDays(1000).toDate());
|
||||
ind.setSunset(dt.plusDays(1000).toDate());
|
||||
Assert.assertTrue( testFn.fn( ind));
|
||||
|
||||
tab.setFlag2Mode("OMIT");
|
||||
testFn = FiltersForTabs.getFilterForTab(tab, new Portal(), false);
|
||||
|
||||
Assert.assertFalse( testFn.fn(ind));
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue