Merge to trunk. Fixing tab flag 1 filtering when there is only one portal. NIHVIVO-987

This commit is contained in:
bdc34 2010-07-23 21:04:08 +00:00
parent ef3222d0d1
commit 5671656d5d
6 changed files with 24 additions and 14 deletions

View file

@ -10,6 +10,7 @@ import java.util.Set;
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean; import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
import edu.cornell.mannlib.vitro.webapp.beans.Tab; import edu.cornell.mannlib.vitro.webapp.beans.Tab;
import edu.cornell.mannlib.vitro.webapp.dao.ApplicationDao;
import edu.cornell.mannlib.vitro.webapp.dao.PortalDao; import edu.cornell.mannlib.vitro.webapp.dao.PortalDao;
import edu.cornell.mannlib.vitro.webapp.dao.TabDao; import edu.cornell.mannlib.vitro.webapp.dao.TabDao;
import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FiltersForTabs; import edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FiltersForTabs;
@ -22,10 +23,12 @@ public class TabDaoFiltering extends BaseFiltering implements TabDao{
final TabDao innerDao; final TabDao innerDao;
final VitroFilters filters; final VitroFilters filters;
private PortalDao innerPortalDao; private PortalDao innerPortalDao;
private ApplicationDao applicationDao;
public TabDaoFiltering(TabDao tabDao, PortalDao portalDao, VitroFilters filters) { public TabDaoFiltering(TabDao tabDao, PortalDao portalDao, ApplicationDao applicationDao, VitroFilters filters) {
this.innerPortalDao = portalDao; this.innerPortalDao = portalDao;
this.innerDao = tabDao; this.innerDao = tabDao;
this.applicationDao = applicationDao;
this.filters = filters; this.filters = filters;
} }
@ -195,13 +198,15 @@ public class TabDaoFiltering extends BaseFiltering implements TabDao{
if( in.grabEntityFactory() == null ) if( in.grabEntityFactory() == null )
return in; return in;
else{ else{
boolean flag1Filtering = applicationDao.isFlag1Active(); //( !applicationDao.isFlag1Active() || innerPortalDao.getAllPortals().size() == 1 );
/* NOTICE: this does not use the individualFilter that was passed in the constructor /* NOTICE: this does not use the individualFilter that was passed in the constructor
it uses one based on the parameters of the tab. */ it uses one based on the parameters of the tab. */
boolean ascendingSort = !"desc".equalsIgnoreCase(in.getEntitySortDirection()); boolean ascendingSort = !"desc".equalsIgnoreCase(in.getEntitySortDirection());
TabEntityFactoryFiltering filteringFact = TabEntityFactoryFiltering filteringFact =
new TabEntityFactoryFiltering( new TabEntityFactoryFiltering(
in.grabEntityFactory(), in.grabEntityFactory(),
FiltersForTabs.getFilterForTab( in, innerPortalDao.getPortal(in.getPortalId())), FiltersForTabs.getFilterForTab( in, innerPortalDao.getPortal(in.getPortalId()), flag1Filtering ),
new VitroFilterUtils.EntitySortTransform( in.getEntitySortField(),ascendingSort)); new VitroFilterUtils.EntitySortTransform( in.getEntitySortField(),ascendingSort));
in.placeEntityFactory(filteringFact); in.placeEntityFactory(filteringFact);
} }

View file

@ -131,7 +131,7 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
public TabDao getTabDao() { public TabDao getTabDao() {
if( filteringTabDao == null) if( filteringTabDao == null)
filteringTabDao = filteringTabDao =
new TabDaoFiltering(innerWebappDaoFactory.getTabDao(),innerWebappDaoFactory.getPortalDao(),filters); new TabDaoFiltering(innerWebappDaoFactory.getTabDao(),innerWebappDaoFactory.getPortalDao(),innerWebappDaoFactory.getApplicationDao(),filters);
return filteringTabDao; return filteringTabDao;
} }

View file

@ -31,13 +31,14 @@ import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
*/ */
public class FiltersForTabs { public class FiltersForTabs {
public static final UnaryFunctor<Individual,String> firstLetterOfName = new FirstLetterOfEnt(); public static final UnaryFunctor<Individual,String> firstLetterOfName = new FirstLetterOfEnt();
public static UnaryFunctor<Individual,Boolean> getFilterForTab( final Tab tab, final Portal portalThatTabIsIn ){ public static UnaryFunctor<Individual,Boolean> getFilterForTab( final Tab tab, final Portal portalThatTabIsIn, final boolean isFlag1Filtering ){
DateTime now = new DateTime(); DateTime now = new DateTime();
UnaryFunctor<Individual,Boolean> entFilter = getTimeFilter(tab, now); UnaryFunctor<Individual,Boolean> entFilter = getTimeFilter(tab, now);
UnaryFunctor<Individual,Boolean> tabPortalFilter = getPortalFilter(tab); UnaryFunctor<Individual,Boolean> tabPortalFilter = getPortalFilter(tab);
if( tabPortalFilter != null && if( isFlag1Filtering &&
tabPortalFilter != null &&
portalThatTabIsIn != null && portalThatTabIsIn != null &&
portalThatTabIsIn.isFlag1Filtering() ) portalThatTabIsIn.isFlag1Filtering() )
entFilter = AdaptorFunctors.and( entFilter, tabPortalFilter ); entFilter = AdaptorFunctors.and( entFilter, tabPortalFilter );

View file

@ -22,15 +22,16 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
public boolean isFlag1Active() { public boolean isFlag1Active() {
boolean somePortalIsFiltering=false;
if (portalCount == null) { if (portalCount == null) {
boolean active = false; boolean active = false;
for (Portal p : getWebappDaoFactory().getPortalDao().getAllPortals()) { for (Portal p : getWebappDaoFactory().getPortalDao().getAllPortals()) {
if (p.isFlag1Filtering()) { if (p.isFlag1Filtering()) {
return true; somePortalIsFiltering = true;
} }
} }
} }
return false; return somePortalIsFiltering && getWebappDaoFactory().getPortalDao().getAllPortals().size() > 1;
} }

View file

@ -76,7 +76,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
WebappDaoFactory wadf = new WebappDaoFactoryJena(unionOms, defaultNamespace, null, null); WebappDaoFactory wadf = new WebappDaoFactoryJena(unionOms, defaultNamespace, null, null);
sce.getServletContext().setAttribute("webappDaoFactory",wadf); sce.getServletContext().setAttribute("webappDaoFactory",wadf);
ApplicationBean appBean = getApplicationBeanFromOntModel(memModel); ApplicationBean appBean = getApplicationBeanFromOntModel(memModel,wadf);
if (appBean != null) { if (appBean != null) {
sce.getServletContext().setAttribute("applicationBean", appBean); sce.getServletContext().setAttribute("applicationBean", appBean);
} }
@ -114,7 +114,7 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
public void contextDestroyed(ServletContextEvent sce) { public void contextDestroyed(ServletContextEvent sce) {
} }
private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel) { private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel,WebappDaoFactory wadf) {
ClosableIterator appIt = ontModel.listIndividuals(ResourceFactory.createResource(VitroVocabulary.APPLICATION)); ClosableIterator appIt = ontModel.listIndividuals(ResourceFactory.createResource(VitroVocabulary.APPLICATION));
try { try {
if (appIt.hasNext()) { if (appIt.hasNext()) {
@ -129,6 +129,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
try { try {
appBean.setMaxSharedPortalId(Integer.decode( ((Literal)appInd.getPropertyValue(ResourceFactory.createProperty(VitroVocabulary.APPLICATION_MAXSHAREDPORTALID))).getLexicalForm())); appBean.setMaxSharedPortalId(Integer.decode( ((Literal)appInd.getPropertyValue(ResourceFactory.createProperty(VitroVocabulary.APPLICATION_MAXSHAREDPORTALID))).getLexicalForm()));
} catch (Exception e) { /* ignore bad value */} } catch (Exception e) { /* ignore bad value */}
if( ! wadf.getApplicationDao().isFlag1Active() ){
appBean.setMaxPortalId(1);
}
return appBean; return appBean;
} else { } else {
return null; return null;

View file

@ -59,7 +59,7 @@ public class FiltersForTabsTest {
tab.setPortalId(7); tab.setPortalId(7);
UnaryFunctor<Individual,Boolean> testFn = UnaryFunctor<Individual,Boolean> testFn =
FiltersForTabs.getFilterForTab(tab, new Portal()); FiltersForTabs.getFilterForTab(tab, new Portal(), false);
Assert.assertTrue ( testFn!=null); Assert.assertTrue ( testFn!=null);
@ -75,7 +75,7 @@ public class FiltersForTabsTest {
Assert.assertTrue( testFn.fn( ind)); Assert.assertTrue( testFn.fn( ind));
tab.setFlag2Mode("OMIT"); tab.setFlag2Mode("OMIT");
testFn = FiltersForTabs.getFilterForTab(tab, new Portal()); testFn = FiltersForTabs.getFilterForTab(tab, new Portal(), false);
Assert.assertFalse( testFn.fn(ind)); Assert.assertFalse( testFn.fn(ind));