Commit 9c133387 by Tuomas Riihimäki

Added Automatic product for Reader

1 parent dfe5e1e0
......@@ -40,6 +40,8 @@ public class ReaderBean implements ReaderBeanLocal {
private UserBeanLocal userbean;
@EJB
private CardTemplateBean cardTemplateBean;
@EJB
private ProductPBean productPBean;
private static final Logger logger = LoggerFactory.getLogger(ReaderBean.class);
......@@ -62,10 +64,11 @@ public class ReaderBean implements ReaderBeanLocal {
Reader reader = readerfacade.findOrCreateByIdent(readerIdent);
logger.info("reader {}, card {}", reader, card);
// RfidEvent revent = reventcontainer.foundTag(reader, tag);
List<ReaderEvent> lastevents = readerEventFacade.findLastEvents(reader, 1);
ReaderEvent ret = null;
if (!lastevents.isEmpty())
if (!lastevents.isEmpty() && !reader.isAutoproduct())
{
ReaderEvent lastevent = lastevents.get(0);
if (card == null)
......@@ -84,6 +87,12 @@ public class ReaderBean implements ReaderBeanLocal {
if (ret == null)
{
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 {
ret.setUpdatetime(Calendar.getInstance());
}
......
......@@ -9,6 +9,7 @@ import static javax.persistence.CascadeType.MERGE;
import static javax.persistence.CascadeType.PERSIST;
import static javax.persistence.CascadeType.REFRESH;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
......@@ -53,7 +54,7 @@ public class Reader extends GenericEntity {
@Column(nullable = false, name = "type")
@Enumerated(EnumType.STRING)
private ReaderType type;
private ReaderType type = ReaderType.RFID;
public static final String EVENT_ID_COLUMN = "event_id";
@ManyToOne()
......@@ -68,9 +69,13 @@ public class Reader extends GenericEntity {
@OneToOne(mappedBy = "reader")
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;
@Column(name = "reader_ident")
......@@ -204,4 +209,33 @@ public class Reader extends GenericEntity {
public void setSalesEntity(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 {
public List<LanEventPrivatePropertyKey> getAvailablePrivatePropertyKeys() {
List<LanEventPrivatePropertyKey> ret = null;
if (isPrivatePropertyPermission())
if (isPrivatePropertyPermission() && eventbean.getCurrentEvent().equals(eventorgview.getEvent()))
{
ret = new ArrayList<LanEventPrivatePropertyKey>(Arrays.asList(LanEventPrivatePropertyKey.values()));
if (createPrivateKey != null)
{
ret.remove(createPrivateKey);
}
if (eventorgview.getEvent() != null) {
for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) {
ret.remove(p.getKey());
}
for (LanEventPrivateProperty p : eventbean.getPrivateProperties()) {
ret.remove(p.getKey());
}
}
return ret;
}
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()
......@@ -182,7 +180,7 @@ public class EventPropertyView extends GenericCDIView {
}
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());
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!