Example usage for org.apache.commons.lang BooleanUtils isTrue

List of usage examples for org.apache.commons.lang BooleanUtils isTrue

Introduction

In this page you can find the example usage for org.apache.commons.lang BooleanUtils isTrue.

Prototype

public static boolean isTrue(Boolean bool) 

Source Link

Document

Checks if a Boolean value is true, handling null by returning false.

 BooleanUtils.isTrue(Boolean.TRUE)  = true BooleanUtils.isTrue(Boolean.FALSE) = false BooleanUtils.isTrue(null)          = false 

Usage

From source file:org.talend.repository.services.export.BuildDataServiceHandler.java

protected boolean isOptionChoosed(Object key) {
    if (key != null) {
        final Object object = exportChoice.get(key);
        if (object instanceof Boolean) {
            return BooleanUtils.isTrue((Boolean) object);
        }//from  ww w.  java  2  s.  c o m
    }
    return false;
}

From source file:org.tsm.concharto.web.edit.EventController.java

@SuppressWarnings("unchecked")
@Override//from  w  w  w  .ja v a2  s .  c  o m
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    EventForm eventForm = (EventForm) command;

    Map model = errors.getModel();
    if (BooleanUtils.isTrue(eventForm.getShowPreview())) {
        Event event = EventFormFactory.createEvent(eventForm);
        EventFormFactory.renderWiki(event, request);
        //for processing the drop down selector for positional accuracies
        addAccuracies(model);
        if (null != event.getPositionalAccuracy()) {
            event.setPositionalAccuracy(
                    (PositionalAccuracy) eventDao.getPositionalAccuracy(event.getPositionalAccuracy().getId()));
        }
        eventForm.setPreviewEvent(JSONFormat.toJSON(event));
        return new ModelAndView(getFormView(), model);
    } else if (errors.hasErrors()) {
        addAccuracies(model);
        return new ModelAndView(getFormView(), model);
    } else {
        //change the map center of the search form to wherever we are now!       
        EventSearchForm eventSearchForm = getEventSearchForm(request);
        if (eventSearchForm == null) {
            eventSearchForm = new EventSearchForm();
        }
        //now create or update the event
        Event event;
        if (eventForm.getEventId() != null) {
            //get the event from the session
            event = (Event) WebUtils.getSessionAttribute(request, SESSION_EVENT);
            event = EventFormFactory.updateEvent(event, eventForm);
        } else {
            event = EventFormFactory.createEvent(eventForm);
        }
        //get the catalog from the URL
        event.setCatalog(CatalogUtil.getCatalog(request));
        this.eventDao.saveOrUpdate(event);
        //update the tag cloud
        this.tagAggregateService.refreshRecent(CatalogUtil.getCatalog(request));
        //update the session
        eventSearchForm.setDisplayEventId(event.getId()); //we want to show only the event we've just edited  
        WebUtils.setSessionAttribute(request, SESSION_EVENT, event);
        WebUtils.setSessionAttribute(request, SearchHelper.SESSION_EVENT_SEARCH_FORM, eventSearchForm);
        WebUtils.setSessionAttribute(request, SearchHelper.SESSION_DO_SEARCH_ON_SHOW, true);
        return new ModelAndView(getSuccessView());
    }
}

From source file:org.tsm.concharto.web.eventsearch.EventSearchController.java

