Example usage for org.apache.commons.lang3.builder ToStringBuilder reflectionToString

List of usage examples for org.apache.commons.lang3.builder ToStringBuilder reflectionToString

Introduction

In this page you can find the example usage for org.apache.commons.lang3.builder ToStringBuilder reflectionToString.

Prototype

public static String reflectionToString(final Object object, final ToStringStyle style) 

Source Link

Document

Uses ReflectionToStringBuilder to generate a toString for the specified object.

Usage

From source file:gobblin.writer.http.SalesforceRestWriter.java

/**
 * Check results from batch response, if any of the results is failure throw exception.
 * @param response/*from w ww . j ava2s .c om*/
 * @throws IOException
 * @throws UnexpectedResponseException
 */
private void processBatchRequestResponse(CloseableHttpResponse response)
        throws IOException, UnexpectedResponseException {
    String entityStr = EntityUtils.toString(response.getEntity());
    int statusCode = response.getStatusLine().getStatusCode();
    if (statusCode >= 400) {
        throw new RuntimeException("Failed due to " + entityStr + " (Detail: "
                + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE) + " )");
    }

    JsonObject jsonBody = new JsonParser().parse(entityStr).getAsJsonObject();
    if (!jsonBody.get("hasErrors").getAsBoolean()) {
        return;
    }

    JsonArray results = jsonBody.get("results").getAsJsonArray();
    for (JsonElement jsonElem : results) {
        JsonObject json = jsonElem.getAsJsonObject();
        int subStatusCode = json.get("statusCode").getAsInt();
        if (subStatusCode < 400) {
            continue;
        } else if (subStatusCode == 400 && Operation.INSERT_ONLY_NOT_EXIST.equals(operation)) {
            JsonElement resultJsonElem = json.get("result");
            Preconditions.checkNotNull(resultJsonElem, "Error response should contain result property");
            JsonObject resultJsonObject = resultJsonElem.getAsJsonArray().get(0).getAsJsonObject();
            if (isDuplicate(resultJsonObject, subStatusCode)) {
                continue;
            }
        }
        throw new RuntimeException("Failed due to " + jsonBody + " (Detail: "
                + ToStringBuilder.reflectionToString(response, ToStringStyle.SHORT_PREFIX_STYLE) + " )");
    }
}

From source file:com.omertron.slackbot.listeners.GoogleSheetsListener.java

/**
 * Create a simple formatted message about the future game night
 *
 * @param sheetInfo SheetInfo//from  w ww .  j  a v  a  2s .co  m
 * @param diff Days to next game night
 * @return Slack Prepared Message
 */
public static SlackPreparedMessage createSimpleNightMessage(SheetInfo sheetInfo, Period diff) {
    SlackPreparedMessage.Builder spm = new SlackPreparedMessage.Builder().withUnfurl(false);

    StringBuilder sb = new StringBuilder("Game night is ");
    sb.append(sheetInfo.getFormattedDate("EEEE, d MMMM")).append(", still ").append(diff.getDays())
            .append(" days away\n");

    if (StringUtils.isBlank(sheetInfo.getGameChooser())) {
        sb.append("There is no-one to chose the next game!!! :astonished:");
    } else {
        if ("All".equalsIgnoreCase(sheetInfo.getGameChooser())) {
            sb.append("The group is choosing :open_mouth:");
        } else if ("Other".equalsIgnoreCase(sheetInfo.getGameChooser())) {
            sb.append("It's someone else's turn to choose :open_mouth:");
        } else {
            sb.append("It's *").append(sheetInfo.getGameChooser()).append("'s* turn to choose");
        }

        if (sheetInfo.getNextGameId() <= 0) {
            // There's no game ID, this could be because there's no game selected or an error reading
            if (StringUtils.isBlank(sheetInfo.getGameName())) {
                // No game chosen
                LOG.error("SheetInfo READ:\n{}",
                        ToStringBuilder.reflectionToString(sheetInfo, ToStringStyle.MULTI_LINE_STYLE));
                sb.append(", but no game has been selected yet :angry:\n");
            } else {
                // Error with reading the sheet or with google's API
                sb.append(" and *").append(sheetInfo.getGameName()).append("* has been chosen.\n");
            }
        } else {
            sb.append(" and *").append(SlackBot.formatLink(Constants.BGG_LINK_GAME + sheetInfo.getNextGameId(),
                    sheetInfo.getGameName())).append("* has been picked.\n");
        }

    }

    // Who's attending?
    if (sheetInfo.getPlayers().isEmpty()) {
        sb.append("No-one has said they are going!");
    } else {
        sb.append(sheetInfo.getNameList(", ")).append(" are attending");
    }

    spm.withMessage(sb.toString());

    return spm.build();
}

