Example usage for org.apache.commons.lang StringUtils defaultIfEmpty

List of usage examples for org.apache.commons.lang StringUtils defaultIfEmpty

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils defaultIfEmpty.

Prototype

public static String defaultIfEmpty(String str, String defaultStr) 

Source Link

Document

Returns either the passed in String, or if the String is empty or null, the value of defaultStr.

Usage

From source file:com.gst.infrastructure.codes.domain.CodeValue.java

private CodeValue(final Code code, final String label, final int position, final String description,
        final boolean isActive, final boolean mandatory) {
    this.code = code;
    this.label = StringUtils.defaultIfEmpty(label, null);
    this.position = position;
    this.description = description;
    this.isActive = isActive;
    this.mandatory = mandatory;
}

From source file:com.ning.maven.plugins.duplicatefinder.DependencyWrapper.java

public boolean matches(Artifact artifact) {
    ArtifactVersion version = null;/*from  w ww  .j  av a2  s . c om*/

    try {
        if (artifact.getVersionRange() != null) {
            version = artifact.getSelectedVersion();
        } else {
            version = new DefaultArtifactVersion(artifact.getVersion());
        }
    } catch (OverConstrainedVersionException ex) {
        return false;
    }

    return StringUtils.equals(dependency.getGroupId(), artifact.getGroupId())
            && StringUtils.equals(dependency.getArtifactId(), artifact.getArtifactId())
            && StringUtils.equals(StringUtils.defaultIfEmpty(dependency.getType(), "jar"),
                    StringUtils.defaultIfEmpty(artifact.getType(), "jar"))
            && StringUtils.equals(dependency.getClassifier(), artifact.getClassifier())
            && (versionRange == null || versionRange.containsVersion(version)
                    || StringUtils.equals(artifact.getVersion(), dependency.getVersion()));
}

From source file:com.gst.portfolio.fund.domain.Fund.java

