Package com.sparc.knappsack.util

Examples of com.sparc.knappsack.util.WebRequest


    private String fromAddress;

    @Override
    public boolean sendDomainUserAccessRequestEmail(final Long domainUserRequestId) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (request != null && sendEmail) {

            DomainUserRequest domainUserRequest = domainUserRequestService.get(domainUserRequestId);
            if(domainUserRequest == null) {
                log.error("No DomainUserRequest found with ID: " + domainUserRequestId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Domain Access Request");

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (domainUserRequest != null) {
                    DomainEntityService domainEntityService = domainEntityServiceFactory.getDomainEntityService(domainUserRequest.getDomain().getDomainType());
                    Set<User> users = domainEntityService.getDomainRequestUsersForNotification(domainUserRequest.getDomain());

                    for (User user : users) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("name", user.getFullName());
                        ctx.setVariable("request", domainUserRequest);

                        ctx.setVariable("url", request.generateURL("/manager"));
                        if(domainUserRequest.getDomain().getDomainType().equals(DomainType.ORGANIZATION)) {
                            applyBranding((Organization)domainUserRequest.getDomain(), ctx);
                        }

                        // Create the HTML body using Thymeleaf
View Full Code Here


    }

    @Override
    public boolean sendActivationEmail(Long userId) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (request != null && sendEmail) {

            User user = userService.get(userId);
            if(user == null) {
                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {

                String organizationName = "";
                List<Organization> organizations = userService.getOrganizations(user, null);
                String subject = "Knappsack: Account Activation";
                Organization organization = null;
                if(organizations.size() == 1) {
                    organization = organizations.get(0);
                    organizationName = organizations.get(0).getName();
                    subject =  organizationName + ": Account Activation - Knappsack";
                }
                message.setSubject(subject);

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && !user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("activationCode", user.getActivationCode());
                    ctx.setVariable("organizationName", organizationName);

                    String servletPath = "/activate/" + user.getActivationCode();
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-accountActivationTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
 
View Full Code Here

    }

    @Override
    public boolean sendActivationSuccessEmail(Long userId) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (request != null && sendEmail) {

            User user = userService.get(userId);
            if(user == null) {
                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                String organizationName = "";
                List<Organization> organizations = userService.getOrganizations(user, null);
                String subject = "Knappsack: Account Activation Success";
                Organization organization = null;
                if(organizations.size() == 1) {
                    organization = organizations.get(0);
                    organizationName = organizations.get(0).getName();
                    subject =  organizationName + ": Account Activation Success - Knappsack";
                }
                message.setSubject(subject);

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("organizationName", organizationName);
                    String servletPath = "/";
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    final String htmlContent = this.templateEngine.process("email-accountActivationSuccessTH", ctx);
                    message.setText(htmlContent, true);
                    message.setTo(user.getEmail());
View Full Code Here

    }

    @Override
    public List<Long> sendInvitationsEmail(Long fromUserId, List<Long> invitationIds) {
        Set<Long> invitationsSent = new HashSet<Long>();
        WebRequest request = WebRequest.getInstance();

        // Get all Invitations for supplied IDs
        Set<Invitation> invitations = new HashSet<Invitation>();
        if (invitationIds != null) {
            for (Long invitationId : invitationIds) {
                Invitation invitation = invitationService.get(invitationId);
                if (invitation != null) {
                    invitations.add(invitation);
                }
            }
        }

        if (request != null && sendEmail && !CollectionUtils.isEmpty(invitations)) {

            User fromUser = null;
            if (fromUserId != null) {
                fromUser = userService.get(fromUserId);
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");

            Locale locale = LocaleContextHolder.getLocale();

            Context ctx = new Context(locale);
            if (fromUser != null) {
                ctx.setVariable("adminName", fromUser.getFullName());
            }

            // Convert Invitation List to Map with email addresses being keys
            Map<String, List<Invitation>> emailMap = new HashMap<String, List<Invitation>>();
            for (Invitation invitation : invitations) {
                String key = StringUtils.trimAllWhitespace(invitation.getEmail()).toLowerCase();
                if (emailMap.get(key) == null) {
                    emailMap.put(key, new ArrayList<Invitation>());
                }
                emailMap.get(key).add(invitation);
            }

            Organization parentDomain = null;

            // Loop over each email address and send out a single invitation for each
            for (String emailAddress : emailMap.keySet()) {

                // Create Map separating domains for the email addresses invitations
                Map<String, Set<Invitation>> invitationsMap = new HashMap<String, Set<Invitation>>();
                for (Invitation invitation : emailMap.get(emailAddress)) {
                    if (DomainType.ORGANIZATION.equals(invitation.getDomain().getDomainType())) {
                        if (invitationsMap.get(DomainType.ORGANIZATION.name()) == null) {
                            invitationsMap.put(DomainType.ORGANIZATION.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
                        }
                        invitationsMap.get(DomainType.ORGANIZATION.name()).add(invitation);
                        parentDomain = (Organization) invitation.getDomain();
                    } else if (DomainType.GROUP.equals(invitation.getDomain().getDomainType())) {
                        if (invitationsMap.get(DomainType.GROUP.name()) == null) {
                            invitationsMap.put(DomainType.GROUP.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
                        }
                        invitationsMap.get(DomainType.GROUP.name()).add(invitation);
                        if(parentDomain == null) {
                            Group group = (Group) invitation.getDomain();
                            parentDomain = group.getOrganization();
                        }
                    }
                }

                ctx.setVariable("domainTypes", invitationsMap.keySet());
                ctx.setVariable("groupInvitations", invitationsMap.get(DomainType.GROUP.name()));
                String parentDomainName = parentDomain != null ? parentDomain.getName() : "";
                ctx.setVariable("parentDomainName", StringUtils.trimTrailingWhitespace(parentDomainName));

                User invitee = userService.getByEmail(emailAddress);
                if (invitee == null) {
                    ctx.setVariable("existingUser", false);
                    NameValuePair emailParam = new BasicNameValuePair("email", emailAddress);
                    ctx.setVariable("url", request.generateURL("/auth/register", emailParam));
                } else {
                    ctx.setVariable("existingUser", true);
                    ctx.setVariable("url", request.generateURL(""));
                }
                applyBranding(parentDomain, ctx);

                // Create the HTML body using Thymeleaf
                final String htmlContent = this.templateEngine.process("email-invitationTH", ctx);
View Full Code Here

    }

    @Override
    public boolean sendPasswordResetEmail(final Long userId, final String password) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (request != null && sendEmail) {

            User user = userService.get(userId);
            if(user == null) {
                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Password Changed");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                if (user != null) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("password", password);
                    ctx.setVariable("url", request.generateURL(""));

                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-passwordChangedTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
                    message.setTo(user.getEmail());
View Full Code Here

    }

    @Override
    public boolean sendApplicationPublishRequestEmail(Long applicationVersionId, UserModel userModel) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (sendEmail && userModel != null && applicationVersionId != null && request != null) {

            ApplicationVersion applicationVersion = applicationVersionService.get(applicationVersionId);
            if(applicationVersion == null) {
                log.error("No ApplicationVersion with ID: " + applicationVersionId);
                return true;
            }
            Application application = applicationVersion.getApplication();
            if(application == null) {
                log.error("No application found for ApplicationVersion with ID: " + applicationVersionId);
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Application Publish Request");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                Organization organization = null;
                try {
                    organization = applicationVersion.getApplication().getCategory().getOrganization();
                } catch (NullPointerException ex) {
                    log.error("NPE caused getting organization from application version", ex);
                }

                if (organization != null) {
                    List<UserDomain> userdomains = userDomainService.getAll(organization.getId(), UserRole.ROLE_ORG_ADMIN);

                    for (UserDomain userDomain : userdomains) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("name", userDomain.getUser().getFullName());
                        ctx.setVariable("userName", userModel.getFullName());
                        ctx.setVariable("applicationName", applicationVersion.getApplication().getName());
                        ctx.setVariable("applicationVersion", applicationVersion.getVersionName());
                        ctx.setVariable("organizationName", organization.getName());
                        ctx.setVariable("url", request.generateURL("/manager"));

                        // Create the HTML body using Thymeleaf
                        final String htmlContent = this.templateEngine.process("email-applicationPublishRequestTH", ctx);
                        applyBranding(organization, ctx);
                        message.setText(htmlContent, true /* isHtml */);
 
View Full Code Here

    }

    @Override
    public boolean sendDomainUserAccessConfirmationEmail(DomainUserRequestModel domainUserRequestModel) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (sendEmail && domainUserRequestModel != null && domainUserRequestModel.getDomain() != null && domainUserRequestModel.getUser() != null && request != null) {
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject(String.format("Knappsack: Domain Access Request %s", (Status.ACCEPTED.equals(domainUserRequestModel.getStatus()) ? "Accepted" : "Declined")));
View Full Code Here

    }

    @Override
    public boolean sendOrganizationRegistrationEmail(Long organizationId, UserModel userModel) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (sendEmail && organizationId != null && userModel != null && StringUtils.hasText(userModel.getEmail()) && request != null) {
            Organization organization = organizationService.get(organizationId);
            if(organization == null) {
                log.error("No organization found with ID: " + organizationId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject(String.format("Knappsack: %s Registration", organization.getName().trim()));

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                Context ctx = new Context(locale);
                ctx.setVariable("organization", organization);

                boolean existingUser = false;
                if (userService.getByEmail(userModel.getEmail().trim()) != null) {
                    existingUser = true;
                }
                ctx.setVariable("existingUser", existingUser);
                ctx.setVariable("user", userModel);
                ctx.setVariable("url", request.generateURL(""));
                applyBranding(organization, ctx);

                // Create the HTML body using Thymeleaf
                final String htmlContent = this.templateEngine.process("email-organizationRegistrationTH", ctx);
                message.setText(htmlContent, true /* isHtml */);
 
View Full Code Here

    }

    @Override
    public boolean sendApplicationVersionBecameVisibleEmail(Long applicationVersionId, List<Long> userIds) {
        boolean emailsSent = false;
        WebRequest request = WebRequest.getInstance();
        if (sendEmail && request != null && applicationVersionId != null && userIds != null) {
            ApplicationVersion applicationVersion = applicationVersionService.get(applicationVersionId);
            if(applicationVersion == null) {
                log.error("No ApplicationVersion with ID: " + applicationVersionId);
                return true;
            }
            Application application = applicationVersion.getApplication();
            if(application == null) {
                log.error("No application found for ApplicationVersion with ID: " + applicationVersionId);
            }

            int numSent = 0;
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Application Visibility");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                Context ctx = new Context(locale);
                ctx.setVariable("applicationName", applicationVersion.getApplication().getName());
                ctx.setVariable("url", request.generateURL(String.format("/detail/%s", applicationVersion.getApplication().getId())));
                ctx.setVariable("applicationVersion", applicationVersion.getVersionName());
                applyBranding(application.getOwnedGroup().getOrganization(), ctx);

                List<User> users = userService.get(userIds);
                for (User user : users) {
View Full Code Here

    }

    @Override
    public boolean sendBandwidthLimitNotification(Long organizationId, List<UserModel> users) {
        boolean emailsSent = false;
        WebRequest webRequest = WebRequest.getInstance();
        if (sendEmail) {
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                Organization organization = organizationService.get(organizationId);
                if(organization == null) {
                    log.error("No organization found with ID: " + organizationId);
                    return true;
                }

                int numberOfEmails = 0;
                message.setSubject("Knappsack: Organization Bandwidth Limit Reached");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                if (users != null) {
                    String orgName = organization.getName();
                    String url = webRequest.generateURL("");
                    long bandwidthLimit = organization.getDomainConfiguration().getMegabyteBandwidthLimit();
                    for (UserModel user : users) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("user", user);
                        ctx.setVariable("organizationName", orgName);
View Full Code Here

TOP

Related Classes of com.sparc.knappsack.util.WebRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.