@SuppressWarnings("unchecked")
@Override//  w  ww . j a  v a 2 s. c o  m
protected ModelAndView processFormSubmission(HttpServletRequest request, HttpServletResponse response,
        Object command, BindException errors) throws Exception {
    EventSearchForm eventSearchForm = (EventSearchForm) command;
    //reset zoom and map center overrides, they are only used for get strings
    eventSearchForm.setMapCenterOverride(false);
    eventSearchForm.setZoomOverride(false);
    //reset the tag (which is a hidden form input) unless we are paging with display tag, in which
    //case we need to remember the tag
    if (null == DisplayTagHelper.getPageParameterId(request, SearchHelper.DISPLAYTAG_TABLE_ID)) {
        eventSearchForm.setUserTag(null);
    }
    eventSearchForm.setKml(false);
    ModelAndView returnModelAndView;
    if (errors.hasErrors()) {
        if (log.isDebugEnabled()) {
            log.debug("Data binding errors: " + errors.getErrorCount());
        }
        //clear out the search results
        eventSearchForm.setSearchResults(null);
        Map model = errors.getModel();
        model.put(SearchHelper.MODEL_TOTAL_RESULTS, 0);
        returnModelAndView = new ModelAndView(getFormView(), model);
    } else {
        log.debug("No errors -> processing submit");
        if ((eventSearchForm.getIsAddEvent() != null) && (eventSearchForm.getIsAddEvent())) {
            //we are creating a new event
            eventSearchForm.setIsAddEvent(false);
            //todo may want to inject the view here
            returnModelAndView = new ModelAndView(
                    new RedirectView(request.getContextPath() + "/edit/event.htm?add"));
        } else if ((null != eventSearchForm.getEditEventId())) {
            //we are editing an event
            long id = eventSearchForm.getEditEventId();
            eventSearchForm.setEditEventId(null); //reset
            //todo may want to inject the view here
            returnModelAndView = new ModelAndView(
                    new RedirectView(request.getContextPath() + "/edit/event.htm?id=" + id));
        } else {
            //This is a normal search
            //if this is a GET search, we must first process the query parameters
            if ((!StringUtils.isEmpty(request.getQueryString()) && (null == DisplayTagHelper
                    .getPageParameterId(request, SearchHelper.DISPLAYTAG_TABLE_ID)))) {
                handleGet(request, eventSearchForm);
            }
            //now search
            Map model = doSearch(request, errors, eventSearchForm);

            //fit the map to the search results if they specified a place name
            if (!StringUtils.isEmpty(eventSearchForm.getWhere())) {
                eventSearchForm.setLimitWithinMapBounds(false);
            }
            if (BooleanUtils.isTrue(eventSearchForm.getKml())) {
                //they just want a kml file
                ByteArrayOutputStream kmlOutputStream = new ByteArrayOutputStream();
                OutputStreamWriter outputStreamWriter = new OutputStreamWriter(kmlOutputStream, "UTF-8");
                List<Event> events = (List<Event>) model.get(SearchHelper.MODEL_EVENTS);
                KmlFormat.toKML(events, outputStreamWriter, "Concharto.com search results",
                        "NOTE: all events are time coded, so you may need to adjust the time slider.",
                        UrlFormat.getBasepath(request));
                //throw away the current model, we aren't rendering and just add the kml. 
                //TODO - fix this hack
                model = errors.getModel();
                String utf8Kml = new String(kmlOutputStream.toByteArray(), "UTF8");
                model.put(MODEL_KML, utf8Kml);
                returnModelAndView = new ModelAndView(getKmlView(), model);
            } else {
                //we are rendering to a normal page
                // needed so the displaytag paging can work
                displayTagModelElements(model, request);

                // this is because of a wierd problem in our JSTL where ${pageContex.request.requestURI} yields
                // WEB-INF/jsp/search/eventsearch.jsp instead of the expected /search/eventsearch.htm or 
                // /list/event.htm.  So here we have to put it in the model for the jsp to use
                model.put(PARM_REAL_URI, request.getRequestURI());
                returnModelAndView = new ModelAndView(getSuccessView(), model);
            }
        }
    }

    //put the data into the session in case we are leaving to edit, and then want to come back
    WebUtils.setSessionAttribute(request, SearchHelper.SESSION_EVENT_SEARCH_FORM, eventSearchForm);
    return returnModelAndView;
}

From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * Search for events and return results in the model.  Some search results are also put in the form
 * so that the javascript functions may use them.
 * /*from   w  w  w.  j a  v a2 s.  c o m*/
  * @param mapKey google api key
 * @param request request
 * @param model model containing search results
 * @param eventSearchForm form containing search parameters and search results    
 * @return a list of Event objects
 */
