All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.yodlee.sdk.api.validators.UserValidator Maven / Gradle / Ivy

There is a newer version: 1.0.31
Show newest version
/**
 * Copyright (c) 2019 Yodlee, Inc. All Rights Reserved.
 *
 * Licensed under the MIT License. See LICENSE file in the project root for license information.
 */
package com.yodlee.sdk.api.validators;

import java.util.ArrayList;
import java.util.List;
import com.yodlee.api.model.user.request.UpdateUserRequest;
import com.yodlee.api.model.user.request.UserRequest;
import com.yodlee.api.model.validator.Problem;
import com.yodlee.sdk.api.UserApi;
import com.yodlee.sdk.api.exception.ApiException;
import com.yodlee.sdk.api.util.ApiUtils;
import com.yodlee.sdk.context.ContextType;

public class UserValidator {

	private UserValidator() {}

	public static void validateSamlLogin(UserApi userApi, String methodName, String issuer, String samlResponse,
			String source) throws ApiException {
		Class[] argTypes = new Class[] {String.class, String.class, String.class};
		Object[] argValues = new Object[] {issuer, samlResponse, source};
		List methodProblems = ApiValidator.validate(userApi, methodName, argTypes, argValues);
		List contextProblems = ApiValidator.validateCobrandContext(userApi);
		ApiValidator.collectProblems(methodProblems, contextProblems);
	}

	public static void validateRegisterUser(UserApi userApi, String methodName, UserRequest userRequest)
			throws ApiException {
		Class[] argTypes = new Class[] {UserRequest.class};
		Object[] argValues = new Object[] {userRequest};
		List methodProblems = ApiValidator.validate(userApi, methodName, argTypes, argValues);
		List modelProblems = ApiValidator.validate(userRequest);
		List contextProblems =
				validateContextTypeForRegisteration(ContextType.COBRAND, userApi.getContext().getContextType());
		List problems =
				ApiUtils.validatePattern(userRequest.getUser().getLoginName(), "^\\s+.*", "user.loginName.invalid");
		ApiValidator.collectProblems(methodProblems, modelProblems, contextProblems, problems);
	}

	public static void validateUpdateUser(UserApi userApi, String methodName, UpdateUserRequest userRequest)
			throws ApiException {
		Class[] argTypes = new Class[] {UpdateUserRequest.class};
		Object[] argValues = new Object[] {userRequest};
		List methodProblems = ApiValidator.validate(userApi, methodName, argTypes, argValues);
		List modelProblems = ApiValidator.validate(userRequest);
		List contextProblems = ApiValidator.validateUserContext(userApi);
		ApiValidator.collectProblems(methodProblems, modelProblems, contextProblems);
	}

	public static void validateGetAccessTokens(UserApi userApi, String methodName, Long[] appIds) throws ApiException {
		Class[] argTypes = new Class[] {Long[].class};
		Object[] argValues = new Object[] {appIds};
		List methodProblems = ApiValidator.validate(userApi, methodName, argTypes, argValues);
		List contextProblems = ApiValidator.validateUserContext(userApi);
		ApiValidator.collectProblems(methodProblems, contextProblems);
	}

	public static void validateApiContext(UserApi userApi) throws ApiException {
		List problems = ApiValidator.validateUserContext(userApi);
		ApiValidator.collectProblems(problems);
	}

	private static List validateContextTypeForRegisteration(ContextType expectedContext,
			ContextType currentContext) {
		List problems = new ArrayList<>();
		if (expectedContext != currentContext) {
			Problem problem = new Problem(ApiUtils.getErrorMessage("config.user.token.not.required"), "");
			problems.add(problem);
		}
		return problems;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy