// Path: src/main/java/org/osiam/addons/administration/mail/EmailSender.java
// @Component
// public class EmailSender {
// 
//     @Inject
//     private JavaMailSender mailSender;
// 
//     @Inject
//     private EmailTemplateRenderer renderer;
// 
//     @Value("${org.osiam.mail.from}")
//     private String fromAddress;
// 
//     public void sendDeactivateMail(User user) {
//         sendDeactivateMail(user, new Locale(user.getLocale()));
//     }
// 
//     public void sendDeactivateMail(User user, Locale locale) {
//         Map<String, Object> variables = new HashMap<>();
//         variables.put("user", user);
// 
//         String mailContent = renderer.renderEmailBody("user/deactivate", locale, variables);
//         String mailSubject = renderer.renderEmailSubject("user/deactivate", locale, variables);
//         Optional<Email> email = user.getPrimaryOrFirstEmail();
//         if (!email.isPresent()) {
//             throw new SendEmailException("The user has no email!", "user.no.email");
//         }
// 
//         sendHTMLMail(fromAddress, email.get().getValue(), mailSubject, mailContent);
//     }
// 
//     public void sendActivateMail(User user) {
//         sendActivateMail(user, new Locale(user.getLocale()));
//     }
// 
//     public void sendActivateMail(User user, Locale locale) {
//         Map<String, Object> variables = new HashMap<>();
//         variables.put("user", user);
// 
//         String mailContent = renderer.renderEmailBody("user/activate", locale, variables);
//         String mailSubject = renderer.renderEmailSubject("user/activate", locale, variables);
//         Optional<Email> email = user.getPrimaryOrFirstEmail();
//         if (!email.isPresent()) {
//             throw new SendEmailException("The user has no email!", "user.no.email");
//         }
// 
//         sendHTMLMail(fromAddress, email.get().getValue(), mailSubject, mailContent);
//     }
// 
//     public void sendHTMLMail(String fromAddress, String toAddress, String subject, String htmlContent) {
//         mailSender.send(getMimeMessage(fromAddress, toAddress, subject, htmlContent));
//     }
// 
//     private MimeMessage getMimeMessage(String fromAddress, String toAddress, String subject, String mailContent) {
//         final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
//         final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
//         try {
//             message.setFrom(fromAddress);
//             message.setTo(toAddress);
//             message.setSubject(subject);
//             message.setText(mailContent, true);
//             message.setSentDate(new Date());
//         } catch (MessagingException e) {
//             throw new SendEmailException("Could not create metadata for email", e);
//         }
//         return mimeMessage;
//     }
// }
// 
// Path: src/main/java/org/osiam/addons/administration/model/session/GeneralSessionData.java
// @Component
// @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
// public class GeneralSessionData implements Serializable {
// 
//     private static final long serialVersionUID = 3937661507313495926L;
// 
//     private AccessToken accesstoken;
// 
//     public AccessToken getAccessToken() {
//         return accesstoken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accesstoken = accessToken;
//     }
// }
// 
// Path: src/main/java/org/osiam/addons/administration/model/session/UserlistSession.java
// @Component
// @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
// public class UserlistSession {
//     private PagingInformation pagingInformation = new PagingInformation();
// 
//     public PagingInformation getPagingInformation() {
//         return pagingInformation;
//     }
// 
//     public void setPagingInformation(PagingInformation pagingInformation) {
//         this.pagingInformation = pagingInformation;
//     }
// }


import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.osiam.addons.administration.controller.AdminController;
import org.osiam.addons.administration.mail.EmailSender;
import org.osiam.addons.administration.model.session.GeneralSessionData;
import org.osiam.addons.administration.model.session.UserlistSession;
import org.osiam.addons.administration.paging.PagingBuilder;
import org.osiam.addons.administration.paging.PagingLinks;
import org.osiam.addons.administration.service.UserService;
import org.osiam.addons.administration.util.RedirectBuilder;
import org.osiam.resources.scim.SCIMSearchResult;
import org.osiam.resources.scim.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
    public static final String REQUEST_PARAMETER_USER_ID_ARRAY = "idArray";
    public static final String REQUEST_PARAMETER_SEND_MAIL = "sendMail";

    public static final String REQUEST_PARAMETER_DELETE_SUCCESS = "deleteSuccess";
    public static final String REQUEST_PARAMETER_DELETE_SELECTED_SUCCESS = "deleteSelectedSuccess";
    public static final String REQUEST_PARAMETER_ACTIVATE_SUCCESS = "activateSuccess";
    public static final String REQUEST_PARAMETER_ACTIVATE_SELECTED_SUCCESS = "activateSelectedSuccess";
    public static final String REQUEST_PARAMETER_DEACTIVATE_SUCCESS = "deactivateSuccess";
    public static final String REQUEST_PARAMETER_DEACTIVATE_SELECTED_SUCCESS = "deactivateSelectedSuccess";

    public static final String MODEL_USER_LIST = "userlist";
    public static final String MODEL_SESSION_DATA = "sessionData";
    public static final String MODEL_PAGING_LINKS = "paging";
    public static final String MODEL_ORDER_BY = "orderBy";
    public static final String MODEL_ORDER_DIRECTION = "orderDirection";

    private static final Integer DEFAULT_LIMIT = 20;
    private static final String DEFAULT_SORT_BY = "userName";
    private static final Boolean DEFAULT_SORT_DIRECTION = true;

    @Inject
    private UserService userService;

    @Inject
    private UserlistSession session;

    @Inject
    private EmailSender emailSender;

    @Inject
