Example usage for org.apache.commons.lang3 StringUtils substringAfterLast

List of usage examples for org.apache.commons.lang3 StringUtils substringAfterLast

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils substringAfterLast.

Prototype

public static String substringAfterLast(final String str, final String separator) 

Source Link

Document

Gets the substring after the last occurrence of a separator.

Usage

From source file:org.kuali.kra.protocol.personnel.ProtocolAttachmentPersonnelEventBase.java

/**
 * Logs the event type and some information about the associated unit
 *///from   w  w w. ja va 2 s.c om
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (getProtocolAttachmentPersonnel() == null) {
        logMessage.append("null protocolAttachmentPersonnel");
    } else {
        logMessage.append(getProtocolAttachmentPersonnel().toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.kra.protocol.personnel.ProtocolUnitEventBase.java

/**
 * Logs the event type and some information about the associated unit
 *///from  w w w  . j av  a 2s  .  c  o m
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (getProtocolUnit() == null) {
        logMessage.append("null protocolUnit");
    } else {
        logMessage.append(getProtocolUnit().toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.kra.protocol.protocol.funding.AddProtocolFundingSourceEventBase.java

@Override
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (document == null) {
        logMessage.append("null protocolDocument");
    } else {/* w  w  w  .  j  a  v a  2  s  .  c o m*/
        logMessage.append(document.toString());
    }

    LOG.debug(logMessage);
}

From source file:org.kuali.kra.protocol.protocol.location.ProtocolLocationEventBase.java

/**
 * Logs the event type and some information about the associated location
 *//*from  ww w  .j a  va2  s .  c  om*/
protected void logEvent() {
    StringBuffer logMessage = new StringBuffer(StringUtils.substringAfterLast(this.getClass().getName(), "."));
    logMessage.append(" with ");

    // vary logging detail as needed
    if (getProtocolLocation() == null) {
        logMessage.append("null protocolLocation");
    } else {
        logMessage.append(getProtocolLocation().toString());
    }

    LOG.debug(logMessage);
}

From source file:org.ligoj.app.plugin.vm.azure.VmAzurePluginResource.java

/**
 * Build a described {@link AzureVm} completing the VM details with the instance details.
 * //  ww w  .ja v a 2s.c om
 * @param azureVm
 *            The Azure VM object built from the raw JSON stream.
 * @param sizeProvider
 *            Optional Azure instance size provider.
 * @return The merge VM details.
 */
private AzureVm toVm(final AzureVmEntry azureVm, final BiFunction<String, String, VmSize> sizeProvider) {
    final AzureVm result = new AzureVm();
    final AzureVmDetails properties = azureVm.getProperties();
    result.setId(azureVm.getName()); // ID is the name for Azure
    result.setInternalId(properties.getVmId());
    result.setName(azureVm.getName());
    result.setLocation(azureVm.getLocation());

    // Instance type details if available
    if (sizeProvider != null) {
        final String instanceType = properties.getHardwareProfile().get("vmSize");
        final VmSize size = sizeProvider.apply(instanceType, azureVm.getLocation());
        result.setCpu(size.getNumberOfCores());
        result.setRam(size.getMemoryInMB());
    }

    // OS
    final AzureVmOs image = properties.getStorageProfile().getImageReference();
    if (image.getOffer() == null) {
        // From image
        result.setOs(properties.getStorageProfile().getOsDisk().getOsType() + " ("
                + StringUtils.substringAfterLast(image.getId(), "/") + ")");
    } else {
        // From marketplace : provider
        result.setOs(image.getOffer() + " " + image.getSku() + " " + image.getPublisher());
    }

    // Disk size
    result.setDisk(properties.getStorageProfile().getOsDisk().getDiskSizeGB());

    return result;
}

From source file:org.lockss.util.ObjectSerializerTester.java

/**
 * <p>Tests that the deserializer behaves appropriately for its
 * mode when deserialization fails.</p>
 * @throws Exception if an unexpected or unhandled problem arises.
 *//*from www  .  j  a v  a  2s  .c om*/
public void testFailedDeserializationMode() throws Exception {

    // Define variant actions
    RememberFile[] actions = new RememberFile[] {
            // With a File
            new RememberFile() {
                public void doSomething(ObjectSerializer serializer) throws Exception {
                    serializer.deserialize(file);
                }
            },
            // With a String
            new RememberFile() {
                public void doSomething(ObjectSerializer serializer) throws Exception {
                    serializer.deserialize(file.toString());
                }
            }, };

    // For each variant action...
    for (int action = 0; action < actions.length; ++action) {
        logger.debug("Begin with action " + action);

        // For each type of deserializer...
        ObjectSerializer[] deserializers = getObjectSerializers_ExtMapBean();
        for (int deserializer = 0; deserializer < deserializers.length; ++deserializer) {
            logger.debug("Begin with deserializer " + deserializer);

            try {
                // Create a bad input file
                actions[action].file = File.createTempFile("testfile", ".xml");
                actions[action].file.deleteOnExit();
                FileWriter writer = new FileWriter(actions[action].file);
                writer.write("BAD INPUT");
                writer.close();

                // Perform variant action
                actions[action].doSomething(deserializers[deserializer]);
                fail("Should have thrown SerializationException (" + action + "," + deserializer + ")");
            } catch (SerializationException ignore) {
                // success; keep going
            }

            // Verify results
            switch (deserializers[deserializer].getFailedDeserializationMode()) {
            case ObjectSerializer.FAILED_DESERIALIZATION_COPY:
                File[] files = actions[action].file.getParentFile().listFiles();
                File copy = null;
                for (int file = 0; file < files.length; ++file) {
                    String candidate = files[file].toString();
                    if (!candidate.startsWith(actions[action].file.toString())) {
                        continue; // not the right file
                    }
                    if (!StringUtils.contains(candidate,
                            CurrentConfig.getParam(ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION,
                                    ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION))) {
                        continue; // not the right file
                    }
                    String timestamp = StringUtils.substringAfterLast(candidate, ".");
                    if (StringUtil.isNullString(timestamp)) {
                        continue; // not the right file
                    }
                    try {
                        long time = Long.parseLong(timestamp);
                    } catch (NumberFormatException nfe) {
                        continue; // not the right file
                    }
                    copy = files[file]; // right file found
                    break;
                }
                assertNotNull(
                        "FAILED_DESERIALIZATION_COPY: copy not found (" + action + "," + deserializer + ")",
                        copy);
                copy.deleteOnExit(); // clean up
                assertTrue("FAILED_DESERIALIZATION_COPY: copy does not match (" + action + "," + deserializer
                        + ")", FileUtil.isContentEqual(actions[action].file, copy));
                break;
            case ObjectSerializer.FAILED_DESERIALIZATION_IGNORE:
                // nothing; keep going
                break;
            case ObjectSerializer.FAILED_DESERIALIZATION_RENAME:
                File rename = new File(actions[action].file.toString()
                        + CurrentConfig.getParam(ObjectSerializer.PARAM_FAILED_DESERIALIZATION_EXTENSION,
                                ObjectSerializer.DEFAULT_FAILED_DESERIALIZATION_EXTENSION));
                assertTrue("FAILED_DESERIALIZATION_RENAME: renamed file did not exist (" + action + ","
                        + deserializer + ")", rename.exists());
                rename.deleteOnExit(); // clean up
                break;
            default: // shouldn't happen
                fail("Unexpected failed deserialization mode (" + action + "," + deserializer + ")");
                break;
            }
        }
    }

}

From source file:org.mayocat.search.elasticsearch.ElasticSearchSearchEngine.java

public void index(final Entity entity, final Tenant tenant) throws SearchEngineException {
    try {/*from ww  w . j  a v a2  s  .co m*/
        Map<String, Object> source = entityIndexDocumentPurveyor.purveyDocument(entity, tenant);

        if (source.keySet().size() > 0) {
            String entityName = StringUtils.substringAfterLast(entity.getClass().getName(), ".").toLowerCase();

            this.logger.debug("Indexing {} with id {}...", entityName, entity.getId());

            IndexRequestBuilder builder = this.client
                    .prepareIndex("entities", entityName, entity.getId().toString()).setSource(source);

            if (tenant != null && !Tenant.class.isAssignableFrom(entity.getClass())) {
                builder.setParent(tenant.getId().toString());
            }

            IndexResponse response = builder.execute().actionGet();
            this.logger.debug("" + response.getType());
        }
    } catch (Exception e) {
        throw new SearchEngineException("Failed to index entity", e);
    }
}

From source file:org.mayocat.url.DefaultEntityURLFactory.java

@Override
protected String getEntityName(Entity entity) {
    return StringUtils.substringAfterLast(entity.getClass().getName(), ".").toLowerCase();
}

From source file:org.noroomattheinn.tesla.Tesla.java

private JSONObject call(String command, Content payload) {
    JSONObject rawResponse = null;//from ww w  .  j  av  a 2 s . co m
    try {
        if (payload == null)
            rawResponse = api.json(command).object();
        else
            rawResponse = api.json(command, payload).object();
        if (rawResponse == null)
            return new JSONObject();
        return rawResponse.getJSONObject("response");
    } catch (IOException | JSONException ex) {
        String error = ex.toString().replace("\n", " -- ");
        Tesla.logger.finer("Failed invoking (" + StringUtils.substringAfterLast(command, "/") + "): ["
                + StringUtils.substringAfter(error, "["));
        return (rawResponse == null) ? new JSONObject() : rawResponse;
    }
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_8.ObsComplexValueController1_8.java

@RequestMapping(value = "/{uuid}/value", method = RequestMethod.GET)
public void getFile(@PathVariable("uuid") String uuid,
        @RequestParam(required = false, defaultValue = "RAW_VIEW") String view, HttpServletResponse response)
        throws Exception {
    Obs obs = obsService.getObsByUuid(uuid);
    if (!obs.isComplex()) {
        throw new IllegalRequestException("It is not a complex obs, thus have no data.");
    }/*  w  ww . j  a v  a2  s.  c  o  m*/
    obs = obsService.getComplexObs(obs.getId(), view);
    ComplexData complexData = obs.getComplexData();

    String mimeType;
    try {
        mimeType = BeanUtils.getProperty(complexData, "mimeType");
    } catch (Exception e) {
        mimeType = "application/force-download"; //no mimeType for openmrs-api 1.11 and below
    }

    response.setContentType(mimeType);
    if (StringUtils.isNotBlank(complexData.getTitle())) {
        response.setHeader("Content-Disposition", "attachment; filename=" + complexData.getTitle());
    }
    Object data = complexData.getData();
    if (data instanceof byte[]) {
        response.getOutputStream().write((byte[]) data);
    } else if (data instanceof InputStream) {
        IOUtils.copy((InputStream) data, response.getOutputStream());
    } else if (data instanceof BufferedImage) {
        //special case for ImageHandler
        BufferedImage image = (BufferedImage) data;
        File file = AbstractHandler.getComplexDataFile(obs);
        String type = StringUtils.substringAfterLast(file.getName(), ".");
        if (type == null) {
            type = "jpg";
        }
        ImageIO.write(image, type, response.getOutputStream());
    }

    response.flushBuffer();
}