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, String nullStr) 

Source Link

Document

Gets the toString of an Object returning a specified text if null input.

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

Usage

From source file:org.emonocot.model.Annotation.java

@Override
public SolrInputDocument toSolrInputDocument() {
    SolrInputDocument sid = new SolrInputDocument();
    sid.addField("id", getClassName() + "_" + getId());
    sid.addField("base.id_l", getId());
    sid.addField("base.class_searchable_b", false);
    sid.addField("base.class_s", getClass().getName());
    sid.addField("annotation.job_id_l", getJobId());
    sid.addField("annotation.type_s", ObjectUtils.toString(getType(), null));
    sid.addField("annotation.record_type_s", ObjectUtils.toString(getRecordType(), null));
    sid.addField("annotation.code_s", ObjectUtils.toString(getCode(), null));
    StringBuilder summary = new StringBuilder().append(getType()).append(" ").append(getRecordType())
            .append(" ").append(getCode()).append(" ").append(getText());

    if (getAuthority() != null) {
        sid.addField("base.authority_s", getAuthority().getIdentifier());
        summary.append(" ").append(getAuthority().getIdentifier());
    }/*from   w  w w  . ja v  a  2  s .c o m*/

    sid.addField("searchable.solrsummary_t", summary.toString());
    return sid;
}

From source file:org.emonocot.model.Comment.java

@Override
public SolrInputDocument toSolrInputDocument() {
    SolrInputDocument sid = new SolrInputDocument();
    sid.addField("id", getClassName() + "_" + getId());
    sid.addField("base.id_l", getId());
    sid.addField("base.class_searchable_b", false);
    sid.addField("base.class_s", getClass().getName());
    if (getAboutData() != null) {
        sid.addField("comment.about_class_s", getAboutData().getClass().getName());
    }//from w  w w. ja va2  s. c o  m
    StringBuilder summary = new StringBuilder().append(getComment());
    if (getCommentPage() != null) {
        if (getCommentPage() instanceof Taxon) {
            sid.addField("comment.comment_page_class_s", "org.emonocot.model.Taxon");
            Taxon taxon = (Taxon) getCommentPage();
            summary.append(" ").append(" ").append(taxon.getClazz()).append(" ").append(taxon.getFamily())
                    .append(" ").append(taxon.getGenus()).append(" ").append(taxon.getKingdom()).append(" ")
                    .append(taxon.getOrder()).append(" ").append(taxon.getPhylum()).append(" ")
                    .append(taxon.getScientificName()).append(" ").append(taxon.getScientificNameAuthorship())
                    .append(" ").append(taxon.getSpecificEpithet()).append(" ").append(taxon.getSubfamily())
                    .append(" ").append(taxon.getSubgenus()).append(" ").append(taxon.getSubtribe()).append(" ")
                    .append(taxon.getTaxonomicStatus()).append(" ").append(taxon.getTribe());
            sid.addField("taxon.family_ss", taxon.getFamily());
        } else if (getCommentPage() instanceof IdentificationKey) {
            sid.addField("comment.comment_page_class_s", "org.emonocot.model.IdentificationKey");
            IdentificationKey identificationKey = (IdentificationKey) getCommentPage();
            summary.append(" ").append(identificationKey.getTitle());
        } else if (getCommentPage() instanceof Image) {
            Image image = (Image) getCommentPage();
            summary.append(" ").append(image.getTitle());
            sid.addField("comment.comment_page_class_s", "org.emonocot.model.Image");
        }
    }
    //sid.addField("comment.comment_t",getComment());
    sid.addField("comment.created_dt", dateTimeFormatter.print(getCreated()));
    sid.addField("comment.status_t", ObjectUtils.toString(getStatus(), null));
    sid.addField("comment.subject_s", getSubject());
    sid.addField("searchable.solrsummary_t", summary.toString());
    return sid;
}

From source file:org.emonocot.model.registry.Resource.java