// Path: src/main/java/org/osiam/addons/administration/mail/EmailSender.java
// @Component
// public class EmailSender {
// 
//     @Inject
//     private JavaMailSender mailSender;
// 
//     @Inject
//     private EmailTemplateRenderer renderer;
// 
//     @Value("${org.osiam.mail.from}")
//     private String fromAddress;
// 
//     public void sendDeactivateMail(User user) {
//         sendDeactivateMail(user, new Locale(user.getLocale()));
//     }
// 
//     public void sendDeactivateMail(User user, Locale locale) {
//         Map<String, Object> variables = new HashMap<>();
//         variables.put("user", user);
// 
//         String mailContent = renderer.renderEmailBody("user/deactivate", locale, variables);
//         String mailSubject = renderer.renderEmailSubject("user/deactivate", locale, variables);
//         Optional<Email> email = user.getPrimaryOrFirstEmail();
//         if (!email.isPresent()) {
//             throw new SendEmailException("The user has no email!", "user.no.email");
//         }
// 
//         sendHTMLMail(fromAddress, email.get().getValue(), mailSubject, mailContent);
//     }
// 
//     public void sendActivateMail(User user) {
//         sendActivateMail(user, new Locale(user.getLocale()));
//     }
// 
//     public void sendActivateMail(User user, Locale locale) {
//         Map<String, Object> variables = new HashMap<>();
//         variables.put("user", user);
// 
//         String mailContent = renderer.renderEmailBody("user/activate", locale, variables);
//         String mailSubject = renderer.renderEmailSubject("user/activate", locale, variables);
//         Optional<Email> email = user.getPrimaryOrFirstEmail();
//         if (!email.isPresent()) {
//             throw new SendEmailException("The user has no email!", "user.no.email");
//         }
// 
//         sendHTMLMail(fromAddress, email.get().getValue(), mailSubject, mailContent);
//     }
// 
//     public void sendHTMLMail(String fromAddress, String toAddress, String subject, String htmlContent) {
//         mailSender.send(getMimeMessage(fromAddress, toAddress, subject, htmlContent));
//     }
// 
//     private MimeMessage getMimeMessage(String fromAddress, String toAddress, String subject, String mailContent) {
//         final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
//         final MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
//         try {
//             message.setFrom(fromAddress);
//             message.setTo(toAddress);
//             message.setSubject(subject);
//             message.setText(mailContent, true);
//             message.setSentDate(new Date());
//         } catch (MessagingException e) {
//             throw new SendEmailException("Could not create metadata for email", e);
//         }
//         return mimeMessage;
//     }
// }
// 
// Path: src/main/java/org/osiam/addons/administration/model/session/GeneralSessionData.java
// @Component
// @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
// public class GeneralSessionData implements Serializable {
// 
//     private static final long serialVersionUID = 3937661507313495926L;
// 
//     private AccessToken accesstoken;
// 
//     public AccessToken getAccessToken() {
//         return accesstoken;
//     }
// 
//     public void setAccessToken(AccessToken accessToken) {
//         this.accesstoken = accessToken;
//     }
// }
// 
// Path: src/main/java/org/osiam/addons/administration/model/session/UserlistSession.java
// @Component
// @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
// public class UserlistSession {
//     private PagingInformation pagingInformation = new PagingInformation();
// 
//     public PagingInformation getPagingInformation() {
//         return pagingInformation;
//     }
// 
//     public void setPagingInformation(PagingInformation pagingInformation) {
//         this.pagingInformation = pagingInformation;
//     }
// }


// Path: src/main/java/org/osiam/addons/administration/controller/user/UserViewController.java
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import org.osiam.addons.administration.controller.AdminController;
import org.osiam.addons.administration.mail.EmailSender;
import org.osiam.addons.administration.model.session.GeneralSessionData;
import org.osiam.addons.administration.model.session.UserlistSession;
import org.osiam.addons.administration.paging.PagingBuilder;
import org.osiam.addons.administration.paging.PagingLinks;
import org.osiam.addons.administration.service.UserService;
import org.osiam.addons.administration.util.RedirectBuilder;
import org.osiam.resources.scim.SCIMSearchResult;
import org.osiam.resources.scim.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

    public static final String REQUEST_PARAMETER_USER_ID_ARRAY = "idArray";
    public static final String REQUEST_PARAMETER_SEND_MAIL = "sendMail";

    public static final String REQUEST_PARAMETER_DELETE_SUCCESS = "deleteSuccess";
    public static final String REQUEST_PARAMETER_DELETE_SELECTED_SUCCESS = "deleteSelectedSuccess";
    public static final String REQUEST_PARAMETER_ACTIVATE_SUCCESS = "activateSuccess";
    public static final String REQUEST_PARAMETER_ACTIVATE_SELECTED_SUCCESS = "activateSelectedSuccess";
    public static final String REQUEST_PARAMETER_DEACTIVATE_SUCCESS = "deactivateSuccess";
    public static final String REQUEST_PARAMETER_DEACTIVATE_SELECTED_SUCCESS = "deactivateSelectedSuccess";

    public static final String MODEL_USER_LIST = "userlist";
    public static final String MODEL_SESSION_DATA = "sessionData";
    public static final String MODEL_PAGING_LINKS = "paging";
    public static final String MODEL_ORDER_BY = "orderBy";
    public static final String MODEL_ORDER_DIRECTION = "orderDirection";

    private static final Integer DEFAULT_LIMIT = 20;
    private static final String DEFAULT_SORT_BY = "userName";
    private static final Boolean DEFAULT_SORT_DIRECTION = true;

    @Inject
    private UserService userService;

    @Inject
    private UserlistSession session;

    @Inject
    private EmailSender emailSender;

    @Inject
    private GeneralSessionData generalSessionData;