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

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

Introduction

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

Prototype

public static boolean equals(final CharSequence cs1, final CharSequence cs2) 

Source Link

Document

Compares two CharSequences, returning true if they represent equal sequences of characters.

null s are handled without exceptions.

Usage

From source file:ch.cyberduck.core.sds.SDSDelegatingCopyFeature.java

@Override
public boolean isRecursive(final Path source, final Path target) {
    if (containerService.getContainer(source).getType().contains(Path.Type.vault)
            || containerService.getContainer(target).getType().contains(Path.Type.vault)) {
        return new DefaultCopyFeature(session).isRecursive(source, target);
    }//w w  w.j  ava2  s  . c om
    if (StringUtils.equals(source.getName(), target.getName())) {
        return proxy.isRecursive(source, target);
    }
    return new DefaultCopyFeature(session).isRecursive(source, target);
}

From source file:com.glaf.batch.domain.JobInstance.java

public Integer getIntValue(String keyName) {
    if (params != null && !params.isEmpty()) {
        for (JobParam param : params) {
            if (StringUtils.equals(keyName, param.getKeyName())) {
                return param.getIntVal();
            }//from  w  w w  . ja  va  2  s  . c om
        }
    }
    return null;
}

From source file:com.glaf.core.xml.XmlWriter.java

public Document write(List<ClassDefinition> rows) {
    Document doc = DocumentHelper.createDocument();
    Element root = doc.addElement("mapping");
    for (ClassDefinition classDefinition : rows) {
        Element element = root.addElement("entity");
        element.addAttribute("name", classDefinition.getEntityName());
        element.addAttribute("package", classDefinition.getPackageName());
        element.addAttribute("moduleName", classDefinition.getModuleName());
        element.addAttribute("table", classDefinition.getTableName());
        element.addAttribute("title", classDefinition.getTitle());
        element.addAttribute("englishTitle", classDefinition.getEnglishTitle());
        FieldDefinition idField = classDefinition.getIdField();
        if (idField != null) {
            Element idElement = element.addElement("id");
            idElement.addAttribute("name", idField.getName());
            idElement.addAttribute("column", idField.getColumnName());
            idElement.addAttribute("type", idField.getType());
            idElement.addAttribute("title", idField.getTitle());
            idElement.addAttribute("englishTitle", idField.getEnglishTitle());
            if (idField.getLength() > 0) {
                idElement.addAttribute("length", String.valueOf(idField.getLength()));
            }/*from   ww  w .  j  ava 2  s . com*/
        }

        Map<String, FieldDefinition> fields = classDefinition.getFields();
        Set<Entry<String, FieldDefinition>> entrySet = fields.entrySet();
        for (Entry<String, FieldDefinition> entry : entrySet) {
            String name = entry.getKey();
            FieldDefinition field = entry.getValue();
            if (idField != null
                    && StringUtils.equalsIgnoreCase(idField.getColumnName(), field.getColumnName())) {
                continue;
            }
            Element elem = element.addElement("property");
            elem.addAttribute("name", name);
            elem.addAttribute("column", field.getColumnName());
            elem.addAttribute("type", field.getType());
            elem.addAttribute("title", field.getTitle());
            elem.addAttribute("englishTitle", field.getEnglishTitle());

            if (StringUtils.equals(field.getType(), "String") && field.getLength() > 0) {
                elem.addAttribute("length", String.valueOf(field.getLength()));
            }
            if (field.isUnique()) {
                elem.addAttribute("unique", String.valueOf(field.isUnique()));
            }
            if (field.isSearchable()) {
                elem.addAttribute("searchable", String.valueOf(field.isSearchable()));
            }
            if (!field.isNullable()) {
                elem.addAttribute("nullable", String.valueOf(field.isNullable()));
            }
            if (field.isEditable()) {
                elem.addAttribute("editable", String.valueOf(field.isEditable()));
            }
            if (field.getDisplayType() > 0) {
                elem.addAttribute("displayType", String.valueOf(field.getDisplayType()));
            }
        }
    }
    return doc;
}

From source file:com.epam.dlab.core.ModuleData.java

/**
 * Set value for given key or delete entry if the value is <b>null</b>.
 *
 * @param key   the key of entry.//from  w  w w .j a  va  2  s . c om
 * @param value the value.
 */
public void set(String key, String value) {
    if (StringUtils.equals(entries.get(key), value)) {
        return;
    } else if (value == null) {
        entries.remove(key);
    } else {
        entries.put(key, value);
    }
    modified = true;
}

From source file:com.glaf.oa.assessinfo.web.springmvc.AssessinfoController.java

@ResponseBody
@RequestMapping("/delete")
public void delete(HttpServletRequest request, ModelMap modelMap) {
    LoginContext loginContext = RequestUtils.getLoginContext(request);
    Long indexid = RequestUtils.getLong(request, "indexid");
    String indexids = request.getParameter("indexids");
    if (StringUtils.isNotEmpty(indexids)) {
        StringTokenizer token = new StringTokenizer(indexids, ",");
        while (token.hasMoreTokens()) {
            String x = token.nextToken();
            if (StringUtils.isNotEmpty(x)) {
                assessinfoService.deleteById(Long.valueOf(x));
            }/*w  w w  . j a v a2s .com*/
        }
    } else if (indexid != null) {
        Assessinfo assessinfo = assessinfoService.getAssessinfo(Long.valueOf(indexid));
        /**
         * 
         */
        if (assessinfo != null && (StringUtils.equals(assessinfo.getCreateBy(), loginContext.getActorId())
                || loginContext.isSystemAdministrator())) {
            // assessinfo.setDeleteFlag(1);
            assessinfoService.save(assessinfo);
        }
    }
}

From source file:com.netflix.spinnaker.config.secrets.SecretManager.java

/**
 * DecryptAsFile deserializes the configValue into an EncryptedSecret object, decrypts the EncryptedSecret based
 * on the secretEngine referenced in the configValue, writes the decrypted value into a temporary file, and returns
 * the absolute path to the temporary file.
 *
 * Based on the EncryptedSecret's parameters, the contents of the temporary file can be:
 * - The decrypted contents of a file stored externally
 * OR (if a key is present in the EncryptedSecret's parameters)
 * - The value of the key in the external file
 *
 * Note: The temporary file that is created is deleted upon exiting the application.
 *
 * @param filePathOrEncrypted//from  w  ww. jav a 2 s  .c o m
 * @return path to temporary file that contains decrypted contents or null if param not encrypted
 */
public Path decryptAsFile(String filePathOrEncrypted) {
    Path decryptedFile = getCachedSecretFile(filePathOrEncrypted);
    if (decryptedFile != null) {
        return decryptedFile;
    }

    String decryptedContents = decrypt(filePathOrEncrypted);
    if (StringUtils.equals(decryptedContents, filePathOrEncrypted)) {
        return Paths.get(filePathOrEncrypted);
    }

    decryptedFile = decryptedFilePath("tmp", decryptedContents);
    cacheSecretFile(filePathOrEncrypted, decryptedFile);

    return decryptedFile;
}

From source file:ch.cyberduck.core.azure.AzureReadFeature.java

@Override
public InputStream read(final Path file, final TransferStatus status, final ConnectionCallback callback)
        throws BackgroundException {
    try {//  w w  w  .java2s .c o  m
        final CloudBlob blob = session.getClient()
                .getContainerReference(containerService.getContainer(file).getName())
                .getBlobReferenceFromServer(containerService.getKey(file));
        final BlobRequestOptions options = new BlobRequestOptions();
        options.setConcurrentRequestCount(1);
        final BlobInputStream in = blob.openInputStream(AccessCondition.generateEmptyCondition(), options,
                context);
        if (status.isAppend()) {
            try {
                return StreamCopier.skip(in, status.getOffset());
            } catch (IndexOutOfBoundsException e) {
                // If offset is invalid
                throw new DefaultExceptionMappingService().map(e);
            }
        }
        return new ProxyInputStream(in) {
            @Override
            protected void handleIOException(final IOException e) throws IOException {
                if (StringUtils.equals(SR.STREAM_CLOSED, e.getMessage())) {
                    log.warn(String.format("Ignore failure %s", e));
                    return;
                }
                final Throwable cause = ExceptionUtils.getRootCause(e);
                if (cause instanceof StorageException) {
                    throw new IOException(e.getMessage(),
                            new AzureExceptionMappingService().map((StorageException) cause));
                }
                throw e;
            }
        };
    } catch (StorageException e) {
        throw new AzureExceptionMappingService().map("Download {0} failed", e, file);
    } catch (URISyntaxException e) {
        throw new NotfoundException(e.getMessage(), e);
    }
}

From source file:de.micromata.genome.gwiki.controls.GWikiPageListActionBean.java

protected String getjqGridOrderByExpression() {
    String sortBy = getReqParam("sidx");
    String sort = getReqParam("sord");
    if (StringUtils.isEmpty(sortBy) == true) {
        return null;
    }/*from  ww  w .j  a  va2 s .  c  o  m*/
    String order = StringUtils.equals(sort, "desc") ? "DESC" : "ASC";
    return "prop:" + sortBy + " " + order;
}

