Example usage for org.springframework.util StringUtils isEmpty

List of usage examples for org.springframework.util StringUtils isEmpty

Introduction

In this page you can find the example usage for org.springframework.util StringUtils isEmpty.

Prototype

public static boolean isEmpty(@Nullable Object str) 

Source Link

Document

Check whether the given object (possibly a String ) is empty.

Usage

From source file:gov.nyc.doitt.gis.geoclient.parser.test.ChunkSpecParser.java

/**
 * Given the spec body:// ww  w. j  a  v a 2 s.  c o  m
 *  '[59] [Maiden Lane] [Manhattan]=COUNTY(0-24:BOROUGH_NAME{3})|ADDRESS(0-19:HOUSE_NUMBER{1},STREET_NAME{2})'
 * Expects the following parameter tokenType format
 * @param chunkDefinition example: 'ADDRESS(0-19:HOUSE_NUMBER{1},STREET_NAME{2})'
 * @param delimitedTokenText example: '[59] [Maiden Lane] [Manhattan]'
 * @return
 */
protected Chunk parseChunk(String chunkDefinition, String delimitedTokenText,
        List<MutableToken> untypedTokens) {
    if (StringUtils.isEmpty(chunkDefinition)) {
        throw new TestConfigurationException("Parameter 'unparsedChunkSpec' cannot be null or empty.");
    }
    if (StringUtils.isEmpty(delimitedTokenText)) {
        throw new TestConfigurationException("Parameter 'delimitedTokenText' cannot be null or empty.");
    }
    Matcher matcher = CHUNK_DEFINITION_BODY_PATTERN.matcher(chunkDefinition);
    if (!matcher.matches()) {
        throw new TestConfigurationException(
                String.format("Could not parse chunk definition from input '%s' using pattern '%s'",
                        chunkDefinition, CHUNK_DEFINITION_BODY_PATTERN.pattern()));
    }
    String chunkDefinitionBody = matcher.group(1);
    if (chunkDefinitionBody == null) {
        throw new TestConfigurationException(
                String.format("Did not find chunk definition body in input '%s'", chunkDefinition));
    }
    // Must exist:  splits[0] == '0-24'
    // Might exist: splits[1] == 'HOUSE_NUMBER,STREET_NAME'
    String[] splits = chunkDefinitionBody.split(":");
    int splitsLength = splits.length;
    if (splitsLength < 1 || splitsLength > 2) {
        throw new TestConfigurationException(String.format(
                "Expected format '2-12:TYPE1{2},TYPE2{1}' for chunk definition body but found '%s'.",
                chunkDefinitionBody));
    }
    LOGGER.debug("Parsing Chunk definition '{}'", chunkDefinition);
    ChunkType chunkType = parseChunkType(chunkDefinition);
    String plainText = removeBrackets(delimitedTokenText);
    Range chunkRange = parseChunkRange(splits[0]);
    Chunk chunk = new Chunk(chunkType, chunkRange.substring(plainText));
    if (splitsLength == 1) {
        // Chunk definition does not contain tokens
        return chunk;
    }
    String[] tokenTypeNameAndPositions = splits[1].split(",");
    for (int i = 0; i < tokenTypeNameAndPositions.length; i++) {
        TokenTypeOccurrence typeOccurrence = parseTokenTypeOccurrence(tokenTypeNameAndPositions[i]);
        if (typeOccurrence.occurrence() > untypedTokens.size()) {
            throw new TestConfigurationException(
                    String.format("TokenType specified for value %d but there are only %d Token values.",
                            typeOccurrence.occurrence(), untypedTokens.size()));
        }
        MutableToken untypedToken = untypedTokens.get(typeOccurrence.zeroIndexOccurrence());
        untypedToken.setTokenType(typeOccurrence.tokenType());
        chunk.add(untypedToken.toToken());
    }
    return chunk;
}

From source file:webFramework.MappingJackson2PrettyJsonView.java

private String getJsonpParameterValue(HttpServletRequest request) {
    if (this.jsonpParameterNames != null) {
        for (String name : this.jsonpParameterNames) {
            String value = request.getParameter(name);
            if (StringUtils.isEmpty(value)) {
                continue;
            }//  ww  w  .  ja v  a2 s  .c  o  m
            if (!isValidJsonpQueryParam(value)) {
                continue;
            }
            return value;
        }
    }
    return null;
}

From source file:net.paslavsky.springrest.SpringAnnotationPreprocessor.java

