Commit 2ceeca89 by Tuukka Kivilahti

Merge branch 'master' of codecrew.fi:codecrew/moya into applicationRestStuff

2 parents ff690cbd 7a882794
Showing with 407 additions and 189 deletions
...@@ -117,7 +117,6 @@ public interface PlaceBeanLocal { ...@@ -117,7 +117,6 @@ public interface PlaceBeanLocal {
*/ */
List<Product> getMapProducts(EventMap map); List<Product> getMapProducts(EventMap map);
List<PlaceSlot> getFreePlaceslots(EventUser user, Product product); List<PlaceSlot> getFreePlaceslots(EventUser user, Product product);
List<Place> findPlacePrintlistForUser(EventUser user); List<Place> findPlacePrintlistForUser(EventUser user);
......
...@@ -37,18 +37,15 @@ public class CheckoutBank { ...@@ -37,18 +37,15 @@ public class CheckoutBank {
private static final Logger logger = LoggerFactory.getLogger(CheckoutBank.class); private static final Logger logger = LoggerFactory.getLogger(CheckoutBank.class);
public CheckoutBank(Node bank) { public CheckoutBank(Node bank) {
if (bank.getNodeType() != 1) if (bank.getNodeType() != Node.ELEMENT_NODE) {
{
throw new RuntimeException("Wrong type of node " + bank + " type " + bank.getNodeType()); throw new RuntimeException("Wrong type of node " + bank + " type " + bank.getNodeType());
} }
key = bank.getNodeName(); key = bank.getNodeName();
logger.info("Bank type {}", bank);
NamedNodeMap attrs = bank.getAttributes(); NamedNodeMap attrs = bank.getAttributes();
String iconval = null; String iconval = null;
String nameval = null; String nameval = null;
String urlval = null; String urlval = null;
for (int j = 0; j < attrs.getLength(); ++j) for (int j = 0; j < attrs.getLength(); ++j) {
{
Node attr = attrs.item(j); Node attr = attrs.item(j);
if (attr.getNodeName().equals("icon")) { if (attr.getNodeName().equals("icon")) {
iconval = attr.getNodeValue(); iconval = attr.getNodeValue();
...@@ -63,18 +60,14 @@ public class CheckoutBank { ...@@ -63,18 +60,14 @@ public class CheckoutBank {
url = urlval; url = urlval;
NodeList children = bank.getChildNodes(); NodeList children = bank.getChildNodes();
for (int i = 0; i < children.getLength(); ++i) for (int i = 0; i < children.getLength(); ++i) {
{
Node childnode = children.item(i); Node childnode = children.item(i);
if (childnode.getNodeType() == 1) if (childnode.getNodeType() == Node.ELEMENT_NODE) {
{
String paramName = childnode.getNodeName(); String paramName = childnode.getNodeName();
String paramValue = childnode.getTextContent(); String paramValue = childnode.getTextContent();
getPostParams().add(new Valuepair(paramName, paramValue)); getPostParams().add(new Valuepair(paramName, paramValue));
logger.info("Added param for {} name {} value {}", new Object[] { key, paramName, paramValue });
} }
} }
// System.out.println();
} }
......
...@@ -24,6 +24,7 @@ package fi.codecrew.moya.beans; ...@@ -24,6 +24,7 @@ package fi.codecrew.moya.beans;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
...@@ -50,6 +51,7 @@ import javax.ejb.Timer; ...@@ -50,6 +51,7 @@ import javax.ejb.Timer;
import javax.ejb.TimerService; import javax.ejb.TimerService;
import javax.xml.registry.infomodel.Slot; import javax.xml.registry.infomodel.Slot;
import fi.codecrew.moya.facade.*;
import fi.codecrew.moya.model.*; import fi.codecrew.moya.model.*;
import org.slf4j.Logger; import org.slf4j.Logger;
...@@ -63,13 +65,6 @@ import com.pdfjet.TextLine; ...@@ -63,13 +65,6 @@ import com.pdfjet.TextLine;
import fi.codecrew.moya.enums.apps.MapPermission; import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission; import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.exceptions.BortalCatchableException; import fi.codecrew.moya.exceptions.BortalCatchableException;
import fi.codecrew.moya.facade.EventMapFacade;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType; import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/** /**
...@@ -128,6 +123,9 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -128,6 +123,9 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB @EJB
private PlaceSlotFacade placeSlotFacade; private PlaceSlotFacade placeSlotFacade;
@EJB
private BillFacade billFacade;
@Override @Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS) @RolesAllowed(MapPermission.S_MANAGE_MAPS)
public Place mergeChanges(Place place) { public Place mergeChanges(Place place) {
...@@ -176,7 +174,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -176,7 +174,7 @@ public class PlaceBean implements PlaceBeanLocal {
Map<Product, Integer> mockmap = getPlaceProductcount(places); Map<Product, Integer> mockmap = getPlaceProductcount(places);
BigDecimal total = BigDecimal.ZERO; BigDecimal total = Bill.BILL_SCALED_ZERO_PRICE;
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
for (Entry<Product, Integer> entry : mockmap.entrySet()) { for (Entry<Product, Integer> entry : mockmap.entrySet()) {
...@@ -185,7 +183,7 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -185,7 +183,7 @@ public class PlaceBean implements PlaceBeanLocal {
total = total.add(productBean.calculateTotal(entry.getKey(), new BigDecimal(entry.getValue()), now, user)); total = total.add(productBean.calculateTotal(entry.getKey(), new BigDecimal(entry.getValue()), now, user));
} }
} }
return total; return total.setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP);
} }
private static Map<Product, Integer> getPlaceProductcount(Collection<Place> places) { private static Map<Product, Integer> getPlaceProductcount(Collection<Place> places) {
...@@ -482,78 +480,6 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -482,78 +480,6 @@ public class PlaceBean implements PlaceBeanLocal {
return placeFacade.setBuyable(map, like, b); return placeFacade.setBuyable(map, like, b);
} }
// @Override
// @RolesAllowed("MAP/READ")
// public Place find(EventPk id) {
// return placeFacade.find(id);
// }
// @Override
// public void checkMemberships() {
// List<Place> all = placeFacade.findAll(eventBean.getCurrentEvent());
// for (Place p : all) {
// if (p.getGroup() != null && p.getPlaceReserver() == null) {
// LanEvent event = eventBean.getCurrentEvent();
// String token = gmemfacade.createInviteToken(event);
//
// GroupMembership gm = new GroupMembership(event, p.getGroup(), p, token);
// p.getGroup().getMembers().add(gm);
// p.setPlaceReserver(gm);
//
// }
//
// }
//
// }
// @Override
// @RolesAllowed("SHOP/EXECUTE")
// public Place lockPlace(User user, Place place) throws
// PermissionDeniedException {
// if (place.isTaken()) {
// logger.warn("Place {} is already taken", place);
// // throw new PermissionDeniedException(secubean,
// // permbean.getCurrentUser(), "Place already taken!");
// return null;
// }
//
// LanEvent ev = eventBean.getCurrentEvent();
// PlaceGroup pg = new PlaceGroup(ev, Calendar.getInstance(),
// Calendar.getInstance(), true);
// pg.setCreator(user);
//
// user.getPlaceGroups().add(pg);
//
// place.reserve(user);
// place.buy(pg);
//
// GroupMembership newgm = new GroupMembership(ev, pg, place,
// gmemfacade.createInviteToken(ev));
//
// pg.getMembers().add(newgm);
//
// boolean foundGm = false;
// for (GroupMembership gm : user.getGroupMemberships()) {
// logger.debug("Checking users gm:s found: {}", gm);
// if (gm.getId().getEventId().equals(ev.getId())) {
// foundGm = true;
// break;
// }
// }
// logger.debug("Foundgm {}", foundGm);
// if (!foundGm) {
// logger.debug("Membership not found. associating");
// newgm.setUser(user);
// user.getGroupMemberships().add(newgm);
//
// userbean.mergeChanges(user);
// }
// pgfacade.create(pg);
// place = placeFacade.merge(place);
//
// return place;
// }
/** /**
* Release reservation from user * Release reservation from user
* *
......
...@@ -19,24 +19,23 @@ ...@@ -19,24 +19,23 @@
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;
import javax.annotation.security.DeclareRoles; import javax.annotation.security.DeclareRoles;
import javax.annotation.security.RolesAllowed; import javax.annotation.security.RolesAllowed;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.ConcurrencyManagementType;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Singleton; import javax.ejb.Singleton;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.SessionMgmtBeanLocal;
import fi.codecrew.moya.enums.apps.UserPermission; import fi.codecrew.moya.enums.apps.UserPermission;
/** /**
...@@ -44,6 +43,8 @@ import fi.codecrew.moya.enums.apps.UserPermission; ...@@ -44,6 +43,8 @@ import fi.codecrew.moya.enums.apps.UserPermission;
*/ */
@Singleton @Singleton
@LocalBean @LocalBean
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
@DeclareRoles({ UserPermission.S_MANAGE_HTTP_SESSION }) @DeclareRoles({ UserPermission.S_MANAGE_HTTP_SESSION })
public class SessionMgmtBean implements SessionMgmtBeanLocal { public class SessionMgmtBean implements SessionMgmtBeanLocal {
...@@ -54,7 +55,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal { ...@@ -54,7 +55,7 @@ public class SessionMgmtBean implements SessionMgmtBeanLocal {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
private final ConcurrentSkipListMap<String, String> sessionUsers = new ConcurrentSkipListMap<String, String>(); private final ConcurrentHashMap<String, String> sessionUsers = new ConcurrentHashMap<String, String>();
private final Set<HttpSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<HttpSession, Boolean>()); private final Set<HttpSession> sessions = Collections.newSetFromMap(new ConcurrentHashMap<HttpSession, Boolean>());
@SuppressWarnings("unused") @SuppressWarnings("unused")
......
package fi.codecrew.moya.checkoutfi;
public enum CheckoutFiCheckParam implements CheckoutQueryParam {
// DO NOT CHANGE THE ORDER OF THESE!
// The md5 checksum is calculated from
// these values...
VERSION("0001"),
STAMP(null),
REFERENCE(null),
MERCHANT(null),
AMOUNT(null),
CURRENCY("EUR"),
FORMAT("1"),
ALGORITHM("1"),
// MAC gets added automatically in querybuilder
;
private final String defaultValue;
private CheckoutFiCheckParam(String def) {
defaultValue = def;
}
public String getDefaultValue() {
return defaultValue;
}
}
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
package fi.codecrew.moya.checkoutfi; package fi.codecrew.moya.checkoutfi;
public enum CheckoutFiParam { public enum CheckoutFiPaymentParam implements CheckoutQueryParam {
// DO NOT CHANGE THE ORDER OF THESE! // DO NOT CHANGE THE ORDER OF THESE!
// The md5 checksum is calculated from // The md5 checksum is calculated from
...@@ -45,11 +45,14 @@ public enum CheckoutFiParam { ...@@ -45,11 +45,14 @@ public enum CheckoutFiParam {
FAMILYNAME(null), FAMILYNAME(null),
ADDRESS(null), ADDRESS(null),
POSTCODE(null), POSTCODE(null),
POSTOFFICE(null), ; POSTOFFICE(null),
// MAC gets added automatically in querybuilder
;
private final String defaultValue; private final String defaultValue;
private CheckoutFiParam(String def) { private CheckoutFiPaymentParam(String def) {
defaultValue = def; defaultValue = def;
} }
......
package fi.codecrew.moya.checkoutfi;
public interface CheckoutQueryParam {
public String name();
public String getDefaultValue();
}
...@@ -110,6 +110,9 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> { ...@@ -110,6 +110,9 @@ public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
Path<Bill> bill = root.get(PlaceSlot_.bill); Path<Bill> bill = root.get(PlaceSlot_.bill);
q.where(cb.equal(bill.get(Bill_.user), user), q.where(cb.equal(bill.get(Bill_.user), user),
cb.isNotNull(bill.get(Bill_.paidDate))); cb.isNotNull(bill.get(Bill_.paidDate)));
q.orderBy(cb.asc(root.get(PlaceSlot_.place)));
return getEm().createQuery(q).getResultList(); return getEm().createQuery(q).getResultList();
} }
......
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import org.testng.annotations.BeforeTest;
import javax.ejb.embeddable.EJBContainer; import javax.ejb.embeddable.EJBContainer;
import javax.naming.NamingException; import javax.naming.NamingException;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
@Test
public abstract class AbstractEjbTest { public abstract class AbstractEjbTest {
@BeforeTest @BeforeTest
......
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
package fi.codecrew.moya.beans; package fi.codecrew.moya.beans;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@Test
public class BarcodeTests { public class BarcodeTest {
@Test @Test
public void tbd() { public void tbd() {
} }
......
package fi.codecrew.moya.beans;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import static org.testng.AssertJUnit.fail;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.http.NameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Test;
import fi.codecrew.moya.checkoutfi.CheckoutFiPaymentParam;
import fi.codecrew.moya.checkoutfi.CheckoutQueryParam;
import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.BillLine;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.util.CheckoutBank;
public class CheckoutFiBeanTest {
@Test
public void testQuery() {
new CheckoutFiBeanMock().testQuery();
}
@Test
public void testXml() {
new CheckoutFiBeanMock().testXml();
}
@Test
public void testPollXml() throws UnsupportedEncodingException
{
new CheckoutFiBeanMock().testPollXml();
}
public static class CheckoutFiBeanMock extends CheckoutFiBean {
private static final Logger logger = LoggerFactory.getLogger(CheckoutFiBeanTest.class);
public void testQuery() {
QueryBuilder queryBuilder = new QueryBuilder(CheckoutFiPaymentParam.values(), new Date(System.currentTimeMillis() + 60000), "375917", "SAIPPUAKAUPPIAS");
assertTrue("Credentials are valid!", queryBuilder.isCredentialsValid());
final String returnUrl = new StringBuilder()
.append("https://")
.append("localhost")
.append("/MoyaWeb/checkout/")
.toString();
LanEvent lanevent = new LanEvent();
lanevent.setReferenceNumberBase(100000);
Date d = new Date(1427495053008l);
Bill bill = new Bill();
bill.setEvent(lanevent);
bill.setId(67890);
bill.setBillNumber(12345);
bill.setAddr1("Teemu Teekkari");
bill.setAddr2("Hervannantie 1");
bill.setAddr3("33600 Tampere");
bill.setAddr4("FINLAND");
bill.setSentDateTime(d);
Product prod = new Product();
prod.setName("Hurr");
prod.setPrice(new BigDecimal(111.11).setScale(4, RoundingMode.HALF_UP));
bill.getBillLines().add(new BillLine(bill, prod, new BigDecimal(5)));
final String priceInCents = Integer.valueOf(bill.totalPrice().multiply(TO_CENTS).intValue()).toString();
final Map<String, String> requiredParams = new HashMap<>();
requiredParams.put("VERSION", "0001");
requiredParams.put("COUNTRY", "FIN");
requiredParams.put("CURRENCY", "EUR");
requiredParams.put("DEVICE", "10");
requiredParams.put("CONTENT", "1");
requiredParams.put("TYPE", "0");
requiredParams.put("ALGORITHM", "2");
requiredParams.put("LANGUAGE", "FI");
queryBuilder.addParam((CheckoutQueryParam) CheckoutFiPaymentParam.STAMP, getStamp(bill));
requiredParams.put("STAMP", "67890a1427495053");
queryBuilder.addParam(CheckoutFiPaymentParam.AMOUNT, priceInCents);
requiredParams.put("AMOUNT", "55555");
queryBuilder.addParam(CheckoutFiPaymentParam.REFERENCE, bill.getReferenceNumber().toString());
// 112345 + checksum(2)
requiredParams.put("REFERENCE", "1123452");
queryBuilder.addParam(CheckoutFiPaymentParam.MERCHANT, queryBuilder.getMerchantId());
requiredParams.put("MERCHANT", "375917");
queryBuilder.addParam(CheckoutFiPaymentParam.RETURN, returnUrl + "return.jsf");
requiredParams.put("RETURN", "https://localhost/MoyaWeb/checkout/return.jsf");
queryBuilder.addParam(CheckoutFiPaymentParam.CANCEL, returnUrl + "cancel.jsf");
requiredParams.put("CANCEL", "https://localhost/MoyaWeb/checkout/cancel.jsf");
queryBuilder.addParam(CheckoutFiPaymentParam.REJECT, returnUrl + "reject.jsf");
requiredParams.put("REJECT", "https://localhost/MoyaWeb/checkout/reject.jsf");
queryBuilder.addParam(CheckoutFiPaymentParam.DELAYED, returnUrl + "delayed.jsf");
requiredParams.put("DELAYED", "https://localhost/MoyaWeb/checkout/delayed.jsf");
queryBuilder.addParam(CheckoutFiPaymentParam.DELIVERY_DATE, new SimpleDateFormat(DATEFORMAT).format(d));
requiredParams.put("DELIVERY_DATE", "20150328");
requiredParams.put("MAC", "7FBDC5A633794B7292E6B02020330E64");
List<NameValuePair> nvpairs = queryBuilder.getNameValuePairs();
for (NameValuePair p : nvpairs) {
assertTrue("Missing required param: " + p.getName() + " val " + p.getValue(), requiredParams.containsKey(p.getName()));
String val = requiredParams.remove(p.getName());
assertEquals("Wrong value for " + p.getName(), val, p.getValue());
}
for (Entry<String, String> p : requiredParams.entrySet()) {
logger.warn("Not found param {} with value {}", p.getKey(), p.getValue());
}
}
@Test
public void testXml()
{
InputStream testfile1 = getClass().getResourceAsStream("checkoutTestfile.xml");
List<CheckoutBank> ret = CheckoutFiBean.parseTokenXml(testfile1);
// Huom! Neopay, ape ja tilisiirto poistettu parsinnassa.
assertEquals(8, ret.size());
for (int i = 0; i < ret.size(); ++i) {
CheckoutBank bnk = ret.get(i);
switch (i) {
case 0:
assertEquals("nordea", bnk.getKey());
assertEquals(17, bnk.getPostParams().size());
break;
case 1:
assertEquals("osuuspankki", bnk.getKey());
assertEquals(13, bnk.getPostParams().size());
break;
case 2:
assertEquals("samlink", bnk.getKey());
assertEquals(13, bnk.getPostParams().size());
break;
case 3:
assertEquals("sampo", bnk.getKey());
assertEquals(9, bnk.getPostParams().size());
break;
case 4:
assertEquals("handelsbanken", bnk.getKey());
assertEquals(13, bnk.getPostParams().size());
break;
case 5:
assertEquals("spankki", bnk.getKey());
assertEquals(17, bnk.getPostParams().size());
break;
case 6:
assertEquals("alandsbanken", bnk.getKey());
assertEquals(18, bnk.getPostParams().size());
break;
case 7:
assertEquals("tapiola", bnk.getKey());
assertEquals(18, bnk.getPostParams().size());
break;
case 8:
assertEquals("neopay", bnk.getKey());
assertEquals(9, bnk.getPostParams().size());
break;
case 9:
assertEquals("tilisiirto", bnk.getKey());
assertEquals(6, bnk.getPostParams().size());
break;
case 10:
assertEquals("ape", bnk.getKey());
assertEquals(4, bnk.getPostParams().size());
break;
default:
fail("Wrong number of banks: " + i);
break;
}
}
}
private static final String pollReturnXML = "<?xml version=\"1.0\"?> <trade> <status> 2 </status></trade> ";
private static final String LATIN1 = "ISO-8859-1";
@Test
public void testPollXml() throws UnsupportedEncodingException
{
String ret = CheckoutFiBean.parsePollXml(new ByteArrayInputStream(pollReturnXML.getBytes(LATIN1)));
assertEquals("2", ret);
}
}
}
...@@ -6,13 +6,13 @@ import org.testng.annotations.Test; ...@@ -6,13 +6,13 @@ import org.testng.annotations.Test;
@Test @Test
public class VipBeanTest { public class VipBeanTest {
private static final Logger log = LoggerFactory.getLogger(VipBeanTest.class); private static final Logger log = LoggerFactory.getLogger(VipBeanTest.class);
@Test @Test
public void testVip() { public void testVip() {
log.info("testVip"); log.info("testVip");
VipBean vipBean = new VipBean(); VipBean vipBean = new VipBean();
} }
} }
...@@ -42,7 +42,6 @@ import javax.persistence.Table; ...@@ -42,7 +42,6 @@ import javax.persistence.Table;
public class BillLine extends GenericEntity { public class BillLine extends GenericEntity {
private static final long serialVersionUID = 2L; private static final long serialVersionUID = 2L;
private static final BigDecimal DEFAULT_VAT = BigDecimal.ZERO;
/** /**
* Which bill this bill line belongs to * Which bill this bill line belongs to
*/ */
...@@ -67,8 +66,8 @@ public class BillLine extends GenericEntity { ...@@ -67,8 +66,8 @@ public class BillLine extends GenericEntity {
* How much one(1) unit of this product costs * How much one(1) unit of this product costs
* *
*/ */
@Column(name = "unit_price", nullable = false, precision = 24, scale = 4) @Column(name = "unit_price", nullable = false, precision = 24, scale = Bill.BILL_PRICE_SCALE)
private BigDecimal unitPrice = BigDecimal.ZERO; private BigDecimal unitPrice = Bill.BILL_SCALED_ZERO_PRICE;
/** /**
* *
...@@ -79,8 +78,8 @@ public class BillLine extends GenericEntity { ...@@ -79,8 +78,8 @@ public class BillLine extends GenericEntity {
/** /**
* How much VAT this product contains ( 0, 0.22 ) etc * How much VAT this product contains ( 0, 0.22 ) etc
*/ */
@Column(name = "vat", nullable = false, precision = 4, scale = 3) @Column(name = "vat", nullable = false, precision = 4, scale = Bill.VAT_SCALE)
private BigDecimal vat = DEFAULT_VAT; private BigDecimal vat = Bill.VAT_SCALED_ZERO;
@JoinColumn(name = "lineProduct_id", referencedColumnName = "id", nullable = true, updatable = false) @JoinColumn(name = "lineProduct_id", referencedColumnName = "id", nullable = true, updatable = false)
@OneToOne @OneToOne
...@@ -111,7 +110,7 @@ public class BillLine extends GenericEntity { ...@@ -111,7 +110,7 @@ public class BillLine extends GenericEntity {
*/ */
public BigDecimal getLinePriceVatless() { public BigDecimal getLinePriceVatless() {
BigDecimal vatMultiplicand = BigDecimal.ONE.add(getVat()); BigDecimal vatMultiplicand = BigDecimal.ONE.add(getVat());
return getLinePrice().divide(vatMultiplicand, 2, RoundingMode.HALF_UP); return getLinePrice().divide(vatMultiplicand, Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP);
} }
public BillLine() { public BillLine() {
...@@ -157,8 +156,8 @@ public class BillLine extends GenericEntity { ...@@ -157,8 +156,8 @@ public class BillLine extends GenericEntity {
public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) { public BillLine(Bill bill2, Product product, Discount disc, BigDecimal count) {
super(); super();
this.bill = bill2; this.bill = bill2;
BigDecimal unitPrice = product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage())).negate().setScale(2, RoundingMode.HALF_UP); BigDecimal unitPrice = product.getPrice().subtract(product.getPrice().multiply(disc.getPercentage())).negate().setScale(Bill.BILL_PRICE_SCALE, RoundingMode.HALF_UP);
this.name = disc.getShortdesc(); this.name = disc.getShortdesc();
this.unitName = product.getUnitName(); this.unitName = product.getUnitName();
this.quantity = count; this.quantity = count;
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
...@@ -45,13 +46,15 @@ public class Discount extends GenericEntity { ...@@ -45,13 +46,15 @@ public class Discount extends GenericEntity {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final String EVENT_ID = "event_id"; private static final String EVENT_ID = "event_id";
private static final BigDecimal SCALE4_ZERO = BigDecimal.ZERO.setScale(4, RoundingMode.HALF_UP);
private static final BigDecimal SCALE6_ZERO = BigDecimal.ZERO.setScale(6, RoundingMode.HALF_UP);
@ManyToOne() @ManyToOne()
@JoinColumn(name = EVENT_ID, nullable = false) @JoinColumn(name = EVENT_ID, nullable = false)
private LanEvent event; private LanEvent event;
@Column(name = "percentage", nullable = false, precision = 9, scale = 6) @Column(name = "percentage", nullable = false, precision = 9, scale = 6)
private BigDecimal percentage = BigDecimal.ZERO; private BigDecimal percentage = SCALE6_ZERO;
@Column(name = "code") @Column(name = "code")
private String code; private String code;
...@@ -71,22 +74,22 @@ public class Discount extends GenericEntity { ...@@ -71,22 +74,22 @@ public class Discount extends GenericEntity {
private String shortdesc; private String shortdesc;
@Column(name = "amount_min", nullable = false, precision = 24, scale = 4) @Column(name = "amount_min", nullable = false, precision = 24, scale = 4)
private BigDecimal amountMin = BigDecimal.ZERO; private BigDecimal amountMin = SCALE4_ZERO;
@Column(name = "amount_max", nullable = false, precision = 24, scale = 4) @Column(name = "amount_max", nullable = false, precision = 24, scale = 4)
private BigDecimal amountMax = BigDecimal.ZERO; private BigDecimal amountMax = SCALE4_ZERO;
@Column(name = "active", nullable = false) @Column(name = "active", nullable = false)
private boolean active = false; private boolean active = false;
@Column(name = "max_num", nullable = false, precision = 24, scale = 4) @Column(name = "max_num", nullable = false, precision = 24, scale = 4)
private BigDecimal maxNum = BigDecimal.ZERO; private BigDecimal maxNum = SCALE4_ZERO;
@Column(name = "per_user", nullable = false, precision = 24, scale = 4) @Column(name = "per_user", nullable = false, precision = 24, scale = 4)
private BigDecimal perUser = BigDecimal.ZERO; private BigDecimal perUser = SCALE4_ZERO;
@Column(name = "total_count", nullable = false, precision = 24, scale = 4) @Column(name = "total_count", nullable = false, precision = 24, scale = 4)
private BigDecimal totalCount = BigDecimal.ZERO; private BigDecimal totalCount = SCALE4_ZERO;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "discount") @OneToMany(cascade = CascadeType.ALL, mappedBy = "discount")
private List<DiscountInstance> discountInstances; private List<DiscountInstance> discountInstances;
......
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import java.util.Calendar;
import java.util.Date; import java.util.Date;
import javax.persistence.Entity; import javax.persistence.Entity;
...@@ -37,6 +38,19 @@ public class PlaceSlot extends GenericEntity { ...@@ -37,6 +38,19 @@ public class PlaceSlot extends GenericEntity {
@Lob @Lob
private String description; private String description;
public PlaceSlot(Product product, Bill bill, String description) {
this();
this.product = product;
this.bill = bill;
this.description = description;
}
public PlaceSlot() {
this.created = Calendar.getInstance().getTime();
}
public Date getCreated() { public Date getCreated() {
return created; return created;
} }
......
...@@ -66,35 +66,36 @@ ...@@ -66,35 +66,36 @@
<h2>Place slots</h2> <h2>Place slots</h2>
<h:form> <h:form>
<p:dataTable var="slot" value="#{placeGroupView.placeslots}">
<p:column headerText="#{i18n['placeslot.id']}"> <p:dataTable var="slot" value="#{placeGroupView.placeslots}" id="placeslots">
<h:outputText value="#{slot.id}" /> <p:column headerText="#{i18n['placeslot.id']}">
</p:column> <h:outputText value="#{slot.id}" />
<p:column headerText="#{i18n['placeslot.state']}"> </p:column>
<h:outputText value="#{slot.bill.expired ? i18n['placeslot.state.expired'] : ( slot.bill.paid ? i18n['placeslot.state.paid'] : i18n['placeslot.state.notPaid'])}" /> <p:column headerText="#{i18n['placeslot.state']}">
</p:column> <h:outputText value="#{slot.bill.expired ? i18n['placeslot.state.expired'] : ( slot.bill.paid ? i18n['placeslot.state.paid'] : i18n['placeslot.state.notPaid'])}" />
<p:column headerText="#{i18n['placeslot.product']}"> </p:column>
<h:outputText value="#{slot.product.name}" /> <p:column headerText="#{i18n['placeslot.product']}">
</p:column> <h:outputText value="#{slot.product.name}" />
<p:column headerText="#{i18n['placeslot.place']}"> </p:column>
<h:outputText rendered="#{!empty slot.place}" value="#{slot.place.name}" /> <p:column headerText="#{i18n['placeslot.place']}">
</p:column> <h:outputText rendered="#{!empty slot.place}" value="#{slot.place.name}" />
<p:column headerText="#{i18n['placeslot.used']}"> </p:column>
<h:outputText value="#{slot.used}"> <p:column headerText="#{i18n['placeslot.used']}">
<f:convertDateTime timeZone="#{sessionHandler.timezone}" pattern="#{sessionHandler.shortDatetimeFormat}" /> <h:outputText value="#{slot.used}">
</h:outputText> <f:convertDateTime timeZone="#{sessionHandler.timezone}" pattern="#{sessionHandler.shortDatetimeFormat}" />
</p:column> </h:outputText>
<p:column headerText="#{i18n['placeslot.bill']}"> </p:column>
<h:link outcome="/bill/showBill" value="#{i18n['bill.billNumber']}: #{slot.bill.id}"> <p:column headerText="#{i18n['placeslot.bill']}">
<f:param name="billid" value="#{slot.bill.id}" /> <h:link outcome="/bill/showBill" value="#{i18n['bill.billNumber']}: #{slot.bill.id}">
</h:link> <f:param name="billid" value="#{slot.bill.id}" />
</p:column> </h:link>
<p:column > </p:column>
<h:commandButton rendered="#{empty slot.place and empty slot.used}" value="#{i18n['placeslot.lockSlot']}" ajax="false" action="#{placeGroupView.lockSlot}" /> <p:column >
<h:commandButton rendered="#{empty slot.place and not empty slot.used}" value="#{i18n['placeslot.releaseSlot']}" ajax="false" action="#{placeGroupView.releaseSlot}" /> <p:commandButton rendered="#{empty slot.place and empty slot.used}" value="#{i18n['placeslot.lockSlot']}" actionListener="#{placeGroupView.lockSlot}" update="placeslots" />
</p:column> <p:commandButton rendered="#{empty slot.place and not empty slot.used}" value="#{i18n['placeslot.releaseSlot']}" actionListener="#{placeGroupView.releaseSlot}" update="placeslots" />
</p:dataTable> </p:column>
</h:form> </p:dataTable>
</h:form>
......
...@@ -90,7 +90,7 @@ public class PlacemapRestViewV1 { ...@@ -90,7 +90,7 @@ public class PlacemapRestViewV1 {
EventMap map = placebean.findMap(id); EventMap map = placebean.findMap(id);
byte[] data = map.getMapData(); byte[] data = map.getMapData();
ResponseBuilder ret = Response.ok(data, "image/png"); ResponseBuilder ret = Response.ok(data, map.getMimeType());
ret.expires(new Date(System.currentTimeMillis() + 6 * 60 * 60 * 1000)); ret.expires(new Date(System.currentTimeMillis() + 6 * 60 * 60 * 1000));
return ret.build(); return ret.build();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
package fi.codecrew.moya.web.cdiview.map; package fi.codecrew.moya.web.cdiview.map;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -28,6 +29,7 @@ import javax.ejb.EJB; ...@@ -28,6 +29,7 @@ import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped; import javax.enterprise.context.ConversationScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent; import javax.faces.event.ActionEvent;
import javax.imageio.ImageIO;
import javax.inject.Named; import javax.inject.Named;
import org.primefaces.model.DefaultStreamedContent; import org.primefaces.model.DefaultStreamedContent;
...@@ -133,7 +135,19 @@ public class MapManageView extends GenericCDIView { ...@@ -133,7 +135,19 @@ public class MapManageView extends GenericCDIView {
} }
map.setMapData(bytes); map.setMapData(bytes);
map.setMimeType(bgFile.getContentType()); map.setMimeType(bgFile.getContentType());
map = eventmapBean.saveMap(map);
try {
BufferedImage image = ImageIO.read(new ByteArrayInputStream(map.getMapData()));
map.setWidth(image.getWidth());
map.setHeight(image.getHeight());
map = eventmapBean.saveMap(map);
} catch (IOException e) {
addFaceMessage("map.upload.failed");
}
return null; return null;
} }
......
...@@ -29,10 +29,7 @@ import javax.faces.model.ListDataModel; ...@@ -29,10 +29,7 @@ import javax.faces.model.ListDataModel;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.*;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission; import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.*; import fi.codecrew.moya.model.*;
import fi.codecrew.moya.web.annotations.SelectedUser; import fi.codecrew.moya.web.annotations.SelectedUser;
...@@ -79,8 +76,12 @@ public class PlacegroupView extends GenericCDIView { ...@@ -79,8 +76,12 @@ public class PlacegroupView extends GenericCDIView {
@EJB @EJB
private PlaceBeanLocal placeslotBean; private PlaceBeanLocal placeslotBean;
@EJB
private ProductBeanLocal productBean;
private ListDataModel<PlaceSlot> placeslots; private ListDataModel<PlaceSlot> placeslots;
public String editGroup() { public String editGroup() {
setGroup(placegroups.getRowData()); setGroup(placegroups.getRowData());
setPlacelist(new ListDataModel<Place>(group.getPlaces())); setPlacelist(new ListDataModel<Place>(group.getPlaces()));
...@@ -211,18 +212,16 @@ public class PlacegroupView extends GenericCDIView { ...@@ -211,18 +212,16 @@ public class PlacegroupView extends GenericCDIView {
return null; return null;
} }
public String lockSlot() { public void lockSlot() {
PlaceSlot row = placeslots.getRowData(); PlaceSlot row = placeslots.getRowData();
placeslotBean.lockSlot(row); placeslotBean.lockSlot(row);
placeslots = null; placeslots = null;
return null;
} }
public String releaseSlot() { public void releaseSlot() {
PlaceSlot row = placeslots.getRowData(); PlaceSlot row = placeslots.getRowData();
placeslotBean.releaseSlot(row); placeslotBean.releaseSlot(row);
placeslots = null; placeslots = null;
return null;
} }
public ListDataModel<PlaceGroup> getPlacegroups() { public ListDataModel<PlaceGroup> getPlacegroups() {
...@@ -318,4 +317,9 @@ public class PlacegroupView extends GenericCDIView { ...@@ -318,4 +317,9 @@ public class PlacegroupView extends GenericCDIView {
inviteMails.put(row.getId(), inviteMail); inviteMails.put(row.getId(), inviteMail);
} }
} }
} }
...@@ -54,7 +54,7 @@ public class EventOrgView extends GenericCDIView { ...@@ -54,7 +54,7 @@ public class EventOrgView extends GenericCDIView {
private transient EventOrganiserBeanLocal eventorgbean; private transient EventOrganiserBeanLocal eventorgbean;
@EJB @EJB
private transient EventBeanLocal eventbean; private transient EventBeanLocal eventbean;
private static final Logger logger = LoggerFactory.getLogger(EventOrgView.class); private static final Logger logger = LoggerFactory.getLogger(EventOrgView.class);
@LoggedIn @LoggedIn
...@@ -155,12 +155,14 @@ public class EventOrgView extends GenericCDIView { ...@@ -155,12 +155,14 @@ public class EventOrgView extends GenericCDIView {
if (eventorg.getEvents() == null) { if (eventorg.getEvents() == null) {
eventorg.setEvents(new ArrayList<LanEvent>()); eventorg.setEvents(new ArrayList<LanEvent>());
} }
setEvent(new LanEvent()); event = new LanEvent();
getEvent().setName(eventname); event.setName(eventname);
getEvent().setOrganiser(eventorg); event.setOrganiser(eventorg);
eventname = ""; eventname = "";
eventorg.getEvents().add(getEvent()); eventorg.getEvents().add(getEvent());
eventorgbean.save(eventorg); eventbean.create(event);
//eventorg = eventorgbean.save(eventorg);
return "/eventorg/editEvent"; return "/eventorg/editEvent";
...@@ -267,12 +269,12 @@ public class EventOrgView extends GenericCDIView { ...@@ -267,12 +269,12 @@ public class EventOrgView extends GenericCDIView {
for (LanEvent lanEvent : eventbean.findAllEvents()) { for (LanEvent lanEvent : eventbean.findAllEvents()) {
if (lanEvent.getStartTime() != null && lanEvent.getEndTime() != null && lanEvent.getTicketSalesBegin() != null) { if (lanEvent.getStartTime() != null && lanEvent.getEndTime() != null && lanEvent.getTicketSalesBegin() != null) {
DefaultScheduleEvent event = new DefaultScheduleEvent("<"+lanEvent.getId() + "> " + lanEvent.getName() + ": " + I18n.get("event.ticketSale"), lanEvent.getTicketSalesBegin(), lanEvent.getEndTime()); DefaultScheduleEvent event = new DefaultScheduleEvent("<" + lanEvent.getId() + "> " + lanEvent.getName() + ": " + I18n.get("event.ticketSale"), lanEvent.getTicketSalesBegin(), lanEvent.getEndTime());
event.setAllDay(true); event.setAllDay(true);
eventsCalendar.addEvent(event); eventsCalendar.addEvent(event);
event.setStyleClass("calendarEventStyle"); event.setStyleClass("calendarEventStyle");
event = new DefaultScheduleEvent( "<"+lanEvent.getId() + "> " + lanEvent.getName() + ": " + I18n.get("event.running"), lanEvent.getStartTime(), lanEvent.getEndTime()); event = new DefaultScheduleEvent("<" + lanEvent.getId() + "> " + lanEvent.getName() + ": " + I18n.get("event.running"), lanEvent.getStartTime(), lanEvent.getEndTime());
event.setAllDay(true); event.setAllDay(true);
event.setStyleClass("eventRunningCalendar"); event.setStyleClass("eventRunningCalendar");
eventsCalendar.addEvent(event); eventsCalendar.addEvent(event);
...@@ -285,9 +287,3 @@ public class EventOrgView extends GenericCDIView { ...@@ -285,9 +287,3 @@ public class EventOrgView extends GenericCDIView {
} }
} }
...@@ -124,7 +124,7 @@ public class EventPropertyView extends GenericCDIView { ...@@ -124,7 +124,7 @@ public class EventPropertyView extends GenericCDIView {
} }
public String deleteProperty() { public String deleteProperty() {
eventbean.deleteProperty(properties.getRowData()); eventorgview.setEvent(eventbean.deleteProperty(properties.getRowData()));
properties = null; properties = null;
return null; return null;
} }
...@@ -237,16 +237,14 @@ public class EventPropertyView extends GenericCDIView { ...@@ -237,16 +237,14 @@ public class EventPropertyView extends GenericCDIView {
} }
public ListDataModel<LanEventProperty> getProperties() { public ListDataModel<LanEventProperty> getProperties() {
if (properties == null && eventorgview != null && eventorgview.getEvent() != null) if (properties == null && eventorgview != null && eventorgview.getEvent() != null) {
{
properties = new ListDataModel<LanEventProperty>(eventorgview.getEvent().getProperties()); properties = new ListDataModel<LanEventProperty>(eventorgview.getEvent().getProperties());
} }
return properties; return properties;
} }
public ListDataModel<LanEventPrivateProperty> getPrivateProperties() { public ListDataModel<LanEventPrivateProperty> getPrivateProperties() {
if (privateProperties == null && eventorgview != null && eventbean.getCurrentEvent().equals(eventorgview.getEvent())) if (privateProperties == null && eventorgview != null && eventbean.getCurrentEvent().equals(eventorgview.getEvent())) {
{
privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties()); privateProperties = new ListDataModel<LanEventPrivateProperty>(eventbean.getPrivateProperties());
} }
return privateProperties; return privateProperties;
......
...@@ -522,3 +522,7 @@ bortalApplication.vip.VIEW=View VIP list ...@@ -522,3 +522,7 @@ bortalApplication.vip.VIEW=View VIP list
bortalApplication.vip.USAGE=Use VIP list bortalApplication.vip.USAGE=Use VIP list
bortalApplication.vip.EDIT=Edit VIP list bortalApplication.vip.EDIT=Edit VIP list
bortalApplication.event.VIEW_STATISTICS=View event statistics bortalApplication.event.VIEW_STATISTICS=View event statistics
eventmap.width=Kartan leveys (px)
eventmap.height=Kartan korkeus (px)
eventmap.uploaderror=Virhe lis\u00E4tess\u00E4 karttapohjaa
placeslot.add=Lis\u00E4\u00E4 placeslot
...@@ -1739,3 +1739,7 @@ bortalApplication.vip.VIEW=View VIP list ...@@ -1739,3 +1739,7 @@ bortalApplication.vip.VIEW=View VIP list
bortalApplication.vip.USAGE=Use VIP list bortalApplication.vip.USAGE=Use VIP list
bortalApplication.vip.EDIT=Edit VIP list bortalApplication.vip.EDIT=Edit VIP list
bortalApplication.event.VIEW_STATISTICS=View event statistics bortalApplication.event.VIEW_STATISTICS=View event statistics
eventmap.width=Map width (px)
eventmap.height=Map height (px)
eventmap.uploaderror=Error when adding map
placeslot.add=Add placeslot
...@@ -1718,8 +1718,12 @@ cardObjectData.delete=Poista ...@@ -1718,8 +1718,12 @@ cardObjectData.delete=Poista
cardTextData.delete=Poista cardTextData.delete=Poista
placegroup.noPlacegroups=Sinulla t\u00E4ytyy olla paikkoja ett\u00E4 voit n\u00E4hd\u00E4 lippusi placegroup.noPlacegroups=Sinulla t\u00E4ytyy olla paikkoja ett\u00E4 voit n\u00E4hd\u00E4 lippusi
bortalApplication.VIP=VIP-lista bortalApplication.VIP=VIP-lista
bortalApplication.vip.VIEW=Näytä VIP-lista bortalApplication.vip.VIEW=N\u00E4yt\u00E4 VIP-lista
bortalApplication.vip.USAGE=Käytä VIP-listaa bortalApplication.vip.USAGE=K\u00E4yt\u00E4 VIP-listaa
bortalApplication.vip.EDIT=Muokkaa VIP-listaa bortalApplication.vip.EDIT=Muokkaa VIP-listaa
bortalApplication.event.VIEW_STATISTICS=Näytä tapahtuman tilastot bortalApplication.event.VIEW_STATISTICS=N\u00E4yt\u00E4 tapahtuman tilastot
lecture.showParticipants=Näytä osallistujat lecture.showParticipants=N\u00E4yt\u00E4 osallistujat
eventmap.width=Kartan leveys (px)
eventmap.height=Kartan korkeus (px)
eventmap.uploaderror=Virhe lis\u00E4tt\u00E4ess\u00E4 karttapohjaa
placeslot.add=Lis\u00E4\u00E4 placeslot
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!