Java Code Examples for spark.utils.StringUtils#isEmpty()

The following examples show how to use spark.utils.StringUtils#isEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InternalCommandSnippetsControllerV1.java    From gocd with Apache License 2.0 6 votes vote down vote up
public String index(Request request, Response response) throws IOException {
    String prefix = request.queryParams(PREFIX_PARAM);
    if (StringUtils.isEmpty(prefix)) {
        throw HaltApiResponses.haltBecauseRequiredParamMissing(PREFIX_PARAM);
    }

    List<CommandSnippet> commandSnippets = commandRepositoryService.lookupCommand(prefix);

    String etag = etagFor(commandSnippets);

    if (fresh(request, etag)) {
        return notModified(response);
    }

    setEtagHeader(response, etag);
    return writerForTopLevelObject(request, response, outputWriter -> CommandSnippetsRepresenter.toJSON(outputWriter, commandSnippets, prefix));
}
 
Example 2
Source File: User.java    From minitwit with MIT License 5 votes vote down vote up
public String validate() {
	String error = null;
	
	if(StringUtils.isEmpty(username)) {
		error = "You have to enter a username";
	} else if(!EMAIL_ADDRESS_REGEX.matcher(email).matches()) {
		error = "You have to enter a valid email address";
	} else if(StringUtils.isEmpty(password)) {
		error = "You have to enter a password";
	} else if(!password.equals(password2)) {
		error = "The two passwords do not match";
	}
	
	return error;
}
 
Example 3
Source File: User.java    From ha-bridge with Apache License 2.0 5 votes vote down vote up
public String validate() {
	String error = null;
	
	if(StringUtils.isEmpty(username)) {
		error = "You have to enter a username";
	} else if(StringUtils.isEmpty(password)) {
		error = "You have to enter a password";
	} else if(!password.equals(password2)) {
		error = "The two passwords do not match";
	}
	
	return error;
}
 
Example 4
Source File: UsageStatisticsControllerV3.java    From gocd with Apache License 2.0 5 votes vote down vote up
private boolean verifySignatureAndPublicKey(String signature, String subordinatePublicKey, HttpLocalizedOperationResult result) throws Exception {
    if (StringUtils.isEmpty(signature)) {
        result.unprocessableEntity(String.format("Please provide '%s' field.", SIGNATURE_KEY));
        return false;
    }

    if (StringUtils.isEmpty(subordinatePublicKey)) {
        result.unprocessableEntity(String.format("Please provide '%s' field.", SUBORDINATE_PUBLIC_KEY));
        return false;
    }

    String masterPublicKey = FileUtils.readFileToString(new File(systemEnvironment.getUpdateServerPublicKeyPath()), "utf8");

    boolean isVerified;
    try {
        isVerified = EncryptionHelper.verifyRSASignature(subordinatePublicKey, signature, masterPublicKey);
    } catch (Exception e) {
        isVerified = false;
    }

    if (!isVerified) {
        result.unprocessableEntity(String.format("Invalid '%s' or '%s' provided.", SIGNATURE_KEY, SUBORDINATE_PUBLIC_KEY));
        return false;
    }

    return true;
}