private Map<String, Integer> getParametersWithAnnotation(Method method,
        Class<? extends Annotation> annotationClass) {
    Map<String, Integer> parameters = new HashMap<String, Integer>();
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for (int i = 0; i < parameterAnnotations.length; i++) {
        Annotation[] annotations = parameterAnnotations[i];
        if (isAnnotationPresent(annotations, annotationClass)) {
            String name = getValue(annotations, annotationClass);
            if (StringUtils.isEmpty(name)) {
                throw new SpringRestClientConfigurationException(
                        "REST client can't identify name by " + annotationClass);
            }//from ww w  .  j a v a  2s.co  m
            parameters.put(name, i);
        }
    }
    return parameters;
}

From source file:org.ihtsdo.otf.snomed.service.ConceptLookUpServiceImplv1_0.java

@Override
@Cacheable(value = { "concept" })
public Concept getConcept(String conceptId) throws ConceptServiceException, EntityNotFoundException {

    LOGGER.debug("getting concept details for {} ", conceptId);

    if (StringUtils.isEmpty(conceptId)) {

        throw new EntityNotFoundException(String.format("Invalid concept id", conceptId));
    }/*  w  ww . j  a  v  a 2 s  . c om*/

    TitanGraph g = null;

    try {

        g = factory.getReadOnlyGraph();

        Iterable<Vertex> vs = g.getVertices(Properties.sctid.toString(), conceptId);

        for (Vertex r : vs) {

            Concept c = new Concept();

            Vertex v = r;

            String sctId = v.getProperty(Properties.sctid.toString());
            c.setId(sctId);

            Long effectiveTime = v.getProperty(Properties.effectiveTime.toString());

            if (effectiveTime != null) {

                c.setEffectiveTime(new DateTime(effectiveTime));

            }

            String status = v.getProperty(Properties.status.toString());
            boolean active = "1".equals(status) ? true : false;
            c.setActive(active);

            String label = v.getProperty(Properties.title.toString());
            c.setLabel(label);

            Iterable<Edge> es = v.getEdges(Direction.OUT, Relationship.hasModule.toString());

            for (Edge edge : es) {

                Vertex vE = edge.getVertex(Direction.IN);

                if (vE != null) {

                    String moduleId = vE.getProperty(Properties.sctid.toString());
                    c.setModuleId(moduleId);
                    break;

                }

            }

            RefsetGraphFactory.commit(g);

            return c;

        }

        RefsetGraphFactory.commit(g);

    } catch (Exception e) {

        LOGGER.error("Error duing concept details fetch", e);
        RefsetGraphFactory.rollback(g);

        throw new ConceptServiceException(e);

    } finally {

        RefsetGraphFactory.shutdown(g);
    }

    throw new EntityNotFoundException(String.format("Invalid concept id", conceptId));

}

From source file:com.github.springfox.loader.SpringfoxLoaderConfig.java

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    if (!StringUtils.isEmpty(springfoxLoader.swaggerUiBasePath())) {
        registry.addResourceHandler(resourcePath("/swagger-ui.html**"))
                .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
        registry.addResourceHandler(resourcePath("/webjars/**"))
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }//from  www.  jav  a2 s.c o  m
}

From source file:com.ocs.dynamo.importer.impl.BaseXlsImporter.java

/**
 * Retrieves the numeric value of a cell, or falls back to a suitable default if the cell is
 * empty and the default is defined/* ww w .  j a va 2 s  .c  om*/
 * 
 * @param cell
 * @param field
 * @return
 */
@Override
public Double getNumericValueWithDefault(Cell cell, XlsField field) {
    Double value = getNumericValue(cell);
    if (value == null && !StringUtils.isEmpty(field.defaultValue())) {
        value = Double.valueOf(field.defaultValue());
    }
    return value;
}

From source file:bamons.process.monitoring.web.BatchMonitoringController.java

/**
 *
 * Job ?//  w w  w .j a  v a2s  .  c om
 *
 * @param request request ?
 * @param response response ?
 * @return job  JSON
 * @throws Exception
 */
