Class ProfileService

  • All Implemented Interfaces:
    org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>

    @Service
    public class ProfileService
    extends Object
    implements org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
    This class handles all of the business logic for getting, putting, posting, and deleting items from the Profile on behalf of the ProfileService class, using methods from the ProfileRepository interface.
    • Constructor Detail

      • ProfileService

        @Autowired
        public ProfileService​(Random rng,
                              ProfileRepository profileRepository,
                              org.springframework.boot.system.ApplicationHome applicationHome)
        The constructor initializes a new instance of Random and a ProfileRepository.
        Parameters:
        rng - A new instance of Random.
        profileRepository - The instance of ProfileRepository to be initialized.
        applicationHome - The AlbuQuirky home directory.
    • Method Detail

      • getOrCreate

        public Profile getOrCreate​(String oauth,
                                   String username,
                                   String email)
        Method to get the user Profile, or create it if it does not already exist.
        Parameters:
        oauth - The user OAuth key.
        username - The username associated with the user Profile.
        email - The user's email address.
        Returns:
        The Profile retrieved or created.
      • convert

        public org.springframework.security.authentication.UsernamePasswordAuthenticationToken convert​(org.springframework.security.oauth2.jwt.Jwt jwt)
        Converts the JWT to a UsernamePasswordAuthenticationToken.
        Specified by:
        convert in interface org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
        Parameters:
        jwt - The bearer token.
        Returns:
        The converted UsernamePasswordAuthenticationToken.
      • findByUsername

        public Optional<Profile> findByUsername​(String name)
        Retrieves a Profile by their username.
        Parameters:
        name - The username to be searched.
        Returns:
        An Optional intended to contain the matching Profile.
      • findByAuth

        public Optional<Profile> findByAuth​(String auth)
        Retrieves a Profile by their authorization.
        Parameters:
        auth - The authorization to be searched.
        Returns:
        An Optional intended to contain the matching Profile.
      • uploadFile

        public Profile uploadFile​(org.springframework.web.multipart.MultipartFile file,
                                  Profile profile)
                           throws IOException
        Uploads a file to the database.
        Parameters:
        file - The file to be uploaded.
        profile - The Profile the file will be attached to.
        Returns:
        The Profile that has been updated with the new profile picture.
        Throws:
        IOException - If the file cannot be accessed from the reference provided.
      • retrieve

        public org.springframework.core.io.Resource retrieve​(Profile profile)
                                                      throws IOException
        Retrieves the profile picture associated with the given profile.
        Parameters:
        profile - The user Profile.
        Returns:
        A Resource of the ProfilePicture.
        Throws:
        IOException - If the file cannot be accessed from the reference provided.