Example usage for org.apache.commons.lang ObjectUtils toString

List of usage examples for org.apache.commons.lang ObjectUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ObjectUtils toString.

Prototype

public static String toString(Object obj) 

Source Link

Document

Gets the toString of an Object returning an empty string ("") if null input.

 ObjectUtils.toString(null)         = "" ObjectUtils.toString("")           = "" ObjectUtils.toString("bat")        = "bat" ObjectUtils.toString(Boolean.TRUE) = "true" 

Usage

From source file:org.jtalks.jcommune.service.transactional.TransactionalBannerService.java

/** {@inheritDoc} */
@Override/*from w  w  w. jav a 2s .c  o  m*/
public Map<String, Banner> getAllBanners() {
    Collection<Banner> allBanners = getDao().getAll();
    Map<String, Banner> positionAndBannerMap = new HashMap<String, Banner>();
    for (Banner banner : allBanners) {
        BannerPosition positionOnPage = banner.getPositionOnPage();
        positionAndBannerMap.put(ObjectUtils.toString(positionOnPage), banner);
    }
    return positionAndBannerMap;
}

From source file:org.kuali.kfs.module.bc.document.service.impl.SalarySettingRuleHelperServiceImpl.java

/**
 * @see org.kuali.kfs.module.bc.document.service.SalarySettingRuleHelperService#hasValidRequestedFundingMonth(org.kuali.kfs.module.bc.businessobject.PendingBudgetConstructionAppointmentFunding,
 *      org.kuali.core.util.MessageMap)//from   w  w w  . j  ava 2 s  .  co  m
 */
public boolean hasValidRequestedFundingMonth(PendingBudgetConstructionAppointmentFunding appointmentFunding,
        MessageMap errorMap) {
    Integer fundingMonths = appointmentFunding.getAppointmentFundingMonth();
    if (fundingMonths == null) {
        errorMap.putError(BCPropertyConstants.APPOINTMENT_FUNDING_MONTH,
                BCKeyConstants.ERROR_EMPTY_FUNDIN_MONTH);
        return false;
    }

    // Requested funding months must be between 0 and position normal work months if there is a leave
    String leaveDurationCode = appointmentFunding.getAppointmentFundingDurationCode();
    Integer normalWorkMonths = appointmentFunding.getBudgetConstructionPosition().getIuNormalWorkMonths();
    if (!StringUtils.equals(leaveDurationCode, NONE.durationCode)) {
        if (fundingMonths < 0 || fundingMonths > normalWorkMonths) {
            errorMap.putError(BCPropertyConstants.APPOINTMENT_FUNDING_MONTH,
                    BCKeyConstants.ERROR_FUNDIN_MONTH_NOT_IN_RANGE, ObjectUtils.toString(fundingMonths), "0",
                    ObjectUtils.toString(normalWorkMonths));
            return false;
        }

        return true;
    }

    // Requested funding months must equal to position normal work months if no leave
    if (!fundingMonths.equals(normalWorkMonths)) {
        errorMap.putError(BCPropertyConstants.APPOINTMENT_FUNDING_MONTH,
                BCKeyConstants.ERROR_NOT_EQUAL_NORMAL_WORK_MONTHS, ObjectUtils.toString(fundingMonths),
                ObjectUtils.toString(normalWorkMonths));
        return false;
    }

    return true;
}

From source file:org.kuali.kfs.module.ec.businessobject.inquiry.EffortLedgerBalanceInquirableImpl.java

/**
 * @see org.kuali.kfs.gl.businessobject.inquiry.AbstractGeneralLedgerInquirableImpl#addMoreParameters(java.util.Properties, java.lang.String)
 *///  ww w  .j a  va2s. c  o  m
@Override
protected void addMoreParameters(Properties parameter, String attributeName) {
    BusinessObject businessObject = this.getBusinessObject();
    EffortCertificationDocument document = null;

    if (businessObject instanceof EffortCertificationDetailBuild) {
        EffortCertificationDetailBuild effortCertificationDetail = (EffortCertificationDetailBuild) businessObject;
        document = effortCertificationDetail.getEffortCertificationDocumentBuild();
    } else if (businessObject instanceof EffortCertificationDetail) {
        EffortCertificationDetail effortCertificationDetail = (EffortCertificationDetail) businessObject;
        document = effortCertificationDetail.getEffortCertificationDocument();
    }

    if (document != null) {
        parameter.put(KFSPropertyConstants.UNIVERSITY_FISCAL_YEAR,
                ObjectUtils.toString(document.getUniversityFiscalYear()));
        parameter.put(EffortPropertyConstants.EFFORT_CERTIFICATION_REPORT_NUMBER,
                document.getEffortCertificationReportNumber());
        parameter.put(KFSPropertyConstants.EMPLID, document.getEmplid());
    }
}

