Package sk.vrto.web.presenters

Source Code of sk.vrto.web.presenters.NewContactPresenter

package sk.vrto.web.presenters;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import sk.vrto.domain.Contact;
import sk.vrto.domain.User;
import sk.vrto.service.dao.ContactRepository;
import sk.vrto.web.base.Presenter;
import sk.vrto.web.events.ContactInsertedEvent;
import sk.vrto.web.views.NewContactView;

@Component
public class NewContactPresenter extends Presenter<NewContactView> {

    private final ContactRepository contactRepository;
    private final User user;

    /**
     * @param contactRepository Repository for accessing contacts
     * @param user Logged user
     */
    @Autowired
    public NewContactPresenter(
            @Qualifier("dao.contactRepository") ContactRepository contactRepository,
            User user) {
        this.contactRepository = contactRepository;
        this.user = user;
    }

    /**
     * Creates and inserts new contact, and then propagates {@link ContactInsertedEvent}
     * @param name Contact's name
     * @param email Contact's email
     */
    public void createContact(String name, String email) {
        Contact contact = new Contact(name, email, user);
        contactRepository.insert(contact);
        eventBus.post(new ContactInsertedEvent(contact));
    }

}
TOP

Related Classes of sk.vrto.web.presenters.NewContactPresenter

TOP
Copyright © 2018 www.massapi.com. 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.