@SuppressWarnings("unchecked")
public List<Event> doSearch(String mapKey, HttpServletRequest request, Map model,
        EventSearchForm eventSearchForm) {
    /*
     * 1. Get the lat-long bounding box of whatever zoom
     * level we are at. 2. Parse the time field to extract a time range 3.
     * Do a search to find the count of all events within that text filter,
     * time range and bounding box
     * TODO cache the total results if nothing has changed (e.g. pagination)
     */
    List<Event> events;
    Long totalResults;
    Integer firstRecord;
    if (eventSearchForm.getDisplayEventId() != null) {
        Event event = eventSearchService.findById(eventSearchForm.getDisplayEventId());
        events = new ArrayList<Event>();
        events.add(event);
        eventSearchForm.setMapCenter(event.getTsGeometry().getGeometry().getCentroid());
        //Don't override the zoom for polylines or polygons no matter what.  Otherwise, there is too
        //much opportunity for confusion.  For example, the centroid of the polyline may be nowhere 
        //near the border in which case you won't see the line at all.
        if (event.getTsGeometry().getGeometry() instanceof Point) {
            eventSearchForm.setMapCenterOverride(true);
            eventSearchForm.setZoomOverride(true);
        } else {
            eventSearchForm.setMapCenterOverride(false);
            eventSearchForm.setZoomOverride(false);
        }
        eventSearchForm.setMapZoom(event.getZoomLevel());
        eventSearchForm.setMapType(event.getMapType());
        totalResults = 1L;
        firstRecord = 0;
        //now remove the id from the form - we don't want to get stuck forever showing this event
        //the browser javascript still needs the event id so it can crate a linkHere url, so we make
        //a copy of the id
        eventSearchForm.setLinkHereEventId(eventSearchForm.getDisplayEventId());
        eventSearchForm.setDisplayEventId(null);

    } else {
        eventSearchForm.setLinkHereEventId(null);
        eventSearchForm.setDisplayEventId(null);
        if (eventSearchForm.getMapCenter() == null) {
            //geocode
            try {
                geocode(mapKey, request, eventSearchForm);
            } catch (IOException e) {
                //TODO, perhaps some better error handling here??
                log.info("Exception geocoding location " + eventSearchForm.getWhere() + e);
            }
        }
        //we are ok to go if IsGeocodeSuccess is null or True
        if (!BooleanUtils.isFalse(eventSearchForm.getIsGeocodeSuccess())) {
            firstRecord = DisplayTagHelper.getFirstRecord(request, DISPLAYTAG_TABLE_ID, DISPLAYTAG_PAGESIZE);
            LatLngBounds bounds = getBounds(eventSearchForm);
            SearchParams params = new SearchParams();
            params.setTextFilter(eventSearchForm.getWhat());
            params.setUserTag(eventSearchForm.getUserTag());
            params.setTimeRange(eventSearchForm.getWhen());
            params.setVisibility(getVisibility(eventSearchForm));
            params.setCatalog(CatalogUtil.getCatalog(request));
            //note these are opposites.. a value of null or false = false, true=true
            params.setIncludeTimeRangeOverlaps(
                    !BooleanUtils.isTrue(eventSearchForm.getExcludeTimeRangeOverlaps()));
            events = eventSearchService.search(DISPLAYTAG_PAGESIZE, firstRecord, bounds, params);

            //for debugging
            //addDebugBoundingBox(events, bounds);

            totalResults = eventSearchService.getCount(bounds, params);
        } else {
            //failed geocode, no points
            events = new ArrayList<Event>();
            totalResults = 0L;
            firstRecord = 0;
        }

    }

    prepareModel(model, events, totalResults, firstRecord);
    //NOTE: we are putting the events into the command so that the page javascript
    //functions can properly display them using google's mapping API
    List<Event> renderedEvents = renderWiki(events, request);
    eventSearchForm.setSearchResults(JSONFormat.toJSON(renderedEvents));

    setupPageTitle(request, eventSearchForm, model, events);
    return events;
}

From source file:org.tsm.concharto.web.eventsearch.SearchHelper.java

