parent
5395430640
commit
75d6ed4f09
@ -1,46 +1,46 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.persistence.EntityManager; |
||||
import javax.persistence.TypedQuery; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
public abstract class AbstractDaoImpl<T> implements IDao<T> { |
||||
|
||||
@Autowired |
||||
protected EntityManager em; |
||||
|
||||
private final Class<T> entityClass; |
||||
|
||||
public AbstractDaoImpl(Class<T> entityClass) { |
||||
super(); |
||||
this.entityClass = entityClass; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional |
||||
public void save(T obj) { |
||||
em.persist(obj); |
||||
} |
||||
|
||||
@Override |
||||
@Transactional |
||||
public T update(T obj) { |
||||
return em.merge(obj); |
||||
} |
||||
|
||||
@Override |
||||
public T get(Object primaryKey) { |
||||
return em.find(entityClass, primaryKey); |
||||
} |
||||
|
||||
@Override |
||||
public List<T> listAll() { |
||||
TypedQuery<T> query = em.createNamedQuery(entityClass.getSimpleName() + ".findAll", entityClass); |
||||
return query.getResultList(); |
||||
} |
||||
|
||||
} |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.dao; |
||||
|
||||
import java.util.List; |
||||
|
||||
import javax.persistence.EntityManager; |
||||
import javax.persistence.TypedQuery; |
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired; |
||||
import org.springframework.transaction.annotation.Transactional; |
||||
|
||||
public abstract class AbstractDaoImpl<T> implements IDao<T> { |
||||
|
||||
@Autowired |
||||
protected EntityManager em; |
||||
|
||||
private final Class<T> entityClass; |
||||
|
||||
public AbstractDaoImpl(Class<T> entityClass) { |
||||
super(); |
||||
this.entityClass = entityClass; |
||||
} |
||||
|
||||
@Override |
||||
@Transactional |
||||
public void save(T obj) { |
||||
em.persist(obj); |
||||
} |
||||
|
||||
@Override |
||||
@Transactional |
||||
public T update(T obj) { |
||||
return em.merge(obj); |
||||
} |
||||
|
||||
@Override |
||||
public T get(Object primaryKey) { |
||||
return em.find(entityClass, primaryKey); |
||||
} |
||||
|
||||
@Override |
||||
public List<T> listAll() { |
||||
TypedQuery<T> query = em.createNamedQuery(entityClass.getSimpleName() + ".findAll", entityClass); |
||||
return query.getResultList(); |
||||
} |
||||
|
||||
} |
||||
|
||||
@ -1,4 +1,4 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; |
||||
|
||||
import java.time.YearMonth; |
||||
import java.util.Calendar; |
||||
@ -1,4 +1,4 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; |
||||
|
||||
import java.io.InputStream; |
||||
import java.sql.Timestamp; |
||||
@ -1,4 +1,4 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; |
||||
|
||||
import java.time.LocalDate; |
||||
import java.time.YearMonth; |
||||
@ -1,4 +1,4 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components; |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.jasper; |
||||
|
||||
import java.io.InputStream; |
||||
import java.time.LocalDate; |
||||
@ -1,52 +1,52 @@ |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; |
||||
|
||||
import com.vaadin.navigator.Navigator; |
||||
import com.vaadin.navigator.View; |
||||
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
||||
import com.vaadin.ui.Alignment; |
||||
import com.vaadin.ui.LoginForm; |
||||
import com.vaadin.ui.Notification; |
||||
import com.vaadin.ui.VerticalLayout; |
||||
|
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; |
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
||||
|
||||
public class LoginUI extends VerticalLayout implements View { |
||||
|
||||
private static final long serialVersionUID = 4339018452507960084L; |
||||
public static final String VIEW_NAME = "LoginUI"; |
||||
|
||||
private Navigator navigator; |
||||
private String parameters; |
||||
|
||||
public LoginUI(PersonDao personDao) { |
||||
|
||||
LoginForm lf = new LoginForm(); |
||||
lf.addLoginListener(e -> { |
||||
|
||||
String username = e.getLoginParameter("username"); |
||||
String password = e.getLoginParameter("password"); |
||||
|
||||
try { |
||||
Person loggedin = personDao.findLoginUser(username, password); |
||||
this.getSession().setAttribute(Person.SESSION_LOGIN, loggedin); |
||||
navigator.navigateTo(MainView.VIEW_NAME + '/' + parameters); |
||||
} catch (final Exception ex) { |
||||
String message = "Incorrect user or password:" + ex.getMessage() + e.getLoginParameter("username") + ":" |
||||
+ e.getLoginParameter("password"); |
||||
Notification.show(message, Notification.Type.ERROR_MESSAGE); |
||||
} |
||||
}); |
||||
addComponent(lf); |
||||
setComponentAlignment(lf, Alignment.MIDDLE_CENTER); |
||||
setSizeFull(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void enter(ViewChangeEvent event) { |
||||
View.super.enter(event); |
||||
navigator = event.getNavigator(); |
||||
parameters = event.getParameters(); |
||||
} |
||||
} |
||||
package de.kreth.vaadin.clubhelper.vaadinclubhelper.ui; |
||||
|
||||
import com.vaadin.navigator.Navigator; |
||||
import com.vaadin.navigator.View; |
||||
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent; |
||||
import com.vaadin.ui.Alignment; |
||||
import com.vaadin.ui.LoginForm; |
||||
import com.vaadin.ui.Notification; |
||||
import com.vaadin.ui.VerticalLayout; |
||||
|
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.dao.PersonDao; |
||||
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; |
||||
|
||||
public class LoginUI extends VerticalLayout implements View { |
||||
|
||||
private static final long serialVersionUID = 4339018452507960084L; |
||||
public static final String VIEW_NAME = "LoginUI"; |
||||
|
||||
private Navigator navigator; |
||||
private String parameters; |
||||
|
||||
public LoginUI(PersonDao personDao) { |
||||
|
||||
LoginForm lf = new LoginForm(); |
||||
lf.addLoginListener(e -> { |
||||
|
||||
String username = e.getLoginParameter("username"); |
||||
String password = e.getLoginParameter("password"); |
||||
|
||||
try { |
||||
Person loggedin = personDao.findLoginUser(username, password); |
||||
this.getSession().setAttribute(Person.SESSION_LOGIN, loggedin); |
||||
navigator.navigateTo(MainView.VIEW_NAME + '/' + parameters); |
||||
} catch (final Exception ex) { |
||||
String message = "Incorrect user or password:" + ex.getMessage() + e.getLoginParameter("username") + ":" |
||||
+ e.getLoginParameter("password"); |
||||
Notification.show(message, Notification.Type.ERROR_MESSAGE); |
||||
} |
||||
}); |
||||
addComponent(lf); |
||||
setComponentAlignment(lf, Alignment.MIDDLE_CENTER); |
||||
setSizeFull(); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void enter(ViewChangeEvent event) { |
||||
View.super.enter(event); |
||||
navigator = event.getNavigator(); |
||||
parameters = event.getParameters(); |
||||
} |
||||
} |
||||
|
||||
@ -1,12 +1,12 @@ |
||||
/* This file is automatically managed and will be overwritten from time to time. */ |
||||
/* Do not manually edit this file. */ |
||||
|
||||
/* Provided by calendar-component-2.0-BETA4.jar */ |
||||
/* This file is automatically managed and will be overwritten from time to time. */ |
||||
/* Do not manually edit this file. */ |
||||
|
||||
/* Provided by calendar-component-2.0-BETA4.jar */ |
||||
@import "../../../VAADIN/addons/calendar/calendar-addon.scss"; |
||||
|
||||
|
||||
/* Import and include this mixin into your project theme to include the addon themes */ |
||||
@mixin addons { |
||||
@include calendar-addon; |
||||
} |
||||
|
||||
|
||||
|
||||
/* Import and include this mixin into your project theme to include the addon themes */ |
||||
@mixin addons { |
||||
@include calendar-addon; |
||||
} |
||||
|
||||
|
||||
Loading…
Reference in new issue