Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge remote-tracking branch 'fregaham/master'
  • Loading branch information
maschmid committed Mar 29, 2012
2 parents 6331170 + 22f8275 commit c517e4f
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 23 deletions.
@@ -1,11 +1,14 @@
package cz.muni.fi.pv243.lesson03.action;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Model;
import javax.inject.Inject;
import javax.inject.Named;

import cz.muni.fi.pv243.lesson03.model.Cake;

@Model
@ApplicationScoped
@Named
public class CakeEditAction
{
@Inject
Expand Down
Expand Up @@ -2,7 +2,6 @@

import javax.ejb.Stateful;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
Expand All @@ -16,31 +15,29 @@
@Stateful
public class CurrentBakeryProducer implements Serializable {

private Bakery bakery;
@Inject
CurrentBakeryUnwrapper bakeryUnwrapper;

@Inject
EntityManager em;

public void setBakery(Bakery bakery) {
this.bakery = bakery;
bakeryUnwrapper.setCurrentBakery(bakery);
}

public Bakery getBakery() {
return bakeryUnwrapper.getCurrentBakery();
}

public void setBakeryById(String bakeryId) {
this.bakery = em.find(Bakery.class, Long.parseLong(bakeryId));
bakeryUnwrapper.setCurrentBakery(em.find(Bakery.class, Long.parseLong(bakeryId)));
}

public String getBakeryById() {
if (this.bakery == null) {
if (bakeryUnwrapper.getCurrentBakery() == null) {
return null;
}

return this.bakery.getId().toString();
}

@Named
@Produces
@Current
public Bakery getBakery() {
return bakery;
return bakeryUnwrapper.getCurrentBakery().getId().toString();
}
}
@@ -0,0 +1,31 @@
package cz.muni.fi.pv243.lesson03.action;

import java.io.Serializable;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;

import org.jboss.solder.unwraps.Unwraps;

import cz.muni.fi.pv243.lesson03.model.Bakery;

@ConversationScoped
public class CurrentBakeryUnwrapper implements Serializable
{
private Bakery bakery;

public void setCurrentBakery(Bakery bakery) {
this.bakery = bakery;
}

public Bakery getCurrentBakery() {
return bakery;
}

@Unwraps
@Current
@Named("bakery")
public Bakery produceCurrentBakery() {
return bakery;
}
}
Expand Up @@ -2,7 +2,6 @@

import javax.ejb.Stateful;
import javax.enterprise.context.ConversationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
Expand All @@ -16,19 +15,17 @@
@Stateful
public class CurrentCakeProducer implements Serializable {

private Cake cake;
@Inject
public CurrentCakeUnwrapper cakeUnwrapper;

@Inject
EntityManager em;

public void setCake(Cake cake) {
this.cake = cake;
cakeUnwrapper.setCurrentCake(cake);
}

@Named
@Produces
@Current
public Cake getCake() {
return cake;
return cakeUnwrapper.getCurrentCake();
}
}
@@ -0,0 +1,31 @@
package cz.muni.fi.pv243.lesson03.action;

import java.io.Serializable;

import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;

import org.jboss.solder.unwraps.Unwraps;

import cz.muni.fi.pv243.lesson03.model.Cake;

@ConversationScoped
public class CurrentCakeUnwrapper implements Serializable
{
private Cake cake;

public void setCurrentCake(Cake cake) {
this.cake = cake;
}

public Cake getCurrentCake() {
return cake;
}

@Unwraps
@Current
@Named("cake")
public Cake produceCurrentCake() {
return cake;
}
}
Expand Up @@ -12,7 +12,10 @@
import javax.persistence.OneToMany;
import javax.persistence.Version;

import org.jboss.solder.core.Veto;

@Entity
@Veto
public class Bakery implements Serializable
{
private Long id;
Expand Down
Expand Up @@ -14,7 +14,10 @@
import javax.persistence.Transient;
import javax.persistence.Version;

import org.jboss.solder.core.Veto;

@Entity
@Veto
public class Cake implements Serializable
{
private Long id;
Expand Down
@@ -1,6 +1,8 @@
package cz.muni.fi.pv243.lesson03.security;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import javax.inject.Inject;

import org.jboss.seam.security.Identity;
import org.jboss.seam.security.events.LoggedInEvent;
Expand All @@ -10,13 +12,19 @@
import cz.muni.fi.pv243.lesson03.action.Current;
import cz.muni.fi.pv243.lesson03.model.Bakery;

@ApplicationScoped
public class ManagerLogging {


@Inject
@Current
Bakery bakery;

public void managerLoggedIn(@Observes LoggedInEvent event, Logger log) {
log.info("Manager " + event.getUser().getId() + " logged in.");
}

public void bakeryEdited(@Observes BakeryEditedEvent event, Logger log, Identity identity, @Current Bakery bakery) {
log.info("Bakery " + bakery.getName() + " edited by " + identity.getUser().getId() );
public void bakeryEdited(@Observes BakeryEditedEvent event, Logger log, Identity identity) {
log.info("Bakery " + bakery.getName() + " edited by " + identity.getUser().getId() );
}
}

0 comments on commit c517e4f

Please sign in to comment.