Commit 380c6c51 by Tuukka Kivilahti

Merge branch 'logging' into 'master'

Placeslot and seatmap stuff

Kaikenmoista mahdollista slotteihin ja paikkakarttaan liittyvää.

HUOM! Ei vielä täysin toimivaa koodia ja paljon läpikäytävää ja testattavaa.

Vilkuili ja hyväksyi: @tkfftk

See merge request !134
2 parents cad83996 e8b510a7
Showing with 1053 additions and 417 deletions
......@@ -21,15 +21,20 @@ package fi.codecrew.moya.beans;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Local
public interface LoggingBeanLocal {
//
// LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, Object... description);
//
// LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description);
LogEntry logMessage(SecurityLogType paramType, LanEvent event, User user, Object... description);
void sendMessage(MoyaEventMessage moyaMessage);
LogEntry logMessage(SecurityLogType paramType, EventUser user, Object... description);
void sendMessage(MoyaEventType type, EventUser user, String message);
void sendMessage(MoyaEventType type, EventUser user, Object... message);
}
......@@ -35,6 +35,7 @@ import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.PlaceSlot;
/**
*
......@@ -64,8 +65,10 @@ public interface PlaceBeanLocal {
Place unbuyPlace(Place place);
@Deprecated
BigDecimal getTotalReservationPrice(EventUser user, Place newPlace);
@Deprecated
BigDecimal getTotalReservationPrice(Place newPlace);
/**
......@@ -115,4 +118,6 @@ public interface PlaceBeanLocal {
List<Product> getMapProducts(EventMap map);
List<PlaceSlot> getFreePlaceslots(EventUser user, Product product);
}
......@@ -85,7 +85,7 @@ public interface ProductBeanLocal {
AccountEvent find(Integer id);
void shopCash(EventUser shoppingUser, Map<Product, BigDecimal> shopMap, boolean buyInstant);
// void shopCash(EventUser shoppingUser, Map<Product, BigDecimal> shopMap, boolean buyInstant);
List<Role> getRolesFromAccountEvents(EventUser u);
......
......@@ -18,7 +18,9 @@
*/
package fi.codecrew.moya.exceptions;
public class BortalCatchableException extends Exception {
import javax.ejb.EJBException;
public class BortalCatchableException extends EJBException {
private String i18nMessage;
......
......@@ -58,13 +58,14 @@ import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class BillBean
*/
@Stateless
@LocalBean
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, SpecialPermission.S_VERKKOMAKSU_CHECK, })
@DeclareRoles({ BillPermission.S_CREATE_BILL, BillPermission.S_READ_ALL, BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL, SpecialPermission.S_USER, })
public class BillBean implements BillBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(BillBean.class);
......@@ -96,9 +97,11 @@ public class BillBean implements BillBeanLocal {
@EJB
private DiscountBean discountBean;
@EJB
private LoggingBeanLocal logbean;
@EJB
private BillPBean billpbean;
/**
* Default constructor.
......@@ -229,10 +232,9 @@ public class BillBean implements BillBeanLocal {
return ret;
}
/**
* We will mark bill paid in different transaction. That's because we don't wont it to fail if something other fails.
* We will mark bill paid in different transaction. That's because we don't
* wont it to fail if something other fails.
*
* @param bill
* @param when
......@@ -240,108 +242,19 @@ public class BillBean implements BillBeanLocal {
* @return
* @throws BillException
*/
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to doublemark bill paid", bill.getId());
throw new BillExceptionAlreadyPaid("Trying to mark bill paid, already paid, BillID: "+bill.getId());
}
Product creditproduct = productBean.findCreditProduct();
EventUser user = bill.getUser();
if(useCredits) {
// check if there is enought credits
if(bill.getUser().getAccountBalance().compareTo(bill.getTotalPrice()) < 1) {
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: ", bill.getId());
throw new BillExceptionNotEnoughtCredits("There is not enought credits to pay. , BillID: "+bill.getId());
}
} else {
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user);
logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size());
ac.setEventTime(when);
ac.setBill(bill);
ac.setSeller(permbean.getCurrentUser());
bill.setAccountEvent(ac);
}
bill.setPaidDate(when.getTime());
return bill;
}
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL,
SpecialPermission.S_VERKKOMAKSU_CHECK })
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = markPaidSafeTransaction(bill, when,useCredits);
EventUser user = bill.getUser();
if (bill.isFoowavePaymentOver() && !permbean.hasPermission(ShopPermission.MANAGE_FOODWAVES))
{
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "FoodwaveClosed and marking bill for it paid");
throw new EJBException("Trying to mark paid a closed or left foodwave");
}
// bill = billFacade.merge(bill);
for (BillLine bl : bill.getBillLines()) {
Product prod = bl.getLineProduct();
if (prod != null && !prod.getProductFlags().contains(ProductFlag.PREPAID_CREDIT)) {
logger.debug("Creating Bill prepaidInstant product {}, {}", prod.getName(), bl.getQuantity());
AccountEvent ac2 = productPBean.createAccountEvent(prod, bl.getQuantity(), null, user, bill.getSentDate(), bl.getFoodwave());
logger.info("Created ac from product. {}, userproducts {}", ac2, user.getAccountEvents().size());
ac2.setSeller(permbean.getCurrentUser());
@Override
@RolesAllowed({ BillPermission.S_WRITE_ALL })
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
}
}
billFacade.flush();
/*
MailMessage msg = new MailMessage();
String subject = MessageFormat.format(eventbean.getPropertyString(LanEventPropertyKey.BILL_PAID_MAIL_SUBJECT), user.getEvent().getName());
String content = MessageFormat.format(eventbean.getPropertyString(LanEventPropertyKey.BILL_PAID_MAIL_CONTENT), (bill.getBillNumber() == null) ? "----" : bill.getBillNumber().toString());
logger.info("Bill mail subject: {}, content {}", subject, content);
msg.setSubject(subject);
msg.setMessage(content);
msg.setTo(bill.getUser().getUser());
utilbean.sendMail(msg);
*/
eventUserFacade.flush();
logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Marking bill paid, for user: ", bill.getUser().getId(),"BillId: ",bill.getId());
eventUserFacade.evict(bill.getUser());
return bill;
return billpbean.markPaid(bill, when, useCredits);
}
@Override
@RolesAllowed({ BillPermission.S_CREATE_BILL, BillPermission.S_WRITE_ALL })
public Bill createBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to create bill for user ");
loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to create bill for user: ", bill.getUser());
throw new EJBAccessException("Could not create bill for another user");
}
billFacade.create(bill);
......@@ -358,7 +271,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_READ_ALL })
public List<Bill> find(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(BillPermission.READ_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to get bill list for user ");
loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to get bill list for user ", user);
throw new EJBAccessException("Could not list bills for another user");
}
return billFacade.find(user);
......@@ -368,7 +281,7 @@ public class BillBean implements BillBeanLocal {
@RolesAllowed({ BillPermission.S_VIEW_OWN, BillPermission.S_WRITE_ALL })
public Bill expireBill(Bill bill) {
if (!permbean.isCurrentUser(bill.getUser()) && !permbean.hasPermission(BillPermission.WRITE_ALL)) {
loggingBean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enought rights to expire a bill for user ");
loggingBean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Not enought rights to expire a bill for user", bill);
throw new EJBAccessException("Could not list bills for another user");
}
......
package fi.codecrew.moya.beans;
import java.util.Calendar;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.enums.apps.ShopPermission;
import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.exceptions.BillExceptionAlreadyPaid;
import fi.codecrew.moya.exceptions.BillExceptionNotEnoughtCredits;
import fi.codecrew.moya.facade.BillFacade;
import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.BillLine;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* EJB private bean for bill functions Does not check allowed roles! All
* rolechecks should be done outside this. class
*
* @author tuomari
*
*/
@Stateless
@LocalBean
public class BillPBean {
@EJB
private LoggingBeanLocal logbean;
@EJB
private BillFacade billFacade;
@EJB
private ProductBean productBean;
@EJB
private PermissionBean permbean;
@EJB
private ProductPBean productPBean;
@EJB
private EventUserFacade eventUserFacade;
private static final Logger logger = LoggerFactory.getLogger(BillPBean.class);
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
private Bill markPaidSafeTransaction(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = billFacade.reload(bill);
if (bill.getAccountEvent() != null || bill.getPaidDate() != null) {
logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Tried to mark already paid bill as paid: " + bill.getId());
// logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to doublemark bill paid", bill.getId());
throw new BillExceptionAlreadyPaid("Trying to mark bill paid, already paid, BillID: " + bill.getId());
}
Product creditproduct = productBean.findCreditProduct();
EventUser user = bill.getUser();
if (useCredits) {
// check if there is enought credits
if (bill.getUser().getAccountBalance().compareTo(bill.getTotalPrice()) < 1) {
logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: " + bill.getId());
// logbean.logMessage(SecurityLogType.bill, permbean.getCurrentUser(), "Trying to pay bill with accountevents, and there is no saldo, billid: ", bill.getId());
throw new BillExceptionNotEnoughtCredits("There is not enought credits to pay. , BillID: " + bill.getId());
}
} else {
AccountEvent ac = productBean.createAccountEvent(creditproduct, bill.totalPrice(), user);
logger.info("Created creditentry. {}, userproducts {}", ac, user.getAccountEvents().size());
ac.setEventTime(when);
ac.setBill(bill);
ac.setSeller(permbean.getCurrentUser());
bill.setAccountEvent(ac);
}
bill.setPaidDate(when.getTime());
return bill;
}
public Bill markPaid(Bill bill, Calendar when, boolean useCredits) throws BillException {
bill = markPaidSafeTransaction(bill, when, useCredits);
EventUser user = bill.getUser();
if (bill.isFoowavePaymentOver() && !permbean.hasPermission(ShopPermission.MANAGE_FOODWAVES))
{
logbean.sendMessage(MoyaEventType.BILL_ERROR, permbean.getCurrentUser(), "FoodwaveClosed and marking bill for it paid. Billid: " + bill.getId());
throw new EJBException("Trying to mark paid a closed or left foodwave");
}
// bill = billFacade.merge(bill);
for (BillLine bl : bill.getBillLines()) {
Product prod = bl.getLineProduct();
if (prod != null && !prod.getProductFlags().contains(ProductFlag.PREPAID_CREDIT)) {
logger.debug("Creating Bill prepaidInstant product {}, {}", prod.getName(), bl.getQuantity());
AccountEvent ac2 = productPBean.createAccountEvent(prod, null,bl.getQuantity(), user, bill.getSentDate(), bl.getFoodwave());
logger.info("Created ac from product. {}, userproducts {}", ac2, user.getAccountEvents().size());
ac2.setSeller(permbean.getCurrentUser());
}
}
billFacade.flush();
/*
MailMessage msg = new MailMessage();
String subject = MessageFormat.format(eventbean.getPropertyString(LanEventPropertyKey.BILL_PAID_MAIL_SUBJECT), user.getEvent().getName());
String content = MessageFormat.format(eventbean.getPropertyString(LanEventPropertyKey.BILL_PAID_MAIL_CONTENT), (bill.getBillNumber() == null) ? "----" : bill.getBillNumber().toString());
logger.info("Bill mail subject: {}, content {}", subject, content);
msg.setSubject(subject);
msg.setMessage(content);
msg.setTo(bill.getUser().getUser());
utilbean.sendMail(msg);
*/
eventUserFacade.flush();
logbean.sendMessage(MoyaEventType.BILL_PAID, permbean.getCurrentUser(), "Marking bill paid, for user: ", bill.getUser().getId(), "BillId: ", bill.getId());
eventUserFacade.evict(bill.getUser());
return bill;
}
}
......@@ -249,6 +249,13 @@ public class BootstrapBean implements BootstrapBeanLocal {
"ALTER TABLE maps ADD COLUMN height integer",
});
dbUpdates.add(new String[] {
"CREATE TABLE place_slots (id SERIAL NOT NULL, CREATED TIMESTAMPTZ, DESCRIPTION TEXT, meta json, USED TIMESTAMPTZ, BILL_id INTEGER NOT NULL, PRODUCT_id INTEGER NOT NULL, PLACE_id INTEGER UNIQUE, PRIMARY KEY (id))",
"ALTER TABLE place_slots ADD CONSTRAINT FK_place_slots_BILL_id FOREIGN KEY (BILL_id) REFERENCES bills (id)",
"ALTER TABLE place_slots ADD CONSTRAINT FK_place_slots_PLACE_id FOREIGN KEY (PLACE_id) REFERENCES places (id)",
"ALTER TABLE place_slots ADD CONSTRAINT FK_place_slots_PRODUCT_id FOREIGN KEY (PRODUCT_id) REFERENCES products (id)"
});
} // start_time timestamp without time zone,
@EJB
......
......@@ -44,8 +44,11 @@ import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -65,6 +68,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.CheckoutBank;
import fi.codecrew.moya.util.CheckoutReturnType;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class CheckoutFiBean
......@@ -92,7 +96,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
@EJB
private BillFacade billfacade;
@EJB
private VerkkomaksuRunner vmrunner;
private BillPBean billpbean;
private static final Logger logger = LoggerFactory.getLogger(CheckoutFiBean.class);
private static final BigDecimal TO_CENTS = BigDecimal.valueOf(100);
......@@ -194,6 +198,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
}
mdString.append(merchantPassword);
CloseableHttpResponse response = null;
try {
final String calculatedHash = PasswordFunctions.calculateMd5(mdString.toString());
......@@ -204,9 +209,12 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
final HttpPost postRequest = new HttpPost(REMOTE_URL);
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpClientBuilder cliBuilder = HttpClientBuilder.create();
CloseableHttpClient cli = cliBuilder.build();
response = cli.execute(postRequest);
final DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(postRequest);
// final DefaultHttpClient client = new DefaultHttpClient();
// HttpResponse response = client.execute(postRequest);
// final StringWriter writer = new StringWriter();
//
......@@ -220,6 +228,14 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
} catch (IOException e) {
logger.warn("Error sending checkout.fi request", e);
} finally {
try {
if (response != null) {
response.close();
}
} catch (IOException e) {
logger.warn("Error closing checkout.fi request", e);
}
}
return null;
......@@ -308,7 +324,7 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
String[] splittedStamp = stamp.split(STAMP_SPLITCHAR);
if (splittedStamp.length != 2)
{
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to split stamp ", stamp, " with splitchar ", STAMP_SPLITCHAR);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to split stamp '", stamp, "' with splitchar ", STAMP_SPLITCHAR);
return false;
}
......@@ -321,17 +337,17 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
switch (returnType)
{
case CANCEL:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received cancel for stamp ", stamp);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received cancel for stamp ", stamp);
// Return true when checksum was correct
ret = true;
break;
case DELAYED:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received delayed for stamp ", stamp);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received delayed for stamp ", stamp);
// Return true when checksum was correct
ret = true;
break;
case REJECT:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "received reject for stamp ", stamp);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "received reject for stamp ", stamp);
// Return true when checksum was correct
ret = true;
break;
......@@ -351,30 +367,30 @@ public class CheckoutFiBean implements CheckoutFiBeanLocal {
&& bill.getPaidDate() == null)
{
logger.info("Trying to mark bill {} paid", bill);
vmrunner.markPaid(bill, Calendar.getInstance());
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Marking bill paid. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference);
billpbean.markPaid(bill, Calendar.getInstance(), false);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Marking bill paid from checkout. Received bill status ", statusInt, " for bill ", bill, " stamp ", stamp, " payment: ", payment, " reference ", reference);
ret = true;
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Bill already marked paid: ", bill, " status ", status, " stamp ", stamp, " payment ", payment);
}
break;
default:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Not marking bill paid: Return status ", status, " for bill ", bill, " stamp ", stamp, " payment ", payment);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Not marking bill paid because of invalid status: Return status ", status, " for bill ", bill, " stamp ", stamp, " payment ", payment);
break;
}
break;
default:
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Valid mac, but Invalid return type: ", returnType, " for stamp ", stamp, " payment ", payment, " status ", status);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Valid mac, but Invalid return type: ", returnType, " for stamp ", stamp, " payment ", payment, " status ", status);
throw new EJBException("Unknown return type!");
}
}
else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Validated mac, but bill not found for id: ", splittedStamp[0], " stamp ", stamp, " mac: ", mac);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Validated mac, but bill not found for id: ", splittedStamp[0], " stamp ", stamp, " mac: ", mac);
}
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to validate order reference: ", reference, " calculated checksum: ", calculatedMac, " version ", version, " stamp ", stamp, " status ", status, " mac ", mac);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to validate order reference: ", reference, " calculated checksum: ", calculatedMac, " version ", version, " stamp ", stamp, " status ", status, " mac ", mac);
}
......
......@@ -49,6 +49,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class SessionHandlerBean
......@@ -65,9 +66,6 @@ public class JaasBean implements MoyaRealmBeanRemote {
private EventUserFacade eventUserFacade;
@EJB
private LoggingBeanLocal secubean;
@EJB
private UserBean userbean;
@EJB
private PermissionBeanLocal permbean;
......@@ -83,6 +81,9 @@ public class JaasBean implements MoyaRealmBeanRemote {
@EJB
private EventBean eventorgbean;
@EJB
private LoggingBeanLocal secubean;
public EventUser tryLogin(String username, String password) {
// username = username.trim().toLowerCase();
......@@ -104,7 +105,8 @@ public class JaasBean implements MoyaRealmBeanRemote {
if (user.isAnonymous()) {
logger.info("logging in as anonymous!!!");
} else if (!user.checkPassword(password)) {
secubean.logMessage(SecurityLogType.permissionDenied, eventUser, "Login failed: wrong password for username ", username);
secubean.sendMessage(MoyaEventType.LOGIN_FAILED, eventUser, "Login failed: wrong password for username ", username);
eventUser = null;
user = null;
}
......@@ -124,7 +126,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
eventUser.setCreator(eventUser);
}
} else {
secubean.logMessage(SecurityLogType.permissionDenied, eventbean.getCurrentEvent(), null, "Login failed: Username not found: ", username);
secubean.sendMessage(MoyaEventType.LOGIN_FAILED, eventUserFacade.findByLogin(User.ANONYMOUS_LOGINNAME), "Login failed: Username not found: ", username);
}
return eventUser;
......@@ -188,10 +190,7 @@ public class JaasBean implements MoyaRealmBeanRemote {
roleset.add(UserPermission.ANYUSER.getFullName());
if (usr == null) {
if (SpecialPermission.VERKKOMAKSU_CHECKER.name().equals(user)) {
roleset.add(SpecialPermission.VERKKOMAKSU_CHECKER.name());
}
usr = permbean.getAnonEventUser();
roleset.add(SpecialPermission.ANONYMOUS.name());
}
......
......@@ -64,6 +64,7 @@ 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.model.EventMap;
import fi.codecrew.moya.model.EventUser;
......@@ -71,8 +72,10 @@ import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
*
......@@ -127,6 +130,8 @@ public class PlaceBean implements PlaceBeanLocal {
private BarcodeBeanLocal barcodeBean;
@EJB
private EventMapFacade eventMapFacade;
@EJB
private PlaceSlotFacade placeSlotFacade;
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
......@@ -146,6 +151,8 @@ public class PlaceBean implements PlaceBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
@Override
/** Use place slots */
@Deprecated
public BigDecimal getTotalReservationPrice(Place newPlace)
{
return addAndCalcPrice(permbean.getCurrentUser(), newPlace);
......@@ -153,12 +160,16 @@ public class PlaceBean implements PlaceBeanLocal {
@RolesAllowed(MapPermission.S_MANAGE_OTHERS)
@Override
/** Use place slots */
@Deprecated
public BigDecimal getTotalReservationPrice(EventUser user, Place newPlace)
{
return addAndCalcPrice(user, newPlace);
}
/** Use place slots */
@Deprecated()
private BigDecimal addAndCalcPrice(EventUser user, Place newPlace) {
Set<Place> places = new HashSet<Place>();
......@@ -227,6 +238,17 @@ public class PlaceBean implements PlaceBeanLocal {
if (!place.isTaken() || (permbean.hasPermission(MapPermission.MANAGE_OTHERS) && permbean.getCurrentUser().equals(place.getCurrentUser()))) {
if (place.isBuyable() || permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
if (place.getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT)) {
// TODO: We should check there is enough credits...
} else {
List<PlaceSlot> slots = placeSlotFacade.findFreePlaceSlots(user, place.getProduct());
if (slots != null && !slots.isEmpty()) {
PlaceSlot slot = slots.get(0);
slot.setPlace(place);
slot.setUsed(new Date());
}
}
if (!place.isBuyable()) {
place.setBuyable(true);
}
......@@ -241,6 +263,7 @@ public class PlaceBean implements PlaceBeanLocal {
for (Timer t : ts.getTimers()) {
if (t.getInfo().equals(PLACE_RESERVE_TIMEOUTER)) {
foundTimeout = true;
break;
}
}
if (!foundTimeout) {
......@@ -292,7 +315,7 @@ public class PlaceBean implements PlaceBeanLocal {
user = permbean.getCurrentUser();
} else {
if (!user.equals(permbean.getCurrentUser()) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Can not buy places for user " + user);
loggerbean.sendMessage(MoyaEventType.PLACE_ERROR, permbean.getCurrentUser(), "Can not buy places for user " + user);
throw new EJBAccessException("Not enough permissions to buy place");
}
user = eventUserFacade.reload(user);
......@@ -534,13 +557,18 @@ public class PlaceBean implements PlaceBeanLocal {
}
place.setCurrentUser(null);
place.setReleaseTime(null);
PlaceSlot slot = placeSlotFacade.findSlotForPlace(place);
if (slot != null) {
slot.setPlace(null);
slot.setUsed(null);
}
return true;
}
@Override
@RolesAllowed(MapPermission.S_MANAGE_MAPS)
@RolesAllowed(MapPermission.S_VIEW)
public Place find(int placeId) {
return placeFacade.find(placeId);
}
......@@ -553,6 +581,7 @@ public class PlaceBean implements PlaceBeanLocal {
place.getGroup().getPlaces().remove(place);
}
place.setGroup(null);
place.setCurrentUser(null);
if (place.getPlaceReserver() != null)
{
......@@ -692,6 +721,15 @@ public class PlaceBean implements PlaceBeanLocal {
}
@Override
public List<PlaceSlot> getFreePlaceslots(EventUser user, Product product) {
user = eventUserFacade.reload(user);
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(MapPermission.MANAGE_OTHERS))
throw new EJBAccessException("User " + permbean.getCurrentUser() + "tried to fetch free places for user " + user);
return placeSlotFacade.findFreePlaceSlots(user, product);
}
@Override
public List<Product> getMapProducts(EventMap map) {
return placeFacade.getMapProducts(map);
}
......
......@@ -52,6 +52,7 @@ import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class PlaceGroupBean
......@@ -293,7 +294,7 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
gmem = gmemfacade.reload(gmem);
if (!(permbean.getCurrentUser().getId().equals(gmem.getPlaceGroup().getCreator().getId()) || permbean.hasPermission(MapPermission.MANAGE_OTHERS))) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to release and generate group membership: " + gmem);
loggerbean.sendMessage(MoyaEventType.PLACE_ERROR, permbean.getCurrentUser(), "User tried to release and generate group membership: " + gmem);
throw new EJBAccessException("Not enough rights to release token");
}
gmem.setUser(null);
......
......@@ -51,6 +51,7 @@ import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.InventoryEventFacade;
import fi.codecrew.moya.facade.PlaceFacade;
import fi.codecrew.moya.facade.PlaceSlotFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.AccountEvent;
......@@ -62,6 +63,7 @@ import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.ProductLimitation;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class ProductBean
......@@ -136,6 +138,9 @@ public class ProductBean implements ProductBeanLocal {
@EJB
private GroupMembershipFacade gmfacade;
@EJB
private PlaceSlotFacade slotfacade;
private static final Logger logger = LoggerFactory.getLogger(ProductBean.class);
/**
......@@ -197,6 +202,7 @@ public class ProductBean implements ProductBeanLocal {
@Override
public HashMap<Integer, BigDecimal> getProductLimit(Map<Integer, BigDecimal> prodCounts, EventUser user)
{
Set<Role> userroles = new HashSet<Role>(userbean.findUsersRoles(user));
HashMap<Integer, BigDecimal> ret = new HashMap<Integer, BigDecimal>();
for (Entry<Integer, BigDecimal> pc : prodCounts.entrySet())
......@@ -205,6 +211,18 @@ public class ProductBean implements ProductBeanLocal {
BigDecimal lim = getPrivateProductLimit(prod, user, prodCounts, userroles);
ret.put(prod.getId(), lim);
// logger.info("Added product limit {} to {}", lim, prod);
if (!prod.getProductFlags().contains(ProductFlag.PREPAID_CREDIT))
{
if (prod.getPlaces() != null && !prod.getPlaces().isEmpty()) {
int totalcount = prod.getPlaces().size();
Long boughtSlots = slotfacade.totalSlotcount(prod);
int freeCount = totalcount - boughtSlots.intValue();
logger.info("Prodlimit totcnt {}, bought {}, free {}, prod {}", totalcount, boughtSlots, freeCount, prod);
ret.put(prod.getId(), BigDecimal.valueOf(freeCount));
}
}
}
return ret;
}
......@@ -406,16 +424,16 @@ public class ProductBean implements ProductBeanLocal {
return ret;
}
@Override
public AccountEvent createAccountEvent(Product product, BigDecimal overriddenUnitPrice, BigDecimal quantity, EventUser user) {
user = eventUserFacade.reload(user);
@Override
public AccountEvent createAccountEvent(Product product, BigDecimal overriddenUnitPrice, BigDecimal quantity, EventUser user) {
user = eventUserFacade.reload(user);
AccountEvent ret = productPBean.createAccountEvent(product, quantity, overriddenUnitPrice, user, Calendar.getInstance(), null);
cardTemplateBean.checkPrintedCard(user);
return ret;
}
AccountEvent ret = productPBean.createAccountEvent(product, overriddenUnitPrice, quantity, user, Calendar.getInstance(), null);
cardTemplateBean.checkPrintedCard(user);
return ret;
}
@Override
@Override
// @RolesAllowed(ShopPermission.S_LIST_ALL_PRODUCTS)
public Product findByBarcode(String barcode) {
return productFacade.findProductByBarcode(barcode);
......@@ -462,7 +480,7 @@ public class ProductBean implements ProductBeanLocal {
EventUser ret = acco.getUser();
ret.getAccountEvents().remove(acco);
loggingbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "Deleting AccountEvent '", acco.getProduct().getName(), "' count: '", acco.getQuantity().toString(), "' unitprice: '", acco.getUnitPrice().toString(), "' accouser: '", acco.getUser().getUser().getLogin(), "'");
loggingbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "Deleting AccountEvent '", acco.getProduct().getName(), "' count: '", acco.getQuantity().toString(), "' unitprice: '", acco.getUnitPrice().toString(), "' accouser: '", acco.getUser().getUser().getLogin(), "'");
acco.getProduct().getAccountEvents().remove(acco);
acco.getUser().getAccountEvents().remove(acco);
if (acco.getBill() != null) {
......@@ -483,49 +501,60 @@ public class ProductBean implements ProductBeanLocal {
return accounteventfacade.findProvidedRoles(eventBean.getCurrentEvent(), u);
}
/**
* Create accountevents for the products in the parameter shopMap
*/
@Override
@RolesAllowed(ShopPermission.S_SHOP_PRODUCTS)
public void shopCash(EventUser shoppingUser, Map<Product, BigDecimal> shopMap, boolean buyInstant) {
logger.debug("Shoping cash. buyinstant {}", buyInstant);
EventUser seller = permbean.getCurrentUser();
shoppingUser = userbean.findByEventUserId(shoppingUser.getId());
BigDecimal tot = BigDecimal.ZERO;
for (Entry<Product, BigDecimal> prodentry : shopMap.entrySet()) {
// Create account event for the product.
AccountEvent ac = new AccountEvent(shoppingUser, prodentry.getKey(), prodentry.getKey().getPrice(), prodentry.getValue(), Calendar.getInstance());
ac.setSeller(seller);
accounteventfacade.create(ac);
if (buyInstant && prodentry.getKey().getPrice().compareTo(BigDecimal.ZERO) > 0) {
tot = tot.add(prodentry.getValue().multiply(prodentry.getKey().getPrice()));
}
if (prodentry.getKey().getProductFlags().contains(ProductFlag.RESERVE_PLACE_WHEN_BOUGHT) || prodentry.getKey().getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
logger.debug("Prepaidplace");
placebean.lockPlaceProduct(shoppingUser, prodentry.getKey(), BigDecimal.ONE);
}
}
logger.debug("ShopCash price {}", tot);
if (buyInstant && tot.compareTo(BigDecimal.ZERO) > 0) {
logger.debug("Creating buy instant product!");
Product creditProd = findCreditProduct();
AccountEvent ac = new AccountEvent(shoppingUser, creditProd, creditProd.getPrice(), tot, Calendar.getInstance());
accounteventfacade.create(ac);
}
userbean.mergeEventUserChanges(shoppingUser);
}
// /**
// * Create accountevents for the products in the parameter shopMap
// */
// @Override
// @RolesAllowed(ShopPermission.S_SHOP_PRODUCTS)
// public void shopCash(EventUser shoppingUser, Map<Product, BigDecimal>
// shopMap, boolean buyInstant) {
// logger.debug("Shoping cash. buyinstant {}", buyInstant);
// EventUser seller = permbean.getCurrentUser();
// shoppingUser = userbean.findByEventUserId(shoppingUser.getId());
//
// BigDecimal tot = BigDecimal.ZERO;
//
// for (Entry<Product, BigDecimal> prodentry : shopMap.entrySet()) {
//
// // Create account event for the product.
// AccountEvent ac = new AccountEvent(shoppingUser, prodentry.getKey(),
// prodentry.getKey().getPrice(), prodentry.getValue(),
// Calendar.getInstance());
// ac.setSeller(seller);
// accounteventfacade.create(ac);
//
// if (buyInstant &&
// prodentry.getKey().getPrice().compareTo(BigDecimal.ZERO) > 0) {
// tot =
// tot.add(prodentry.getValue().multiply(prodentry.getKey().getPrice()));
// }
//
// if
// (prodentry.getKey().getProductFlags().contains(ProductFlag.RESERVE_PLACE_WHEN_BOUGHT)
// ||
// prodentry.getKey().getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT))
// {
// logger.debug("Prepaidplace");
//
// placebean.lockPlaceProduct(shoppingUser, prodentry.getKey(),
// BigDecimal.ONE);
//
// }
//
// }
//
// logger.debug("ShopCash price {}", tot);
// if (buyInstant && tot.compareTo(BigDecimal.ZERO) > 0) {
// logger.debug("Creating buy instant product!");
// Product creditProd = findCreditProduct();
// AccountEvent ac = new AccountEvent(shoppingUser, creditProd,
// creditProd.getPrice(), tot, Calendar.getInstance());
// accounteventfacade.create(ac);
// }
//
// userbean.mergeEventUserChanges(shoppingUser);
//
// }
@Override
public AccountEvent markDelivered(AccountEvent e, Calendar c) {
......
......@@ -37,6 +37,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
* Session Bean implementation class ProductPBean
......@@ -59,9 +60,8 @@ public class ProductPBean {
@EJB
private ProductFacade productFacade;
@EJB
private LoggingBean lbean;
@EJB
private LoggingBeanLocal lbean;
private static final Logger logger = LoggerFactory
.getLogger(ProductPBean.class);
......@@ -104,24 +104,23 @@ public class ProductPBean {
throw new EJBException("Trying to create accountevent for different event in user and product");
}
BigDecimal unitPrice = product.getPrice().negate();
List<Discount> discounts = new ArrayList<>();
List<Discount> discounts = new ArrayList<>();
if(overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) < 0) {
if (overriddenUnitPrice != null && BigDecimal.ZERO.compareTo(overriddenUnitPrice) < 0) {
unitPrice = overriddenUnitPrice;
unitPrice = overriddenUnitPrice;
lbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "User creating accountevent with discount");
// lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User creating accountevent with discount");
} else {
lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User creating accountevent with discount");
} else {
// no discounts if custom price
discounts = discountBean.getActiveDiscountsByProduct(product, quantity, date, user);
for (Discount d : discounts) {
unitPrice = unitPrice.multiply(d.getPercentage());
}
}
// no discounts if custom price
discounts = discountBean.getActiveDiscountsByProduct(product, quantity, date, user);
for (Discount d : discounts) {
unitPrice = unitPrice.multiply(d.getPercentage());
}
}
AccountEvent ret = new AccountEvent(user, product, unitPrice, quantity, Calendar.getInstance());
......@@ -159,7 +158,7 @@ public class ProductPBean {
// flush changes to db.
// userFacade.flush();
lbean.logMessage(SecurityLogType.accountEvent, permbean.getCurrentUser(), "User created accountevent: ", ret.getId());
lbean.sendMessage(MoyaEventType.ACCOUNTEVENT_INFO, permbean.getCurrentUser(), "User created accountevent: ", ret.getId());
return ret;
}
}
......@@ -47,6 +47,7 @@ import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.ApplicationPermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Role;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
*
......@@ -241,7 +242,7 @@ public class RoleBean implements RoleBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
public List<Role> getRoles(EventUser selectedUser) {
if (!permbean.isCurrentUser(selectedUser) && !permbean.hasPermission(UserPermission.READ_ROLES)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to touch another user roles: " + selectedUser);
loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to touch another user roles: " + selectedUser);
throw new EJBAccessException("Not enough rights to read user permissions");
}
return roleFacade.findForUser(selectedUser);
......
......@@ -76,7 +76,6 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Feedback;
import fi.codecrew.moya.model.GameID;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.IUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup;
......@@ -93,6 +92,7 @@ import fi.codecrew.moya.utilities.I18n;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@LocalBean
@Stateless
......@@ -186,7 +186,7 @@ public class UserBean implements UserBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
public EventUser mergeChanges(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to save another user: " + user);
loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to save another user: " + user);
throw new EJBAccessException("Not enough rights to save user");
}
......@@ -201,7 +201,7 @@ public class UserBean implements UserBeanLocal {
EventUser currusr = permbean.getCurrentUser();
if (!currusr.equals(u) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to fetc another users roles: " + u);
loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, permbean.getCurrentUser(), "User tried to fetc another users roles: " + u);
throw new EJBAccessException("Not enough rights to find roles");
}
......@@ -287,7 +287,7 @@ public class UserBean implements UserBeanLocal {
EventUser curruser = permbean.getCurrentUser();
if (!curruser.equals(user) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, curruser, "user tried to save picture to userid " + user + " without sufficient permissions!");
loggerbean.sendMessage(MoyaEventType.USER_PERMISSION_VIOLATION, curruser, "user tried to save picture for userid " + user + " without sufficient permissions!");
throw new EJBAccessException("No permission to upload image as another user");
}
......@@ -406,7 +406,7 @@ public class UserBean implements UserBeanLocal {
} else {
ret = userimagefacade.find(id);
if (ret != null && !permbean.isCurrentUser(ret.getUser()) && permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "Not enough rights to access image id: " + id + " for user " + ret.getUser());
loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(), "Not enough rights to access image id: ", id, " for user ", ret.getUser());
throw new EJBAccessException("Not enough permissions to fetch image");
}
......@@ -698,7 +698,7 @@ public class UserBean implements UserBeanLocal {
// At the very least it safeguards the situation if user gets another
// users gameid in somehow..
if (!permbean.isCurrentUser(gi.getEventUser())) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to remove GameID from another user: " + gi.getEventUser());
loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(), "User tried to remove GameID from another user: ", gi.getEventUser());
throw new EJBAccessException("Not enough rights to remove another users' GameIDs");
}
......@@ -714,7 +714,7 @@ public class UserBean implements UserBeanLocal {
@Override
public boolean userExists(String login) {
IUser usr = userFacade.findByLogin(login);
User usr = userFacade.findByLogin(login);
return usr != null;
}
......@@ -727,7 +727,7 @@ public class UserBean implements UserBeanLocal {
@RolesAllowed(SpecialPermission.S_USER)
public EventUser mergeEventUserChanges(EventUser user) {
if (!permbean.isCurrentUser(user) && !permbean.hasPermission(UserPermission.MODIFY)) {
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(), "User tried to save another user: " + user);
loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(), "User tried to save another user: ", user);
throw new EJBAccessException("Not enough rights to save user");
}
......
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.beans;
import java.util.Calendar;
import javax.annotation.security.RunAs;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.beans.BillBeanLocal;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.exceptions.BillException;
import fi.codecrew.moya.model.Bill;
@Stateless
@LocalBean
@RunAs(SpecialPermission.S_VERKKOMAKSU_CHECK)
public class VerkkomaksuRunner {
@EJB
private BillBeanLocal billbean;
public void markPaid(Bill bill, Calendar when) {
try {
billbean.markPaid(bill, when, false);
} catch (BillException x) {
throw new RuntimeException(x);
}
}
}
......@@ -18,8 +18,10 @@
*/
package fi.codecrew.moya.beans;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StringWriter;
import java.math.BigDecimal;
import java.util.Arrays;
......@@ -42,9 +44,14 @@ import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.auth.params.AuthPNames;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.AuthPolicy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
......@@ -62,6 +69,7 @@ import fi.codecrew.moya.model.LanEventPrivatePropertyKey;
import fi.codecrew.moya.util.SvmReturnType;
import fi.codecrew.moya.util.VerkkomaksutReturnEntry;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.codecrew.moya.verkkomaksutfi.PaymentEntry;
/**
......@@ -80,11 +88,11 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
private PermissionBeanLocal permbean;
@EJB
private VerkkomaksuRunner vmrunner;
@EJB
private LoggingBeanLocal logbean;
@EJB
private BillFacade billFacade;
@EJB
private BillPBean billpbean;
@Override
public boolean isSvmEnabled()
......@@ -122,22 +130,23 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
{
// If bill is unpaid, mark it paid...
if (SvmReturnType.PENDING.equals(type) || paid.equals("0000000000")) {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Received pending message ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Received pending message ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
} else if (bill.getAccountEvent() == null
&& bill.getPaidDate() == null
&& (SvmReturnType.NOTIFICATION.equals(type) || SvmReturnType.SUCCESS.equals(type))) {
vmrunner.markPaid(bill, Calendar.getInstance());
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
billpbean.markPaid(bill, Calendar.getInstance(), false);
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "Validated order number ", orderNumber, " bill ", bill == null ? "null" : bill.toString(), " with authcode: ", authcode);
ret = true;
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Bill already marked paid or other error. ", orderNumber, " bill ", bill.toString(), " with authcode: ", authcode);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Bill already marked paid or other error. ", orderNumber, " bill ", bill.toString(), " with authcode: ", authcode);
ret = true;
}
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Mac validated, but unable to find bill for order number ", orderNumber);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Mac validated, but unable to find bill for order number ", orderNumber);
}
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "Unable to validate order number: ", orderNumber, " calculated checksum: ", calculatedHash, " authcode ", authcode, " paid ", paid, " method ", method);
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "Unable to validate order number: ", orderNumber, " calculated checksum: ", calculatedHash, " authcode ", authcode, " paid ", paid, " method ", method);
}
......@@ -170,9 +179,9 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
VerkkomaksutReturnEntry ret = sendMessage(message, merchantid, merchantPassword);
if (ret != null)
if (ret.isError()) {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "User trieed to create new token for bill: ", bill.toString(), " but received error: ", ret.getErrorCode(), " message ", ret.getErrorMessage());
logbean.sendMessage(MoyaEventType.BANKING_ERROR, permbean.getCurrentUser(), "User trieed to create new token for bill: ", bill.toString(), " but received error: ", ret.getErrorCode(), " message ", ret.getErrorMessage());
} else {
logbean.logMessage(SecurityLogType.verkkomaksu, permbean.getCurrentUser(), "User crated new token for bill: ", bill.toString(), " Got: ", ret.getOrderNumber(), " token ", ret.getToken());
logbean.sendMessage(MoyaEventType.BANKING_MESSAGE, permbean.getCurrentUser(), "User crated new token for bill: ", bill.toString(), " Got: ", ret.getOrderNumber(), " token ", ret.getToken());
}
......@@ -194,8 +203,9 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
}
private static final String AUTH_SCOPE = "payment.paytrail.com";
private static final String REMOTE_URL =
"https://payment.verkkomaksut.fi/api-payment/create";
"https://payment.paytrail.com/api-payment/create";
// private static final String url = "http://iudex.fi/api-payment/create";
......@@ -203,31 +213,42 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
{
VerkkomaksutReturnEntry ret = null;
CloseableHttpClient client = null;
try {
// DefaultHttpClient httpClient = new DefaultHttpClient();
DefaultHttpClient client = new DefaultHttpClient();
client.getCredentialsProvider().setCredentials(
// new AuthScope("payment.verkkomaksut.fi", 443),
AuthScope.ANY,
HttpClientBuilder clientBuilder = HttpClientBuilder.create();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AUTH_SCOPE, AuthScope.ANY_PORT, AuthScope.ANY_REALM),
new UsernamePasswordCredentials(merchantId, merchantPassword));
client.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, Arrays.asList(AuthPolicy.BASIC));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
client = clientBuilder.build();
HttpPost postRequest = new HttpPost(REMOTE_URL);
postRequest.setHeader("Content-Type", "application/xml");
postRequest.setHeader("X-Verkkomaksut-Api-Version", "1");
// postRequest.setEntity(new
// StringEntity(outputPayment(paymentMsg)));
postRequest.setEntity(new StringEntity(outputPayment(paymentMsg)));
HttpResponse response = client.execute(postRequest);
logger.info("Got statuscode from suomenverkkomaksut.fi: {} ", response.getStatusLine().getStatusCode());
ret = parseMessageReturn(response.getEntity().getContent());
client.getConnectionManager().shutdown();
} catch (Throwable t)
{
} catch (Throwable t) {
logger.warn("Got exception while creating payment to suomenverkkomaksut", t);
} finally {
try {
if (client != null)
client.close();
} catch (IOException e) {
logger.warn("Error closing client for verkkomaksutfi", e);
}
}
return ret;
......@@ -252,12 +273,19 @@ public class VerkkomaksutFiBean implements VerkkomaksutFiBeanLocal {
}
private static VerkkomaksutReturnEntry parseMessageReturn(InputStream inputStream) throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document parsed = dBuilder.parse(inputStream);
parsed.normalize();
NodeList rootElements = parsed.getChildNodes();
VerkkomaksutReturnEntry ret = null;
for (int i = 0; i < rootElements.getLength(); ++i) {
Node node = rootElements.item(i);
logger.info("Got root: {} {}, name {}", i, node, node.getNodeName());
}
if (rootElements.getLength() != 1) {
logError("Unknown number of entries for root {}", parsed, rootElements.getLength());
} else {
......
......@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BotBean;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/**
* Message-Driven Bean implementation class for: IrcBotTopicListener
......
......@@ -17,8 +17,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
@Stateless
@JMSDestinationDefinition(name = MoyaEventSender.MOYA_EVENT_SENDER_TOPIC,
......@@ -29,7 +32,7 @@ import fi.codecrew.moya.model.EventUser;
)
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
//@TransactionManagement(value = TransactionManagementType.CONTAINER)
public class MoyaEventSender {
public class MoyaEventSender implements LoggingBeanLocal {
static final String MOYA_EVENT_TOPIC_DESTINATION = "moyaEventTopic";
......@@ -48,11 +51,13 @@ public class MoyaEventSender {
private static final Logger logger = LoggerFactory.getLogger(MoyaEventSender.class);
@Override
public void sendMessage(MoyaEventMessage moyaMessage) {
ObjectMessage msg = context.createObjectMessage(moyaMessage);
context.createProducer().send(topic, msg);
}
@Override
public void sendMessage(MoyaEventType type, EventUser user, String message) {
MoyaEventMessage msg = new MoyaEventMessage();
......@@ -65,4 +70,15 @@ public class MoyaEventSender {
logger.info("Sending Moya message {} with description ", type, message);
sendMessage(msg);
}
@Override
public void sendMessage(MoyaEventType type, EventUser user, Object... message) {
StringBuilder sb = new StringBuilder();
for (Object m : message) {
sb.append(m);
}
sendMessage(type, user, sb.toString());
}
}
......@@ -44,6 +44,7 @@ import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LogEntry;
import fi.codecrew.moya.model.LogEntryType;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
/**
* Session Bean implementation class SercurityBean
......
......@@ -19,7 +19,7 @@
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJBAccessException;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
......@@ -50,5 +50,17 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
cq.where(cb.equal(root.get(EventMap_.event), eventbean.getCurrentEvent()),
cb.isTrue(root.get(EventMap_.active)));
return getEm().createQuery(cq).getResultList();
}
@Override
public EventMap find(Integer id) {
EventMap ret = super.find(id);
if (ret != null && !ret.getEvent().equals(eventbean.getCurrentEvent())) {
throw new EJBAccessException("Trying to find map from wrong event!");
}
return ret;
}
}
/*
* Copyright Codecrew Ry
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Root;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.model.Bill;
import fi.codecrew.moya.model.Bill_;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.PlaceSlot_;
import fi.codecrew.moya.model.Product;
@Stateless
@LocalBean
public class PlaceSlotFacade extends IntegerPkGenericFacade<PlaceSlot> {
private static final Logger logger = LoggerFactory.getLogger(PlaceSlotFacade.class);
@EJB
EventBeanLocal eventBean;
public PlaceSlotFacade() {
super(PlaceSlot.class);
}
/**
* Returns placeslots this user can use.
*
* @param user
* @param product
* @return
*/
public List<PlaceSlot> findFreePlaceSlots(EventUser user, Product product) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PlaceSlot> q = cb.createQuery(PlaceSlot.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
Path<Bill> bill = root.get(PlaceSlot_.bill);
q.where(cb.equal(bill.get(Bill_.user), user),
cb.isNotNull(bill.get(Bill_.paidDate)),
cb.isNull(root.get(PlaceSlot_.used)),
cb.equal(root.get(PlaceSlot_.product), product)
);
return getEm().createQuery(q).getResultList();
}
// private List<PlaceSlot> getSlotsForUser(EventUser u) {
//
// CriteriaBuilder cb = getEm().getCriteriaBuilder();
// CriteriaQuery<PlaceSlot> cq = cb.createQuery(PlaceSlot.class);
//
// }
public PlaceSlot findSlotForPlace(Place place) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PlaceSlot> q = cb.createQuery(PlaceSlot.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
q.where(cb.equal(root.get(PlaceSlot_.place), place));
PlaceSlot slot = super.getSingleNullableResult(getEm().createQuery(q));
return slot;
}
public Long totalSlotcount(Product prod) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Long> q = cb.createQuery(Long.class);
Root<PlaceSlot> root = q.from(PlaceSlot.class);
q.select(cb.count(root));
q.where(cb.equal(root.get(PlaceSlot_.product), prod));
Long count = super.getSingleNullableResult(getEm().createQuery(q));
return count;
}
}
......@@ -139,6 +139,10 @@ public class Place extends GenericEntity implements Comparable<Place> {
return ret;
}
@OneToOne(mappedBy = "place")
@JoinColumn(nullable = true)
private PlaceSlot reserverSlot;
public Place() {
super();
}
......@@ -346,13 +350,13 @@ public class Place extends GenericEntity implements Comparable<Place> {
if (this.getName() == null || o.getName() == null) {
if (this.getName() == null) {
return 1;
}
}
if (o.getName() == null) {
return -1;
}
return -1;
}
// both names are null. Compare IDs
return this.getNonNullId().compareTo(o.getNonNullId());
}
}
if (this.getName().equals(o.getName())) {
return 0;
......
package fi.codecrew.moya.model;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "place_slots")
public class PlaceSlot extends GenericEntity {
private static final long serialVersionUID = -7163361140751806941L;
@Temporal(TemporalType.TIMESTAMP)
private Date created;
@Temporal(TemporalType.TIMESTAMP)
private Date used;
@JoinColumn(nullable = false)
@ManyToOne
private Bill bill;
@JoinColumn(nullable = false)
@ManyToOne
private Product product;
@JoinColumn(nullable = true, unique = true)
@OneToOne
private Place place;
@Lob
private String description;
public Date getCreated() {
return created;
}
public void setCreated(Date created) {
this.created = created;
}
public Date getUsed() {
return used;
}
public void setUsed(Date used) {
this.used = used;
}
public Bill getBill() {
return bill;
}
public void setBill(Bill bill) {
this.bill = bill;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Place getPlace() {
return place;
}
public void setPlace(Place place) {
this.place = place;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
}
......@@ -20,9 +20,11 @@ package fi.codecrew.moya.model;
public enum ProductFlag {
// FOODWAVE_ITEM, Äy... Ei kai tämän täällä tarvitse olla....
PREPAID_CREDIT, // Tämä ei ole missään käytössä. Poistetaas jossain
// vaiheessa --tuomari
/**
* Tämä tuote lisää käyttäjälle merkityn määrän kredittejä tilille mutta ei
* luo vastatuotetta.
*/
PREPAID_CREDIT,
/**
* Luodaan uusi paikka kun tuote ostetaan. Esim sisäänpääsylipuille kun
* halutaan GroupMembership mutta ei ole tarpeellista valita tiettyä
......
......@@ -23,7 +23,6 @@ public enum SpecialPermission {
USER,
ANONYMOUS,
// ORGANISATION_ADMIN,
VERKKOMAKSU_CHECKER,
REST
;
......@@ -31,6 +30,5 @@ public enum SpecialPermission {
public static final String S_SUPERADMIN = "SUPERADMIN";
public static final String S_ANONYMOUS = "ANONYMOUS";
//public static final String S_ORGANISATION_ADMIN = "ORGANISATION_ADMIN";
public static final String S_VERKKOMAKSU_CHECK = "VERKKOMAKSU_CHECKER";
}
package fi.codecrew.moya.beans.moyamessage;
package fi.codecrew.moya.utilities.moyamessage;
import java.io.Serializable;
import java.util.Calendar;
......
package fi.codecrew.moya.beans.moyamessage;
package fi.codecrew.moya.utilities.moyamessage;
public enum MoyaEventType {
LOGIN_FAILED(MoyaEventSource.USER),
......@@ -6,6 +6,12 @@ public enum MoyaEventType {
USER_INSUFFICIENT_PERMISSIONS(MoyaEventSource.USER),
BILL_CREATED(MoyaEventSource.SHOP),
BILL_PAID(MoyaEventSource.SHOP),
BILL_ERROR(MoyaEventSource.SHOP),
BANKING_ERROR(MoyaEventSource.SHOP),
BANKING_MESSAGE(MoyaEventSource.SHOP),
PLACE_ERROR(MoyaEventSource.PLACEMAP),
ACCOUNTEVENT_INFO(MoyaEventSource.USER),
USER_PERMISSION_VIOLATION(MoyaEventSource.USER),
;
......@@ -20,7 +26,7 @@ public enum MoyaEventType {
}
private static enum MoyaEventSource {
USER, EVENT, SHOP
USER, EVENT, SHOP, PLACEMAP
}
}
......@@ -68,13 +68,6 @@
<!-- <servlet> <servlet-name>ViewStatusMessages</servlet-name> <servlet-class>ch.qos.logback.classic.ViewStatusMessagesServlet
</servlet-class> </servlet> <servlet-mapping> <servlet-name>ViewStatusMessages</servlet-name>
<url-pattern>/logback</url-pattern> </servlet-mapping> -->
<servlet>
<servlet-name>repl-servlet</servlet-name>
<servlet-class>fi.codecrew.moya.management.ReplServlet</servlet-class>
<load-on-startup>5</load-on-startup>
</servlet>
<session-config>
<session-timeout>120</session-timeout>
</session-config>
......
......@@ -28,39 +28,8 @@
<br />
<bill:showBill bill="#{billEditView.bill}" />
<ui:fragment rendered="#{!billEditView.bill.paid and !billEditView.bill.expired and billEditView.verkkomaksuFiAvailable}">
<div id="svm-payment">
<a href="#{billEditView.verkkomaksuFiToken.url}"> </a>
</div>
<script type="text/javascript" src="//payment.verkkomaksut.fi/js/sv-widget.min.js"></script>
<script type="text/javascript">
SV.widget.initWithToken('svm-payment',
'#{billEditView.verkkomaksuToken.token}', {
width : '800'
});
</script>
</ui:fragment>
<ui:fragment rendered="#{!billEditView.bill.paid and !billEditView.bill.expired and billEditView.checkoutFiAvailable}">
<table border="0">
<tr>
<ui:repeat varStatus="idx" value="#{billEditView.checkoutFiToken}" var="bank">
<td>
<form action="#{bank.url}" method="post">
<ui:repeat value="#{bank.postParams}" var="valp">
<input type="hidden" name="#{valp.key}" value="#{valp.value}" />
</ui:repeat>
<input type='image' src='#{bank.icon}' />
</form>
</td>
<h:outputText escape="false" value="&lt;/tr>&lt;tr>" rendered="#{idx.index % 4 == 3}" />
</ui:repeat>
</tr>
</table>
</ui:fragment>
<bill:verkkomaksubuttons rendered="#{!billEditView.bill.paid and !billEditView.bill.expired}"/>
<p:outputPanel rendered="#{billEditView.bill.foodwaveBill}">
<span class="notify"><h:outputText value="#{i18n['foodshop.canBuyToCounter']}" /></span>
......
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{ajaxMapView.initReserveMap()}" />
</f:metadata>
<ui:define name="content">
<h:form>
<p:remoteCommand name="placeClicker" update=":fbdiag"
action="#{ajaxMapView.placeClicked()}" />
</h:form>
<p:dialog visible="#{!empty ajaxMapView.place}" id="fbdiag">
Clicked place name : #{ajaxMapView.place.name};
<h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit">
<f:param name="placeid" value="#{ajaxMapView.place.id}" />
Muokkaa
</h:link>
</p:dialog>
<h:outputScript target="head" library="seatjs" name="d3.min.js" />
<h:outputScript target="head" library="seatjs" name="d3-tip.js" />
<h:outputScript target="head" library="seatjs" name="seatmap.js" />
<h:outputStylesheet library="seatjs" name="placemap.css" />
<svg id="seatmap" style="margin: auto; border: 1px solid black; background-image: url()"
width="#{ajaxMapView.map.width}px" height="#{ajaxMapView.map.height}px" />
<script type="text/javascript">
px = placemap({
element : document.getElementById("seatmap"),
moyaurl : "#{request.contextPath}",
map_id : #{ajaxMapView.map.id},
onclick : function(d) {
placeClicker([{name: 'placeId', value: d}])
return false;
}
});
</script>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:map="http://java.sun.com/jsf/composite/cditools/map"
xmlns:tools="http://java.sun.com/jsf/composite/cditools"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:event type="preRenderView" listener="#{ajaxMapView.initViewMap()}" />
</f:metadata>
<ui:param name="thispage" value="page.place.placemap" />
<ui:define name="content">
<h:form>
<p:remoteCommand name="placeClicker" update=":fbdiag"
action="#{ajaxMapView.placeClicked()}" />
</h:form>
<p:dialog rendered="#{ajaxMapView.isMgmtPermission()}"
visible="#{!empty ajaxMapView.place}" id="fbdiag">
Clicked place name : #{ajaxMapView.place.name};
<h:link rendered="#{!empty ajaxMapView.place}" outcome="/place/edit">
<f:param name="placeid" value="#{ajaxMapView.place.id}" />
Muokkaa
</h:link>
</p:dialog>
<h:outputScript target="head" library="seatjs" name="d3.min.js" />
<h:outputScript target="head" library="seatjs" name="d3-tip.js" />
<h:outputScript target="head" library="seatjs" name="seatmap.js" />
<h:outputStylesheet library="seatjs" name="placemap.css" />
<button onclick="px.update()" >Update</button><br/>
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="#{ajaxMapView.map.width}px"
height="#{ajaxMapView.map.height}px" />
<script type="text/javascript">
px = placemap({
element : document.getElementById("seatmap"),
moyaurl : "#{request.contextPath}",
map_id : #{ajaxMapView.map.id},
onclick : function(d) {
px.update();
//alert(d);
// #{ajaxMapView.isMgmtPermission()?'placeClicker([{name: \'placeId\', value: d}])':''}
return false;
}
});
// document.getElementById("editbutton").addEventListener("click",
// function() {
// px.enable_edit();
// });
//px.enable_edit();
</script>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
......@@ -18,13 +18,11 @@
</f:metadata>
<ui:param name="thispage" value="page.place.placemap" />
<ui:define name="content">
<button
onclick="alert('pre');placeClicker([{name:'placeId', value:1}]);alert('post');">button</button>
<p:growl widgetVar="g" />
<h:form>
<p:remoteCommand name="placeClicker" update=":fbdiag"
action="#{ajaxMapView.placeClicked()}" />
<!-- update=":fbdiag" -->
<p:remoteCommand name="placeClicker"
action="#{ajaxMapView.placeClicked()}" onsuccess="return px.update_place()" />
</h:form>
<p:dialog visible="#{!empty ajaxMapView.place}" id="fbdiag">
......@@ -40,25 +38,19 @@
<h:outputScript target="head" library="seatjs" name="seatmap.js" />
<h:outputStylesheet library="seatjs" name="placemap.css" />
<svg id="seatmap" style="margin: auto; border: 1px solid black;"
width="1200px" height="800px" />
width="#{ajaxMapView.map.width}px" height="#{ajaxMapView.map.width}px" />
<script type="text/javascript">
px = placemap({
element : document.getElementById("seatmap"),
moyaurl : "#{request.contextPath}",
map_id : #{ajaxMapView.map.id},
onclick : function(d) {
alert(d);
placeClicker([{name: 'placeId', value: d}])
return true;
}
return placeClicker([{name: 'placeId', value: d.id}]);
},
locale: "#{sessionHandler.locale}"
});
// document.getElementById("editbutton").addEventListener("click",
// function() {
// px.enable_edit();
// });
//px.enable_edit();
</script>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
</html>
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:composite="http://java.sun.com/jsf/composite"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:tools="http://java.sun.com/jsf/composite/tools">
<composite:interface>
</composite:interface>
<composite:implementation>
<ui:fragment rendered="#{billEditView.verkkomaksuFiAvailable}">
<p id="svmpayment">
<a href="#{billEditView.verkkomaksuFiToken.url}">Go to payments</a>
</p>
<!-- When called via ajax this needs to be already loaded!
-->
<script type="text/javascript" src="//payment.paytrail.com/js/payment-widget-v1.0.min.js"></script>
<script type="text/javascript">
function initPaymentButtons() {
SV.widget.initWithToken('svmpayment',
'#{billEditView.verkkomaksuFiToken.token}', {
width : '800'
});
}
</script>
</ui:fragment>
<ui:fragment rendered="#{billEditView.checkoutFiAvailable}">
<table border="0">
<tr>
<ui:repeat varStatus="idx" value="#{billEditView.checkoutFiToken}"
var="bank">
<td>
<form action="#{bank.url}" method="post">
<ui:repeat value="#{bank.postParams}" var="valp">
<input type="hidden" name="#{valp.key}" value="#{valp.value}" />
</ui:repeat>
<input type='image' src='#{bank.icon}' />
</form>
</td>
<h:outputText escape="false" value="&lt;/tr>&lt;tr>"
rendered="#{idx.index % 4 == 3}" />
</ui:repeat>
</tr>
</table>
</ui:fragment>
</composite:implementation>
</html>
......@@ -19,8 +19,16 @@
<h:panelGrid columns="2">
<h:outputLabel value="#{i18n['eventmap.name']}:" />
<h:inputText value="#{mapManageView.map.name}" />
<h:outputLabel value="#{i18n['eventmap.width']}:" />
<h:inputText value="#{mapManageView.map.width}" />
<h:outputLabel value="#{i18n['eventmap.height']}:" />
<h:inputText value="#{mapManageView.map.height}" />
<h:outputLabel value="#{i18n['eventmap.notes']}:" />
<h:inputTextarea cols="40" rows="5" value="#{mapManageView.map.notes}" />
<h:outputLabel value="#{i18n['eventmap.active']}:" />
<h:selectBooleanCheckbox value="#{mapManageView.map.active}" />
......
......@@ -15,7 +15,7 @@
<!-- <h:outputScript target="head" library="script" name="jquery.min.js" /> -->
<!-- <h:outputScript target="head" library="script" name="shopscript.js" /> -->
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<p:dataTable columnClasses="nowrap,numalign,numalign,numalign,nowrap" id="billcart" value="#{cc.attrs.items}" var="cart">
<p:column>
<f:facet name="header">
......@@ -106,7 +106,12 @@
</h:panelGroup>
<br />
<p:commandButton onerror="location.reload(true);" action="#{cc.attrs.commitaction}" id="commitbutton-botton" value="#{cc.attrs.commitValue}" />
<!-- Paytrail needs to initialize after the ajax call is complete -->
<!-- This function is to be override by the paytrail init function -->
<script type="text/javascript">
function initPaymentButtons(){};
</script>
<p:commandButton oncomplete="initPaymentButtons()" onerror="location.reload(true);" action="#{cc.attrs.commitaction}" id="commitbutton-botton" value="#{cc.attrs.commitValue}" />
......
......@@ -14,11 +14,15 @@
<ui:define name="title">
<h1>#{i18n['page.product.createBill.header']}</h1>
</ui:define>
<ui:define name="headerdata">
<ui:fragment rendered="#{billEditView.verkkomaksuFiAvailable}">
<script type="text/javascript" src="//payment.paytrail.com/js/payment-widget-v1.0.min.js"></script>
</ui:fragment>
</ui:define>
<ui:define name="content">
<h:form id="billshopform">
<products:shop commitaction="#{productShopView.commitBillCart()}" items="#{productShopView.shoppingcart}" commitValue="#{i18n['productshop.commit']}" />
</h:form>
</ui:define>
</ui:composition>
......
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html" xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:bill="http://java.sun.com/jsf/composite/cditools/bills" xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:tools="http://java.sun.com/jsf/composite/tools"
xmlns:bill="http://java.sun.com/jsf/composite/cditools/bills"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:body>
......@@ -11,38 +15,17 @@
<ui:define name="title">
<h1>#{i18n['page.product.validateBillProducts.header']}</h1>
</ui:define>
<ui:define name="content">
<bill:showBill bill="#{billEditView.bill}" />
<ui:define name="headerdata">
<ui:fragment rendered="#{billEditView.verkkomaksuFiAvailable}">
<div id="svm-payment">
<a href="#{billEditView.verkkomaksuFiToken.url}"> </a>
</div>
<script type="text/javascript" src="//payment.verkkomaksut.fi/js/sv-widget.min.js"></script>
<script type="text/javascript">
SV.widget.initWithToken('svm-payment', '#{billEditView.verkkomaksuToken.token}', {width: '800'});
</script>
<script type="text/javascript" src="//payment.paytrail.com/js/payment-widget-v1.0.min.js"></script>
</ui:fragment>
<ui:fragment rendered="#{billEditView.checkoutFiAvailable}">
<table border="0">
<tr>
<ui:repeat varStatus="idx" value="#{billEditView.checkoutFiToken}" var="bank">
<td>
<form action="#{bank.url}" method="post">
<ui:repeat value="#{bank.postParams}" var="valp" >
<input type="hidden" name="#{valp.key}" value="#{valp.value}" />
</ui:repeat>
<input type='image' src='#{bank.icon}' />
</form>
</td>
<h:outputText escape="false" value="&lt;/tr>&lt;tr>" rendered="#{idx.index % 4 == 3}"/>
</ui:repeat>
</tr>
</table>
</ui:fragment>
</ui:define>
<ui:define name="content">
<bill:showBill bill="#{billEditView.bill}" />
<bill:verkkomaksubuttons />
</ui:define>
</ui:composition>
......
......@@ -9,19 +9,28 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.matlux.NreplServer;
// XXX: The annotation did not cause the servlet to start. Thus the servlet is also defined in web.xml.
@WebServlet(loadOnStartup = 5, name = "repl-servlet")
public class ReplServlet implements Servlet {
public class ReplServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = -344649442062099092L;
private static final int NREPL_DEFAULT_PORT = 1112;
private NreplServer nreplServer;
private ServletConfig servletConfig;
private static final Logger logger = LoggerFactory.getLogger(ReplServlet.class);
@Override
public void init(ServletConfig config) throws ServletException {
logger.info("initializing Repl servlet for port {}", NREPL_DEFAULT_PORT);
servletConfig = config;
int port = NREPL_DEFAULT_PORT;
String portStr = config.getInitParameter("port");
......
package fi.codecrew.moya.rest.placemap.v1;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
......@@ -12,16 +14,22 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo;
import fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.user.UserView;
@RequestScoped
@Path("/placemap/v1")
......@@ -33,6 +41,12 @@ public class PlacemapRestViewV1 {
private PlaceBeanLocal placebean;
private static final Logger logger = LoggerFactory.getLogger(PlacemapRestViewV1.class);
@EJB
private PermissionBeanLocal permbean;
@Inject
private UserView userView;
// @GET
// @Path("/maps")
// public PlacemapMapRootPojo getMaps()
......@@ -45,7 +59,7 @@ public class PlacemapRestViewV1 {
@POST
@Path("/place/{id}/reserve")
public void reservePlace() {
logger .warn("Reserving not yet implemented");
logger.warn("Reserving not yet implemented");
}
@GET
......@@ -59,11 +73,59 @@ public class PlacemapRestViewV1 {
}
@GET
@Path("{id}/background")
public Response getBackground(@PathParam("id") Integer id) {
EventMap map = placebean.findMap(id);
byte[] data = map.getMapData();
ResponseBuilder ret = Response.ok(data, "image/png");
ret.expires(new Date(System.currentTimeMillis() + 6 * 60 * 60 * 1000));
return ret.build();
}
@GET
@Path("{id}/places")
public SimplePlacelistRoot getPlaces(@PathParam("id") Integer mapId)
{
EventMap map = placebean.findMap(mapId);
return SimplePlacelistRoot.wrap(map.getPlaces(), null);
EventUser user = null;
if (userView != null) {
user = userView.getSelectedUser();
}
return SimplePlacelistRoot.wrap(map.getPlaces(), user);
}
@GET
@Path("/place/{place}")
public SimplePlacelistRoot getPlace(@PathParam("place") Integer placeId)
{
List<Place> thisplace = new ArrayList<Place>();
thisplace.add(placebean.find(placeId));
return SimplePlacelistRoot.wrap(thisplace, permbean.getCurrentUser());
}
@POST
@Path("/place/{place}")
public SimplePlacelistRoot togglePlaceReservation(@PathParam("place") Integer placeId)
{
EventUser user = null;
if (userView != null) {
user = userView.getSelectedUser();
}
Place p = placebean.find(placeId);
if (p.isReservedFor(user)) {
placebean.releasePlace(p);
} else if (p.isBuyable() && !p.isTaken()) {
placebean.reservePlace(p, user);
}
p = placebean.find(placeId);
List<Place> thisplace = new ArrayList<Place>();
thisplace.add(p);
return SimplePlacelistRoot.wrap(thisplace, user);
}
}
......@@ -54,6 +54,7 @@ import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
/**
*
......@@ -145,7 +146,7 @@ public class PlaceMapServlet extends HttpServlet {
if (!permbean.hasPermission(MapPermission.VIEW))
{
loggerbean.logMessage(SecurityLogType.permissionDenied, permbean.getCurrentUser(),
loggerbean.sendMessage(MoyaEventType.USER_INSUFFICIENT_PERMISSIONS, permbean.getCurrentUser(),
"User tried to print the placemap to stream without sufficient permissions");
throw new EJBAccessException("Not enough permissions to print placemap");
}
......
package fi.codecrew.moya.web.cdiview.map;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
......@@ -12,7 +13,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
......@@ -22,33 +25,76 @@ import fi.codecrew.moya.web.cdiview.GenericCDIView;
@ConversationScoped
public class AjaxMapView extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 8203589456357519480L;
@Inject
private PlaceView placeview;
private static final Logger logger = LoggerFactory.getLogger(AjaxMapView.class);;
private String testVal = "Testval1";
@EJB
private EventBeanLocal eventbean;
private transient EventBeanLocal eventbean;
@EJB
private PlaceBeanLocal placebean;
@EJB
private PermissionBeanLocal permbean;
@Inject
private transient FacesContext context;
private EventMap map;
private Place place;
private Integer mapId;
public void initReserveMap() {
initMap();
map = placebean.findMap(mapId);
}
public void initViewMap() {
initMap();
}
private void initMap() {
if (mapId != null) {
map = placebean.findMap(mapId);
}
if (map == null) {
List<EventMap> maps = placebean.getMaps();
if (maps != null && !maps.isEmpty()) {
for (EventMap m : maps) {
if (m.isActive()) {
this.map = m;
break;
}
}
}
}
}
public void initMap() {
LanEvent e = eventbean.getCurrentEvent();
setMap(e.getEventMaps().get(0));
public boolean isMgmtPermission()
{
return permbean.hasPermission(MapPermission.MANAGE_OTHERS);
}
public void placeClicked()
{
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> vmap = context.getExternalContext().getRequestParameterMap();
logger.info("placeid {}", vmap.get("pl aceId"));
Map<String, String> vmap = context.getExternalContext().getRequestParameterMap();
int placeId = Integer.parseInt(vmap.get("placeId"));
place = placebean.find(placeId);
logger.info("Found place {} with placeid {}", place, placeId);
if (place.isReservedFor(permbean.getCurrentUser()))
{
placebean.releasePlace(place);
}
else if (place.isBuyable() && !place.isTaken())
{
placebean.reservePlace(place, permbean.getCurrentUser());
}
}
public String getTestVal() {
......@@ -74,4 +120,12 @@ public class AjaxMapView extends GenericCDIView {
public void setPlace(Place place) {
this.place = place;
}
public FacesContext getContext() {
return context;
}
public void setContext(FacesContext context) {
this.context = context;
}
}
......@@ -19,6 +19,7 @@
package fi.codecrew.moya.web.cdiview.map;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import javax.ejb.EJB;
......@@ -40,6 +41,8 @@ import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.PlaceSlot;
import fi.codecrew.moya.model.ProductFlag;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchQuery.QuerySortOrder;
......@@ -117,26 +120,37 @@ public class PlaceView extends GenericCDIView {
} else if (place.isBuyable() && !place.isTaken()) {
BigDecimal balance = user.getAccountBalance();
BigDecimal price = null;
boolean canReserve = false;
// If place product is marked "PREPAID_CREDIT", places are bought from
// slots. If flag does not exist place slot is created from a bill.
if (place.getProduct().getProductFlags().contains(ProductFlag.PREPAID_CREDIT)) {
BigDecimal balance = user.getAccountBalance();
BigDecimal price = null;
if (permbean.isCurrentUser(user)) {
price = placebean.getTotalReservationPrice(place);
} else {
price = placebean.getTotalReservationPrice(user, place);
}
canReserve = (price.compareTo(balance) <= 0);
logger.debug("Balance {}, price {}", balance, price);
if (balance.compareTo(BigDecimal.ZERO) > 0) {
addFaceMessage("mapView.notEnoughCreditsToReserve");
}
if (!canReserve)
logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance);
if (permbean.isCurrentUser(user)) {
price = placebean.getTotalReservationPrice(place);
} else {
price = placebean.getTotalReservationPrice(user, place);
List<PlaceSlot> placeslots = placebean.getFreePlaceslots(user, place.getProduct());
canReserve = placeslots.size() > 0;
}
logger.debug("Balance {}, price {}", balance, price);
if (price.compareTo(balance) <= 0) {
if (canReserve) {
logger.debug("Place was free. Marking for user.");
if (!placebean.reservePlace(place, user)) {
this.addFaceMessage("mapView.errorWhenReservingPlace");
}
} else {
if (balance.compareTo(BigDecimal.ZERO) > 0) {
addFaceMessage("mapView.notEnoughCreditsToReserve");
}
logger.debug("Did not have enought credits to reserve place! required {} , got {}", price, balance);
}
}
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!