public Map<String, Object> update(final JsonCommand command) {

    final Map<String, Object> actualChanges = new LinkedHashMap<>(7);

    final String nameParamName = "name";
    if (command.isChangeInStringParameterNamed(nameParamName, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(nameParamName);
        actualChanges.put(nameParamName, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }// ww w  . ja va2  s  .  c  o  m

    final String externalIdParamName = "externalId";
    if (command.isChangeInStringParameterNamed(externalIdParamName, this.externalId)) {
        final String newValue = command.stringValueOfParameterNamed(externalIdParamName);
        actualChanges.put(externalIdParamName, newValue);
        this.externalId = StringUtils.defaultIfEmpty(newValue, null);
    }

    return actualChanges;
}

From source file:com.adaptris.core.MetadataFileNameCreator.java

/**
 * <p>//from w w w  .j av a 2  s  .  c o  m
 * Obtains the value for the configured metadata key, if this is not null or
 * empty it is returned.  If the metadata value is null or empty then the
 * configured 'default name' is returned.
 * </p>
 * @see com.adaptris.core.FileNameCreator
 *   #createName(com.adaptris.core.AdaptrisMessage)
 */
public String createName(AdaptrisMessage msg) throws CoreException {
    if (getMetadataKey() == null) {
        throw new CoreException("illegal metadata key [" + metadataKey + "]");
    }
    return StringUtils.defaultIfEmpty(msg.getMetadataValue(metadataKey), defaultName);
}

From source file:com.gst.infrastructure.documentmanagement.domain.Document.java

private Document(final String parentEntityType, final Long parentEntityId, final String name,
        final String fileName, final Long size, final String type, final String description,
        final String location, final StorageType storageType) {
    this.parentEntityType = StringUtils.defaultIfEmpty(parentEntityType, null);
    this.parentEntityId = parentEntityId;
    this.name = StringUtils.defaultIfEmpty(name, null);
    this.fileName = StringUtils.defaultIfEmpty(fileName, null);
    this.size = size;
    this.type = StringUtils.defaultIfEmpty(type, null);
    this.description = StringUtils.defaultIfEmpty(description, null);
    this.location = StringUtils.defaultIfEmpty(location, null);
    this.storageType = storageType.getValue();
}

From source file:com.seyren.core.service.notification.VictorOpsNotificationService.java

@Override
public void sendNotification(Check check, Subscription subscription, List<Alert> alerts)
        throws NotificationFailedException {

    String victorOpsRestEndpoint = seyrenConfig.getVictorOpsRestEndpoint();
    String victorOpsRoutingKey = StringUtils.defaultIfEmpty(subscription.getTarget(), "default");

    if (victorOpsRestEndpoint == null) {
        LOGGER.warn("VictorOps REST API endpoint needs to be set before sending notifications");
        return;//w ww .  j a v  a 2s .  c o m
    }

    URI victorOpsUri = null;
    try {
        victorOpsUri = new URI(victorOpsRestEndpoint).resolve(new URI(victorOpsRoutingKey));
    } catch (URISyntaxException use) {
        LOGGER.warn("Invalid endpoint is given.");
        return;
    }

    HttpClient client = HttpClientBuilder.create().useSystemProperties().build();
    HttpPost post = new HttpPost(victorOpsUri);
    try {
        HttpEntity entity = new StringEntity(getDescription(check, alerts), ContentType.APPLICATION_JSON);
        post.setEntity(entity);
        HttpResponse response = client.execute(post);
        HttpEntity responseEntity = response.getEntity();
        if (responseEntity != null) {
            LOGGER.info("Response : {} ", EntityUtils.toString(responseEntity));
        }
    } catch (Exception e) {
        throw new NotificationFailedException("Failed to send notification to VictorOps", e);
    } finally {
        post.releaseConnection();
        HttpClientUtils.closeQuietly(client);
    }
}

From source file:com.tikal.tallerWeb.servicio.reporte.global.RenglonFactoryRG.java

private void fillClienteData(RenglonRG r, Customer customer) {
    if (customer != null) {
        if (customer.getName() instanceof OrganizationName) {
            OrganizationName n = (OrganizationName) customer.getName();
            r.getDatosCliente().setNombre(n.getName());
        }//from w w  w.  j a v  a  2s.c o  m
        if (customer instanceof ClienteMx) {
            ClienteMx mx = (ClienteMx) customer;
            if (mx.getDomicilioFiscal() instanceof MexicoAddress) {
                MexicoAddress dir = (MexicoAddress) mx.getDomicilioFiscal();
                r.getDatosCliente().setCiudad(StringUtils.defaultIfEmpty(dir.getCiudad(), ""));
                r.getDatosCliente().setColonia(StringUtils.defaultIfEmpty(dir.getColonia(), ""));
                r.getDatosCliente().setDireccion(StringUtils.defaultIfEmpty(dir.getCalle(), ""));
            }
        }
        if (customer.getPrimaryContact() != null) {
            if (customer.getPrimaryContact().getName() instanceof OrganizationName) {
                OrganizationName n = (OrganizationName) customer.getPrimaryContact().getName();
                r.getDatosCliente().setContacto(n.getName());
            }
            if (customer.getPrimaryContact().getPhoneNumber() != null
                    && customer.getPrimaryContact().getPhoneNumber().length > 0
                    && customer.getPrimaryContact().getPhoneNumber()[0] instanceof MexicoPhoneNumber) {
                MexicoPhoneNumber telefono = (MexicoPhoneNumber) customer.getPrimaryContact()
                        .getPhoneNumber()[0];
                r.getDatosCliente().setTelefono(StringUtils.defaultIfEmpty(telefono.getTelefono(), ""));
            }
        }
    }
}

From source file:ch.admin.suis.msghandler.config.Inbox.java

/**
 * @param directory the directory of the inbox
 * @param sedexId   sedexId//from w ww . ja v  a2 s  .  com
 * @param types     msgTypes to handle
 * @param mode      transparent application or native MessageHandler application
 * @throws ConfigurationException Config Problems
 */
public Inbox(File directory, String sedexId, Collection<MessageType> types, Mode mode)
        throws ConfigurationException {
    super(directory);
    this.mode = mode;
    this.types.addAll(types);
    this.sedexId = sedexId;

    LOG.info("Created Inbox: SedexId: " + StringUtils.defaultIfEmpty(sedexId, ClientCommons.NOT_SPECIFIED)
            + ", Types: {"
            + StringUtils.defaultIfEmpty(MessageType.collectionToString(types), ClientCommons.NOT_SPECIFIED)
            + "}, Mode: " + mode + ", Path: " + directory.getAbsolutePath());
}

From source file:com.gst.portfolio.tax.domain.TaxGroup.java

public Map<String, Object> update(final JsonCommand command, final Set<TaxGroupMappings> taxGroupMappings) {
    final Map<String, Object> changes = new HashMap<>();

    if (command.isChangeInStringParameterNamed(TaxApiConstants.nameParamName, this.name)) {
        final String newValue = command.stringValueOfParameterNamed(TaxApiConstants.nameParamName);
        changes.put(TaxApiConstants.nameParamName, newValue);
        this.name = StringUtils.defaultIfEmpty(newValue, null);
    }/*ww  w .j  a  v a  2 s.  c  o m*/

    List<Long> taxComponentList = new ArrayList<>();
    final List<Map<String, Object>> modifications = new ArrayList<>();

    for (TaxGroupMappings groupMappings : taxGroupMappings) {
        TaxGroupMappings mappings = findOneBy(groupMappings);
        if (mappings == null) {
            this.taxGroupMappings.add(groupMappings);
            taxComponentList.add(groupMappings.getTaxComponent().getId());
        } else {
            mappings.update(groupMappings.getEndDate(), modifications);
        }
    }

    if (!taxComponentList.isEmpty()) {
        changes.put("addComponents", taxComponentList);
    }
    if (!modifications.isEmpty()) {
        changes.put("modifiedComponents", modifications);
    }

    return changes;
}

From source file:edu.wisc.my.portlets.bookmarks.web.ToggleFolderFormController.java

/**
 * @see org.springframework.web.portlet.mvc.AbstractController#handleActionRequestInternal(javax.portlet.ActionRequest, javax.portlet.ActionResponse)
 *//*w ww  .  j a v a 2s  . c o  m*/
@Override
protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
    final String folderIndex = StringUtils.defaultIfEmpty(request.getParameter("folderIndex"), null);

    //Get the BookmarkSet from the store
    final BookmarkSet bs = this.bookmarkSetRequestResolver.getBookmarkSet(request, false);
    if (bs == null) {
        throw new IllegalArgumentException("No BookmarkSet exists for request='" + request + "'");
    }

    final IdPathInfo targetFolderPathInfo = FolderUtils.getEntryInfo(bs, folderIndex);
    if (targetFolderPathInfo != null && targetFolderPathInfo.getTarget() != null) {
        final CollapsibleEntry targetFolder = (CollapsibleEntry) targetFolderPathInfo.getTarget();
        targetFolder.setMinimized(!targetFolder.isMinimized());

        //Persist the changes to the BookmarkSet 
        this.bookmarkStore.storeBookmarkSet(bs);
    } else {
        this.logger.warn("No IdPathInfo found for BaseFolder='" + bs + "' and idPath='" + folderIndex + "'");
    }

    //Go back to view bookmarks
    response.setRenderParameter("action", "viewBookmarks");
}