Search in sources :

Example 6 with VXMessage

use of org.apache.ranger.view.VXMessage in project ranger by apache.

the class RESTErrorUtil method createRESTException.

public WebApplicationException createRESTException(String errorMessage, MessageEnums messageEnum) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    messageList.add(messageEnum.getMessage());
    VXResponse gjResponse = new VXResponse();
    gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
    gjResponse.setMsgDesc(errorMessage);
    gjResponse.setMessageList(messageList);
    WebApplicationException webAppEx = createRESTException(gjResponse);
    logger.info("Operation error. response=" + gjResponse, webAppEx);
    return webAppEx;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 7 with VXMessage

use of org.apache.ranger.view.VXMessage in project ranger by apache.

the class UserService method validateForCreate.

@Override
protected void validateForCreate(VXPortalUser userProfile) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    if (stringUtil.isEmpty(userProfile.getEmailAddress())) {
        logger.info("Empty Email Address." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "emailAddress"));
    }
    if (stringUtil.isEmpty(userProfile.getFirstName())) {
        logger.info("Empty firstName." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "firstName"));
    }
    if (stringUtil.isEmpty(userProfile.getLastName())) {
        logger.info("Empty lastName." + userProfile);
        messageList.add(MessageEnums.NO_INPUT_DATA.getMessage(null, "lastName"));
    }
    // firstName
    if (!stringUtil.isValidName(userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    userProfile.setFirstName(stringUtil.toCamelCaseAllWords(userProfile.getFirstName()));
    // lastName
    if (!stringUtil.isValidName(userProfile.getLastName())) {
        logger.info("Invalid last name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
    }
    userProfile.setLastName(stringUtil.toCamelCaseAllWords(userProfile.getLastName()));
    if (!stringUtil.validateEmail(userProfile.getEmailAddress())) {
        logger.info("Invalid email address." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "emailAddress"));
    }
    // Normalize email. Make it lower case
    userProfile.setEmailAddress(stringUtil.normalizeEmail(userProfile.getEmailAddress()));
    // loginId
    userProfile.setLoginId(userProfile.getEmailAddress());
    // password
    if (!stringUtil.validatePassword(userProfile.getPassword(), new String[] { userProfile.getFirstName(), userProfile.getLastName() })) {
        logger.info("Invalid password." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "password"));
    }
    // firstName
    if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getFirstName())) {
        logger.info("Invalid first name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
    }
    // lastName
    if (!stringUtil.validateString(StringUtil.VALIDATION_NAME, userProfile.getLastName())) {
        logger.info("Invalid last name." + userProfile);
        messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
    }
    // create the public screen name
    userProfile.setPublicScreenName(userProfile.getFirstName() + " " + userProfile.getLastName());
    if (!messageList.isEmpty()) {
        VXResponse gjResponse = new VXResponse();
        gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
        gjResponse.setMsgDesc("Validation failure");
        gjResponse.setMessageList(messageList);
        logger.info("Validation Error in createUser() userProfile=" + userProfile + ", error=" + gjResponse);
        throw restErrorUtil.createRESTException(gjResponse);
    }
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Aggregations

ArrayList (java.util.ArrayList)7 VXMessage (org.apache.ranger.view.VXMessage)7 VXResponse (org.apache.ranger.view.VXResponse)7 WebApplicationException (javax.ws.rs.WebApplicationException)3 Response (javax.ws.rs.core.Response)1 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)1