Commit 9fe3c878 by Tuomas Riihimäki

Merge branch 'devel' of codecrew.fi:bortal into devel

Conflicts:
	code/MoyaWeb/src/fi/codecrew/moya/servlet/UserPngImageServlet.java
2 parents cb63614a 60853e1f
Showing with 1062 additions and 107 deletions
package fi.codecrew.moya.beans;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import fi.codecrew.moya.facade.NewsGroupFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.GameBeanLocal;
/**
* Session Bean implementation class GameBean
*/
@Stateless
public class GameBean implements GameBeanLocal {
@EJB
private EventBeanLocal eventbean;
@EJB
private NewsGroupFacade ngfacade;
/**
* Default constructor.
*/
public GameBean() {
// TODO Auto-generated constructor stub
}
}
package fi.codecrew.moya.beans;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.facade.LicenseCodeFacade;
import fi.codecrew.moya.facade.LicenseTargetFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LicenseCode;
import fi.codecrew.moya.model.LicenseTarget;
import fi.codecrew.moya.model.User;
/**
* Session Bean implementation class GameBean
*/
@Stateless
public class LicenseBean implements LicenseBeanLocal {
@EJB
LicenseCodeFacade licenseCodeFacade;
@EJB
UserFacade userFacade;
@EJB
LicenseTargetFacade licenseTargetFacade;
@EJB
EventBeanLocal eventBean;
@EJB
PlaceBeanLocal placeBean;
private static final Logger logger = LoggerFactory.getLogger(LicenseBean.class);
/**
* Check, and if needed generate code for gamecode.
*
* @param code
*/
private LicenseCode generateCode(LicenseCode code) throws GenerationException {
if (code.getCode() == null || code.getCode().trim().equals("")) {
if (code.getLicenseTarget().getCodeUrl() == null || code.getLicenseTarget().getCodeUrl().trim().equals("")) {
throw new GenerationException("Code generate failed");
}
try {
URL url = new URL(code.getLicenseTarget().getCodeUrl());
URLConnection uc;
uc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
String codeString = "";
String tmpLine;
while ((tmpLine = in.readLine()) != null) {
if (!codeString.equals("")) {
codeString += "\n";
}
codeString += tmpLine;
}
if(codeString.trim().equals("0") || codeString.trim().equals("")) {
throw new GenerationException("Code generate failed");
}
code.setCode(codeString);
code = licenseCodeFacade.merge(code);
return code;
} catch (IOException e) {
logger.warn("Code generate failed", e);
throw new GenerationException("Code generate failed");
}
}
throw new RuntimeException("LOL, what?");
}
public LicenseCode accessCode(LicenseCode code) throws GenerationException {
code = generateCode(code);
if (!code.isAccessed()) {
code.setAccessed(Calendar.getInstance());
code = licenseCodeFacade.merge(code);
}
return code;
}
public List<LicenseTarget> findAll(LanEvent event) {
return event.getGames();
}
public void saveOrCreateLicense(LicenseTarget target) {
if (target.getId() == null) {
target.setEvent(eventBean.getCurrentEvent());
eventBean.getCurrentEvent().getGames().add(target);
licenseTargetFacade.create(target);
target = licenseTargetFacade.merge(target);
}
else {
target = licenseTargetFacade.merge(target);
}
}
/**
* Default constructor.
*/
public LicenseBean() {
// TODO Auto-generated constructor stub
}
@Override
public List<LicenseTarget> findUserGames(EventUser user) {
ArrayList<LicenseTarget> returnLicenses = new ArrayList<LicenseTarget>();
if(user.getGroupMemberships() != null) {
for(GroupMembership memberShip : user.getGroupMemberships()) {
if(memberShip.getPlaceReservation() == null)
continue;
for(LicenseTarget license : memberShip.getPlaceReservation().getProduct().getLicenseTargets()) {
if(license.isActive()) {
returnLicenses.add(license);
}
}
}
}
return returnLicenses;
}
@Override
public List<LicenseTarget> findUnopenedUserGames(EventUser user) {
List<LicenseTarget> returnLicenses = findUserGames(user);
for(LicenseCode code : user.getUser().getLicenseCodes()) {
returnLicenses.remove(code.getLicenseTarget());
}
return returnLicenses;
}
@Override
public LicenseCode createAndAccessCode(LicenseTarget target, User user) throws GenerationException {
user = userFacade.reload(user);
LicenseCode code = new LicenseCode(target);
user.getLicenseCodes().add(code);
code.setUser(user);
licenseCodeFacade.create(code);
code = accessCode(code);
return code;
}
}
......@@ -11,12 +11,11 @@ import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.xml.registry.uddi.infomodel.OrganizationImpl;
import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.LicensePermission;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.PollPermission;
import fi.codecrew.moya.enums.apps.ShopPermission;
......@@ -313,6 +312,7 @@ public class MenuBean implements MenuBeanLocal {
userTopnavi.addPage(menuitemfacade.findOrCreate("/user/accountEvents"), UserPermission.VIEW_SELF);
userTopnavi.addPage(menuitemfacade.findOrCreate("/place/myGroups"), UserPermission.VIEW_SELF);
userTopnavi.addPage(menuitemfacade.findOrCreate("/user/sendPicture"), UserPermission.VIEW_SELF);
MenuNavigation placemapTopmenu = usernavi.addPage(null, null);
placemapTopmenu.setKey("topnavi.placemap");
......@@ -345,6 +345,11 @@ public class MenuBean implements MenuBeanLocal {
// ShopPermission.SHOP_FOODWAVE);
foodwaveTopmenu.addPage(menuitemfacade.findOrCreate("/foodwave/listProducts"), ShopPermission.SHOP_FOODWAVE).setVisible(false);
foodwaveTopmenu.addPage(menuitemfacade.findOrCreate("/foodwave/ThanksForOrderingFromCounter"), ShopPermission.SHOP_FOODWAVE).setVisible(false);
MenuNavigation gameTopmenu = usernavi.addPage(null, null);
gameTopmenu.setKey("topnavi.license");
gameTopmenu.addPage(menuitemfacade.findOrCreate("/license/viewCodes"), LicensePermission.VIEW_OWN_CODES);
MenuNavigation pollTopmenu = usernavi.addPage(null, null);
pollTopmenu.setKey("topnavi.poll");
......@@ -433,6 +438,9 @@ public class MenuBean implements MenuBeanLocal {
foodnavi.addPage(menuitemfacade.findOrCreate("/foodadmin/createTemplate"), ShopPermission.MANAGE_FOODWAVES);
foodnavi.addPage(menuitemfacade.findOrCreate("/foodadmin/editTemplate"), ShopPermission.MANAGE_FOODWAVES).setVisible(false);
MenuNavigation gamenavi = adminnavi.addPage(null, null);
gamenavi.setKey("topnavi.license");
gamenavi.addPage(menuitemfacade.findOrCreate("/license/manageCodes"), LicensePermission.MANAGE);
}
@Override
......
......@@ -17,6 +17,7 @@ import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.LicensePermission;
import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.PollPermission;
......@@ -91,7 +92,9 @@ import fi.codecrew.moya.model.User;
EventPermission.S_MANAGE_PRIVATE_PROPERTIES,
EventPermission.S_MANAGE_PROPERTIES,
LicensePermission.S_MANAGE,
LicensePermission.S_VIEW_OWN_CODES
})
@LocalBean
public class PermissionBean implements PermissionBeanLocal {
......@@ -113,11 +116,6 @@ public class PermissionBean implements PermissionBeanLocal {
@EJB
private EventBeanLocal eventbean;
//
// @Override
// public boolean hasPermission(String perm) {
// return context.isCallerInRole(perm);
// }
@Override
public boolean hasPermission(IAppPermission perm) {
......@@ -130,36 +128,7 @@ public class PermissionBean implements PermissionBeanLocal {
}
// @Override
// public boolean fatalPermission(IAppPermission permission, Object...
// failmessage) {
// boolean ret = hasPermission(permission);
// if (!ret) {
// StringBuilder message = new
// StringBuilder().append(" permission: ").append(permission);
// if (failmessage == null || failmessage.length == 0) {
// message.append(" MSG: SessionHandler mbean permission exception: Permission: ")
// .append(permission);
// } else {
// for (Object part : failmessage) {
// message.append(part == null ? "NULL" : part.toString());
// }
// }
// // throw new SecurityException("Foobar");
//
// throw new PermissionDeniedException(loggingbean, getCurrentUser(),
// message.toString());
// }
// return true;
// }
//
// @Override
// public void fatalNotLoggedIn() throws PermissionDeniedException {
// if (!isLoggedIn()) {
// throw new PermissionDeniedException(loggingbean, getCurrentUser(),
// "User is not logged in!");
// }
// }
@Override
public boolean isCurrentUser(User user) {
......@@ -178,8 +147,6 @@ public class PermissionBean implements PermissionBeanLocal {
// logger.info("Checking principal {} against anon: {}", principal,
// ret);
return ret;
// return !getAnonEventUser().equals(getCurrentUser()) ||
// getCurrentUser().getUser().isSuperadmin();
}
@Override
......
......@@ -2,6 +2,7 @@ package fi.codecrew.moya.beans;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
......@@ -19,6 +20,8 @@ import javax.ejb.Stateless;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.enums.apps.ShopPermission;
import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.BillLineFacade;
import fi.codecrew.moya.facade.DiscountFacade;
......@@ -26,13 +29,6 @@ import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.InventoryEventFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.facade.UserFacade;
import fi.codecrew.moya.beans.BillBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.bortal.views.BillSummary;
import fi.codecrew.moya.enums.apps.ShopPermission;
import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.EventUser;
......@@ -365,4 +361,18 @@ public class ProductBean implements ProductBeanLocal {
public List<Product> findProductsForEvent() {
return productFacade.findAll();
}
@Override
public List<Product> findPlaceProducts() {
ArrayList<Product> returnProducts = new ArrayList<Product>();
for(Product product : findProductsForEvent()) {
if(product.getPlaces() != null && product.getPlaces().size() > 0) {
returnProducts.add(product);
}
}
return returnProducts;
}
}
......@@ -274,7 +274,6 @@ public class UserBean implements UserBeanLocal {
public void createNewUser(EventUser user, String password) {
user.getUser().resetPassword(password);
// todo add barcode
user.setEvent(eventBean.getCurrentEvent());
// Tallennetaan olio kantaan...
eventUserFacade.create(user);
......
package fi.codecrew.moya.facade;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.model.LicenseCode;
@Stateless
@LocalBean
public class LicenseCodeFacade extends IntegerPkGenericFacade<LicenseCode> {
public LicenseCodeFacade() {
super(LicenseCode.class);
}
}
package fi.codecrew.moya.facade;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import fi.codecrew.moya.model.LicenseTarget;
@Stateless
@LocalBean
public class LicenseTargetFacade extends IntegerPkGenericFacade<LicenseTarget> {
public LicenseTargetFacade() {
super(LicenseTarget.class);
}
}
......@@ -88,9 +88,9 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
// }
@Override
public void create(User user) {
public User create(User user) {
user.setLogin(user.getLogin().toLowerCase().trim());
super.create(user);
return super.create(user);
}
@Override
......
package fi.codecrew.moya.beans;
import javax.ejb.Local;
@Local
public interface GameBeanLocal {
}
package fi.codecrew.moya.beans;
import java.util.List;
import javax.ejb.ApplicationException;
import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.LicenseCode;
import fi.codecrew.moya.model.LicenseTarget;
import fi.codecrew.moya.model.User;
@Local
public interface LicenseBeanLocal {
public LicenseCode accessCode(LicenseCode code) throws GenerationException;
public List<LicenseTarget> findAll(LanEvent event);
public void saveOrCreateLicense(LicenseTarget game);
public List<LicenseTarget> findUserGames(EventUser user);
public List<LicenseTarget> findUnopenedUserGames(EventUser user);
public LicenseCode createAndAccessCode(LicenseTarget target, User user) throws GenerationException;
@ApplicationException(rollback=true)
public static class GenerationException extends Exception {
public GenerationException() {
super();
}
public GenerationException(String message) {
super(message);
}
/**
*
*/
private static final long serialVersionUID = 1L;
}
}
\ No newline at end of file
......@@ -55,5 +55,7 @@ public interface ProductBeanLocal {
void saveInventoryEvent(InventoryEvent ie);
List<Product> findProductsForEvent();
List<Product> findPlaceProducts();
}
......@@ -26,12 +26,14 @@ org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_resources_in_try=80
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch=16
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
......@@ -69,6 +71,7 @@ org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
org.eclipse.jdt.core.formatter.comment.line_length=80
org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true
org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true
org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=false
org.eclipse.jdt.core.formatter.compact_else_if=true
org.eclipse.jdt.core.formatter.continuation_indentation=2
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
......@@ -160,12 +163,14 @@ org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invoca
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources=insert
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
......@@ -189,6 +194,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invoc
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
......@@ -244,6 +250,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invoc
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try=insert
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
......@@ -253,6 +260,7 @@ org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=inser
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources=do not insert
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
......@@ -279,4 +287,5 @@ org.eclipse.jdt.core.formatter.tabulation.size=4
org.eclipse.jdt.core.formatter.use_on_off_tags=false
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch=true
org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true
#Sun Mar 07 12:30:58 EET 2010
cleanup_settings_version=2
eclipse.preferences.version=1
formatter_profile=_InsomniaConventions
formatter_settings_version=11
formatter_settings_version=12
......@@ -61,7 +61,7 @@ public class AccountEvent extends GenericEntity {
private Calendar delivered;
@Column(name = "delivered_count", nullable = false, precision = 24, scale = 4)
private BigDecimal deliveredCount;
private BigDecimal deliveredCount = new BigDecimal(0);
/**
* If this AccountEvent is a product in foodwace, this field is a reference
......
......@@ -104,6 +104,9 @@ public class EventUser extends GenericEntity {
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "createtime", nullable = false, updatable = false)
private Date eventuserCreated;
public EventUser getCreator() {
return creator;
......@@ -443,4 +446,5 @@ public class EventUser extends GenericEntity {
}
}
......@@ -58,6 +58,7 @@ public class GroupMembership extends GenericEntity {
private Place placeReservation;
@JoinColumn(name = EVENTUSER_ID, referencedColumnName = EventUser.ID_COLUMN)
@ManyToOne
private EventUser user;
......
......@@ -73,6 +73,9 @@ public class LanEvent extends GenericEntity {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
private List<Compo> compos;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "event")
private List<LicenseTarget> games;
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
private List<CardTemplate> cardTemplates;
......@@ -281,4 +284,14 @@ public class LanEvent extends GenericEntity {
this.properties = properties;
}
public List<LicenseTarget> getGames() {
if(games == null)
games = new ArrayList<LicenseTarget>();
return games;
}
public void setGames(List<LicenseTarget> games) {
this.games = games;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.codecrew.moya.model;
import java.util.Calendar;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
*
*/
@Entity
@Table(name = "licensecodes")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LicenseCode extends GenericEntity {
private static final long serialVersionUID = 1L;
@Column(name = "accessed", nullable = true)
@Temporal(TemporalType.TIMESTAMP)
private Calendar accessed = null;
@Column(name = "code")
private String code;
@JoinColumn(name = "game_id", referencedColumnName = "id")
@ManyToOne
private LicenseTarget licenseTarget;
@JoinColumn(name = "user_id", referencedColumnName = "id")
@ManyToOne
private User user;
public LicenseCode() {
super();
}
public LicenseCode(LicenseTarget target) {
this();
this.licenseTarget = target;
}
public boolean isAccessed() {
return (accessed != null);
}
public Calendar getAccessed() {
return accessed;
}
public void setAccessed(Calendar accessed) {
this.accessed = accessed;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public LicenseTarget getLicenseTarget() {
return licenseTarget;
}
public void setLicenseTarget(LicenseTarget licenseTarget) {
this.licenseTarget = licenseTarget;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package fi.codecrew.moya.model;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import org.eclipse.persistence.annotations.OptimisticLocking;
import org.eclipse.persistence.annotations.OptimisticLockingType;
/**
*
*/
@Entity
@Table(name = "licenseTargets")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LicenseTarget extends GenericEntity {
private static final long serialVersionUID = 1L;
@Column(name = "active")
private boolean active = false;
@Column(name = "name")
private String name;
@Column(name = "service")
private String service;
@Column(name = "description")
private String description;
@Column(name = "code_url")
private String codeUrl;
@JoinColumn(name = "event_id", referencedColumnName = "id")
@ManyToOne
private LanEvent event;
@OneToMany(mappedBy = "licenseTarget", fetch = FetchType.LAZY)
@OrderBy()
private List<LicenseCode> licenseCodes;
@JoinColumn(name = "product_id", referencedColumnName = "id")
@ManyToOne
private Product product;
public LicenseTarget() {
super();
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getCodeUrl() {
return codeUrl;
}
public void setCodeUrl(String codeUrl) {
this.codeUrl = codeUrl;
}
public LanEvent getEvent() {
return event;
}
public void setEvent(LanEvent event) {
this.event = event;
}
public String getService() {
return service;
}
public void setService(String service) {
this.service = service;
}
public List<LicenseCode> getGameCodes() {
return licenseCodes;
}
public void setGameCodes(List<LicenseCode> gameCodes) {
this.licenseCodes = gameCodes;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public boolean isActive() {
return active;
}
public boolean getActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public List<LicenseCode> getLicenseCodes() {
return licenseCodes;
}
public void setLicenseCodes(List<LicenseCode> licenseCodes) {
this.licenseCodes = licenseCodes;
}
}
package fi.codecrew.moya.model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
......
......@@ -70,6 +70,11 @@ public class Product extends GenericEntity {
@Column(name = "barcode")
private String barcode;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "product")
private List<LicenseTarget> licenseTargets;
@Enumerated(EnumType.STRING)
@PrivateOwned
@ElementCollection()
......@@ -332,4 +337,12 @@ public class Product extends GenericEntity {
this.inventoryEvents = inventoryEvents;
}
public List<LicenseTarget> getLicenseTargets() {
return licenseTargets;
}
public void setLicenseTargets(List<LicenseTarget> licenseTargets) {
this.licenseTargets = licenseTargets;
}
}
package fi.codecrew.moya.model;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
......@@ -9,6 +10,7 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
......@@ -108,6 +110,10 @@ public class User extends GenericEntity implements IUser {
@OrderBy
@PrivateOwned
private List<UserImage> userImageList;
@OneToMany(mappedBy = "user", fetch = FetchType.LAZY)
@OrderBy()
private List<LicenseCode> licenseCodes;
@Transient
private static final Logger logger = LoggerFactory.getLogger(User.class);
......@@ -353,5 +359,17 @@ public class User extends GenericEntity implements IUser {
}
return isAnon;
}
public List<LicenseCode> getLicenseCodes() {
if(licenseCodes == null)
licenseCodes = new ArrayList<LicenseCode>();
return licenseCodes;
}
public void setLicenseCodes(List<LicenseCode> codes) {
this.licenseCodes = codes;
}
}
......@@ -4,6 +4,7 @@ import fi.codecrew.moya.enums.apps.BillPermission;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.enums.apps.EventPermission;
import fi.codecrew.moya.enums.apps.LicensePermission;
import fi.codecrew.moya.enums.apps.IAppPermission;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.PollPermission;
......@@ -23,6 +24,7 @@ public enum BortalApplication {
SALESPOINT(SalespointPermission.class),
COMPO(CompoPermission.class),
EVENT(EventPermission.class),
LICENSE(LicensePermission.class),
;
......
package fi.codecrew.moya.enums.apps;
import fi.codecrew.moya.enums.BortalApplication;
public enum LicensePermission implements IAppPermission {
MANAGE,
VIEW_OWN_CODES,
;
public static final String S_MANAGE = "LICENSE/MANAGE";
public static final String S_VIEW_OWN_CODES = "LICENSE/VIEW_OWN_CODES";
private final String fullName;
private final String key;
private static final String I18N_HEADER = "bortalApplication.license.";
private LicensePermission() {
fullName = new StringBuilder().append(getParent().toString()).append(DELIMITER).append(toString()).toString();
key = I18N_HEADER + name();
}
@Override
public BortalApplication getParent() {
return BortalApplication.LICENSE;
}
@Override
public String getFullName() {
return fullName;
}
@Override
public String getI18nKey() {
return key;
}
}
......@@ -38,8 +38,10 @@ public abstract class GenericFacade<C extends ModelInterface> {
protected abstract EntityManager getEm();
public void create(C entity) {
public C create(C entity) {
getEm().persist(entity);
return entity;
}
public void remove(C entity) {
......@@ -52,8 +54,8 @@ public abstract class GenericFacade<C extends ModelInterface> {
}
public void refresh(C usr) {
getEm().refresh(usr);
public void refresh(C entity) {
getEm().refresh(entity);
}
public C find(Integer id) {
......
<!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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{licenseView.initAdminView}" />
</f:metadata>
<ui:param name="thispage" value="page.license.manageCodes" />
<ui:define name="content">
<h:form id="licenseForm">
<p:dataTable border="1" id="games" value="#{licenseView.licenses}" var="license">
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['game.name']}" />
</f:facet>
<h:outputText value="#{license.name}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="edit" />
</f:facet>
<p:commandButton value="muokkaa" update=":editgame" >
<f:setPropertyActionListener value="#{license}" target="#{licenseView.currentLicense}" />
</p:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['game.codecount']}" />
</f:facet>
<h:outputText value="#{license.licenseCodes.size()}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['game.active']}" />
</f:facet>
<h:outputText rendered="#{license.active}" value="X" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['game.product']}" />
</f:facet>
<h:outputText value="#{license.product.name}" />
</p:column>
</p:dataTable>
</h:form>
<br /><br />
<h:form id="editgame" >
<p:panelGrid columns="2">
<f:facet name="header">
<h:outputLabel rendered="#{licenseView.currentLicense.id == null}" value="#{i18n['game.create']}" />
<h:outputLabel rendered="#{licenseView.currentLicense.id != null}" value="#{i18n['game.edit']}" />
</f:facet>
<h:outputLabel value="service" />
<p:inputText value="#{licenseView.currentLicense.service}" />
<h:outputLabel value="name" />
<p:inputText value="#{licenseView.currentLicense.name}" />
<h:outputLabel value="description" />
<p:inputText value="#{licenseView.currentLicense.description}" />
<h:outputLabel value="url" />
<p:inputText value="#{licenseView.currentLicense.codeUrl}" />
<h:outputLabel value="active" />
<p:selectBooleanCheckbox value="#{licenseView.currentLicense.active}" />
<h:outputLabel value="product" />
<h:selectOneMenu converter="#{productConverter}" value="#{licenseView.currentLicense.product}">
<f:selectItems var="product" itemLabel="#{product.name}" value="#{licenseView.productsForLicenses}" />
</h:selectOneMenu>
<p:commandButton action="#{licenseView.saveCurrentLicense}" update=":licenseForm" value="save" />
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
<!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:products="http://java.sun.com/jsf/composite/tools/products" xmlns:tools="http://java.sun.com/jsf/composite/tools" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui">
<h:body>
<ui:composition template="#{sessionHandler.template}">
<ui:param name="thispage" value="page.gamecode.viewCodes" />
<f:metadata>
<f:viewParam name="userid" value="#{userView.userid}" />
<f:event type="preRenderView" listener="#{licenseView.initUserView}" />
</f:metadata>
<ui:define name="content">
<h:form>
<h1><h:outputLabel value="#{i18n['game.codes.opened']}" /></h1>
<h:outputLabel rendered="#{licenseView.noLicenseCodes}" value="#{i18n['game.noGameCodes']}" />
<p:dataTable rendered="#{not licenseView.noLicenseCodes}" columnClasses="nowrap,numalign,numalign,nowrap,numalign" styleClass="bordertable" id="codes" value="#{licenseView.licenseCodes}" var="code">
<p:column sortBy="#{code.license.service}">
<f:facet name="header">
<h:outputText value="#{i18n['game.service']}" />
</f:facet>
<h:outputText value="#{code.licenseTarget.service}" />
</p:column>
<p:column sortBy="#{code.license.name}">
<f:facet name="header">
<h:outputText value="#{i18n['game.name']}" />
</f:facet>
<h:outputText value="#{code.licenseTarget.name}" />
</p:column>
<p:column sortBy="#{code.license.description}">
<f:facet name="header">
<h:outputText value="#{i18n['game.description']}" />
</f:facet>
<h:outputText value="#{code.licenseTarget.description}" />
</p:column>
<p:column sortBy="#{code.code}">
<f:facet name="header">
<h:outputText value="#{i18n['game.code']}" />
</f:facet>
<h:outputText rendered="#{code.accessed}" value="#{code.code}" />
<h:outputText rendered="#{not code.accessed}" value="ei avattu, ota yhteyttä ylläpitoon" />
</p:column>
</p:dataTable>
</h:form>
<br /><br /><br />
<h:form>
<h1><h:outputLabel rendered="#{not licenseView.noLicenses}" value="#{i18n['game.codes.available']}" /></h1>
<p:dataTable rendered="#{not licenseView.noLicenses}" columnClasses="nowrap,numalign,numalign,nowrap,numalign" styleClass="bordertable" id="codes" value="#{licenseView.licenses}" var="license">
<p:column sortBy="#{license.service}">
<f:facet name="header">
<h:outputText value="#{i18n['game.service']}" />
</f:facet>
<h:outputText value="#{license.service}" />
</p:column>
<p:column sortBy="#{license.name}">
<f:facet name="header">
<h:outputText value="#{i18n['game.name']}" />
</f:facet>
<h:outputText value="#{license.name}" />
</p:column>
<p:column sortBy="#{license.description}">
<f:facet name="header">
<h:outputText value="#{i18n['game.description']}" />
</f:facet>
<h:outputText value="#{license.description}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{i18n['game.open']}" />
</f:facet>
<h:commandButton value="#{i18n['game.open']}" action="#{licenseView.openSelectedCode}" />
</p:column>
</p:dataTable>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
......@@ -41,17 +41,7 @@
<h:selectManyCheckbox id="permissions" layout="pageDirection" value="#{bapp.selected}">
<f:selectItems value="#{bapp.permissions}" var="per" itemLabel="#{i18n[per.i18nKey]}" />
</h:selectManyCheckbox>
<!-- <ui:repeat id="permDescs" var="perm" value="#{bapp.permissions}"> -->
<!-- <div>#{perm.name} / #{perm.description}</div> -->
<!-- </ui:repeat> -->
</h:column>
<!-- <h:column> -->
<!-- <ui:repeat id="permissions" var="perm" value="#{bapp.permissions}"> -->
<!-- <div> -->
<!-- <h:selectBooleanCheckbox value="#{perm.canHas}" /> -->
<!-- </div> -->
<!-- </ui:repeat> -->
<!-- </h:column> -->
</h:dataTable>
<h:commandButton id="save2" value="#{i18n['role.savePermissions']}" action="#{roleView.savePermissions}" />
......
......@@ -7,8 +7,7 @@
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title><h:outputText value="#{layoutView.getHeader()}" /></title>
<meta name="description" content="Insomnia lippukauppa" />
<meta name="author" content="Niko Juusela, csharp" />
<meta name="description" content="#{layoutView.getHeader()}" />
<meta http-equiv="Content-Language" content="fi" />
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/resources/templates/insomnia2/css/tyyli.css" />
......
......@@ -86,6 +86,15 @@ error.error = You have encountered an error.
eventorg.create = Create
game.active = Aktiivinen
game.codecount = Avattuja
game.codes.available = Lisenssikoodit
game.codes.opened = Avatut lisenssikoodit
game.create = Create
game.edit = Edit
game.out = Gamecodes are out, pleace contact administration
game.product = Tuote
generic.sure.header = Confirmation
generic.sure.message = Are you sure?
generic.sure.no = No
......@@ -158,4 +167,6 @@ resetmailSent.header = Email sent
subnavi.cards = \u0009\u0009
topnavi.license = Lisenssikoodit
user.unauthenticated = Kirjautumaton
......@@ -277,7 +277,21 @@ foodwavetemplate.selectproducts = Products
foodwavetemplate.startTime = Foodwave time
foodwavetemplate.waveName = Wave name
game.gamepoints = Game points
game.active = Active
game.code = Code
game.codecount = Opened
game.codes.available = Licensecodes
game.codes.opened = Opened licensecodes
game.create = Create
game.description = Description
game.edit = Edit
game.gamepoints = Game points
game.name = Name
game.noGameCodes = You have no opened gamecodes
game.open = Open code
game.out = Please contact out customer service
game.product = Product
game.service = Game service
gamepoints = Gamepoints
......@@ -780,6 +794,8 @@ topnavi.createuser = Create user
topnavi.event = Event
topnavi.foodwave = Food
topnavi.frontpage = Front page
topnavi.game = Gamecodes
topnavi.license = Licensecodes
topnavi.log = Log
topnavi.login = Login
topnavi.maps = Maps
......
......@@ -277,7 +277,21 @@ foodwavetemplate.selectproducts = Tuotteet
foodwavetemplate.startTime = Tilausaika
foodwavetemplate.waveName = Tilauksen nimi
game.gamepoints = Insomnia Game pisteet:
game.active = Aktiivinen
game.code = Koodi
game.codecount = Avattuja
game.codes.available = Lisenssikoodit
game.codes.opened = Avatut lisenssikoodit
game.create = Luo
game.description = Kuvaus
game.edit = Muokkaa
game.gamepoints = Insomnia Game pisteet:
game.name = Nimi
game.noGameCodes = Sinulla ei ole avattuja pelikoodeja.
game.open = Ota koodi k\u00E4ytt\u00F6\u00F6n
game.out = Ei voitu avata pelikoodia, ota yhteytt\u00E4 asiakaspalveluun.
game.product = Tuote
game.service = Pelipalvelu
gamepoints = Pelipisteit\u00E4
......@@ -765,6 +779,8 @@ topnavi.createuser = Luo k\u00E4ytt\u00E4j\u00E4
topnavi.event = Tapahtuma
topnavi.foodwave = Ruokatilaus
topnavi.frontpage = Etusivu
topnavi.game = Pelikoodit
topnavi.license = Lisenssikoodit
topnavi.log = Logi
topnavi.login = Kirjaudu sis\u00E4\u00E4n
topnavi.maps = Kartat
......
package fi.codecrew.moya.web.cdiview.license;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.model.ListDataModel;
import javax.inject.Named;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LicenseBeanLocal;
import fi.codecrew.moya.beans.LicenseBeanLocal.GenerationException;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.enums.apps.LicensePermission;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LicenseCode;
import fi.codecrew.moya.model.LicenseTarget;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class LicenseView extends GenericCDIView {
private static final long serialVersionUID = -8346420143750551402L;
private EventUser currentUser;
@EJB
private PermissionBeanLocal permissionBean;
@EJB
private EventBeanLocal eventBean;
@EJB
private LicenseBeanLocal licenseBean;
@EJB
private ProductBeanLocal productBean;
private ListDataModel<LicenseTarget> licenses;
private ListDataModel<LicenseCode> licenseCodes;
private LicenseTarget currentLicense;
public void initAdminView() {
if (super.requirePermissions(LicensePermission.MANAGE)) {
if (licenses == null) {
this.currentLicense = new LicenseTarget();
this.currentLicense.setEvent(eventBean.getCurrentEvent());
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findAll(eventBean.getCurrentEvent()));
this.beginConversation();
}
}
}
public void initUserView() {
if (super.requirePermissions(LicensePermission.VIEW_OWN_CODES)) {
if (licenseCodes == null) {
currentUser = permissionBean.getCurrentUser();
this.licenseCodes = new ListDataModel<LicenseCode>(currentUser.getUser().getLicenseCodes());
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findUnopenedUserGames(currentUser));
this.beginConversation();
}
}
}
public String saveCurrentLicense() {
licenseBean.saveOrCreateLicense(currentLicense);
this.licenses = new ListDataModel<LicenseTarget>(licenseBean.findAll(eventBean.getCurrentEvent()));
return null;
}
public String editSelected() {
return null;
}
public String openSelectedCode() {
if(this.licenses != null && this.licenses.isRowAvailable()) {
LicenseTarget license = this.licenses.getRowData();
try {
LicenseCode code = licenseBean.createAndAccessCode(license, currentUser.getUser());
} catch(GenerationException x) {
this.addFaceMessage("game.out");
}
licenseCodes = null;
initUserView();
}
return null;
}
public boolean isNoLicenseCodes() {
return (getLicenseCodes().getRowCount() <= 0);
}
public boolean isNoLicenses() {
return (getLicenses().getRowCount() <= 0);
}
public ListDataModel<LicenseCode> getLicenseCodes() {
return licenseCodes;
}
public void setLicenseCodes(ListDataModel<LicenseCode> licenseCodes) {
this.licenseCodes = licenseCodes;
}
public ListDataModel<LicenseTarget> getLicenses() {
return licenses;
}
public void setLicenses(ListDataModel<LicenseTarget> licenses) {
this.licenses = licenses;
}
public LicenseTarget getCurrentLicense() {
return currentLicense;
}
public void setCurrentLicense(LicenseTarget currentLicense) {
this.currentLicense = currentLicense;
}
public List<Product> getProductsForLicenses() {
return productBean.findPlaceProducts();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!