Class UserUtil

java.lang.Object
com.skava.util.UserUtil

public final class UserUtil extends Object
This is a Utility class for User model which contains validator and helper methods used in this service.
Author:
Infosys Equinox
  • Field Details

  • Method Details

    • getLong

      public static long getLong(String strVal, long defaultValue)
      This method is used to convert the given string to long value, also returns default value if the given input string is invalid.
      Parameters:
      strVal - Indicates the string value which is used to parse into valid long value
      defaultValue - Indicates the default value if the string value is null, then default value will be returned
      Returns:
      The long value
    • getLong

      public static long getLong(Long longVal, long defaultValue)
      This method is used to convert the given Long to long value, also returns default value if the given input Long is invalid.
      Parameters:
      longVal - Indicates the string value which is used to parse into valid long value
      defaultValue - Indicates the default value if the string value is null, then default value will be returned
      Returns:
      The long value
    • getString

      public static String getString(String strVal, String defaultValue)
      This method is used to validate the given input string value and returns the same if valid else returns the default value.
      Parameters:
      strVal - Indicates the string value which is used to get the valid string value
      defaultValue - Indicates the default value if the string value is null, then default value will be returned.
      Returns:
      The valid string value.
    • getLoginToken

      public static String getLoginToken(long userId, UserCommonServices userCommonServices)
      This method is used to generate login token.
      Parameters:
      userId - Indicates the user id.
      userCommonServices - Instance of UserCommonServices object for encryption.
      Returns:
      The valid bearer token.
    • getEncryptedSecretCode

      public static String getEncryptedSecretCode(UserCommonServices userCommonServices, String randomToken)
      This method is used to encrypt secret code.
      Parameters:
      userCommonServices -
      randomToken -
      Returns:
    • getDecryptedSecretCode

      public static String getDecryptedSecretCode(UserCommonServices userCommonServices, String randomToken)
      This method is used to decrypt secret code.
      Parameters:
      userCommonServices -
      randomToken -
      Returns:
    • loadMFAValueFromDB

      public static String loadMFAValueFromDB(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name)
      This method is used to load collection property value from DB
      Parameters:
      collection - Holds Collection object to get collection property value.
      userCommonServices - Holds UserCommonServices object to get property value from DB.
      collectionCommonServices - Holds CollectionCommonServices object to get property value.
      name - Indicates the name of the property which is used for loading the value from DB.
      Returns:
      The valid String value.
    • getBearerToken

      public static String getBearerToken(long userId, String identityType, String authorizationData, long bearerExpiryTimeMins, UserCommonServices userCommonServices)
      This method is used to generate bearer token
      Parameters:
      userId - Indicates the user id.
      identityType - identityType
      authorizationData - authorizationData
      bearerExpiryTimeMins - Indicates the bearer token expiry time in minutes.
      userCommonServices - Instance of UserCommonServices object for encryption.
      Returns:
      The valid bearer token.
    • deleteMultipleCustomPropertiesFromDB

      public static void deleteMultipleCustomPropertiesFromDB(UsersEntity user, UserCommonServices userCommonServices, List<String> names)
      Deletes multiple custom properties from the database for a given user.
      Parameters:
      user - The user entity for which the properties need to be deleted.
      userCommonServices - The user common services object.
      names - The list of property names to be deleted.
    • loadEnableUserMergeValueFromDB

      public static String loadEnableUserMergeValueFromDB(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices)
      This method is used to load collection property value from DB
      Parameters:
      collection - Holds Collection object to get collection property value.
      userCommonServices - Holds UserCommonServices object to get property value from DB.
      collectionCommonServices - Holds CollectionCommonServices object to get property value.
      Returns:
      The valid String value.
    • loadResendMaxLimitFromCollectionProperties

      public static int loadResendMaxLimitFromCollectionProperties(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices)
      This method used to load collection property of resend limit for MFA
      Parameters:
      collection - Holds Collection object used to load resent limit property for that particular collection id.
      userCommonServices - Holds UserCommonServices object for getting collection attributes.
      collectionCommonServices - Holds CollectionCommonServices object for getting collection attributes.
      Returns:
      The valid resends limit integer value.
    • loadFailMaxLimitFromCollectionProperties

      public static int loadFailMaxLimitFromCollectionProperties(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices)
      This method used to load collection property of resend limit for MFA
      Parameters:
      collection - Holds Collection object used to load resent limit property for that particular collection id.
      userCommonServices - Holds UserCommonServices object for getting collection attributes.
      collectionCommonServices - Holds CollectionCommonServices object for getting collection attributes.
      Returns:
      The valid resends limit integer value.
    • setUsersResponseAndToken

      public static UsersResponse setUsersResponseAndToken(String token, Users user, int availableRetries, int maxFailLimit)
      This method is used to set login token and availableRetries in auth response and set user id in user model object.
      Parameters:
      token - Indicates the login token.
      availableRetries - Indicates the available retry count of an user.
      maxFailLimit - Indicates the maximum fail limit of the user.
      Returns:
      The UserAuthResponse object which contains user object and login tokens.
    • setUserCreateResponseAndToken

      public static UserCreateResponse setUserCreateResponseAndToken(String token, Users user, int availableRetries, int maxFailLimit)
      This method is used to set login token and availableRetries in auth response and set user id in user model object.
      Parameters:
      token - Indicates the login token.
      availableRetries - Indicates the available retry count of an user.
      maxFailLimit - Indicates the maximum fail limit of the user.
      Returns:
      The UserAuthResponse object which contains user object and login tokens.
    • doCreateAddressValidation

      public static void doCreateAddressValidation(Addresses addresses, org.springframework.context.MessageSource messageSource, org.slf4j.Logger logger, String locale)
      This method is used to validate the address given and set a default Id to it. In case of invalid address error message will be thrown.
      Parameters:
      addresses - Holds Addresses object used for address validation while creating an address.
      messageSource - Holds MessageSource object which is used to validate the address.
      logger - Indicates the logger object.
      locale - API Response and error messages will be responded in the locale mentioned in this parameter.
    • getAdminOrUserId

      public static Long getAdminOrUserId(com.skava.core.auth.AuthTokenHandler authTokenHandler)
      This method will return admin userid if it is 0 then return userid
      Parameters:
      authTokenHandler - authTokenHandler
      Returns:
      long adminid or userid
    • resetMillisecond

      public static Date resetMillisecond(Date date)
      This method is used to reset millisecond to zero in date object.
      Parameters:
      date - Indicates the date which is used for reseting the date into milliseconds
      Returns:
      The date
    • isValidSortParam

      public static boolean isValidSortParam(String sortParam)
      This method is used to validate user sort params.
      Parameters:
      sortParam - Indicates the search and sort params which is used for validating the sort and search params.
      Returns:
      boolean value.
    • isValidSortOrder

      public static boolean isValidSortOrder(String order)
      This method is used to validate the sorting order, returns TRUE if valid else FALSE.
      Parameters:
      order - Indicates the order of an user's sorting. eg : ASC or DESC
      Returns:
      boolean value
    • saveActivationParam

      public static String saveActivationParam(PropertiesRepository userpropertiesRepository, com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity)
      This method is used save activation param as a User Property.
      Parameters:
      userpropertiesRepository - Holds PropertiesRepository object used to save activation param.
      textEncryptorComponent - Instancs of TextEncryptorComponent object used to encrypt the activation param.
      userEntity - Holds the List of IdentitiesEntity object used for saving the activation param.
      Returns:
      String a valid activation param.
    • saveActivationParam

      public static String saveActivationParam(com.skava.core.crypto.TextEncryptorComponent textEncryptorComponent, UsersEntity userEntity)
      This method is used save activation parameter as a User Property.
      Parameters:
      textEncryptorComponent - Holds TextEncryptorComponent object which is used to encrypt the activation parameter.
      userEntity - Holds the list of IdentitiesEntity object which is used to activation parameter.
      Returns:
      String object.
    • isValidateStatus

      public static String isValidateStatus(String status, String locale, org.springframework.context.MessageSource messageSource)
      This method is used to validate the User status, returns ACTIVE if current status is null or ACTIVE, returns INACTIVE if current status is INACTIVE, else throws validate exception.
      Parameters:
      status - Indicates the user status which is used to validate the user's status.
      locale - API Response and error messages will be responded in the locale mentioned in this parameter.
      messageSource - Holds MessageSource object which is used for throwing response message.
      Returns:
      String object.
    • isValidateStatus

      public static boolean isValidateStatus(String status)
      This method is used to validate the given status, return TRUE if given status is ACTIVE or INACTIVE else FALSE.
      Parameters:
      status - Indicates the user status which is used to validate the user's status.
      Returns:
      boolean value
    • useParamForExactSearch

      public static boolean useParamForExactSearch(String param)
      This method is used to check whether the given parameter should be used for exact search or not.
      Parameters:
      param - Indicates the valid search param which is used for exact search
      Returns:
      boolean value
    • getCurrentMilliseconds

      public static long getCurrentMilliseconds()
      This method will return the current milliseconds using Calendar object.
      Returns:
      long time in milliseconds
    • setUserValue

      public static List<Users> setUserValue(UsersEntity usersEntity, long collectionId, String resetParam)
      This method is used to set user value.
      Parameters:
      usersEntity - Holds UsersEntity object to set user value from entity.
      collectionId - Indicates the collection id to set collection id value to users.
      resetParam - Indicates the user's reset parameter which is used for reseting user's password
      Returns:
      The list of user's object.
    • findOnePropertyByNameAndUserId

      public static PropertiesEntity findOnePropertyByNameAndUserId(PropertiesRepository propertiesRepository, long userId, String propertyName)
      Parameters:
      propertiesRepository - Holds PropertiesRepository object used to find property.
      userId - Indicates the user id.
      propertyName - Indicates the name of the user property.
      Returns:
      propertiesEntity returns PropertiesEntity or null
    • getPropertiesMap

      public static Map<String,String> getPropertiesMap(long collectionId, String locale, UserCommonServices userCommonServices)
      This method is used to fetch collection from collection repository and returns the collection properties as key-value map.
      Parameters:
      collectionId - Indicates the user collection id.
      locale - Indicates the locale value.
      userCommonServices - Indicates the common service component.
      Returns:
      Map object.
    • removePropertiesNotAllowedToUpdate

      public static void removePropertiesNotAllowedToUpdate(Map<String,String> propertiesToUpdate, List<String> restrictedPatchFields)
      This method is used to remove properties that are not allowed to be updated
      Parameters:
      propertiesToUpdate -
      restrictedPatchFields -
    • isMFAEnabledFor

      public static boolean isMFAEnabledFor(Collection collection, UserCommonServices userCommonServices, CollectionCommonServices collectionCommonServices, String name)
      isMFAEnabledFor method will fetch the list of process that allows MFA , i.e. login/signup/update
      Parameters:
      collection -
      userCommonServices -
      collectionCommonServices -
      name -
      Returns:
    • setTimeStamp

      public static Date setTimeStamp(Date timeStamp)