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

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

Introduction

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

Prototype

public static boolean contains(final CharSequence seq, final CharSequence searchSeq) 

Source Link

Document

Checks if CharSequence contains a search CharSequence, handling null .

Usage

From source file:BackupRestoreTest.java

private static void checkRestoreTo(final String passwordData, final String passwordMeta,
        final Collection<String> repoPatern, List<String> argList) throws Exception {
    CipherProvider dataCipherProvider = new CipherProvider();
    dataCipherProvider.setPassword(passwordData);
    CipherProvider metaCipherProvider = new CipherProvider();
    metaCipherProvider.setPassword(passwordMeta);

    String repoPathStr = REPO_TST;
    Repository repository = new Repository(repoPathStr, dataCipherProvider, metaCipherProvider);

    VOConfig cfg = new VOConfig(REPO_TST, ID_BCK_TST, getExcl("*.excl"), getExcl("*Excl"), argList);

    BackupService backup = new BackupService(cfg, repository);
    final String bck = backup.run();

    // check repo content
    List<String> contentRepo = getContentDir(REPO_TST + File.separator + "data", false);
    printContent(contentRepo);//from  ww w .j  a v  a2 s  .  co m
    checkCollectionIn(repoPatern, contentRepo);

    RestoreService restore = new RestoreService(bck, repository, argList, RESTORE_TST);
    restore.run();

    // check new dir content
    List<String> contentRestore = getContentDir(RESTORE_TST, false);
    // TODO Lebeda - do check with date - on source tst files must be dat prepared on setup test
    printContent(contentRestore);
    Assert.assertEquals(16, contentRestore.size());
    Assert.assertTrue(0 == CollectionUtils.countMatches(contentRestore, new Predicate() {
        @Override
        public boolean evaluate(final Object object) {
            String s = (String) object;
            return StringUtils.contains(s, "excl");
        }
    }));
    Assert.assertTrue(CollectionUtils.isSubCollection(getContentRestorePatern(), contentRestore));
}

From source file:com.thoughtworks.go.matchers.ConsoleOutMatcher.java

public static TypeSafeMatcher<String> printedBuildFailed() {
    return new TypeSafeMatcher<String>() {
        private String consoleOut;

        public boolean matchesSafely(String consoleOut) {
            this.consoleOut = consoleOut;
            return StringUtils.contains(consoleOut.toLowerCase(), "build failed");
        }/*from  ww  w  .  ja  v  a 2 s. c  o  m*/

        public void describeTo(Description description) {
            description.appendText("expected console to contain [build failed] but was " + consoleOut);
        }
    };
}

From source file:com.dchq.docker.volume.driver.controller.DockerVolumeDriverControllerIntegrationTests.java

@Test
public void mountTest() {

    String name = RandomStringUtils.randomAlphabetic(6);
    CreateRequest request = new CreateRequest();
    request.setName(name);/* w  ww . ja va  2s .c  o  m*/

    String response = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.CREATE, request,
            String.class);
    Assert.assertNotNull(response);
    Assert.assertEquals(response, "{\"Err\":\"\"}");

    MountRequest mountRequest = new MountRequest();
    mountRequest.setName(name);

    String mountResponse = restTemplate.postForObject(baseUrl + DockerVolumeDriverController.MOUNT,
            mountRequest, String.class);
    Assert.assertNotNull(mountResponse);
    Assert.assertTrue(StringUtils.contains(mountResponse, "\"Err\":\"\""));
    logger.info("Response [{}]", mountResponse);
}

From source file:cz.muni.fi.editor.services.api.notifications.NotificationServiceImpl.java

@TransactionalEventListener
@Async/* w  w w. ja v a 2s. com*/
@Override
@Transactional
public void notify(ERequestCreated rec) {
    if (StringUtils.contains(rec.getRequest().getClazz(), "Organization")) {
        if (rec.getRequest().getAction().equals("create")) {
            notifyMultiple(rec, organizationDAO.getById(1L).getMembers());
        } else if (rec.getRequest().getAction().equals("join")) {
            Organization o = organizationDAO.getById(rec.getRequest().getTargetId());

            Notification n = notificationFactory.provideNotification(rec);
            n.setNotified(o.getOwner());
            notificationDAO.create(n);
        }
    }
}

From source file:ke.co.tawi.babblesms.server.persistence.utils.DbFileUtils.java

/**
 * This is used to import the results of CSV text file to the database.
 *
 * @param sqlQuery//from w  w w. ja v a 2s .  c o  m
 * @param fileLocation this should include the full path of the file e.g.
 * /tmp/myFile.csv
 *
 * @return whether the action was successful or not
 */