@RequestMapping(value = "/job/start.do", produces = { "application/json; charset=UTF-8" })
public @ResponseBody Map<String, Object> jobStart(HttpServletRequest request, HttpServletResponse response)
        throws Exception {

    boolean status = true;
    String jobName = ServletRequestUtils.getStringParameter(request, "jobName", "");
    String targetDate = ServletRequestUtils.getStringParameter(request, "targetDate", "");
    String statusMessage = "";

    Map<String, Object> map = new HashMap<String, Object>();

    if (!StringUtils.isEmpty(jobName) && !StringUtils.isEmpty(targetDate)) {

        try {
            batchMonitoringService.jobStart(jobName, targetDate);
        } catch (Exception e) {
            statusMessage = e.toString();
            status = false;
        }

    } else {
        status = false;
        statusMessage = "jobName or targetDate Error";
    }

    map.put("success", true);
    map.put("status", status);
    map.put("statusMessage", statusMessage);
    return map;
}

From source file:cz.muni.fi.mir.tools.SiteTitleInterceptor.java

private void resolveClassLevelSeparator(SiteTitle siteTitle, SiteTitleContainer result) {
    if (!StringUtils.isEmpty(siteTitle.separator())) {
        result.setSeparator(siteTitle.separator());
    } else {/*w  w  w .  j  a va2  s  .  c  om*/
        result.setSeparator(this.separator);
    }
}

From source file:au.com.ors.rest.controller.JobAppController.java

/**
 * Create a new application<br/>/*from   w w w  . j  a  va2s.com*/
 * 
 * @param application
 *            application JSON object
 * @return a HATEOAS application object with HTTP status 201 created
 * @throws JobAppMalformatException
 * @throws TransformerException
 */
@RequestMapping(method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<JobApplicationResource> createApplication(@RequestBody JobApplication application)
        throws JobAppMalformatException, TransformerException {
    if (application == null) {
        throw new JobAppMalformatException("Cannot create null job application");
    }

    if (StringUtils.isEmpty(application.get_jobId())) {
        throw new JobAppMalformatException("Job application malformed: _jobId required");
    }

    JobPosting jobFound = jobDao.findByJid(application.get_jobId());
    if (jobFound == null) {
        throw new JobAppMalformatException("Job application malformed: job with _jobId not found in database");
    }

    if (StringUtils.isEmpty(application.getDriverLicenseNumber())) {
        throw new JobAppMalformatException("Job application malformed: driverLicenseNumber required");
    }

    if (StringUtils.isEmpty(application.getFullName())) {
        throw new JobAppMalformatException("Job application malformed: fullName required");
    }

    if (StringUtils.isEmpty(application.getPostCode())) {
        throw new JobAppMalformatException("Job application malformed: postCode required");
    }

    application.set_appId(UUID.randomUUID().toString());

    if (StringUtils.isEmpty(application.getTextCoverLetter())) {
        application.setTextCoverLetter("");
    }

    if (StringUtils.isEmpty(application.getTextBriefResume())) {
        application.setTextBriefResume("");
    }

    // after the create, status becomes submit but not processed yet
    application.setStatus(JobAppStatus.APP_SUBMITTED_NOT_PROCESSED.name());

    JobApplication createdApp = jobAppDao.create(application);

    JobApplicationResource createdAppResource = appResourceAssembler.toResource(createdApp);

    return new ResponseEntity<JobApplicationResource>(createdAppResource, HttpStatus.CREATED);
}

From source file:com.biz.report.service.impl.ReportServiceImpl.java

@Override
public List<Report4DataSet> readColumnChart(String types, String months, String year) {
    if (!StringUtils.isEmpty(types) && types.contains("[")) {
        types = types.substring(1, types.length() - 1);
    }//from  w w w . ja  v  a  2s . c o m
    String[] typeAr;
    if (!StringUtils.isEmpty(types) && types.contains(",")) {
        typeAr = types.split("[,]");
    } else {
        typeAr = new String[] { types };
    }
    if (!StringUtils.isEmpty(months) && months.contains("[")) {
        months = months.substring(1, months.length() - 1);
    }
    String[] monthAr;
    if (!StringUtils.isEmpty(months) && months.contains(",")) {
        monthAr = months.split("[,]");
    } else {
        monthAr = new String[] { months };
    }
    int typeCount = typeAr.length;
    List list = reportDao.read(types, year, months);
    List<Report1> reportList = new MappingEngine().getList(list);
    logger.info(reportList.size());
    List<Report4DataSet> dataSets = new ArrayList<Report4DataSet>();
    for (int i = 0; i < typeCount; i++) {
        List<DataPoint> dataPoints = constructDataPoints(reportList, typeAr[i].trim(), monthAr, i);
        dataSets.add(new Report4DataSet("column", dataPoints, typeAr[i]));
    }
    return dataSets;
}