From source file:org.kuali.kfs.sys.DynamicCollectionComparator.java

/**
 * compare the two given objects for order. Returns a negative integer, zero, or a positive integer as this object is less than,
 * equal to, or greater than the specified object. If the objects implement Comparable interface, the objects compare with each
 * other based on the implementation; otherwise, the objects will be converted into Strings and compared as String.
 *//*w  w w.  j  a  va  2s .com*/
public int compare(T object0, T object1, String fieldName) {
    int comparisonResult = 0;

    try {
        Object propery0 = PropertyUtils.getProperty(object0, fieldName);
        Object propery1 = PropertyUtils.getProperty(object1, fieldName);

        if (propery0 == null && propery1 == null) {
            comparisonResult = 0;
        } else if (propery0 == null) {
            comparisonResult = -1;
        } else if (propery1 == null) {
            comparisonResult = 1;
        } else if (propery0 instanceof Comparable) {
            Comparable comparable0 = (Comparable) propery0;
            Comparable comparable1 = (Comparable) propery1;

            comparisonResult = comparable0.compareTo(comparable1);
        } else {
            String property0AsString = ObjectUtils.toString(propery0);
            String property1AsString = ObjectUtils.toString(propery1);

            comparisonResult = property0AsString.compareTo(property1AsString);
        }
    } catch (IllegalAccessException e) {
        throw new RuntimeException("unable to compare property: " + fieldName, e);
    } catch (InvocationTargetException e) {
        throw new RuntimeException("unable to compare property: " + fieldName, e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException("unable to compare property: " + fieldName, e);
    }

    return comparisonResult * this.getSortOrderAsNumber();
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaBoLookupableHelperService.java

/**
 * Loads a saved search//w ww. j av  a2s  .co m
 * @return returns true on success to run the loaded search, false on error.
 */
protected boolean loadSavedSearch(boolean ignoreErrors) {
    Map<String, String[]> fieldValues = new HashMap<String, String[]>();

    String savedSearchName = getSavedSearchName();
    if (StringUtils.isEmpty(savedSearchName) || "*ignore*".equals(savedSearchName)) {
        if (!ignoreErrors) {
            GlobalVariables.getMessageMap().putError(SAVED_SEARCH_NAME_PARAM, RiceKeyConstants.ERROR_CUSTOM,
                    "You must select a saved search");
        } else {
            //if we're ignoring errors and we got an error just return, no reason to continue.  Also set false to indicate not to perform lookup
            return false;
        }
        getFormFields().setFieldValue(SAVED_SEARCH_NAME_PARAM, "");
    }
    if (!GlobalVariables.getMessageMap().hasNoErrors()) {
        throw new ValidationException("errors in search criteria");
    }

    DocumentSearchCriteria criteria = KEWServiceLocator.getDocumentSearchService()
            .getSavedSearchCriteria(GlobalVariables.getUserSession().getPrincipalId(), savedSearchName);

    // get the document type
    String docTypeName = criteria.getDocumentTypeName();

    // update the parameters to include whether or not this is an advanced search
    if (this.getParameters().containsKey(KRADConstants.ADVANCED_SEARCH_FIELD)) {
        Map<String, String[]> parameters = this.getParameters();
        String[] params = (String[]) parameters.get(KRADConstants.ADVANCED_SEARCH_FIELD);
        if (ArrayUtils.isNotEmpty(params)) {
            params[0] = criteria.getIsAdvancedSearch();
            this.setParameters(parameters);
        }
    }

    // and set the rows based on doc type
    setRows(docTypeName);

    // clear the name of the search in the form
    //fieldValues.put(SAVED_SEARCH_NAME_PARAM, new String[0]);

    // set the custom document attribute values on the search form
    for (Map.Entry<String, List<String>> entry : criteria.getDocumentAttributeValues().entrySet()) {
        fieldValues.put(entry.getKey(), entry.getValue().toArray(new String[entry.getValue().size()]));
    }

    // sets the field values on the form, trying criteria object properties if a field value is not present in the map
    for (Field field : getFormFields().getFields()) {
        if (field.getPropertyName() != null && !field.getPropertyName().equals("")) {
            // UI Fields know whether they are single or multiple value
            // just set both so they can make the determination and render appropriately
            String[] values = null;
            if (fieldValues.get(field.getPropertyName()) != null) {
                values = fieldValues.get(field.getPropertyName());
            } else {
                //may be on the root of the criteria object, try looking there:
                try {
                    if (field.isRanged() && field.isDatePicker()) {
                        if (field.getPropertyName()
                                .startsWith(KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX)) {
                            String lowerBoundName = field.getPropertyName().replace(
                                    KRADConstants.LOOKUP_RANGE_LOWER_BOUND_PROPERTY_PREFIX, "") + "From";
                            Object lowerBoundDate = PropertyUtils.getProperty(criteria, lowerBoundName);
                            if (lowerBoundDate != null) {
                                values = new String[] { CoreApiServiceLocator.getDateTimeService()
                                        .toDateTimeString(((org.joda.time.DateTime) lowerBoundDate).toDate()) };
                            }
                        } else {
                            // the upper bound prefix may or may not be on the propertyName.  Using "replace" just in case.
                            String upperBoundName = field.getPropertyName()
                                    .replace(KRADConstants.LOOKUP_RANGE_UPPER_BOUND_PROPERTY_PREFIX, "") + "To";
                            Object upperBoundDate = PropertyUtils.getProperty(criteria, upperBoundName);
                            if (upperBoundDate != null) {
                                values = new String[] { CoreApiServiceLocator.getDateTimeService()
                                        .toDateTimeString(((org.joda.time.DateTime) upperBoundDate).toDate()) };
                            }
                        }
                    } else {
                        values = new String[] { ObjectUtils
                                .toString(PropertyUtils.getProperty(criteria, field.getPropertyName())) };
                    }
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                } catch (NoSuchMethodException e) {
                    // e.printStackTrace();
                    //hmm what to do here, we should be able to find everything either in the search atts or at the base as far as I know.
                }
            }
            if (values != null) {
                getFormFields().setFieldValue(field, values);
            }
        }
    }

    return true;
}

From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaTranslatorImpl.java

/**
 * Looks up a property on the criteria object and sets it as a key/value pair in the values Map
 * @param criteria the DocumentSearchCriteria
 * @param property the DocumentSearchCriteria property name
 * @param fieldName the destination field name
 * @param values the map of values to update
 *///from   ww w  .j  a v  a  2  s . c om
protected static void convertCriteriaPropertyToField(DocumentSearchCriteria criteria, String property,
        String fieldName, Map<String, String[]> values) {
    try {
        Object val = PropertyUtils.getProperty(criteria, property);
        if (val != null) {
            values.put(fieldName, new String[] { ObjectUtils.toString(val) });
        }
    } catch (NoSuchMethodException nsme) {
        LOG.error("Error reading property '" + property + "' of criteria", nsme);
    } catch (InvocationTargetException ite) {
        LOG.error("Error reading property '" + property + "' of criteria", ite);
    } catch (IllegalAccessException iae) {
        LOG.error("Error reading property '" + property + "' of criteria", iae);

    }
}

From source file:org.kuali.rice.kns.web.struts.action.KualiAction.java

/**
 * Handles rendering a question prompt - with a specified context.
 *
 * @param mapping//w  w w  .j a  v  a 2s.co  m
 * @param form
 * @param request
 * @param response
 * @param questionId
 * @param questionText
 * @param questionType
 * @param caller
 * @param context
 * @param showReasonField
 * @param reason
 * @param errorKey
 * @param errorPropertyName
 * @param errorParameter
 * @return ActionForward
 * @throws Exception
 */
private ActionForward performQuestion(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response, String questionId, String questionText, String questionType,
        String caller, String context, boolean showReasonField, String reason, String errorKey,
        String errorPropertyName, String errorParameter) throws Exception {
    Properties parameters = new Properties();

    parameters.put(KRADConstants.DISPATCH_REQUEST_PARAMETER, "start");
    parameters.put(KRADConstants.DOC_FORM_KEY,
            GlobalVariables.getUserSession().addObjectWithGeneratedKey(form));
    parameters.put(KRADConstants.CALLING_METHOD, caller);
    parameters.put(KRADConstants.QUESTION_INST_ATTRIBUTE_NAME, questionId);
    parameters.put(KRADConstants.QUESTION_IMPL_ATTRIBUTE_NAME, questionType);
    //parameters.put(KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME, questionText);
    parameters.put(KRADConstants.RETURN_LOCATION_PARAMETER, getReturnLocation(request, mapping));
    parameters.put(KRADConstants.QUESTION_CONTEXT, context);
    parameters.put(KRADConstants.QUESTION_SHOW_REASON_FIELD, Boolean.toString(showReasonField));
    parameters.put(KRADConstants.QUESTION_REASON_ATTRIBUTE_NAME, reason);
    parameters.put(KRADConstants.QUESTION_ERROR_KEY, errorKey);
    parameters.put(KRADConstants.QUESTION_ERROR_PROPERTY_NAME, errorPropertyName);
    parameters.put(KRADConstants.QUESTION_ERROR_PARAMETER, errorParameter);
    parameters.put(KRADConstants.QUESTION_ANCHOR,
            form instanceof KualiForm ? ObjectUtils.toString(((KualiForm) form).getAnchor()) : "");
    Object methodToCallAttribute = request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE);
    if (methodToCallAttribute != null) {
        parameters.put(KRADConstants.METHOD_TO_CALL_PATH, methodToCallAttribute);
        ((PojoForm) form).registerEditableProperty(String.valueOf(methodToCallAttribute));
    }

    if (form instanceof KualiDocumentFormBase) {
        String docNum = ((KualiDocumentFormBase) form).getDocument().getDocumentNumber();
        if (docNum != null) {
            parameters.put(KRADConstants.DOC_NUM,
                    ((KualiDocumentFormBase) form).getDocument().getDocumentNumber());
        }
    }

    // KULRICE-8077: PO Quote Limitation of Only 9 Vendors
    String questionTextAttributeName = KRADConstants.QUESTION_TEXT_ATTRIBUTE_NAME + questionId;
    GlobalVariables.getUserSession().addObject(questionTextAttributeName, (Object) questionText);

    String questionUrl = UrlFactory
            .parameterizeUrl(getApplicationBaseUrl() + "/kr/" + KRADConstants.QUESTION_ACTION, parameters);
    return new ActionForward(questionUrl, true);
}

From source file:org.marketcetera.client.ClientImpl.java

void notifyExecutionReport(ExecutionReport inReport) {
    SLF4JLoggerProxy.debug(TRAFFIC, "Received Exec Report:{}", inReport); //$NON-NLS-1$
    synchronized (mReportListeners) {
        for (ReportListener listener : mReportListeners) {
            try {
                listener.receiveExecutionReport(inReport);
            } catch (Throwable t) {
                Messages.LOG_ERROR_RECEIVE_EXEC_REPORT.warn(this, t, ObjectUtils.toString(inReport));
                ExceptUtils.interrupt(t);
            }//from ww w . j  a  v a 2 s.c  o  m
        }
    }
}

From source file:org.marketcetera.client.ClientImpl.java

void notifyCancelReject(OrderCancelReject inReport) {
    SLF4JLoggerProxy.debug(TRAFFIC, "Received Cancel Reject:{}", inReport); //$NON-NLS-1$
    synchronized (mReportListeners) {
        for (ReportListener listener : mReportListeners) {
            try {
                listener.receiveCancelReject(inReport);
            } catch (Throwable t) {
                Messages.LOG_ERROR_RECEIVE_CANCEL_REJECT.warn(this, t, ObjectUtils.toString(inReport));
                ExceptUtils.interrupt(t);
            }/*from   w  w w .  ja  v a 2s.  c  o  m*/
        }
    }
}

From source file:org.marketcetera.client.ClientImpl.java

void notifyBrokerStatus(BrokerStatus status) {
    SLF4JLoggerProxy.debug(TRAFFIC, "Received Broker Status:{}", status); //$NON-NLS-1$
    synchronized (mBrokerStatusListeners) {
        for (BrokerStatusListener listener : mBrokerStatusListeners) {
            try {
                listener.receiveBrokerStatus(status);
            } catch (Throwable t) {
                Messages.LOG_ERROR_RECEIVE_BROKER_STATUS.warn(this, t, ObjectUtils.toString(status));
                ExceptUtils.interrupt(t);
            }//from  w  ww. j  a v  a 2s. c o  m
        }
    }
}