@Override
public SolrInputDocument toSolrInputDocument() {
    DateTimeFormatter solrDateTimeFormat = DateTimeFormat.forPattern("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
    SolrInputDocument sid = new SolrInputDocument();
    sid.addField("id", getClassName() + "_" + getId());
    sid.addField("base.id_l", getId());
    sid.addField("base.class_searchable_b", false);
    sid.addField("base.class_s", getClass().getName());

    if (getDuration() != null) {
        sid.addField("resource.duration_l", getDuration().getStandardSeconds());
    }//from  w w w .java2s .c  o  m
    sid.addField("resource.exit_code_s", getExitCode());
    sid.addField("resource.exit_description_t", getExitDescription());
    if (getLastHarvested() != null) {
        sid.addField("resource.last_harvested_dt", solrDateTimeFormat.print(getLastHarvested()));
    }
    if (getNextAvailableDate() != null) {
        sid.addField("resource.next_available_date_dt", solrDateTimeFormat.print(getNextAvailableDate()));
    }
    sid.addField("resource.process_skip_l", getProcessSkip());
    sid.addField("resource.records_read_l", getRecordsRead());
    sid.addField("resource.resource_type_s", ObjectUtils.toString(getResourceType().toString(), null));
    sid.addField("resource.scheduled_b", getScheduled());
    sid.addField("resource.scheduling_period_s", ObjectUtils.toString(getSchedulingPeriod(), null));
    if (getOrganisation() != null) {
        sid.addField("resource.organisation_s", getOrganisation().getIdentifier());
    }
    if (getStartTime() != null) {
        sid.addField("resource.start_time_dt", solrDateTimeFormat.print(getStartTime()));
    }
    sid.addField("resource.status_s", ObjectUtils.toString(getStatus(), null));
    sid.addField("resource.title_t", getTitle());
    sid.addField("resource.write_skip_l", getWriteSkip());
    sid.addField("resource.written_l", getWritten());
    sid.addField("searchable.label_sort", getTitle());
    StringBuilder summary = new StringBuilder().append(getExitDescription()).append(" ").append(getTitle());
    sid.addField("searchable.solrsummary_t", summary.toString());
    return sid;
}

From source file:org.emonocot.model.Taxon.java

@Override
public SolrInputDocument toSolrInputDocument() {
    SolrInputDocument sid = super.toSolrInputDocument();
    sid.addField("searchable.label_sort", getScientificName());

    StringBuilder summary = new StringBuilder().append(getBibliographicCitation()).append(" ")
            .append(getClazz()).append(" ").append(getFamily()).append(" ").append(getGenus()).append(" ")
            .append(getKingdom()).append(" ").append(getNamePublishedInString()).append(" ")
            .append(getNamePublishedInYear()).append(" ").append(getNomenclaturalStatus()).append(" ")
            .append(getOrder()).append(" ").append(getPhylum()).append(" ").append(getScientificName())
            .append(" ").append(getScientificNameAuthorship()).append(" ").append(getSource()).append(" ")
            .append(getSpecificEpithet()).append(" ").append(getSubfamily()).append(" ").append(getSubgenus())
            .append(" ").append(getSubtribe()).append(" ").append(getTaxonomicStatus()).append(" ")
            .append(getTaxonRank()).append(" ").append(getTaxonRemarks()).append(" ").append(getTribe())
            .append(" ").append(getVerbatimTaxonRank());

    if (Rank.FAMILY.equals(getTaxonRank()) && getFamily() == null) {
        addField(sid, "taxon.family_ns", getScientificName());
        addField(sid, "taxon.family_ss", getScientificName());
    } else {/*from  ww  w  .  j av a2 s.co m*/
        addField(sid, "taxon.family_ns", getFamily());
        addField(sid, "taxon.family_ss", getFamily());
    }
    if (getAcceptedNameUsage() != null) {
        addField(sid, "taxon.family_ss", getAcceptedNameUsage().getFamily());
        summary.append(" ").append(getAcceptedNameUsage().getFamily());
    }

    addField(sid, FacetName.GENUS.getSolrField(), getGenus());
    if (getAcceptedNameUsage() != null) {
        addField(sid, FacetName.GENUS.getSolrField(), getAcceptedNameUsage().getGenus());
    }
    if (Rank.GENUS == getTaxonRank() && getGenus() == null) {
        addField(sid, "taxon.genus_ns", getScientificName());
        addField(sid, FacetName.GENUS.getSolrField(), getScientificName());
    } else {
        addField(sid, "taxon.genus_ns", getGenus());
    }

    addField(sid, "taxon.infraspecific_epithet_s", getInfraspecificEpithet());
    addField(sid, "taxon.infraspecific_epithet_ns", getInfraspecificEpithet());
    addField(sid, "taxon.order_s", getOrder());
    addField(sid, "taxon.scientific_name_t", getScientificName());
    addField(sid, "taxon.scientific_name_authorship_s", getScientificNameAuthorship());
    addField(sid, "taxon.specific_epithet_s", getSpecificEpithet());
    addField(sid, "taxon.specific_epithet_ns", getSpecificEpithet());

    addField(sid, FacetName.SUBFAMILY.getSolrField(), getSubfamily());
    if (Rank.Subfamily.equals(getTaxonRank()) && getSubfamily() == null) {
        addField(sid, FacetName.SUBFAMILY.getSolrField(), getScientificName());
    }
    if (getAcceptedNameUsage() != null) {
        addField(sid, FacetName.SUBFAMILY.getSolrField(), getAcceptedNameUsage().getSubfamily());
    }

    addField(sid, "taxon.subgenus_s", getSubgenus());

    addField(sid, FacetName.SUBTRIBE.getSolrField(), getSubtribe());
    if (Rank.Subtribe.equals(getTaxonRank()) && getSubtribe() == null) {
        addField(sid, FacetName.SUBTRIBE.getSolrField(), getScientificName());
    }
    if (getAcceptedNameUsage() != null) {
        addField(sid, FacetName.SUBTRIBE.getSolrField(), getAcceptedNameUsage().getSubtribe());
    }

    addField(sid, "taxon.taxonomic_status_s", ObjectUtils.toString(getTaxonomicStatus(), null));
    addField(sid, "taxon.taxon_rank_s", ObjectUtils.toString(getTaxonRank(), null));

    addField(sid, FacetName.TRIBE.getSolrField(), getTribe());
    if (Rank.Tribe.equals(getTaxonRank()) && getTribe() == null) {
        addField(sid, FacetName.TRIBE.getSolrField(), getScientificName());
    }
    if (getAcceptedNameUsage() != null) {
        addField(sid, FacetName.TRIBE.getSolrField(), getAcceptedNameUsage().getTribe());
    }

    sid.addField("taxon.descriptions_not_empty_b", !getDescriptions().isEmpty());

    for (Description d : getDescriptions()) {
        summary.append(" ").append(d.getDescription());
        if (d.getAuthority() != null) {
            sid.addField("searchable.sources_ss", d.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.distribution_not_empty_b", !getDistribution().isEmpty());
    for (Distribution d : getDistribution()) {
        sid.addField("taxon.distribution_ss", d.getLocation().getCode());
        switch (d.getLocation().getLevel()) {
        case 0:
            for (Location r : (Set<Location>) d.getLocation().getChildren()) {
                for (Location c : (Set<Location>) r.getChildren()) {
                    for (Location l : (Set<Location>) c.getChildren()) {
                        indexLocality(l, sid);
                    }
                }
            }
            break;
        case 1:
            for (Location c : (Set<Location>) d.getLocation().getChildren()) {
                for (Location l : (Set<Location>) c.getChildren()) {
                    indexLocality(l, sid);
                }
            }
            break;
        case 2:
            for (Location l : (Set<Location>) d.getLocation().getChildren()) {
                indexLocality(l, sid);
            }
            break;
        case 3:
            indexLocality(d.getLocation(), sid);
            break;
        default:
            break;
        }

        if (d.getAuthority() != null) {
            sid.addField("searchable.sources_ss", d.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.images_not_empty_b", !getImages().isEmpty());
    for (Image i : getImages()) {
        if (i != null && i.getAuthority() != null) {
            sid.addField("searchable.sources_ss", i.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.references_not_empty_b", !getReferences().isEmpty());
    for (Reference r : getReferences()) {
        if (r != null && r.getAuthority() != null) {
            sid.addField("searchable.sources_ss", r.getAuthority().getIdentifier());
        }
    }

    boolean hasTaxonomicPlacement = (acceptedNameUsage != null || parentNameUsage != null);
    sid.addField("taxon.taxonomic_placement_not_empty_b", hasTaxonomicPlacement);

    sid.addField("taxon.types_and_specimens_not_empty_b", !getTypesAndSpecimens().isEmpty());
    for (TypeAndSpecimen t : getTypesAndSpecimens()) {
        if (t != null && t.getAuthority() != null) {
            sid.addField("searchable.sources_ss", t.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.identifiers_not_empty_b", !getIdentifiers().isEmpty());
    for (Identifier i : getIdentifiers()) {
        if (i.getAuthority() != null) {
            sid.addField("searchable.sources_ss", i.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.measurements_or_facts_not_empty_b", !getMeasurementsOrFacts().isEmpty());
    boolean hasLifeForm = false;
    boolean hasHabitat = false;
    boolean hasThreatStatus = false;
    for (MeasurementOrFact m : getMeasurementsOrFacts()) {
        sid.addField("taxon.measurement_or_fact_" + m.getMeasurementType().simpleName() + "_txt",
                m.getMeasurementValue());
        if (m.getMeasurementType().equals(WCSPTerm.Habitat)) {
            hasHabitat = true;
        } else if (m.getMeasurementType().equals(WCSPTerm.Lifeform)) {
            hasLifeForm = true;
        } else if (m.getMeasurementType().equals(IucnTerm.threatStatus)) {
            hasThreatStatus = true;
        }
        if (m.getAuthority() != null) {
            sid.addField("searchable.sources_ss", m.getAuthority().getIdentifier());
        }
    }
    if (!hasLifeForm) {
        sid.addField("taxon.measurement_or_fact_" + WCSPTerm.Lifeform.simpleName() + "_txt", "_NULL_");
    }
    if (!hasHabitat) {
        sid.addField("taxon.measurement_or_fact_" + WCSPTerm.Habitat.simpleName() + "_txt", "_NULL_");
    }
    if (!hasThreatStatus) {
        sid.addField("taxon.measurement_or_fact_" + IucnTerm.threatStatus.simpleName() + "_txt", "_NULL_");
    }

    sid.addField("taxon.vernacular_names_not_empty_b", !getVernacularNames().isEmpty());
    for (VernacularName v : getVernacularNames()) {
        summary.append(" ").append(v.getVernacularName());
        if (v.getAuthority() != null) {
            sid.addField("searchable.sources_ss", v.getAuthority().getIdentifier());
        }
    }

    sid.addField("taxon.name_used_b", !getIdentifications().isEmpty());

    Set<String> usedAt = new HashSet<>();
    for (Identification identification : getIdentifications()) {
        usedAt.add(identification.getIdentifiedBy());
    }
    for (String used : usedAt) {
        sid.addField("taxon.name_used_at_ss", used);
    }

    for (Taxon synonym : getSynonymNameUsages()) {
        summary.append(" ").append(synonym.getScientificName());
    }

    sid.addField("searchable.solrsummary_t", summary.toString());
    sid.addField("taxon.has_data_b", hasUsefulData(sid));
    return sid;
}

From source file:org.kuali.kpme.core.api.util.KpmeUtils.java

public static String formatAssignmentKey(String groupKeyCode, Long jobNumber, Long workArea, Long task) {
    String assignmentKey = StringUtils.EMPTY;

    String jobNumberString = ObjectUtils.toString(jobNumber, "0");
    String workAreaString = ObjectUtils.toString(workArea, "0");
    String taskString = ObjectUtils.toString(task, "0");

    if (!jobNumberString.equals("0") || !workAreaString.equals("0") || !taskString.equals("0")) {
        assignmentKey = StringUtils.join(
                new String[] { groupKeyCode, jobNumberString, workAreaString, taskString },
                HrApiConstants.ASSIGNMENT_KEY_DELIMITER);
    }/*from w ww.j av  a  2s  .c o m*/

    return assignmentKey;
}

From source file:org.marketcetera.marketdata.bogus.BogusFeedEventTranslator.java

public List<Event> toEvent(Object inData, String inHandle) throws CoreException {
    if (!(inData instanceof Event)) {
        throw new UnsupportedEventException(
                new I18NBoundMessage1P(UNKNOWN_EVENT_TYPE, ObjectUtils.toString(inData, null)));
    }//from   ww w  .ja  v a  2  s.  c  o m
    Event event = (Event) inData;
    return Arrays.asList(new Event[] { event });
}

From source file:org.marketcetera.marketdata.interactivebrokers.InteractiveBrokersFeedEventTranslator.java

public List<EventBase> toEvent(Object inData, String inHandle) throws CoreException {

    if (!(inData instanceof MarketDataResponse)) {
        throw new UnsupportedEventException(
                new I18NBoundMessage1P(UNKNOWN_EVENT_TYPE, ObjectUtils.toString(inData, null)));
    }/*from   w  w  w  . j a  v a 2 s  .c om*/

    MarketDataResponse response = (MarketDataResponse) inData;

    List<EventBase> events = new ArrayList<EventBase>();
    //int entries = refresh.getInt(NoMDEntries.FIELD);
    // marketcetera feed returns bid/ask/trade for every query (each entry corresponds to one of these).
    // we have to decide which data to convert to events and pass along.  we know the symbol and the handle.
    // the handle is sufficient to determine what content was requested with the original request.
    Request request = InteractiveBrokersFeed.getRequestByHandle(inHandle);
    if (request == null) {
        // this could happen if the request were canceled (and removed from the collection) but the feed
        //  is still sending updates.  just bail out, no worries, the feed will stop soon.
        return events;
    }
    //int entries = refresh.getContracts()).size();

    Set<Content> requestedContent = request.getRequest().getContent();

    String symbol = response.getSymbol();
    // exchange is *somewhat* optional
    if (EventType.Bid.equals(response.getEventType())) {
        if (requestedContent.contains(Content.TOP_OF_BOOK)) {
            BidEvent bid = new BidEvent(System.nanoTime(), System.currentTimeMillis(), new MSymbol(symbol),
                    "NA", response.getPrice(), response.getSize());
            events.add(bid);
        }
    } else if (EventType.Offer.equals(response.getEventType())) {
        if (requestedContent.contains(Content.TOP_OF_BOOK)) {
            AskEvent ask = new AskEvent(System.nanoTime(), System.currentTimeMillis(), new MSymbol(symbol),
                    "NA", response.getPrice(), response.getSize());
            events.add(ask);
        }
    } else if (EventType.Trade.equals(response.getEventType())) {
        if (requestedContent.contains(Content.LATEST_TICK)) {
            TradeEvent trade = new TradeEvent(System.nanoTime(), System.currentTimeMillis(),
                    new MSymbol(symbol), "NA", response.getPrice(), response.getSize());

            events.add(trade);
        }

    } else {
        throw new UnsupportedEventException(
                new I18NBoundMessage1P(UNKNOWN_MESSAGE_ENTRY_TYPE, response.getEventType()));
    }
    return events;
}

From source file:org.marketcetera.marketdata.marketcetera.MarketceteraFeedEventTranslator.java

public List<Event> toEvent(Object inData, String inHandle) throws CoreException {
    if (!(inData instanceof MarketDataSnapshotFullRefresh)) {
        throw new UnsupportedEventException(
                new I18NBoundMessage1P(UNKNOWN_EVENT_TYPE, ObjectUtils.toString(inData, null)));
    }/*from w w w  . j  ava2s . c  om*/
    MarketDataSnapshotFullRefresh refresh = (MarketDataSnapshotFullRefresh) inData;
    List<Event> events = new ArrayList<Event>();
    try {
        int entries = refresh.getInt(NoMDEntries.FIELD);
        // marketcetera feed returns bid/ask/trade for every query (each entry corresponds to one of these).
        // we have to decide which data to convert to events and pass along.  we know the symbol and the handle.
        // the handle is sufficient to determine what content was requested with the original request.
        Request request = MarketceteraFeed.getRequestByHandle(inHandle);
        if (request == null) {
            // this could happen if the request were canceled (and removed from the collection) but the feed
            //  is still sending updates.  just bail out, no worries, the feed will stop soon.
            return events;
        }
        Set<Content> requestedContent = request.getRequest().getContent();
        for (int i = 1; i <= entries; i++) {
            Group group = new MarketDataSnapshotFullRefresh.NoMDEntries();
            refresh.getGroup(i, group);
            String symbol = refresh.getString(Symbol.FIELD);
            // exchange is *somewhat* optional
            String exchange;
            try {
                exchange = group.getString(MDMkt.FIELD);
            } catch (FieldNotFound e) {
                exchange = UNKNOWN;
            }
            String price = group.getString(MDEntryPx.FIELD);
            String size = group.getString(MDEntrySize.FIELD);
            char type = group.getChar(MDEntryType.FIELD);
            switch (type) {
            case MDEntryType.BID:
                if (requestedContent.contains(Content.TOP_OF_BOOK)) {
                    BidEvent bid = QuoteEventBuilder.equityBidEvent().withMessageId(System.nanoTime())
                            .withTimestamp(new Date()).withQuoteDate(DateUtils.dateToString(new Date()))
                            .withInstrument(new Equity(symbol)).withExchange(exchange)
                            .withPrice(new BigDecimal(price)).withSize(new BigDecimal(size)).create();
                    events.add(bid);
                }
                break;
            case MDEntryType.OFFER:
                if (requestedContent.contains(Content.TOP_OF_BOOK)) {
                    AskEvent ask = QuoteEventBuilder.equityAskEvent().withMessageId(System.nanoTime())
                            .withTimestamp(new Date()).withQuoteDate(DateUtils.dateToString(new Date()))
                            .withInstrument(new Equity(symbol)).withExchange(exchange)
                            .withPrice(new BigDecimal(price)).withSize(new BigDecimal(size)).create();
                    events.add(ask);
                }
                break;
            case MDEntryType.TRADE:
                if (requestedContent.contains(Content.LATEST_TICK)) {
                    TradeEvent trade = TradeEventBuilder.equityTradeEvent().withMessageId(System.nanoTime())
                            .withTimestamp(new Date()).withTradeDate(DateUtils.dateToString(new Date()))
                            .withInstrument(new Equity(symbol)).withExchange(exchange)
                            .withPrice(new BigDecimal(price)).withSize(new BigDecimal(size)).create();
                    events.add(trade);
                }
                break;
            default:
                throw new UnsupportedEventException(new I18NBoundMessage1P(UNKNOWN_MESSAGE_ENTRY_TYPE, type));
            }
            ;
        }
    } catch (FieldNotFound e) {
        e.printStackTrace();
    }
    return events;
}

From source file:org.marketcetera.module.IllegalRequestParameterValue.java

/**
 * Creates an instance.//  www  .  j av a 2s .c o m
 *
 * @param inModuleURN the module throwing this exception
 * @param inParameter the offending parameter value
 */
public IllegalRequestParameterValue(ModuleURN inModuleURN, Object inParameter) {
    super(new I18NBoundMessage2P(Messages.ILLEGAL_REQ_PARM_VALUE, inModuleURN.getValue(),
            ObjectUtils.toString(inParameter, null)));
}

From source file:org.marketcetera.module.IllegalRequestParameterValue.java

/**
 * Creates an instance// w  w  w.j ava2 s .  c o  m
 *
 * @param inModuleURN the module throwing this exception
 * @param inParameter the parameter value
 * @param inCause the cause
 */
public IllegalRequestParameterValue(ModuleURN inModuleURN, Object inParameter, Throwable inCause) {
    super(inCause, new I18NBoundMessage2P(Messages.ILLEGAL_REQ_PARM_VALUE, inModuleURN.getValue(),
            ObjectUtils.toString(inParameter, null)));
}