From source file:com.nridge.ds.solr.SolrCollection.java

private ArrayList<String> load(InputStream anIS) throws IOException {
    String jsonName, jsonValue;/*from   w  w w .j a va2  s  . c om*/

    ArrayList<String> configSetList = new ArrayList<>();
    String configSetString = IOUtils.toString(anIS, StrUtl.CHARSET_UTF_8);
    StringReader stringReader = new StringReader(configSetString);
    JsonReader jsonReader = new JsonReader(stringReader);
    jsonReader.beginObject();
    while (jsonReader.hasNext()) {
        jsonName = jsonReader.nextName();
        if (StringUtils.equals(jsonName, "collections")) {
            jsonReader.beginArray();
            while (jsonReader.hasNext()) {
                jsonValue = jsonReader.nextString();
                configSetList.add(jsonValue);
            }
            jsonReader.endArray();
        }
    }
    jsonReader.endObject();

    return configSetList;
}

From source file:com.dominion.salud.pedicom.negocio.service.impl.UsuariosServiceImpl.java

@Override
public Usuarios validarUsuarios(Usuarios usuarios)
        throws UsuarioIncorrectoException, UsuarioNoAsociadoACentroException, Exception {

    CabParInt cabParInt = cabParIntRepository.getCabParIntByCodigo(new CabParInt("LDAP"));
    if (StringUtils.equals(cabParInt.getActivado(), "S")) {
        logger.debug("Iniciando validacion LDAP");

        LDAPFarmatools ldapFarmatools = new LDAPFarmatools();

        try {//w  ww  .  j  av a2 s.co m
            logger.debug("     Obteniendo parametros de la validacion LDAP");
            boolean LDAP_AD = BooleanUtils.toBoolean(linParIntRepository
                    .getLinParIntByCodInterfaceTipo(new LinParInt(new LinParIntPK("LDAP", "LDAP_AD")))
                    .getParametro());
            String[] LDAP_HOSTS = {
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_1"))).getParametro(),
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_2"))).getParametro(),
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_3"))).getParametro(),
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_4"))).getParametro(),
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_5"))).getParametro(),
                    linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_HOST_6"))).getParametro() };
            String LDAP_DOMINIO = linParIntRepository
                    .getLinParIntByCodInterfaceTipo(new LinParInt(new LinParIntPK("LDAP", "LDAP_DOMINIO")))
                    .getParametro();
            String LDAP_USUARIO = linParIntRepository
                    .getLinParIntByCodInterfaceTipo(new LinParInt(new LinParIntPK("LDAP", "LDAP_USUARIO")))
                    .getParametro();
            String LDAP_PASSWORD = linParIntRepository
                    .getLinParIntByCodInterfaceTipo(new LinParInt(new LinParIntPK("LDAP", "LDAP_PASSWORD")))
                    .getParametro();
            String LDAP_RUTA_USUARIOS = linParIntRepository.getLinParIntByCodInterfaceTipo(
                    new LinParInt(new LinParIntPK("LDAP", "LDAP_RUTA_USUARIOS"))).getParametro();

            logger.debug("          LDAP_AD: " + LDAP_AD);
            logger.debug("          LDAP_HOSTS: " + StringUtils.join(LDAP_HOSTS, ","));
            logger.debug("          LDAP_DOMINIO: " + LDAP_DOMINIO);
            logger.debug("          LDAP_USUARIO: " + LDAP_USUARIO);
            logger.debug("          LDAP_PASSWORD: " + LDAP_PASSWORD);
            logger.debug("          LDAP_RUTA_USUARIOS: " + LDAP_RUTA_USUARIOS);
            logger.debug("     Parametros de la validacion LDAP obtenidos correctamente");

            logger.debug("     Validando Usuario LDAP");
            if (ldapFarmatools.validarUsuario(LDAP_AD, LDAP_HOSTS, LDAP_DOMINIO, usuarios.getLoginUsu(),
                    usuarios.getPasswUsu())) {
                logger.debug("     Usuario LDAP validado correctamente");
                boolean LDAP_CREAR_USUARIOS = BooleanUtils
                        .toBoolean(linParIntRepository
                                .getLinParIntByCodInterfaceTipo(
                                        new LinParInt(new LinParIntPK("LDAP", "LDAP_CREAR_USUARIOS")))
                                .getParametro());
                if (LDAP_CREAR_USUARIOS && !existeUsuario(usuarios)) {
                    List<EquiEc> equiGrupo = equiEcRepository
                            .findEquiEcByTipo(new EquiEc(new EquiEcPK("GR", "LDP"), "S"));
                    List<EquiEc> equiTipo = equiEcRepository
                            .findEquiEcByTipo(new EquiEc(new EquiEcPK("TG", "LDP"), "S"));

                    boolean ENCRIPTADO = BooleanUtils
                            .toBoolean(linParIntRepository
                                    .getLinParIntByCodInterfaceTipo(
                                            new LinParInt(new LinParIntPK("PEDICOM", "ENCRIPTADO")))
                                    .getParametro());
                    String LDAP_P_MEMBER_OF = linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_P_IsMemberOf"))).getParametro();
                    String LDAP_P_UID = linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_P_UID"))).getParametro();
                    String LDAP_P_NOMBRE = linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_P_NOMBRE"))).getParametro();
                    String LDAP_P_MAIL = linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_P_MAIL"))).getParametro();
                    String LDAP_CENTRO = linParIntRepository.getLinParIntByCodInterfaceTipo(
                            new LinParInt(new LinParIntPK("LDAP", "LDAP_CENTRO"))).getParametro();
                    String[] attrs = { LDAP_P_MEMBER_OF, LDAP_P_UID, LDAP_P_NOMBRE, LDAP_P_MAIL };

                    logger.debug("          Creando el usuario: " + usuarios.getLoginUsu() + " en FARMATOOLS");
                    HashMap<String, String> params;

                    logger.debug("               Buscando ATRIBUTOS del usuario: " + LDAP_P_UID + "="
                            + usuarios.getLoginUsu());
                    if (StringUtils.isNotBlank(LDAP_USUARIO) && StringUtils.isNotBlank(LDAP_PASSWORD)) {
                        params = ldapFarmatools.findByQueryAttr(LDAP_AD, LDAP_HOSTS, LDAP_DOMINIO, LDAP_USUARIO,
                                LDAP_PASSWORD, LDAP_RUTA_USUARIOS, LDAP_P_UID + "=" + usuarios.getLoginUsu(),
                                attrs);
                    } else {
                        params = ldapFarmatools.findByQueryAttr(LDAP_AD, LDAP_HOSTS, LDAP_DOMINIO,
                                usuarios.getLoginUsu(), usuarios.getPasswUsu(), LDAP_RUTA_USUARIOS,
                                LDAP_P_UID + "=" + usuarios.getLoginUsu(), attrs);
                    }
                    logger.debug("               Atributos del usuario");
                    logger.debug(
                            "                    " + LDAP_P_MEMBER_OF + ": " + params.get(LDAP_P_MEMBER_OF));
                    logger.debug("                    " + LDAP_P_UID + ": " + params.get(LDAP_P_UID));
                    logger.debug("                    " + LDAP_P_NOMBRE + ": " + params.get(LDAP_P_NOMBRE));
                    logger.debug("                    " + LDAP_P_MAIL + ": " + params.get(LDAP_P_MAIL));

                    //Creamos el usuario nuevo
                    Usuarios usu = new Usuarios();
                    usu.setLoginUsu(usuarios.getLoginUsu());

                    if (ENCRIPTADO) {
                        usu.setPasswUsu(encriptar(usuarios.getPasswUsu()));
                    } else {
                        usu.setPasswUsu(usuarios.getPasswUsu());
                    }

                    //Nombre del Usuario
                    if (StringUtils.isNotBlank(params.get(LDAP_P_NOMBRE))) {
                        usu.setNombreUsu(params.get(LDAP_P_NOMBRE));
                    } else {
                        usu.setNombreUsu(usuarios.getLoginUsu());
                    }

                    //Valida el centro
                    if (StringUtils.isNotBlank(LDAP_CENTRO)) {
                        logger.debug("               Validando el CENTRO: " + LDAP_CENTRO);
                        if (!StringUtils.contains(params.get(LDAP_P_MEMBER_OF), LDAP_CENTRO)) {
                            logger.error("El atributo: " + LDAP_P_MEMBER_OF + "[" + params.get(LDAP_P_MEMBER_OF)
                                    + "], no contiene el CENTRO: " + LDAP_CENTRO);
                            throw new UsuarioIncorrectoException(
                                    "El usuario no pertenece al centro: " + LDAP_CENTRO + ". Validacion LDAP");
                        }
                    }

                    //Valida el grupo
                    String grupo = "";
                    logger.debug("               Obteniendo el GRUPO del usuario");
                    if (equiGrupo != null && !equiGrupo.isEmpty()) {
                        for (EquiEc equiEc : equiGrupo) {
                            logger.debug("                    Evaluando si el ATRIBUTO: "
                                    + params.get(LDAP_P_MEMBER_OF) + " contiene la EQUIVALENCIA: "
                                    + equiEc.getEquiEcPK().getCodEc() + " del GRUPO: "
                                    + equiEc.getEquiEcPK().getCodFar());
                            if (StringUtils.contains(params.get(LDAP_P_MEMBER_OF),
                                    equiEc.getEquiEcPK().getCodEc())) {
                                grupo = equiEc.getEquiEcPK().getCodFar();
                                break;
                            }
                        }
                    }
                    if (StringUtils.isBlank(grupo)) {
                        logger.error("El ATRIBUTO: " + params.get(LDAP_P_MEMBER_OF)
                                + " no contiene ningun GRUPO de FARMATOOLS");
                        throw new UsuarioIncorrectoException(
                                "El usuario pertenece a un GRUPO sin acceso a Farmatools. Validacion LDAP");
                    }

                    //Valida el tipo
                    String tipo = "";
                    logger.debug("               Obteniendo el TIPO del usuario");
                    if (equiTipo != null && !equiTipo.isEmpty()) {
                        for (EquiEc equiEc : equiTipo) {
                            logger.debug("                    Evaluando si el ATRIBUTO: "
                                    + params.get(LDAP_P_MEMBER_OF) + " contiene la EQUIVALENCIA: "
                                    + equiEc.getEquiEcPK().getCodEc() + " del TIPO: "
                                    + equiEc.getEquiEcPK().getCodFar());
                            if (StringUtils.contains(params.get(LDAP_P_MEMBER_OF),
                                    equiEc.getEquiEcPK().getCodEc())) {
                                tipo = equiEc.getEquiEcPK().getCodFar();
                                break;
                            }
                        }
                    }
                    if (StringUtils.isBlank(tipo)) {
                        logger.error("El ATRIBUTO: " + params.get(LDAP_P_MEMBER_OF)
                                + " no contiene ningun TIPO de FARMATOOLS");
                        throw new UsuarioIncorrectoException(
                                "El usuario pertenece a un TIPO sin acceso a Farmatools. Validacion LDAP");
                    }

                    usu.setGrpUsu(grupo);
                    usu.setTipoUsu(tipo);

                    //Graba el usuario
                    try {
                        logger.debug(
                                "               Creando el usuario: " + usu.getLoginUsu() + " en FARMATOOLS");
                        usuariosRepository.save(usu);
                        logger.debug("               Usuario: " + usu.getLoginUsu()
                                + " creado correctamente en FARMATOOLS");
                    } catch (Exception e) {
                        logger.warn("No se ha podido almacenar el nuevo usuario: " + e.toString());
                    }
                }
            } else {
                logger.error("El usuario no se ha validado correctamente contra LDAP");
                throw new UsuarioIncorrectoException("El usuario no se ha validado correctamente contra LDAP");
            }
        } catch (Exception e) {
            throw new UsuarioIncorrectoException(
                    "Se han producido errores al realizar la validacion LDAP: " + e.toString());
        }

        try {
            logger.debug("Usuario validado LDAP, comprobando asociacion usuario con centro");
            Usuarios usuariosVal = usuariosRepository.validarCentroUsuarios(usuarios);
            logger.debug("Usuario asociado");
            session.setAttribute("pedicom.usuario", usuariosVal);
            return usuariosVal;
        } catch (NoResultException nre) {
            throw new UsuarioNoAsociadoACentroException(
                    "El usuario no esta asociado al centro: " + nre.toString());
        }
    } else {
        try {
            logger.debug("Comprobando que el usuario existe");
            usuariosRepository.validarUsuarios(usuarios);
            logger.debug("Usuario correcto");
        } catch (NoResultException nre) {
            throw new UsuarioIncorrectoException("Las credenciales no son correctas");
        } catch (NonUniqueResultException nure) {
            throw new UsuarioIncorrectoException("Mas de un usuario con ese login");
        }
        try {
            logger.debug("Comprobando que el usuario esta asociado al centro");
            Usuarios usuariosVal = usuariosRepository.validarCentroUsuarios(usuarios);
            session.setAttribute("pedicom.usuario", usuariosVal);
            logger.debug("Usuario asociado");
            return usuariosVal;
        } catch (NoResultException nre) {
            throw new UsuarioNoAsociadoACentroException("El usuario no esta asociado al centro");
        }
    }
}