Commit 9c133387 by Tuomas Riihimäki

Added Automatic product for Reader

1 parent dfe5e1e0
...@@ -40,6 +40,8 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -40,6 +40,8 @@ public class ReaderBean implements ReaderBeanLocal {
private UserBeanLocal userbean; private UserBeanLocal userbean;
@EJB @EJB
private CardTemplateBean cardTemplateBean; private CardTemplateBean cardTemplateBean;
@EJB
private ProductPBean productPBean;
private static final Logger logger = LoggerFactory.getLogger(ReaderBean.class); private static final Logger logger = LoggerFactory.getLogger(ReaderBean.class);
...@@ -62,10 +64,11 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -62,10 +64,11 @@ public class ReaderBean implements ReaderBeanLocal {
Reader reader = readerfacade.findOrCreateByIdent(readerIdent); Reader reader = readerfacade.findOrCreateByIdent(readerIdent);
logger.info("reader {}, card {}", reader, card); logger.info("reader {}, card {}", reader, card);
// RfidEvent revent = reventcontainer.foundTag(reader, tag); // RfidEvent revent = reventcontainer.foundTag(reader, tag);
List<ReaderEvent> lastevents = readerEventFacade.findLastEvents(reader, 1); List<ReaderEvent> lastevents = readerEventFacade.findLastEvents(reader, 1);
ReaderEvent ret = null; ReaderEvent ret = null;
if (!lastevents.isEmpty()) if (!lastevents.isEmpty() && !reader.isAutoproduct())
{ {
ReaderEvent lastevent = lastevents.get(0); ReaderEvent lastevent = lastevents.get(0);
if (card == null) if (card == null)
...@@ -84,6 +87,12 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -84,6 +87,12 @@ public class ReaderBean implements ReaderBeanLocal {
if (ret == null) if (ret == null)
{ {
ret = createReaderEvent(reader, card); ret = createReaderEvent(reader, card);
if (ret != null && card != null && reader.isAutoproduct())
{
productPBean.createAccountEvent(reader.getAutomaticProduct(), reader.getAutomaticProductCount(), card.getUser(), Calendar.getInstance());
ret.setNotes("Created automatic account event from reader.");
}
} else { } else {
ret.setUpdatetime(Calendar.getInstance()); ret.setUpdatetime(Calendar.getInstance());
} }
......
...@@ -9,6 +9,7 @@ import static javax.persistence.CascadeType.MERGE; ...@@ -9,6 +9,7 @@ import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST; import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REFRESH; import static javax.persistence.CascadeType.REFRESH;
import java.math.BigDecimal;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
...@@ -53,7 +54,7 @@ public class Reader extends GenericEntity { ...@@ -53,7 +54,7 @@ public class Reader extends GenericEntity {
@Column(nullable = false, name = "type") @Column(nullable = false, name = "type")
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private ReaderType type; private ReaderType type = ReaderType.RFID;
public static final String EVENT_ID_COLUMN = "event_id"; public static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne() @ManyToOne()
...@@ -68,9 +69,13 @@ public class Reader extends GenericEntity { ...@@ -68,9 +69,13 @@ public class Reader extends GenericEntity {
@OneToOne(mappedBy = "reader") @OneToOne(mappedBy = "reader")
private SalesEntity salesEntity; private SalesEntity salesEntity;
/** @ManyToOne
* @JoinColumn(name = "automatic_product_id")
*/ private Product automaticProduct;
@Column(precision = 25, scale = 4, name = "automatic_product_count")
private BigDecimal automaticProductCount;
private static final long serialVersionUID = 616803985117256035L; private static final long serialVersionUID = 616803985117256035L;
@Column(name = "reader_ident") @Column(name = "reader_ident")
...@@ -204,4 +209,33 @@ public class Reader extends GenericEntity { ...@@ -204,4 +209,33 @@ public class Reader extends GenericEntity {
public void setSalesEntity(SalesEntity salesEntity) { public void setSalesEntity(SalesEntity salesEntity) {
this.salesEntity = salesEntity; this.salesEntity = salesEntity;
} }
public boolean isAutoproduct() {
return (automaticProduct != null && automaticProductCount != null);
}
public ReaderType getType() {
return type;
}
public void setType(ReaderType type) {
this.type = type;
}
public Product getAutomaticProduct() {
return automaticProduct;
}
public void setAutomaticProduct(Product automaticProduct) {
this.automaticProduct = automaticProduct;
}
public BigDecimal getAutomaticProductCount() {
return automaticProductCount;
}
public void setAutomaticProductCount(BigDecimal automaticProductCount) {
this.automaticProductCount = automaticProductCount;
}
} }
...@@ -62,24 +62,22 @@ public class EventPropertyView extends GenericCDIView { ...@@ -62,24 +62,22 @@ public class EventPropertyView extends GenericCDIView {
public List<LanEventPrivatePropertyKey> getAvailablePrivatePropertyKeys() { public List<LanEventPrivatePropertyKey> getAvailablePrivatePropertyKeys() {
List<LanEventPrivatePropertyKey> ret = null; List<LanEventPrivatePropertyKey> ret = null;
if (isPrivatePropertyPermission()) if (isPrivatePropertyPermission() && eventbean.getCurrentEvent().equals(eventorgview.getEvent()))
{ {
ret = new ArrayList<LanEventPrivatePropertyKey>(Arrays.asList(LanEventPrivatePropertyKey.values())); ret = new ArrayList<LanEventPrivatePropertyKey>(Arrays.asList(LanEventPrivatePropertyKey.values()));
if (createPrivateKey != null) if (createPrivateKey != null)
{ {
ret.remove(createPrivateKey); ret.remove(createPrivateKey);
} }
if (eventorgview.getEvent() != null) { for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) {
for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) { ret.remove(p.getKey());
ret.remove(p.getKey());
}
} }
} }
return ret; return ret;
} }
public boolean isPrivatePropertyPermission() { public boolean isPrivatePropertyPermission() {
return super.hasPermission(EventPermission.MANAGE_PRIVATE_PROPERTIES); return super.hasPermission(EventPermission.MANAGE_PRIVATE_PROPERTIES) && eventbean.getCurrentEvent().equals(eventorgview.getEvent());
} }
public String editProperty() public String editProperty()
...@@ -182,7 +180,7 @@ public class EventPropertyView extends GenericCDIView { ...@@ -182,7 +180,7 @@ public class EventPropertyView extends GenericCDIView {
} }
public ListDataModel<LanEventPrivateProperty> getPrivateProperties() { public ListDataModel<LanEventPrivateProperty> getPrivateProperties() {
if (privateProperties == null && eventorgview != null && eventorgview.getEvent() != null) if (privateProperties == null && eventorgview != null && eventbean.getCurrentEvent().equals(eventorgview.getEvent()))
{ {
privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties()); privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties());
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!