public boolean importCSVToDatabase(String sqlQuery, File fileLocation) {
    boolean success = false;

    FileReader fileReader;

    try (
            // Return a database connection that is not pooled
            // to enable the connection to be cast to BaseConnection
            Connection conn = dbCredentials.getJdbcConnection();) {

        String fileName = fileLocation.getName();
        if (!StringUtils.contains(fileName, "null")) {

            fileReader = new FileReader(fileLocation);

            CopyManager copyManager = new CopyManager((BaseConnection) conn);

            copyManager.copyIn(sqlQuery, fileReader);

            fileReader.close();

            success = true;
        }

    } catch (SQLException e) {
        logger.error(
                "SQLException while importing results of  '" + fileLocation + "' and SQL query: " + sqlQuery);
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;

    } catch (IOException e) {
        logger.error(
                "SQLException while importing results of  '" + fileLocation + "' and SQL query: " + sqlQuery);
        logger.error(ExceptionUtils.getStackTrace(e));
        success = false;
    }

    return success;
}

From source file:com.dell.asm.asmcore.asmmanager.util.discovery.providers.CServer.java

@Override
protected void executeCommand() {
    CommandResponse cmdresponse;//from w  ww.j  a va 2s . co  m
    ExecuteSystemCommands cmdRunner = ExecuteSystemCommands.getInstance();
    String serverMsg = null;

    CredentialEntity cred = CredentialDAO.getInstance().findById(device.getServerCredentialId());
    if (cred != null) {
        Set<FirmwareDeviceInventoryEntity> fwCSeriesInvSet = new HashSet<>();
        Map<String, String> firmwareVersions = new HashMap<String, String>();
        String[] cmdLine = { "/opt/dell/pec/bmc", "-H", device.getIpAddress(), "allinfo" };
        // String cmdLine = "ipmitool -I lan -H " + device.getIpAddress() + " -U " + cred.getUsername() + " -P " + cred.getPassword() + " fru";
        try {
            cmdresponse = cmdRunner.runCommandWithConsoleOutputWithCheckNewLine(cmdLine, true, true);
            if (cmdresponse.getReturnCode().equals("0")) {
                serverMsg = cmdresponse.getReturnMessage();
                if (serverMsg != null) {
                    logger.debug("ipmi response returned for server " + serverMsg);

                    firmwareVersions = parseBMCOutput(serverMsg);
                    if (result.getModel() != null) {
                        result.setRefType(com.dell.pg.asm.server.client.ClientUtils.DISCOVERY_IP_REF_TYPE);
                        //for inventory, check if the service tag already exists in device inventory table, if yes, then use that devicerefID to
                        //update the firmware device inventory table
                        DeviceInventoryEntity devInven = this.deviceInventoryDAO
                                .getDeviceInventoryByServiceTag(result.getServiceTag());
                        if (devInven != null)
                            result.setDeviceRefId(devInven.getRefId());
                        else
                            result.setDeviceRefId(UUID.randomUUID().toString());
                        result.setSystemId(CSERIES_SYSTEMID);
                        for (Map.Entry<String, String> entry : firmwareVersions.entrySet()) {
                            FirmwareDeviceInventoryEntity fwCSeriesInv = new FirmwareDeviceInventoryEntity();
                            fwCSeriesInv.setVersion(entry.getValue());
                            if (StringUtils.contains(entry.getKey(), "BIOS"))
                                fwCSeriesInv.setComponentID(getFirmwareComponentID());
                            fwCSeriesInv.setName(entry.getKey());
                            fwCSeriesInv.setIpaddress(result.getIpAddress());
                            fwCSeriesInv.setServicetag(result.getServiceTag());
                            fwCSeriesInv.setParent_job_id(result.getParentJobId());
                            fwCSeriesInv.setJobId(result.getJobId());
                            fwCSeriesInvSet.add(fwCSeriesInv);
                        }
                        DiscoveryJobUtils.updateFirmwareDiscoveryResult(result, fwCSeriesInvSet);
                        try {
                            DeviceInventoryEntity devInv = this.deviceInventoryDAO
                                    .getDeviceInventory(result.getDeviceRefId());

                            if (devInv != null) {
                                logger.debug("Updating devInv " + devInv + " with ip: " + devInv.getIpAddress()
                                        + " The rediscovered IP was: " + result.getIpAddress());
                                if (!devInv.getIpAddress().equals(result.getIpAddress())) {
                                    devInv.setIpAddress(result.getIpAddress());
                                }
                                this.deviceInventoryDAO.updateDeviceInventory(devInv);
                                this.deviceInventoryDAO
                                        .deleteFirmwareDeviceInventoryForDevice(devInv.getRefId());
                                if (result.getFirmwareDeviceInventories() != null) {
                                    for (FirmwareDeviceInventory fdi : result.getFirmwareDeviceInventories()) {
                                        fdi.setId(null);
                                        FirmwareDeviceInventoryEntity fdiEntity = new FirmwareDeviceInventoryEntity(
                                                fdi);
                                        fdiEntity.setDeviceInventoryId(devInv.getRefId());
                                        this.deviceInventoryDAO.createFirmwareDeviceInventory(fdiEntity);
                                    }
                                }

                            } else {
                                if (device.isFromInventoryJob()) {
                                    logger.debug("Found new blade: service tag=" + result.getServiceTag()
                                            + ", IP=" + result.getIpAddress());
                                    // device will be added in DiscoverIpRangeJob.updateInventory()
                                }
                            }
                        } catch (AsmManagerCheckedException e) {
                            result.setStatus(DiscoveryStatus.ERROR);
                            logger.warn("Error while updating device for refid: " + result.getDeviceRefId()
                                    + ".  The rest of the update was successful.");
                            EEMILocalizableMessage eemiMessage = AsmManagerMessages
                                    .discoveryServiceException(device.getIpAddress());
                            result.setStatusMessage(eemiMessage.getDisplayMessage().localize());
                        }
                    }
                }
            } else {
                logger.debug("BMC server discovery command returned: " + cmdresponse.getReturnMessage());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

From source file:com.thinkbiganalytics.metadata.sla.DefaultServiceLevelAgreementScheduler.java

private String getUniqueName(String name) {
    String uniqueName = name;/*from  w  w  w. j a v  a 2s .co m*/
    final String checkName = name;
    String matchingName = Iterables.tryFind(scheduledJobNames.values(), new Predicate<String>() {
        @Override
        public boolean apply(String s) {
            return s.equalsIgnoreCase(checkName);
        }
    }).orNull();
    if (matchingName != null) {
        //get numeric string after '-';
        if (StringUtils.contains(matchingName, "-")) {
            String number = StringUtils.substringAfterLast(matchingName, "-");
            if (StringUtils.isNotBlank(number)) {
                number = StringUtils.trim(number);
                if (StringUtils.isNumeric(number)) {
                    Integer num = Integer.parseInt(number);
                    num++;
                    uniqueName += "-" + num;
                } else {
                    uniqueName += "-1";
                }
            }
        } else {
            uniqueName += "-1";
        }
    }
    return uniqueName;
}

From source file:net.sf.dynamicreports.jasper.base.tableofcontents.JasperTocReport.java

private static void addTocHeading(Map<String, JasperTocHeading> headings, List<JasperTocHeading> headingList,
        JRPrintElement element, int pageNumber) {
    if (element instanceof JRPrintText && StringUtils.contains(element.getKey(), ".tocReference")) {
        String id = ((JRPrintText) element).getAnchorName();
        JasperTocHeading heading = headings.get(id);
        heading.setPageIndex(pageNumber);
        headingList.add(heading);/*from  w w  w  .  j a v a 2  s .  co  m*/
    }
    if (element instanceof JRPrintFrame) {
        for (JRPrintElement element2 : ((JRPrintFrame) element).getElements()) {
            addTocHeading(headings, headingList, element2, pageNumber);
        }
    }
}

From source file:com.thoughtworks.go.matchers.ConsoleOutMatcherJunit5.java

public ConsoleOutMatcherJunit5 doesNotContain(String str) {
    if (StringUtils.contains(actual, str)) {
        failWithMessage("Expected console to not contain [<%s>] but was <%s>.", str, actual);
    }// w  w  w.ja  va  2 s  .  c om
    return this;
}

From source file:de.crowdcode.kissmda.core.uml.PackageHelper.java

/**
 * Remove the UML type prefixes from {@link #UmlTypePrefix}.
 * /*from w  ww .  ja v a 2s.  c  o m*/
 * @param fullQualifiedName
 *            fully qualified name
 * @return clean type name
 */
public String removeUmlPrefixes(final String fullQualifiedName) {
    // MagicDraw specific prefixes...
    String result = fullQualifiedName.replace(UmlTypePrefix.MAGIC_DRAW_PROFILE_DATATYPES.getValue(), "");
    result = result.replace(UmlTypePrefix.UML_PRIMITIVE_TYPES.getValue(), "");
    result = result.replace(UmlTypePrefix.JAVA_PRIMITIVE_TYPES.getValue(), "");
    result = result.replace(UmlTypePrefix.VALIDATION_PROFILE_OCL_LIBRARY.getValue(), "");

    // Name dataype and dataype-bindings
    if (StringUtils.contains(result, UmlTypePrefix.DATA_DATATYPE.getValue())) {
        result = result.replace(UmlTypePrefix.DATA_DATATYPE.getValue(), "");
    }
    if (StringUtils.contains(result, UmlTypePrefix.DATA_DATATYPE_BINDINGS.getValue())) {
        result = result.replace(UmlTypePrefix.DATA_DATATYPE_BINDINGS.getValue(), "");
    }

    return result;
}