// Path: src/main/java/com/poseidon/builder/ContaViewBuilder.java
// public class ContaViewBuilder {
// 
//     private ContaView myObject;
// 
//     public ContaViewBuilder(){
//         myObject= new ContaView();
//     }
// 
//     public ContaView build(){
//         return myObject;
//     }
// 
//     public ContaViewBuilder convertUsersThroughContaView(Users users){
//         myObject.setPassword(users.getPassword());
//         myObject.setUsername(users.getUsername());
//         return this;
//     }
// 
//     public ContaViewBuilder withAuthority(String authority){
//         myObject.setRole(authority);
//         return this;
//     }
// 
// 
// 
// 
// 
// }
// 
// Path: src/main/java/com/poseidon/dao/AuthoritiesRepository.java
// public interface AuthoritiesRepository extends CrudRepository<Authorities, Long>{
// 	
// 	  public Authorities findByUsername(String username);
// 	  
// }
// 
// Path: src/main/java/com/poseidon/dao/UserRepository.java
// public interface UserRepository  extends CrudRepository<Users, Long> {
// 	
//     public Users findByUsername(String username);
//     
// }
// 
// Path: src/main/java/com/poseidon/enums/CRUDViewEnum.java
// public enum CRUDViewEnum {
// 
//     IS_SAVE("isSave"),
//     IS_DELETE("isDelete"),
//     IS_UPDATE("isUpdate"),
//     IS_SEARCH("isSearch");
// 
// 
// 
//     private String operation;
// 
//     CRUDViewEnum(String operation) {
//     this.operation=operation;
//     }
// 
//     public String getOperation() {
//         return operation;
//     }
// }


import com.google.common.collect.Lists;
import com.poseidon.annotation.NotNullArgs;
import com.poseidon.annotation.ViewName;
import com.poseidon.builder.ContaViewBuilder;
import com.poseidon.dao.AuthoritiesRepository;
import com.poseidon.dao.UserRepository;
import com.poseidon.enums.CRUDViewEnum;
import com.poseidon.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.List;
import java.util.logging.Logger;


    @RequestMapping(value = "/cadastrarConta")
    @ViewName(name = REDIRECT_ADMIN_CONTA)
    @NotNullArgs
    public ModelAndView cadastrarConta(@ModelAttribute ContaView contaView,
                                       @ModelAttribute String role,
                                       ModelAndView modelAndView,
                                       RedirectAttributes redirectAttributes) {
        Users user = Users.createUser(contaView);

        userRepository.save(user);

        authoritiesRepository.save(new Authorities(user.getUsername(),
                new StringBuilder()
                        .append(ROLE_PREFIX)
                        .append(contaView.getRole())
                        .toString()));

        this.buildRedirectFlashAttributes(redirectAttributes, CRUDViewEnum.IS_SAVE);

        return modelAndView;
    }

    private void exibirConta(ModelAndView modelAndView) {
        Iterable<Users> contaList = userRepository.findAll();
        List<ContaView> contasView = Lists.newArrayList();
        for (Users user : contaList) {
            if ((user != null) && (user.getUsername() != null) && (!user.getUsername().isEmpty())) {
                Authorities authority = authoritiesRepository.findByUsername(user.getUsername());
// Path: src/main/java/com/poseidon/builder/ContaViewBuilder.java
// public class ContaViewBuilder {
// 
//     private ContaView myObject;
// 
//     public ContaViewBuilder(){
//         myObject= new ContaView();
//     }
// 
//     public ContaView build(){
//         return myObject;
//     }
// 
//     public ContaViewBuilder convertUsersThroughContaView(Users users){
//         myObject.setPassword(users.getPassword());
//         myObject.setUsername(users.getUsername());
//         return this;
//     }
// 
//     public ContaViewBuilder withAuthority(String authority){
//         myObject.setRole(authority);
//         return this;
//     }
// 
// 
// 
// 
// 
// }
// 
// Path: src/main/java/com/poseidon/dao/AuthoritiesRepository.java
// public interface AuthoritiesRepository extends CrudRepository<Authorities, Long>{
// 	
// 	  public Authorities findByUsername(String username);
// 	  
// }
// 
// Path: src/main/java/com/poseidon/dao/UserRepository.java
// public interface UserRepository  extends CrudRepository<Users, Long> {
// 	
//     public Users findByUsername(String username);
//     
// }
// 
// Path: src/main/java/com/poseidon/enums/CRUDViewEnum.java
// public enum CRUDViewEnum {
// 
//     IS_SAVE("isSave"),
//     IS_DELETE("isDelete"),
//     IS_UPDATE("isUpdate"),
//     IS_SEARCH("isSearch");
// 
// 
// 
//     private String operation;
// 
//     CRUDViewEnum(String operation) {
//     this.operation=operation;
//     }
// 
//     public String getOperation() {
//         return operation;
//     }
// }


// Path: src/main/java/com/poseidon/controller/ContaController.java
import com.google.common.collect.Lists;
import com.poseidon.annotation.NotNullArgs;
import com.poseidon.annotation.ViewName;
import com.poseidon.builder.ContaViewBuilder;
import com.poseidon.dao.AuthoritiesRepository;
import com.poseidon.dao.UserRepository;
import com.poseidon.enums.CRUDViewEnum;
import com.poseidon.model.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.List;
import java.util.logging.Logger;



    @RequestMapping(value = "/cadastrarConta")
    @ViewName(name = REDIRECT_ADMIN_CONTA)
    @NotNullArgs
    public ModelAndView cadastrarConta(@ModelAttribute ContaView contaView,
                                       @ModelAttribute String role,
                                       ModelAndView modelAndView,
                                       RedirectAttributes redirectAttributes) {
        Users user = Users.createUser(contaView);

        userRepository.save(user);

        authoritiesRepository.save(new Authorities(user.getUsername(),
                new StringBuilder()
                        .append(ROLE_PREFIX)
                        .append(contaView.getRole())
                        .toString()));

        this.buildRedirectFlashAttributes(redirectAttributes, CRUDViewEnum.IS_SAVE);

        return modelAndView;
    }

    private void exibirConta(ModelAndView modelAndView) {
        Iterable<Users> contaList = userRepository.findAll();
        List<ContaView> contasView = Lists.newArrayList();
        for (Users user : contaList) {
            if ((user != null) && (user.getUsername() != null) && (!user.getUsername().isEmpty())) {
                Authorities authority = authoritiesRepository.findByUsername(user.getUsername());
                contasView.add(new ContaViewBuilder()