/**
 * Find the search bounding box.  It depends on the map center and zoom level.
 * @param eventSearchForm search form//w  w w .  j a v  a 2s . co  m
 * @return LatLngBounds search bounding box
 */
private LatLngBounds getBounds(EventSearchForm eventSearchForm) {
    //if we are below a certain zoom level, we will still search a wider area
    LatLngBounds bounds = null;
    if ((StringUtils.isEmpty(eventSearchForm.getWhere()))
            && BooleanUtils.isFalse(eventSearchForm.getLimitWithinMapBounds())) {
        //when they specify fit view to all results, we don't want a bounding box, unless
        //they also specify a place, in which case the geocode takes precedence
        return null;
    }

    //if we already have bounds
    if (hasBounds(eventSearchForm)) {
        //if there are no bounds or the user explicitly said to use those bounds
        if ((!zoomedInTooLow(eventSearchForm)
                || (BooleanUtils.isTrue(eventSearchForm.getLimitWithinMapBounds())))) {
            bounds = new LatLngBounds(eventSearchForm.getBoundingBoxSW(), eventSearchForm.getBoundingBoxNE());
        }
        //when we are zoomed in real low we want to search more than just the visible map, instead
        //use the a wider search radius
        else {
            bounds = searchBoxBounds(eventSearchForm);
        }
    } else if (null != eventSearchForm.getWhere()) {
        //there is a location, but no bounds, so we have to make them
        bounds = searchBoxBounds(eventSearchForm);
    }
    return bounds;
}

From source file:org.tsm.concharto.web.login.LoginController.java

@Override
protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,
        BindException errors) throws Exception {
    SignupForm signupForm = (SignupForm) command;
    User user = userDao.find(signupForm.getUsername());

    if ((user != null) && (PasswordUtil.isPasswordValid(signupForm.getPassword(), user.getPassword()))) {
        //matched username and password, ok to proceed
        log.info("user " + signupForm.getUsername() + " signed in");

        //first save the username and roles in the session            
        sessionHelper.setUserInSession(request, user);

        //if they checked "remember me" we set a cookie
        if (BooleanUtils.isTrue(signupForm.getRememberMe())) {
            setRemeberMeCookie(response, user, AuthHelper.COOKIE_REMEMBER_ME_MAX_AGE);
        } else {//from   w  w w.  jav  a2s . c o m
            setRemeberMeCookie(response, user, 0);
        }

        //now go where we were originally heading
        return LoginSignupHelper.continueToRequestedUrl(request);
    } else {
        /* NOTE we are doing validation here instead of the validator so that we don't have to 
         * go to the database twice to get the user object.
         */
        //tell the user there was a problem and let the default form handle the rest
        errors.rejectValue("username", "invalidUserPasswd.authForm.username");
        return new ModelAndView(getFormView(), errors.getModel());
    }
}

From source file:org.xlcloud.console.virtualClusters.controllers.wizard.utils.EditableVirtualClusterParameter.java

/**
 * Indicates whether the input for this parameter should be a password input
 * @return {@code true} if this is password input, {@code false} otherwise
 *//*  ww  w  .j a  v  a  2s.c  o  m*/
public boolean renderPassword() {
    return BooleanUtils.isTrue(templateParameter.getNoEcho());
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.AbstractProject.java

public boolean userCanRead(User user) {
    try {//w  w  w  .j a va 2s  .  c  om
        Boolean bool = false;
        if (BooleanUtils.isTrue(securityProfile.userCanRead(user))) {
            bool = true;
        }
        return bool;
    } catch (NullPointerException e) {
        return false;
    }
}

From source file:uk.ac.bbsrc.tgac.miso.core.data.impl.ProjectImpl.java

@Override
public boolean userCanRead(User user) {
    try {/*from  w ww . ja va 2  s  .c o  m*/
        Boolean bool = false;
        if (BooleanUtils.isTrue(securityProfile.userCanRead(user))) {
            bool = true;
        }
        return bool;
    } catch (NullPointerException e) {
        return false;
    }
}