From source file:io.leishvl.core.dwc.simple.SimpleDarwinRecord.java

@Override
@Generated(value = "com.sun.tools.xjc.Driver", date = "2015-11-04T10:30:09+01:00", comments = "JAXB RI v2.2.11")
public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
}

From source file:nl.opengeogroep.filesetsync.client.SyncJobState.java

@Override
public String toString() {
    return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);

}

From source file:org.ahp.commons.util.AhpStringUtil.java

/**
 * /*from w w  w  .  j  a  va2 s.  co  m*/
 * @param pObject
 * @return
 */
public static String reflectionToString(Object pObject) {
    return ToStringBuilder.reflectionToString(pObject, ToStringStyle.MULTI_LINE_STYLE);
}

From source file:org.apache.cxf.xjc.runtime.JAXBElementToStringStyleTest.java

@Test
public void testToStringMultiLineStyle() throws Exception {
    String ts = ToStringBuilder.reflectionToString(h, JAXBToStringStyle.MULTI_LINE_STYLE);

    validateHolderString(ts);/* ww  w .  j  a v a2 s .co  m*/
    validateElementString(ts);
}

From source file:org.apache.cxf.xjc.runtime.JAXBElementToStringStyleTest.java

@Test
public void testToStringSimpleStyle() throws Exception {
    String ts = ToStringBuilder.reflectionToString(h, JAXBToStringStyle.SIMPLE_STYLE);

    // field names are missing
    Assert.assertTrue("has no obj field", ts.indexOf("obj") == -1);
    Assert.assertTrue("has HolderName", ts.indexOf("HolderName") != -1);
    Assert.assertTrue("has SomeText", ts.indexOf("SomeText") != -1);
}

From source file:org.apache.cxf.xjc.runtime.JAXBToStringBuilder.java

public static String valueOf(Object object, ToStringStyle style) {
    if (object instanceof String) {
        return (String) object;
    }/*from  w  w  w . ja va  2 s . c  o m*/
    if (object instanceof Collection) {
        object = ((Collection<?>) object).toArray();
    }
    return ToStringBuilder.reflectionToString(object, style);
}

From source file:org.apache.cxf.xjc.runtime.JAXBToStringStyle.java

@Override
protected void appendDetail(StringBuffer buffer, String fieldName, Object value) {
    if (value instanceof JAXBElement) {
        buffer.append(ToStringBuilder.reflectionToString(value, this));
    } else {//from  w w  w.  j av  a  2s. c om
        buffer.append(value);
    }
}

From source file:org.apache.openejb.server.cli.StreamManager.java

private static String string(final Object out, final String lineSep) {
    if (!out.getClass().getName().startsWith("java")) {
        try {/*from  w  ww  . j a  v  a  2 s  . c  o m*/
            return new GsonBuilder().setPrettyPrinting().create().toJson(out).replace(OS_LINE_SEP, lineSep);
        } catch (RuntimeException re) {
            return ToStringBuilder.reflectionToString(out, ToStringStyle.SHORT_PREFIX_STYLE)
                    .replace(OS_LINE_SEP, lineSep);
        }
    }
    return out.toString();
}