Commit baf18e5a by Antti Tönkyrä

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

2 parents 97900ed7 9025e382
Showing with 428 additions and 79 deletions
...@@ -244,10 +244,6 @@ public class BillBean implements BillBeanLocal { ...@@ -244,10 +244,6 @@ public class BillBean implements BillBeanLocal {
if (prod != null && prod.getProductFlags().contains(ProductFlag.PREPAID_INSTANT_CREATE)) { if (prod != null && prod.getProductFlags().contains(ProductFlag.PREPAID_INSTANT_CREATE)) {
logger.debug("Creating Bill prepaidInstant product {}, {}", prod.getName(), bl.getQuantity()); logger.debug("Creating Bill prepaidInstant product {}, {}", prod.getName(), bl.getQuantity());
if (prod.getProductFlags().contains(ProductFlag.RESERVE_PLACE_WHEN_BOUGHT)
|| prod.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
placebean.lockPlaceProduct(bill.getUser(), prod, bl.getQuantity());
}
AccountEvent ac2 = productPBean.createAccountEvent(prod, bl.getQuantity(), user, bill.getSentDate(), bl.getFoodwave()); AccountEvent ac2 = productPBean.createAccountEvent(prod, bl.getQuantity(), user, bill.getSentDate(), bl.getFoodwave());
logger.info("Created ac from product. {}, userproducts {}", ac2, user.getAccountEvents().size()); logger.info("Created ac from product. {}, userproducts {}", ac2, user.getAccountEvents().size());
...@@ -320,8 +316,6 @@ public class BillBean implements BillBeanLocal { ...@@ -320,8 +316,6 @@ public class BillBean implements BillBeanLocal {
@Override @Override
public Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave) { public Bill addProductToBill(Bill bill, Product product, BigDecimal count, FoodWave foodwave) {
// If bill number > 0 bill has been sent and extra privileges are needed // If bill number > 0 bill has been sent and extra privileges are needed
// to modify. // to modify.
// if (!iscurrent || billnr != null) { // if (!iscurrent || billnr != null) {
...@@ -342,7 +336,4 @@ public class BillBean implements BillBeanLocal { ...@@ -342,7 +336,4 @@ public class BillBean implements BillBeanLocal {
return bill; return bill;
} }
} }
...@@ -23,6 +23,25 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -23,6 +23,25 @@ public class BootstrapBean implements BootstrapBeanLocal {
public BootstrapBean() { public BootstrapBean() {
} }
/**
* Runs a "ALTER TABLE
* <table>
* <statement>" for each of tables.
*
* @param alterStatement
* e.g. "ADD meta json"
* @param tables
* table name strings
* @return1
*/
private static final String[] alterTables(String alterStatement, String... tables) {
String[] strings = new String[tables.length];
for (int i = 0; i < tables.length; i++) {
strings[i] = "ALTER TABLE \"" + tables[i] + "\" " + alterStatement;
}
return strings;
}
private static final List<String[]> dbUpdates = new ArrayList<String[]>(); private static final List<String[]> dbUpdates = new ArrayList<String[]>();
static { static {
// {"Query1","Query2",...} // {"Query1","Query2",...}
...@@ -60,7 +79,76 @@ public class BootstrapBean implements BootstrapBeanLocal { ...@@ -60,7 +79,76 @@ public class BootstrapBean implements BootstrapBeanLocal {
dbUpdates.add(new String[] { dbUpdates.add(new String[] {
"alter table compos add hidden boolean default false not null" "alter table compos add hidden boolean default false not null"
}); });
dbUpdates.add(alterTables("ADD COLUMN meta json",
"account_events",
"actionlog_message_responses",
"actionlog_message_tags",
"actionlog_messages",
"api_application_instances",
"api_applications",
"application_permissions",
"approvals",
"bill_lines",
"bills",
"card_code",
"card_templates",
"compo_entries",
"compo_entry_files",
"compo_entry_participations",
"compo_votes",
"compos",
"discount_instances",
"discounts",
"event_domains",
"event_log",
"event_log_types",
"event_organiser",
"event_private_properties",
"event_properties",
"event_users",
"events",
"feedback",
"food_wave_templates",
"food_waves",
"game_ids",
"group_memberships",
"groups",
"inventory_events",
"licensetargets",
"licensecodes",
"locations",
"maps",
"match_results",
"matches",
"menu_navigation",
"menuitem",
"news",
"news_groups",
"org_roles",
"places",
"poll",
"poll_answer",
"poll_question",
"possible_answer",
"printed_cards",
"product_limitations",
"products",
"reader_events",
"readers",
"roles",
"sales_entity",
"salespoint",
"site_page_content",
"site_pages",
"tournament_games",
"tournament_participants",
"tournament_rules",
"tournament_team_members",
"tournaments",
"user_approvals",
"user_images",
"user_notes",
"users"));
} }
@EJB @EJB
......
...@@ -122,16 +122,24 @@ public class CardTemplateBean implements CardTemplateBeanLocal { ...@@ -122,16 +122,24 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
List<PrintedCard> myCards = printedcardfacade.getCards(user); List<PrintedCard> myCards = printedcardfacade.getCards(user);
PrintedCard biggestCard = null; PrintedCard biggestCard = null;
PrintedCard smallestCard = null; // PrintedCard smallestCard = null;
for (PrintedCard card : myCards) { for (PrintedCard card : myCards) {
logger.info("Checking card {}", card); // logger.info("Checking card {}", card);
if (card.getEnabled()) { if (card.getEnabled()) {
if (biggestCard == null || biggestCard.getTemplate().getPower() < card.getTemplate().getPower()) { if (biggestCard == null || biggestCard.getTemplate().getPower() < card.getTemplate().getPower()) {
biggestCard = card; // The biggest card should be the only one enabled.
if (biggestCard != null) {
biggestCard.setEnabled(false);
} }
if (smallestCard == null || smallestCard.getTemplate().getPower() > card.getTemplate().getPower()) { biggestCard = card;
smallestCard = card; biggestCard.setEnabled(true);
} }
// if (smallestCard == null ||
// smallestCard.getTemplate().getPower() >
// card.getTemplate().getPower()) {
// smallestCard = card;
// }
} }
} }
......
...@@ -315,6 +315,10 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -315,6 +315,10 @@ public class PlaceBean implements PlaceBeanLocal {
logger.info("Associating buyer {} to place {}", user, gm); logger.info("Associating buyer {} to place {}", user, gm);
associatedToPlace = true; associatedToPlace = true;
gm.setUser(user); gm.setUser(user);
if (user.getGroupMemberships() == null) {
user.setGroupMemberships(new ArrayList<GroupMembership>());
}
user.getGroupMemberships().add(gm);
} }
} }
...@@ -346,7 +350,9 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -346,7 +350,9 @@ public class PlaceBean implements PlaceBeanLocal {
freePlace = new Place(); freePlace = new Place();
freePlace.setProduct(prod); freePlace.setProduct(prod);
freePlace.setProvidesRole(prod.getProvides()); freePlace.setProvidesRole(prod.getProvides());
freePlace.setName("-");
placeFacade.create(freePlace); placeFacade.create(freePlace);
} else if (prod.getPlaces() != null) { } else if (prod.getPlaces() != null) {
for (Place p : prod.getPlaces()) { for (Place p : prod.getPlaces()) {
if (!p.isTaken()) { if (!p.isTaken()) {
...@@ -359,11 +365,16 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -359,11 +365,16 @@ public class PlaceBean implements PlaceBeanLocal {
throw new EJBException("Could find a place to be reserved...."); throw new EJBException("Could find a place to be reserved....");
} }
GroupMembership gm = buy(freePlace, pg); GroupMembership gm = buy(freePlace, pg);
if (!associatedToPlace) if (!associatedToPlace)
{ {
logger.info("Associating buyer {} to place {}", user, gm); logger.info("Associating buyer {} to place {}", user, gm);
associatedToPlace = true; associatedToPlace = true;
gm.setUser(user); gm.setUser(user);
if (user.getGroupMemberships() == null) {
user.setGroupMemberships(new ArrayList<GroupMembership>());
}
user.getGroupMemberships().add(gm);
} }
} }
......
...@@ -14,12 +14,14 @@ import org.slf4j.Logger; ...@@ -14,12 +14,14 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.facade.AccountEventFacade; import fi.codecrew.moya.facade.AccountEventFacade;
import fi.codecrew.moya.facade.ProductFacade;
import fi.codecrew.moya.model.AccountEvent; import fi.codecrew.moya.model.AccountEvent;
import fi.codecrew.moya.model.Discount; import fi.codecrew.moya.model.Discount;
import fi.codecrew.moya.model.DiscountInstance; import fi.codecrew.moya.model.DiscountInstance;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.FoodWave; import fi.codecrew.moya.model.FoodWave;
import fi.codecrew.moya.model.Product; import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ProductFlag;
/** /**
* Session Bean implementation class ProductPBean * Session Bean implementation class ProductPBean
...@@ -35,6 +37,13 @@ public class ProductPBean { ...@@ -35,6 +37,13 @@ public class ProductPBean {
private DiscountBean discountBean; private DiscountBean discountBean;
@EJB @EJB
private AccountEventFacade accounteventfacade; private AccountEventFacade accounteventfacade;
@EJB
private PlaceBean placebean;
@EJB
private ProductFacade productFacade;
private static final Logger logger = LoggerFactory private static final Logger logger = LoggerFactory
.getLogger(ProductPBean.class); .getLogger(ProductPBean.class);
...@@ -70,9 +79,12 @@ public class ProductPBean { ...@@ -70,9 +79,12 @@ public class ProductPBean {
BigDecimal quantity, EventUser user, Calendar date, BigDecimal quantity, EventUser user, Calendar date,
FoodWave foodwave) { FoodWave foodwave) {
if (!accounteventfacade.isAttached(product)) {
product = productFacade.reload(product);
}
if (!product.getEvent().equals(user.getEvent())) { if (!product.getEvent().equals(user.getEvent())) {
throw new EJBException( throw new EJBException("Trying to create accountevent for different event in user and product");
"Trying to create accountevent for different event in user and product");
} }
BigDecimal unitPrice = product.getPrice().negate(); BigDecimal unitPrice = product.getPrice().negate();
...@@ -94,12 +106,21 @@ public class ProductPBean { ...@@ -94,12 +106,21 @@ public class ProductPBean {
foodwave.getAccountEvents().add(ret); foodwave.getAccountEvents().add(ret);
} }
if (product.getProductFlags().contains(ProductFlag.RESERVE_PLACE_WHEN_BOUGHT)
|| product.getProductFlags().contains(ProductFlag.CREATE_NEW_PLACE_WHEN_BOUGHT)) {
placebean.lockPlaceProduct(user, product, quantity);
}
List<DiscountInstance> accEventdiscounts = ret.getDiscountInstances(); List<DiscountInstance> accEventdiscounts = ret.getDiscountInstances();
for (Discount d : discounts) { for (Discount d : discounts) {
// discountsArray.add(discInst); // discountsArray.add(discInst);
// discountinstancefacade.create(discInst); // discountinstancefacade.create(discInst);
accEventdiscounts.add(new DiscountInstance(ret, d)); accEventdiscounts.add(new DiscountInstance(ret, d));
} }
if (product.getAccountEvents() == null) {
product.setAccountEvents(new ArrayList<AccountEvent>());
}
product.getAccountEvents().add(ret);
user.addAccountevent(ret); user.addAccountevent(ret);
accounteventfacade.create(ret); accounteventfacade.create(ret);
......
...@@ -192,7 +192,7 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -192,7 +192,7 @@ public class TournamentBean implements TournamentBeanLocal {
for (TournamentParticipant tp : tournament.getParticipants()) { for (TournamentParticipant tp : tournament.getParticipants()) {
for (TournamentTeamMember tm : tp.getTeamMembers()) { for (TournamentTeamMember tm : tp.getTeamMembers()) {
EventUser eu = tm.getEventUser(); EventUser eu = tm.getEventUser();
System.out.println(eu.getNick());
if (eu.equals(currentUser)) { if (eu.equals(currentUser)) {
return true; return true;
} }
......
...@@ -190,4 +190,9 @@ public class VotingBean implements VotingBeanLocal { ...@@ -190,4 +190,9 @@ public class VotingBean implements VotingBeanLocal {
compoEntryFileFacade.create(cef); compoEntryFileFacade.create(cef);
} }
@Override
public List<CompoEntry> getEntriesForCurrentUser() {
EventUser user = permissionBean.getCurrentUser();
return compoEntryFacade.findUsersEntries(user);
}
} }
package fi.codecrew.moya.facade; package fi.codecrew.moya.facade;
import java.util.List;
import javax.ejb.LocalBean; import javax.ejb.LocalBean;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import fi.codecrew.moya.model.CompoEntry; import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.model.CompoEntry_;
import fi.codecrew.moya.model.EventUser;
@Stateless @Stateless
@LocalBean @LocalBean
...@@ -14,4 +21,11 @@ public class CompoEntryFacade extends IntegerPkGenericFacade<CompoEntry> { ...@@ -14,4 +21,11 @@ public class CompoEntryFacade extends IntegerPkGenericFacade<CompoEntry> {
super(CompoEntry.class); super(CompoEntry.class);
} }
public List<CompoEntry> findUsersEntries(EventUser user) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<CompoEntry> cq = cb.createQuery(CompoEntry.class);
Root<CompoEntry> root = cq.from(CompoEntry.class);
cq.where(cb.equal(root.get(CompoEntry_.creator), user));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -13,7 +13,6 @@ import javax.persistence.criteria.CriteriaBuilder; ...@@ -13,7 +13,6 @@ import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root; import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery;
import fi.codecrew.moya.beans.EventBeanLocal; import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.enums.CardState; import fi.codecrew.moya.enums.CardState;
...@@ -37,7 +36,6 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> { ...@@ -37,7 +36,6 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> {
@EJB @EJB
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
public PrintedCard findByCode(String code) { public PrintedCard findByCode(String code) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
...@@ -49,7 +47,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> { ...@@ -49,7 +47,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> {
CardCode cardcode = getSingleNullableResult(getEm().createQuery(cq)); CardCode cardcode = getSingleNullableResult(getEm().createQuery(cq));
return (cardcode == null)?null : cardcode.getPrintedCard(); return (cardcode == null) ? null : cardcode.getPrintedCard();
} }
public List<PrintedCard> findAllEnabled(LanEvent currentEvent) { public List<PrintedCard> findAllEnabled(LanEvent currentEvent) {
...@@ -71,6 +69,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> { ...@@ -71,6 +69,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> {
cq.where(cb.equal(root.get(PrintedCard_.user), user), cq.where(cb.equal(root.get(PrintedCard_.user), user),
cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent())); cb.equal(root.get(PrintedCard_.event), eventbean.getCurrentEvent()));
cq.orderBy(cb.asc(root.get(PrintedCard_.template).get(CardTemplate_.power)));
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
...@@ -113,7 +112,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> { ...@@ -113,7 +112,7 @@ public class PrintedCardFacade extends IntegerPkGenericFacade<PrintedCard> {
List<PrintedCard> pcl = getEm().createQuery(cq).getResultList(); List<PrintedCard> pcl = getEm().createQuery(cq).getResultList();
HashMap<Integer, PrintedCard> pch = new HashMap<>(); HashMap<Integer, PrintedCard> pch = new HashMap<>();
for(PrintedCard pc : pcl) { for (PrintedCard pc : pcl) {
pch.put(pc.getUser().getId(), pc); pch.put(pc.getUser().getId(), pc);
} }
......
...@@ -38,11 +38,10 @@ public class EventUserCardStateFilter implements FacadeCallback<EventUser> { ...@@ -38,11 +38,10 @@ public class EventUserCardStateFilter implements FacadeCallback<EventUser> {
logger.debug("Requiring states {}", states); logger.debug("Requiring states {}", states);
Path<Integer> rootId = root.get(EventUser_.id); Path<Integer> rootId = root.get(EventUser_.id);
Subquery<Integer> subq = cq.subquery(Integer.class); Subquery<Integer> subq = cq.subquery(Integer.class);
Root<PrintedCard> subroot = subq.from(PrintedCard.class); Root<PrintedCard> subroot = subq.from(PrintedCard.class);
subq.select(subroot.join(PrintedCard_.user).get(EventUser_.id)); subq.select(subroot.join(PrintedCard_.user).get(EventUser_.id));
subq.where(subroot.get(PrintedCard_.cardState).in(states)); subq.where(subroot.get(PrintedCard_.cardState).in(states), cb.isTrue(subroot.get(PrintedCard_.enabled)));
predicates.add(rootId.in(subq)); predicates.add(rootId.in(subq));
} }
......
...@@ -39,4 +39,6 @@ public interface VotingBeanLocal { ...@@ -39,4 +39,6 @@ public interface VotingBeanLocal {
public void create(CompoEntryFile cef); public void create(CompoEntryFile cef);
public List<CompoEntry> getEntriesForCurrentUser();
} }
...@@ -57,5 +57,10 @@ ...@@ -57,5 +57,10 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.3-1100-jdbc41</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<property name="eclipselink.ddl-generation" value="create-tables" /> <property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.cache.size.default" value="16384" /> <property name="eclipselink.cache.size.default" value="16384" />
<property name="eclipselink.ddl-generation.output-mode" <property name="eclipselink.ddl-generation.output-mode"
value="database" /> value="sql-script" />
<property name="eclipselink.logging.logger" value="ServerLogger" /> <property name="eclipselink.logging.logger" value="ServerLogger" />
<property name="eclipselink.jdbc.uppercase-columns" value="false" /> <property name="eclipselink.jdbc.uppercase-columns" value="false" />
<property name="eclipselink.target-database" <property name="eclipselink.target-database"
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
value="org.ancoron.postgresql.jpa.eclipselink.ConverterInitializer" /> value="org.ancoron.postgresql.jpa.eclipselink.ConverterInitializer" />
<property name="eclipselink.descriptor.customizer" <property name="eclipselink.descriptor.customizer"
value="fi.codecrew.moya.database.MoyaDescriptorCustomizer" /> value="fi.codecrew.moya.database.MoyaDescriptorCustomizer" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="moyaCreateDDL.sql"/>
<property name="eclipselink.drop-ddl-jdbc-file-name" value="moyaDropDDL.sql"/>
</properties> </properties>
</persistence-unit> </persistence-unit>
......
...@@ -15,6 +15,7 @@ public class MoyaPostgreSQLPlatform extends PostgreSQLPlatform { ...@@ -15,6 +15,7 @@ public class MoyaPostgreSQLPlatform extends PostgreSQLPlatform {
map.put(String.class, new FieldTypeDefinition("TEXT", false)); map.put(String.class, new FieldTypeDefinition("TEXT", false));
map.put(java.sql.Timestamp.class, new FieldTypeDefinition("TIMESTAMPTZ", false)); map.put(java.sql.Timestamp.class, new FieldTypeDefinition("TIMESTAMPTZ", false));
map.put(javax.json.JsonObject.class, new FieldTypeDefinition("JSON", false));
return map; return map;
} }
......
...@@ -4,22 +4,44 @@ import java.util.Date; ...@@ -4,22 +4,44 @@ import java.util.Date;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import fi.codecrew.moya.utilities.jpa.ModelInterface;
@Entity @Entity
@Table(name = "db_models") @Table(name = "db_models")
public class DBModel extends GenericEntity { public class DBModel implements ModelInterface {
private static final long serialVersionUID = 5073284536090477220L; private static final long serialVersionUID = 5073284536090477221L;
public static final String ID_COLUMN = "id";
@Column(name="revision", nullable=false) @Id
@Column(name = ID_COLUMN, nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(name = "revision", nullable = false)
private Integer revision; private Integer revision;
@Column(name="applied_at") @Column(name = "applied_at")
@Temporal(TemporalType.TIMESTAMP) @Temporal(TemporalType.TIMESTAMP)
private Date appliedAt = new Date(); private Date appliedAt = new Date();
@Override
public final Integer getId() {
return id;
}
@Override
public final void setId(Integer id) {
this.id = id;
}
public Date getAppliedAt() { public Date getAppliedAt() {
return appliedAt; return appliedAt;
} }
......
package fi.codecrew.moya.model;
import javax.json.JsonObject;
/**
* Entities that have a JSON meta data column implement this interface.
*
* Meta data can be just about anything that is not deemed to be essential
* enough to have it's own column. Including people's shirt sizes etc.
*
* @author jkj
*/
public interface EntityMeta {
/**
* Get JSON metadata associated with the entity.
*
* @return JsonObject from meta column in DB.
*/
public JsonObject getMeta();
/**
* Associate JSON metadata to entity.
*
* @param meta
* JsonObject that goes into meta column in DB.
*/
public void setMeta(JsonObject meta);
}
package fi.codecrew.moya.model; package fi.codecrew.moya.model;
import javax.json.JsonObject;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType; import javax.persistence.GenerationType;
...@@ -10,7 +11,7 @@ import fi.codecrew.moya.utilities.jpa.EntityEquals; ...@@ -10,7 +11,7 @@ import fi.codecrew.moya.utilities.jpa.EntityEquals;
import fi.codecrew.moya.utilities.jpa.ModelInterface; import fi.codecrew.moya.utilities.jpa.ModelInterface;
@MappedSuperclass @MappedSuperclass
public class GenericEntity extends EntityEquals implements ModelInterface { public class GenericEntity extends EntityEquals implements ModelInterface, EntityMeta {
private static final long serialVersionUID = -9041737052951021560L; private static final long serialVersionUID = -9041737052951021560L;
public static final String ID_COLUMN = "id"; public static final String ID_COLUMN = "id";
...@@ -20,6 +21,8 @@ public class GenericEntity extends EntityEquals implements ModelInterface { ...@@ -20,6 +21,8 @@ public class GenericEntity extends EntityEquals implements ModelInterface {
@GeneratedValue(strategy = GenerationType.IDENTITY) @GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id; private Integer id;
private JsonObject meta;
@Override @Override
public final Integer getId() { public final Integer getId() {
return id; return id;
...@@ -30,4 +33,14 @@ public class GenericEntity extends EntityEquals implements ModelInterface { ...@@ -30,4 +33,14 @@ public class GenericEntity extends EntityEquals implements ModelInterface {
this.id = id; this.id = id;
} }
@Override
public JsonObject getMeta() {
return meta;
}
@Override
public void setMeta(JsonObject meta) {
this.meta = meta;
}
} }
...@@ -22,7 +22,7 @@ import org.eclipse.persistence.annotations.OptimisticLockingType; ...@@ -22,7 +22,7 @@ import org.eclipse.persistence.annotations.OptimisticLockingType;
* *
*/ */
@Entity @Entity
@Table(name = "licenseTargets") @Table(name = "licensetargets")
@OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS) @OptimisticLocking(type = OptimisticLockingType.CHANGED_COLUMNS)
public class LicenseTarget extends GenericEntity { public class LicenseTarget extends GenericEntity {
......
...@@ -184,22 +184,6 @@ public class ReaderEvent extends GenericEntity { ...@@ -184,22 +184,6 @@ public class ReaderEvent extends GenericEntity {
@Transient @Transient
public String getSeenSince() { public String getSeenSince() {
return "" + ((getUpdatetime().getTime() / 1000) / 60) +" min." ; return "" + ((System.currentTimeMillis() - getUpdatetime().getTime()) / 1000 / 60) + " min.";
} }
} }
package fi.codecrew.moya.model.converters;
import java.io.StringReader;
import java.sql.SQLException;
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
import javax.persistence.AttributeConverter;
import javax.persistence.Converter;
import org.postgresql.util.PGobject;
@Converter(autoApply = true)
public class JsonAttributeConverter implements AttributeConverter<JsonObject, PGobject> {
public PGobject convertToDatabaseColumn(JsonObject attribute) {
if (attribute == null) {
return null;
}
final PGobject dataValue = new PGobject();
dataValue.setType("json");
try {
dataValue.setValue(attribute.toString());
} catch (SQLException e) {
// This will never run because PGobject.setValue() cannot really
// throw an SQLException. There is nothing but setting a property.
throw new RuntimeException("THIS SHOULD NEVER HAPPEN", e);
}
return dataValue;
}
public JsonObject convertToEntityAttribute(PGobject dbData) {
// Has any?
if (dbData == null) {
return null;
}
// Correct type of object?
if (dbData.getType().equals("json") == false) {
throw new RuntimeException("Expected JSON object from database");
}
// Read as JSON object
final StringReader stringReader = new StringReader(dbData.getValue());
final JsonReader jsonReader = Json.createReader(stringReader);
return jsonReader.readObject();
}
}
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
<dependent-module archiveName="org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/ancoron/postgresql/org.ancoron.postgresql.jpa/9.1.901.jdbc4.1-rc9/org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar"> <dependent-module archiveName="org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/ancoron/postgresql/org.ancoron.postgresql.jpa/9.1.901.jdbc4.1-rc9/org.ancoron.postgresql.jpa-9.1.901.jdbc4.1-rc9.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
<dependent-module archiveName="postgresql-9.3-1100-jdbc41.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/org/postgresql/postgresql/9.3-1100-jdbc41/postgresql-9.3-1100-jdbc41.jar">
<dependency-type>uses</dependency-type>
</dependent-module>
<dependent-module archiveName="pdfjet-0.0.0-2013-08-19.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/fi/iudex/pdfjet/pdfjet/0.0.0-2013-08-19/pdfjet-0.0.0-2013-08-19.jar"> <dependent-module archiveName="pdfjet-0.0.0-2013-08-19.jar" deploy-path="/lib" handle="module:/classpath/var/M2_REPO/fi/iudex/pdfjet/pdfjet/0.0.0-2013-08-19/pdfjet-0.0.0-2013-08-19.jar">
<dependency-type>uses</dependency-type> <dependency-type>uses</dependency-type>
</dependent-module> </dependent-module>
......
...@@ -289,4 +289,9 @@ public abstract class GenericFacade<C extends ModelInterface> { ...@@ -289,4 +289,9 @@ public abstract class GenericFacade<C extends ModelInterface> {
public void evict(C entity) { public void evict(C entity) {
getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId()); getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId());
} }
public boolean isAttached(ModelInterface entity) {
return getEm().contains(entity);
}
} }
...@@ -33,13 +33,13 @@ ...@@ -33,13 +33,13 @@
</h:panelGroup> </h:panelGroup>
<h:panelGroup> <h:panelGroup >
<reader:codefield selectaction="#{productShopView.readCode}" selectvalue="#{i18n['shop.readBarcode']}" /> <reader:codefield selectaction="#{productShopView.readCode}" selectvalue="#{i18n['shop.readBarcode']}" />
<br /> <br />
<p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods"> <p:dataTable id="prods" value="#{productShopView.boughtItems}" var="prods" style="width:500px;">
<p:column headerText="#{i18n['shop.count']}"> <p:column headerText="#{i18n['shop.count']}">
<p:inputText value="#{prods.count}" size="2"> <p:inputText value="#{prods.count}" size="2">
<f:ajax render="@form" listener="#{productShopView.countBoughtChangeListener}" /> <f:ajax render="@form" listener="#{productShopView.countBoughtChangeListener}" />
......
<!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:products="http://java.sun.com/jsf/composite/cditools/products" 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="reader" value="#{rfidListenerView.reader}" />
<f:viewParam name="tag" value="#{rfidListenerView.tag}" />
<f:event type="preRenderView" listener="#{rfidListenerView.cardRead()}" />
</f:metadata>
<ui:define name="title">
<h1>#{i18n['page.product.createBill.header']}</h1>
</ui:define>
<ui:define name="content">
Hi.
</ui:define>
</ui:composition>
</h:body>
</html>
\ No newline at end of file
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
<h:messages errorClass="error" /> <h:messages errorClass="error" />
<h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}"> <h:panelGroup rendered="#{tournamentCreateView.tournamentGames.isEmpty() eq false}">
<h2>#{i18n['tournaments.admin.select_a_game']}</h2> <h2>#{i18n['tournaments.admin.select_a_game']}</h2>
<h:selectOneMenu value="#{userGameIDView.gameToAddIdTo}" converter="#{tournamentGameConverter}"> <h:selectOneMenu value="#{tournamentCreateView.game}" converter="#{tournamentGameConverter}">
<f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game}" /> <f:selectItems var="game" itemLabel="#{game.name}" value="#{tournamentCreateView.tournamentGames}" itemValue="#{game}" />
</h:selectOneMenu> </h:selectOneMenu>
</h:panelGroup> </h:panelGroup>
......
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
<h:body> <h:body>
<ui:composition template="#{sessionHandler.template}"> <ui:composition template="#{sessionHandler.template}">
<f:metadata> <f:metadata>
<f:event type="preRenderView" listener="#{userView.initView}" /> <f:event type="preRenderView" listener="#{voteListView.initView}" />
</f:metadata> </f:metadata>
<ui:define name="content"> <ui:define name="content">
<h1>My entries</h1> <h1>My entries</h1>
<h:form> <h:form>
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{userView.user.compoEntries}" var="entry"> <h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{voteListView.entries}" var="entry">
<h:column> <h:column>
<f:facet name="header"> <f:facet name="header">
<h:outputText value="Title" /> <h:outputText value="Title" />
......
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
<dependency> <dependency>
<groupId>org.primefaces</groupId> <groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId> <artifactId>primefaces</artifactId>
<version>5.0.RC2</version> <version>5.0</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -9,7 +9,6 @@ import java.util.zip.CRC32; ...@@ -9,7 +9,6 @@ import java.util.zip.CRC32;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -29,8 +28,8 @@ public class ErrorPageView implements Serializable { ...@@ -29,8 +28,8 @@ public class ErrorPageView implements Serializable {
// private static final long serialVersionUID = -2179309061036632342L; // private static final long serialVersionUID = -2179309061036632342L;
String trace; String trace;
@Inject // @Inject
private transient FacesContext context; // private transient FacesContext context;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class); private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class);
...@@ -70,16 +69,11 @@ public class ErrorPageView implements Serializable { ...@@ -70,16 +69,11 @@ public class ErrorPageView implements Serializable {
} }
public String getTrail() { public String getTrail() {
HttpServletRequest req = (HttpServletRequest) getContext().getExternalContext().getRequest(); FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
Object trail = req.getSession().getAttribute(HostnameFilter.HTTP_TRAIL_NAME); Object trail = req.getSession().getAttribute(HostnameFilter.HTTP_TRAIL_NAME);
return trail != null ? trail.toString() : ""; return trail != null ? trail.toString() : "";
} }
public FacesContext getContext() {
return context;
}
public void setContext(FacesContext context) {
this.context = context;
}
} }
\ No newline at end of file
...@@ -9,7 +9,6 @@ import java.util.Map; ...@@ -9,7 +9,6 @@ import java.util.Map;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent; import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -41,9 +40,6 @@ public class MenuView { ...@@ -41,9 +40,6 @@ public class MenuView {
@Inject @Inject
private transient SessionStore sessionstore; private transient SessionStore sessionstore;
@Inject
private transient FacesContext context;
@EJB @EJB
private transient MenuBeanLocal menubean; private transient MenuBeanLocal menubean;
...@@ -63,8 +59,8 @@ public class MenuView { ...@@ -63,8 +59,8 @@ public class MenuView {
public List<PageContent> getPagecontent(String pagekey) public List<PageContent> getPagecontent(String pagekey)
{ {
String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString(); String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString();
// Removed by tkfftk, enought is enought // Removed by tkfftk, enought is enought
// logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key)); // logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key));
if (!contents.containsKey(key)) { if (!contents.containsKey(key)) {
contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale())); contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale()));
...@@ -234,10 +230,6 @@ public class MenuView { ...@@ -234,10 +230,6 @@ public class MenuView {
return ret; return ret;
} }
public void setContext(FacesContext context) {
this.context = context;
}
public LayoutView getLayoutview() { public LayoutView getLayoutview() {
return layoutview; return layoutview;
} }
......
package fi.codecrew.moya.web.cdiview.reader;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.ReaderBeanLocal;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@ConversationScoped
public class RfidListenerView extends GenericCDIView {
@EJB
private ReaderBeanLocal readerbean;
private String reader;
private String tag;
public void cardRead()
{
readerbean.checkCode(reader, tag);
}
public String getReader() {
return reader;
}
public void setReader(String reader) {
this.reader = reader;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
}
...@@ -104,7 +104,6 @@ public class TournamentCreateView extends GenericCDIView { ...@@ -104,7 +104,6 @@ public class TournamentCreateView extends GenericCDIView {
} }
tournamentRules = tournamentBean.getRulesByGame(game); tournamentRules = tournamentBean.getRulesByGame(game);
System.out.println(tournamentRules);
break; break;
case "selectRuleset": case "selectRuleset":
if (rulesetName != null && rulesetName.length() > 0) { if (rulesetName != null && rulesetName.length() > 0) {
......
package fi.codecrew.moya.web.cdiview.voting;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import fi.codecrew.moya.beans.VotingBeanLocal;
import fi.codecrew.moya.enums.apps.CompoPermission;
import fi.codecrew.moya.model.CompoEntry;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
@Named
@RequestScoped
public class VoteListView extends GenericCDIView {
private static final long serialVersionUID = 4166316634472472472L;
@EJB
private VotingBeanLocal votebean;
private List<CompoEntry> entries;
public void initView()
{
if (super.requirePermissions(CompoPermission.SUBMIT_ENTRY))
setEntries(votebean.getEntriesForCurrentUser());
}
public List<CompoEntry> getEntries() {
return entries;
}
public void setEntries(List<CompoEntry> entries) {
this.entries = entries;
}
}
...@@ -38,8 +38,6 @@ public class LayoutView implements Serializable { ...@@ -38,8 +38,6 @@ public class LayoutView implements Serializable {
* *
*/ */
private static final long serialVersionUID = 4468645109141859301L; private static final long serialVersionUID = 4468645109141859301L;
@Inject
private FacesContext context;
private ResourceBundle rb; private ResourceBundle rb;
private String pagename; private String pagename;
@EJB @EJB
...@@ -106,6 +104,7 @@ public class LayoutView implements Serializable { ...@@ -106,6 +104,7 @@ public class LayoutView implements Serializable {
} }
public String getPagepath() { public String getPagepath() {
FacesContext context = FacesContext.getCurrentInstance();
if (pagename == null && if (pagename == null &&
context != null && context != null &&
context.getExternalContext() != null && context.getExternalContext() != null &&
...@@ -140,6 +139,8 @@ public class LayoutView implements Serializable { ...@@ -140,6 +139,8 @@ public class LayoutView implements Serializable {
} }
private ResourceBundle getResourcebundle() { private ResourceBundle getResourcebundle() {
FacesContext context = FacesContext.getCurrentInstance();
if (rb == null) { if (rb == null) {
rb = context.getApplication().getResourceBundle(context, "i18n"); rb = context.getApplication().getResourceBundle(context, "i18n");
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!