Commit 8a452fa5 by Tuukka Kivilahti

Merge branch 'commenting' into 'master'

Add some comments - and minor changes

Add some comments to functions.

Also some minor changes and updates.

Kattoi @tkfftk
2 parents 8557d61a 661ab5f3
...@@ -8,3 +8,4 @@ ...@@ -8,3 +8,4 @@
.metadata .metadata
/code/*/target/ /code/*/target/
/code/*/test-output/ /code/*/test-output/
moya-git.properties
...@@ -2,7 +2,6 @@ package fi.codecrew.moya.beans; ...@@ -2,7 +2,6 @@ package fi.codecrew.moya.beans;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.annotation.security.DeclareRoles; import javax.annotation.security.DeclareRoles;
...@@ -10,13 +9,10 @@ import javax.annotation.security.RolesAllowed; ...@@ -10,13 +9,10 @@ import javax.annotation.security.RolesAllowed;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.ejb.Stateless; import javax.ejb.Stateless;
import fi.codecrew.moya.facade.ActionLogFacade;
import fi.codecrew.moya.facade.ActionLogMessageTagFacade;
import fi.codecrew.moya.beans.ActionLogBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.RoleBeanLocal;
import fi.codecrew.moya.enums.ActionLogMessageState; import fi.codecrew.moya.enums.ActionLogMessageState;
import fi.codecrew.moya.enums.apps.ContentPermission; import fi.codecrew.moya.enums.apps.ContentPermission;
import fi.codecrew.moya.facade.ActionLogFacade;
import fi.codecrew.moya.facade.ActionLogMessageTagFacade;
import fi.codecrew.moya.model.ActionLogMessage; import fi.codecrew.moya.model.ActionLogMessage;
import fi.codecrew.moya.model.ActionLogMessageResponse; import fi.codecrew.moya.model.ActionLogMessageResponse;
import fi.codecrew.moya.model.ActionLogMessageTag; import fi.codecrew.moya.model.ActionLogMessageTag;
...@@ -39,10 +35,10 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -39,10 +35,10 @@ public class ActionLogBean implements ActionLogBeanLocal {
@EJB @EJB
private PermissionBeanLocal permissionBean; private PermissionBeanLocal permissionBean;
@EJB @EJB
private ActionLogMessageTagFacade actionLogMessageTagFacade; private ActionLogMessageTagFacade actionLogMessageTagFacade;
@EJB @EJB
private EventBean eventBean; private EventBean eventBean;
...@@ -54,7 +50,7 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -54,7 +50,7 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public void createActionLogEvent(String message, boolean isTask) { public void createActionLogEvent(String message, boolean isTask) {
ArrayList<ActionLogMessageTag> almts = resolveTags(message); ArrayList<ActionLogMessageTag> almts = resolveTags(message);
ActionLogMessage alm = new ActionLogMessage(); ActionLogMessage alm = new ActionLogMessage();
if (isTask) { if (isTask) {
alm.setState(ActionLogMessageState.NEW); alm.setState(ActionLogMessageState.NEW);
...@@ -66,7 +62,7 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -66,7 +62,7 @@ public class ActionLogBean implements ActionLogBeanLocal {
alm.setUser(permissionBean.getCurrentUser()); alm.setUser(permissionBean.getCurrentUser());
alm.setLanEvent(permissionBean.getCurrentUser().getEvent()); alm.setLanEvent(permissionBean.getCurrentUser().getEvent());
alm.setTags(almts); alm.setTags(almts);
actionLogFacade.saveToActionLog(alm); actionLogFacade.saveToActionLog(alm);
} }
...@@ -75,11 +71,11 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -75,11 +71,11 @@ public class ActionLogBean implements ActionLogBeanLocal {
public List<ActionLogMessage> getAllActionLogEvents() { public List<ActionLogMessage> getAllActionLogEvents() {
return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent()); return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent());
} }
@Override @Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<ActionLogMessage> getAllActionLogEventsByFilter(List<ActionLogMessageTag> filterTags) { public List<ActionLogMessage> getAllActionLogEventsByFilter(List<ActionLogMessageTag> filterTags) {
if(filterTags.size() == 0) if (filterTags.size() == 0)
return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent()); return actionLogFacade.getAllSortedByTimestamp(permissionBean.getCurrentUser().getEvent());
else else
return actionLogFacade.getAllSortedByTimestampFiltered(permissionBean.getCurrentUser().getEvent(), filterTags); return actionLogFacade.getAllSortedByTimestampFiltered(permissionBean.getCurrentUser().getEvent(), filterTags);
...@@ -92,10 +88,11 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -92,10 +88,11 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<ActionLogMessageResponse> getActionLogMessageResponses(ActionLogMessage alm) { public List<ActionLogMessageResponse> getActionLogMessageResponses(ActionLogMessage alm) {
if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null; if (!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent()))
return null;
return actionLogFacade.getActionLogMessageResponses(alm); return actionLogFacade.getActionLogMessageResponses(alm);
} }
@Override @Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public List<ActionLogMessageTag> getAllTags() { public List<ActionLogMessageTag> getAllTags() {
...@@ -104,8 +101,9 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -104,8 +101,9 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state) { public void addActionLogMessageResponse(ActionLogMessage alm, String message, ActionLogMessageState state) {
if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return; if (!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent()))
return;
if (alm.getState() != state && state != null) { if (alm.getState() != state && state != null) {
alm = actionLogFacade.merge(alm); alm = actionLogFacade.merge(alm);
alm.setState(state); alm.setState(state);
...@@ -124,67 +122,68 @@ public class ActionLogBean implements ActionLogBeanLocal { ...@@ -124,67 +122,68 @@ public class ActionLogBean implements ActionLogBeanLocal {
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public ActionLogMessage find(Integer id) { public ActionLogMessage find(Integer id) {
ActionLogMessage alm = actionLogFacade.find(id); ActionLogMessage alm = actionLogFacade.find(id);
if(!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent())) return null; if (!alm.getLanEvent().equals(permissionBean.getCurrentUser().getEvent()))
else return alm; return null;
else
return alm;
} }
private ArrayList<ActionLogMessageTag> resolveTags(String message) { private ArrayList<ActionLogMessageTag> resolveTags(String message) {
ArrayList<ActionLogMessageTag> almts = new ArrayList<>(); ArrayList<ActionLogMessageTag> almts = new ArrayList<>();
StringBuilder sb = null; StringBuilder sb = null;
boolean rflag = false; boolean rflag = false;
char ch; char ch;
for(int i=0; i < message.length(); i++) { for (int i = 0; i < message.length(); i++) {
if(rflag) { if (rflag) {
if((ch = message.charAt(i)) != ' ') { if ((ch = message.charAt(i)) != ' ') {
sb.append(ch); sb.append(ch);
} else { } else {
if(sb.length() > 0) { if (sb.length() > 0) {
ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString()); ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString());
if(!almts.contains(almt)) { if (!almts.contains(almt)) {
almts.add(almt); almts.add(almt);
} }
} }
rflag = false; rflag = false;
sb = null; sb = null;
} }
} else if(!rflag) { } else if (!rflag) {
if(message.charAt(i) == '#') { if (message.charAt(i) == '#') {
rflag=true; rflag = true;
sb=new StringBuilder(); sb = new StringBuilder();
} }
} }
} }
if(sb != null && sb.length() > 0) { if (sb != null && sb.length() > 0) {
ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString()); ActionLogMessageTag almt = getActionLogMessageTagByString(sb.toString());
if(!almts.contains(almt)) { if (!almts.contains(almt)) {
almts.add(almt); almts.add(almt);
} }
} }
return almts; return almts;
} }
@Override @Override
@RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG) @RolesAllowed(ContentPermission.S_MANAGE_ACTIONLOG)
public ActionLogMessageTag getActionLogMessageTagByString(String s) { public ActionLogMessageTag getActionLogMessageTagByString(String s) {
s = s.toLowerCase(); s = s.toLowerCase();
ActionLogMessageTag almt = null; ActionLogMessageTag almt = null;
if((almt = actionLogMessageTagFacade.findByTagStringInEvent(s, eventBean.getCurrentEvent())) == null) { if ((almt = actionLogMessageTagFacade.findByTagStringInEvent(s, eventBean.getCurrentEvent())) == null) {
almt = new ActionLogMessageTag(); almt = new ActionLogMessageTag();
almt.setEvent(eventBean.getCurrentEvent()); almt.setEvent(eventBean.getCurrentEvent());
almt.setTag(s); almt.setTag(s);
almt = actionLogMessageTagFacade.create(almt); actionLogMessageTagFacade.create(almt);
System.out.println("creating tag: "+s); System.out.println("creating tag: " + s);
return almt; return almt;
} else { } else {
System.out.println("re-using tag: "+s); System.out.println("re-using tag: " + s);
return almt; return almt;
} }
} }
} }
\ No newline at end of file
...@@ -87,7 +87,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal { ...@@ -87,7 +87,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@EJB @EJB
private CardObjectDataFacade codFacade; private CardObjectDataFacade codFacade;
@EJB @EJB
private CardCodeFacade cardCodeFacade; private CardCodeFacade cardCodeFacade;
...@@ -274,18 +274,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal { ...@@ -274,18 +274,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override @Override
public CardTextData save(CardTextData textData) { public CardTextData save(CardTextData textData) {
if (textData.getId() != null && textData.getId() != 0) if (textData.getId() != null && textData.getId() != 0)
return ctdFacade.merge(textData); textData = ctdFacade.merge(textData);
else else
return ctdFacade.create(textData); ctdFacade.create(textData);
return textData;
} }
@RolesAllowed(UserPermission.S_WRITE_ROLES) @RolesAllowed(UserPermission.S_WRITE_ROLES)
@Override @Override
public CardObjectData save(CardObjectData objectData) { public CardObjectData save(CardObjectData objectData) {
if (objectData.getId() != null && objectData.getId() != 0) if (objectData.getId() != null && objectData.getId() != 0)
return codFacade.merge(objectData); objectData = codFacade.merge(objectData);
else else
return codFacade.create(objectData); codFacade.create(objectData);
return objectData;
} }
@Override @Override
...@@ -375,7 +377,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal { ...@@ -375,7 +377,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
card.setCardState(CardState.DELIVERED); card.setCardState(CardState.DELIVERED);
} else { } else {
logger.info("Not marking card to delivered: " + card.getCardState() + " : " + card.getId()); logger.info("Not marking card to delivered: " + card.getCardState() + " : " + card.getId());
} }
if (markUserPlacesDelivered) { if (markUserPlacesDelivered) {
for (GroupMembership membership : gmFacade.findMemberships(user)) { for (GroupMembership membership : gmFacade.findMemberships(user)) {
......
...@@ -35,6 +35,9 @@ import fi.codecrew.moya.model.MenuNavigation; ...@@ -35,6 +35,9 @@ import fi.codecrew.moya.model.MenuNavigation;
/** /**
* *
* HUOM! JOS POISTAT SIVUN, PITÄÄ VIITTAUS POISTAA MYÖS KANNASTA! MUUTEN
* GALAKSIT RÄJÄHTÄÄ! (jsf ei löydä viittausta sivuun ja heittää poikkeuksen)
*
* Kaikki sivut pitää olla jossain menussa, muuten menu häviää näkyvistä ko. * Kaikki sivut pitää olla jossain menussa, muuten menu häviää näkyvistä ko.
* sivulla kokonaan. Älä siis poista sivua vaaan aseta sivu näkymättömäksi: * sivulla kokonaan. Älä siis poista sivua vaaan aseta sivu näkymättömäksi:
* .setVisible(false). * .setVisible(false).
...@@ -154,7 +157,6 @@ public class MenuBean implements MenuBeanLocal { ...@@ -154,7 +157,6 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation createuser = usermenu.addPage(null, null); MenuNavigation createuser = usermenu.addPage(null, null);
createuser.setKey("topnavi.createuser"); createuser.setKey("topnavi.createuser");
createuser.addPage(menuitemfacade.findOrCreate("/user/create"), UserPermission.CREATE_NEW).setVisible(false); createuser.addPage(menuitemfacade.findOrCreate("/user/create"), UserPermission.CREATE_NEW).setVisible(false);
;
navifacade.create(usermenu); navifacade.create(usermenu);
...@@ -168,7 +170,8 @@ public class MenuBean implements MenuBeanLocal { ...@@ -168,7 +170,8 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation adminuser = adminmenu.addPage(null, null); MenuNavigation adminuser = adminmenu.addPage(null, null);
adminuser.setKey("topnavi.usermgmt"); adminuser.setKey("topnavi.usermgmt");
adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/list"), UserPermission.VIEW_ALL); adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/list"), UserPermission.VIEW_ALL);
adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/overview"), UserPermission.VIEW_ALL).setVisible(false);; adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/overview"), UserPermission.VIEW_ALL).setVisible(false);
adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/create"), UserPermission.VIEW_ALL); adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/create"), UserPermission.VIEW_ALL);
adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/sendPicture"), UserPermission.VIEW_ALL).setVisible(false); adminuser.addPage(menuitemfacade.findOrCreate("/useradmin/sendPicture"), UserPermission.VIEW_ALL).setVisible(false);
adminuser.addPage(menuitemfacade.findOrCreate("/place/adminGroups"), UserPermission.VIEW_ALL).setVisible(false); adminuser.addPage(menuitemfacade.findOrCreate("/place/adminGroups"), UserPermission.VIEW_ALL).setVisible(false);
...@@ -202,7 +205,7 @@ public class MenuBean implements MenuBeanLocal { ...@@ -202,7 +205,7 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation adminAssociation = adminmenu.addPage(null, null); MenuNavigation adminAssociation = adminmenu.addPage(null, null);
adminAssociation.setKey("topnavi.adminassoc"); adminAssociation.setKey("topnavi.adminassoc");
adminAssociation.addPage(menuitemfacade.findOrCreate("/networkassociation/index"), NetworkAssociationPermission.CAN_ADMINISTER_ASSOCIATIONS); adminAssociation.addPage(menuitemfacade.findOrCreate("/networkassociation/index"), NetworkAssociationPermission.CAN_ADMINISTER_ASSOCIATIONS);
// shop // shop
MenuNavigation adminshop = adminmenu.addPage(null, null); MenuNavigation adminshop = adminmenu.addPage(null, null);
adminshop.setKey("topnavi.adminshop"); adminshop.setKey("topnavi.adminshop");
......
...@@ -164,7 +164,7 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -164,7 +164,7 @@ public class ReaderBean implements ReaderBeanLocal {
} }
} }
event = readerEventFacade.create(event); readerEventFacade.create(event);
return event; return event;
...@@ -173,11 +173,9 @@ public class ReaderBean implements ReaderBeanLocal { ...@@ -173,11 +173,9 @@ public class ReaderBean implements ReaderBeanLocal {
@Override @Override
public ReaderEvent assocCodeToCard(ReaderEvent readerEvent, PrintedCard card) { public ReaderEvent assocCodeToCard(ReaderEvent readerEvent, PrintedCard card) {
card = cardfacade.reload(card); CardCode code = new CardCode(card, readerEvent.getReader().getType(), readerEvent.getValue());
CardCode code = new CardCode(card, readerEvent.getReader().getType(), readerEvent.getValue(), eventbean.getCurrentEvent());
code = cardCodeFacade.create(code); cardCodeFacade.create(code);
card.getCardCodes().add(code);
return readerEvent; return readerEvent;
} }
......
...@@ -70,13 +70,15 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -70,13 +70,15 @@ public class TournamentBean implements TournamentBeanLocal {
@Override @Override
@RolesAllowed(TournamentPermission.S_MANAGE_ALL) @RolesAllowed(TournamentPermission.S_MANAGE_ALL)
public TournamentGame createGame(TournamentGame tg) { public TournamentGame createGame(TournamentGame tg) {
return tournamentGameFacade.create(tg); tournamentGameFacade.create(tg);
return tg;
} }
@Override @Override
@RolesAllowed(TournamentPermission.S_MANAGE_ALL) @RolesAllowed(TournamentPermission.S_MANAGE_ALL)
public TournamentRule createRule(TournamentRule tr) { public TournamentRule createRule(TournamentRule tr) {
return tournamentRuleFacade.create(tr); tournamentRuleFacade.create(tr);
return tr;
} }
@Override @Override
...@@ -100,12 +102,12 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -100,12 +102,12 @@ public class TournamentBean implements TournamentBeanLocal {
else else
throw new Exception("tournament.invalid_event"); throw new Exception("tournament.invalid_event");
} }
@Override @Override
@RolesAllowed(TournamentPermission.S_MANAGE_ALL) @RolesAllowed(TournamentPermission.S_MANAGE_ALL)
public void updateTournamentRules(TournamentRule tr) throws Exception { public void updateTournamentRules(TournamentRule tr) throws Exception {
// Assert correct event // Assert correct event
if(eventBean.getCurrentEvent().equals(tr.getTournamentGame().getLanEvent())) { if (eventBean.getCurrentEvent().equals(tr.getTournamentGame().getLanEvent())) {
tournamentRuleFacade.merge(tr); tournamentRuleFacade.merge(tr);
} else { } else {
throw new Exception("tournament.invalid_event"); throw new Exception("tournament.invalid_event");
...@@ -115,8 +117,8 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -115,8 +117,8 @@ public class TournamentBean implements TournamentBeanLocal {
@Override @Override
@RolesAllowed(TournamentPermission.S_VIEW) @RolesAllowed(TournamentPermission.S_VIEW)
public List<Tournament> getTournamentsInStatus(TournamentStatus status, boolean useTimeConstraints, boolean invertMatch) { public List<Tournament> getTournamentsInStatus(TournamentStatus status, boolean useTimeConstraints, boolean invertMatch) {
if(useTimeConstraints) if (useTimeConstraints)
if(!invertMatch) if (!invertMatch)
return tournamentFacade.getTournamentsInStatusWithParticipationTimeIn(status, eventBean.getCurrentEvent()); return tournamentFacade.getTournamentsInStatusWithParticipationTimeIn(status, eventBean.getCurrentEvent());
else else
return tournamentFacade.getTournamentsInStatusWithParticipationTimeNotIn(status, eventBean.getCurrentEvent()); return tournamentFacade.getTournamentsInStatusWithParticipationTimeNotIn(status, eventBean.getCurrentEvent());
...@@ -170,7 +172,7 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -170,7 +172,7 @@ public class TournamentBean implements TournamentBeanLocal {
// Assert team has the correct number of players for a match // Assert team has the correct number of players for a match
if (tournamentParticipant.getTeamMembers().size() >= tournamentParticipant.getTournament().getPlayersPerMatch()) { if (tournamentParticipant.getTeamMembers().size() >= tournamentParticipant.getTournament().getPlayersPerMatch()) {
tournamentParticipant = tournamentParticipantFacade.create(tournamentParticipant); tournamentParticipantFacade.create(tournamentParticipant);
t.getParticipants().add(tournamentParticipant); t.getParticipants().add(tournamentParticipant);
} else { } else {
throw new Exception("tournament.not_enough_players"); throw new Exception("tournament.not_enough_players");
...@@ -206,10 +208,10 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -206,10 +208,10 @@ public class TournamentBean implements TournamentBeanLocal {
@RolesAllowed(TournamentPermission.S_VIEW) @RolesAllowed(TournamentPermission.S_VIEW)
public List<TournamentParticipant> findOwnParticipations() { public List<TournamentParticipant> findOwnParticipations() {
EventUser currentUser = permissionBean.getCurrentUser(); EventUser currentUser = permissionBean.getCurrentUser();
return tournamentParticipantFacade.findByParticipator(currentUser); return tournamentParticipantFacade.findByParticipator(currentUser);
} }
@Override @Override
@RolesAllowed(TournamentPermission.S_VIEW) @RolesAllowed(TournamentPermission.S_VIEW)
public EventUser findAvailablePlayerForTournamentByLogin(Tournament t, String login) throws Exception { public EventUser findAvailablePlayerForTournamentByLogin(Tournament t, String login) throws Exception {
...@@ -230,27 +232,27 @@ public class TournamentBean implements TournamentBeanLocal { ...@@ -230,27 +232,27 @@ public class TournamentBean implements TournamentBeanLocal {
public void deleteParticipationById(Integer tpid) throws Exception { public void deleteParticipationById(Integer tpid) throws Exception {
TournamentParticipant tp = tournamentParticipantFacade.find(tpid); TournamentParticipant tp = tournamentParticipantFacade.find(tpid);
EventUser executor = permissionBean.getCurrentUser(); EventUser executor = permissionBean.getCurrentUser();
// Assert we have permission to remove participant // Assert we have permission to remove participant
// TODO: this will include check for remove any participation too! // TODO: this will include check for remove any participation too!
if(!permissionBean.hasPermission(TournamentPermission.REMOVE_OWN_PARTICIPATION) || !tp.getParticipator().equals(executor)) { if (!permissionBean.hasPermission(TournamentPermission.REMOVE_OWN_PARTICIPATION) || !tp.getParticipator().equals(executor)) {
throw new Exception("tournaments.can_only_remove_own_participations"); throw new Exception("tournaments.can_only_remove_own_participations");
} }
// Assert that tournament has not closed participation // Assert that tournament has not closed participation
// TODO: admin exception! // TODO: admin exception!
if(!tp.getTournament().getRegistrationClosesAt().after(new Date())) { if (!tp.getTournament().getRegistrationClosesAt().after(new Date())) {
throw new Exception("tournaments.cannot_remove_participation_from_closed_tournament"); throw new Exception("tournaments.cannot_remove_participation_from_closed_tournament");
} }
// All ok, do nukage // All ok, do nukage
for(TournamentTeamMember ttm : tp.getTeamMembers()) { for (TournamentTeamMember ttm : tp.getTeamMembers()) {
tournamentTeamMemberFacade.remove(ttm); tournamentTeamMemberFacade.remove(ttm);
} }
// Let's not leave anything in cache :) // Let's not leave anything in cache :)
tp.getTournament().getParticipants().remove(tp); tp.getTournament().getParticipants().remove(tp);
tournamentParticipantFacade.remove(tp); tournamentParticipantFacade.remove(tp);
} }
} }
...@@ -155,7 +155,7 @@ public class UserBean implements UserBeanLocal { ...@@ -155,7 +155,7 @@ public class UserBean implements UserBeanLocal {
private EventFacade eventfacade; private EventFacade eventfacade;
@EJB @EJB
private ProductFacade productFacade; private ProductFacade productFacade;
@Override @Override
@RolesAllowed(UserPermission.S_VIEW_ALL) @RolesAllowed(UserPermission.S_VIEW_ALL)
...@@ -339,12 +339,12 @@ public class UserBean implements UserBeanLocal { ...@@ -339,12 +339,12 @@ public class UserBean implements UserBeanLocal {
int sourceCenterY = sourceHeight / 2; int sourceCenterY = sourceHeight / 2;
int sourceTop, sourceLeft, sourceRight, sourceBottom; int sourceTop, sourceLeft, sourceRight, sourceBottom;
double sourceRatio = (double)sourceWidth / (double)sourceHeight; double sourceRatio = (double) sourceWidth / (double) sourceHeight;
if (sourceRatio > targetRatio) { if (sourceRatio > targetRatio) {
// the pic is too wide - reduce width // the pic is too wide - reduce width
targetWidth = (int)((double)sourceHeight * targetRatio); targetWidth = (int) ((double) sourceHeight * targetRatio);
targetHeight = sourceHeight; targetHeight = sourceHeight;
// crop box coords - calculate left and right // crop box coords - calculate left and right
sourceLeft = sourceCenterX - (targetWidth / 2); sourceLeft = sourceCenterX - (targetWidth / 2);
sourceTop = 0; sourceTop = 0;
...@@ -353,15 +353,15 @@ public class UserBean implements UserBeanLocal { ...@@ -353,15 +353,15 @@ public class UserBean implements UserBeanLocal {
} else { } else {
// the pic is too tall - reduce height // the pic is too tall - reduce height
targetWidth = sourceWidth; targetWidth = sourceWidth;
targetHeight = (int)((double)sourceWidth / targetRatio); targetHeight = (int) ((double) sourceWidth / targetRatio);
// crop box coords - calculate top and bottom // crop box coords - calculate top and bottom
sourceLeft = 0; sourceLeft = 0;
sourceTop = sourceCenterY - (targetHeight / 2); sourceTop = sourceCenterY - (targetHeight / 2);
sourceRight = sourceWidth; sourceRight = sourceWidth;
sourceBottom = sourceCenterY + (targetHeight / 2); sourceBottom = sourceCenterY + (targetHeight / 2);
} }
BufferedImage cropped = new BufferedImage(targetWidth, targetHeight, source.getType()); BufferedImage cropped = new BufferedImage(targetWidth, targetHeight, source.getType());
Graphics2D g = cropped.createGraphics(); Graphics2D g = cropped.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
...@@ -477,37 +477,37 @@ public class UserBean implements UserBeanLocal { ...@@ -477,37 +477,37 @@ public class UserBean implements UserBeanLocal {
} }
public PrintedCard rejectPrintedCard(PrintedCard card, MailMessage mail) { public PrintedCard rejectPrintedCard(PrintedCard card, MailMessage mail) {
if(card != null) { if (card != null) {
card.setCardState(CardState.REJECTED); card.setCardState(CardState.REJECTED);
card = printedcardfacade.merge(card); card = printedcardfacade.merge(card);
logger.info("rejectPrintedCard(): Rejected card {}, state {}", card, card.getCardState() ); logger.info("rejectPrintedCard(): Rejected card {}, state {}", card, card.getCardState());
User user = null; User user = null;
if(card.getUser() != null && card.getUser().getUser() != null) if (card.getUser() != null && card.getUser().getUser() != null)
user = card.getUser().getUser(); user = card.getUser().getUser();
LanEvent event = card.getEvent(); LanEvent event = card.getEvent();
if(mail != null) { if (mail != null) {
if(!utilbean.sendMail(mail)) { if (!utilbean.sendMail(mail)) {
logger.info("Sending mail failed"); logger.info("Sending mail failed");
} else } else
logger.info("Sending mail succeeded"); logger.info("Sending mail succeeded");
} else { } else {
if(user == null) if (user == null)
logger.info("user is null"); logger.info("user is null");
if(event == null) if (event == null)
logger.info("event is null"); logger.info("event is null");
} }
} }
logger.info("returning card"); logger.info("returning card");
return card; return card;
} }
// @Override // @Override
// @RolesAllowed(UserPermission.S_VIEW_ALL) // @RolesAllowed(UserPermission.S_VIEW_ALL)
// public User findById(Integer id) { // public User findById(Integer id) {
...@@ -663,7 +663,7 @@ public class UserBean implements UserBeanLocal { ...@@ -663,7 +663,7 @@ public class UserBean implements UserBeanLocal {
gid.setGame(game); gid.setGame(game);
gid.setUser(u); gid.setUser(u);
gid = gameIDFacade.create(gid); gameIDFacade.create(gid);
u.getGameIDs().add(gid); u.getGameIDs().add(gid);
} }
...@@ -942,28 +942,29 @@ public class UserBean implements UserBeanLocal { ...@@ -942,28 +942,29 @@ public class UserBean implements UserBeanLocal {
return eventUserFacade.getOtherOrganisationsEventuser(user, event); return eventUserFacade.getOtherOrganisationsEventuser(user, event);
} }
@Override @Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT) @RolesAllowed(EventPermission.S_MANAGE_EVENT)
public String getAuthCode(EventUser user) { public String getAuthCode(EventUser user) {
logger.info("getAuthCode()"); logger.info("getAuthCode()");
String code = ""; String code = "";
String hex = Integer.toHexString(user.getId()); String hex = Integer.toHexString(user.getId());
logger.info("Hex code {} for id {}", hex, user.getId()); logger.info("Hex code {} for id {}", hex, user.getId());
//padding hex string to 5 characters by adding Xs to the beginning // padding hex string to 5 characters by adding Xs to the beginning
if(hex.length() < 5) { if (hex.length() < 5) {
logger.info("Padding hex ({}) with X.", hex.length()); logger.info("Padding hex ({}) with X.", hex.length());
for(int i = 0; i < 5; i++) { for (int i = 0; i < 5; i++) {
if(hex.length() < 5) { if (hex.length() < 5) {
hex = "X" + hex; hex = "X" + hex;
} }
else break; else
break;
} }
} else } else
logger.info("Hex string too long ({}), no padding needed", hex.length()); logger.info("Hex string too long ({}), no padding needed", hex.length());
String hash = ""; String hash = "";
logger.info("Generating md5 hash from hex {}", hex); logger.info("Generating md5 hash from hex {}", hex);
try { try {
...@@ -971,63 +972,64 @@ public class UserBean implements UserBeanLocal { ...@@ -971,63 +972,64 @@ public class UserBean implements UserBeanLocal {
byte[] array = md.digest(hex.getBytes()); byte[] array = md.digest(hex.getBytes());
hash = new String(Hex.encodeHex(array)); hash = new String(Hex.encodeHex(array));
logger.info("Hash {}", hash); logger.info("Hash {}", hash);
}catch(NoSuchAlgorithmException ex) { } catch (NoSuchAlgorithmException ex) {
logger.info("Catched exeption {}", ex.getMessage()); logger.info("Catched exeption {}", ex.getMessage());
} }
if(hash != "" && hash.length() > 2) { if (hash != "" && hash.length() > 2) {
//Generating code by concatenating hex string and first 3 characters from hash // Generating code by concatenating hex string and first 3
// characters from hash
code = code.concat(hex); code = code.concat(hex);
code = code.concat(hash.substring(0, 3)); code = code.concat(hash.substring(0, 3));
logger.info("Code for user is {}", code); logger.info("Code for user is {}", code);
}else } else
logger.info("No code generated: hash.length() {}", hash.length()); logger.info("No code generated: hash.length() {}", hash.length());
return code.toUpperCase(); return code.toUpperCase();
} }
@Override @Override
@RolesAllowed(EventPermission.S_MANAGE_EVENT) @RolesAllowed(EventPermission.S_MANAGE_EVENT)
public EventUser getUser(String authcode) { public EventUser getUser(String authcode) {
logger.info("getUser({})", authcode); logger.info("getUser({})", authcode);
EventUser user = null; EventUser user = null;
if(authcode.length() == 8) { if (authcode.length() == 8) {
logger.info("authcode length is 8"); logger.info("authcode length is 8");
// First 5 characters are the hex // First 5 characters are the hex
String paddedHex = authcode.substring(0, 5); String paddedHex = authcode.substring(0, 5);
logger.info("Padded hex {}", paddedHex); logger.info("Padded hex {}", paddedHex);
// Removing the padding characters // Removing the padding characters
String hex = paddedHex.replace("X", ""); String hex = paddedHex.replace("X", "");
logger.info("Hex {}", hex); logger.info("Hex {}", hex);
int id = 0; int id = 0;
try { try {
id = Integer.decode("0x"+ hex.toLowerCase()); id = Integer.decode("0x" + hex.toLowerCase());
}catch(NumberFormatException ex) { } catch (NumberFormatException ex) {
logger.info("NumberFormatException was thrown"); logger.info("NumberFormatException was thrown");
} }
logger.info("Id {}", id); logger.info("Id {}", id);
if(id != 0) { if (id != 0) {
user = eventUserFacade.find(id); user = eventUserFacade.find(id);
} }
if(user != null) { if (user != null) {
// Testing if the user is correct // Testing if the user is correct
logger.info("User {} found with id {}", user, id); logger.info("User {} found with id {}", user, id);
String testCode = getAuthCode(user); String testCode = getAuthCode(user);
logger.info("Testcode {}", testCode); logger.info("Testcode {}", testCode);
if(testCode == null || testCode.equals("") || !authcode.equals(testCode)) { if (testCode == null || testCode.equals("") || !authcode.equals(testCode)) {
user = null; user = null;
logger.info("User set to null, test code not the same as user that was found."); logger.info("User set to null, test code not the same as user that was found.");
} }
} else } else
logger.info("User not found with id {}", id); logger.info("User not found with id {}", id);
}else } else
logger.info("authcode length not 8!, length {}", authcode.length()); logger.info("authcode length not 8!, length {}", authcode.length());
return user; return user;
} }
......
...@@ -89,12 +89,6 @@ public class UserFacade extends IntegerPkGenericFacade<User> { ...@@ -89,12 +89,6 @@ public class UserFacade extends IntegerPkGenericFacade<User> {
// } // }
@Override @Override
public User create(User user) {
user.setLogin(user.getLogin().toLowerCase().trim());
return super.create(user);
}
@Override
public User merge(User user) { public User merge(User user) {
user.setLogin(user.getLogin().toLowerCase().trim()); user.setLogin(user.getLogin().toLowerCase().trim());
return super.merge(user); return super.merge(user);
......
...@@ -5,9 +5,31 @@ ...@@ -5,9 +5,31 @@
<artifactId>moya-utils</artifactId> <artifactId>moya-utils</artifactId>
<version>0.2.0</version> <version>0.2.0</version>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.1.10</version>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- this is false by default, forces the plugin to generate the git.properties
file -->
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<!-- The path for the to be generated properties file, it's relative
to ${project.basedir} -->
<generateGitPropertiesFilename>src/main/java/moya-git.properties</generateGitPropertiesFilename>
<dotGitDirectory>${project.basedir}/../../.git</dotGitDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version> <version>3.1</version>
<configuration> <configuration>
......
package fi.codecrew.moya.utilities;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class GitRepositoryState {
private static GitRepositoryState gitRepositoryState;
public static GitRepositoryState getGitRepositoryState() throws IOException
{
if (gitRepositoryState == null) {
gitRepositoryState = new GitRepositoryState();
}
return gitRepositoryState;
}
private final String branch;
private final String describe;
private final String describeShort;
private final String commitId;
private final String buildUserName;
private final String buildUserEmail;
private final String buildTime;
private final String commitUserName;
private final String commitUserEmail;
private final String commitMessageShort;
private final String commitMessageFull;
private final String commitTime;
private GitRepositoryState() throws IOException
{
InputStream resource = getClass().getClassLoader().getResourceAsStream("moya-git.properties");
if (resource == null)
{
throw new IOException("ResourceFile not found");
}
Properties properties = new Properties();
properties.load(resource);
this.branch = properties.get("git.branch").toString();
this.describe = properties.get("git.commit.id.describe").toString();
this.describeShort = properties.get("git.commit.id.describe-short").toString();
this.commitId = properties.get("git.commit.id").toString();
this.buildUserName = properties.get("git.build.user.name").toString();
this.buildUserEmail = properties.get("git.build.user.email").toString();
this.buildTime = properties.get("git.build.time").toString();
this.commitUserName = properties.get("git.commit.user.name").toString();
this.commitUserEmail = properties.get("git.commit.user.email").toString();
this.commitMessageShort = properties.get("git.commit.message.short").toString();
this.commitMessageFull = properties.get("git.commit.message.full").toString();
this.commitTime = properties.get("git.commit.time").toString();
}
public String getBranch() {
return branch;
}
public String getDescribe() {
return describe;
}
public String getDescribeShort() {
return describeShort;
}
public String getCommitId() {
return commitId;
}
public String getBuildUserName() {
return buildUserName;
}
public String getBuildUserEmail() {
return buildUserEmail;
}
public String getBuildTime() {
return buildTime;
}
public String getCommitUserName() {
return commitUserName;
}
public String getCommitUserEmail() {
return commitUserEmail;
}
public String getCommitMessageShort() {
return commitMessageShort;
}
public String getCommitMessageFull() {
return commitMessageFull;
}
public String getCommitTime() {
return commitTime;
}
}
...@@ -38,10 +38,19 @@ public abstract class GenericFacade<C extends ModelInterface> { ...@@ -38,10 +38,19 @@ public abstract class GenericFacade<C extends ModelInterface> {
protected abstract EntityManager getEm(); protected abstract EntityManager getEm();
public C create(C entity) { /*
* This function does not need to return the persisted entity. All changes are made to the parameter.
*
*/
/**
* Persists the entity into database. After calling this function the entity
* is attached and all changes are persisted to database
*
* @param entity
* Entity to be created and attached to database.
*/
public void create(C entity) {
getEm().persist(entity); getEm().persist(entity);
return entity;
} }
public void remove(C entity) { public void remove(C entity) {
...@@ -49,11 +58,28 @@ public abstract class GenericFacade<C extends ModelInterface> { ...@@ -49,11 +58,28 @@ public abstract class GenericFacade<C extends ModelInterface> {
getEm().remove(entity); getEm().remove(entity);
} }
/**
* Merge changes from a detached entity to the database.
*
* This function does nothing if entity is already attached.
*
* @param entity
* Detached entity to be merged into database
* @return Attached entity with changes merged
*/
public C merge(C entity) { public C merge(C entity) {
return getEm().merge(entity); return getEm().merge(entity);
} }
/**
* Refresh the state of the instance from the database, overwriting changes
* made to the entity, if any.
*
* ENTITY MUST BE ATTACHED!
*
* @param entity
*/
public void refresh(C entity) { public void refresh(C entity) {
getEm().refresh(entity); getEm().refresh(entity);
} }
...@@ -282,14 +308,31 @@ public abstract class GenericFacade<C extends ModelInterface> { ...@@ -282,14 +308,31 @@ public abstract class GenericFacade<C extends ModelInterface> {
// return q.getResultList(); // return q.getResultList();
// } // }
/**
* Synchronize the persistence context to the underlying database.
*
* This gives to newly created entities ID, etc.
*/
public void flush() { public void flush() {
getEm().flush(); getEm().flush();
} }
/**
* Remove the given entity from cache.
*
* @param entity
*/
public void evict(C entity) { public void evict(C entity) {
getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId()); getEm().getEntityManagerFactory().getCache().evict(getEntityClass(), entity.getId());
} }
/**
* Tells wether the entity is attached to this transaction. ie. Changes to
* this object are automatically propagated to the database
*
* @param entity
* @return
*/
public boolean isAttached(ModelInterface entity) { public boolean isAttached(ModelInterface entity) {
return getEm().contains(entity); return getEm().contains(entity);
} }
......
...@@ -18,68 +18,44 @@ ...@@ -18,68 +18,44 @@
<compo:editCompo commitAction="#{compoMgmtView.saveCompo}" commitValue="#{i18n['voting.create.saveCompo']}" /> <compo:editCompo commitAction="#{compoMgmtView.saveCompo}" commitValue="#{i18n['voting.create.saveCompo']}" />
<h2>#{i18n['compoMgmtView.compo.entries']}</h2> <h2>#{i18n['compoMgmtView.compo.entries']}</h2>
<h:form> <h:form>
<h:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoMgmtView.entries}" var="entry"> <p:dataTable styleClass="bordertable" rowClasses="roweven,rowodd" id="compolisttable" value="#{compoMgmtView.entries}" var="entry">
<h:column> <p:column headerText="Title">
<f:facet name="header">
<h:outputText value="Title" />
</f:facet>
<h:outputText value="#{entry.title}" /> <h:outputText value="#{entry.title}" />
</h:column> </p:column>
<h:column> <p:column headerText="Author">
<f:facet name="header">
<h:outputText value="Author" />
</f:facet>
<h:outputText value="#{entry.author}" /> <h:outputText value="#{entry.author}" />
</h:column> </p:column>
<h:column> <p:column headerText="Notes">
<f:facet name="header">
<h:outputText value="notes" />
</f:facet>
<h:outputText value="#{entry.notes}" /> <h:outputText value="#{entry.notes}" />
</h:column> </p:column>
<h:column> <p:column headerText="Screenmessage">
<f:facet name="header">
<h:outputText value="screenmessage" />
</f:facet>
<h:outputText value="#{entry.screenMessage}" /> <h:outputText value="#{entry.screenMessage}" />
</h:column> </p:column>
<h:column> <p:column headerText="creator">
<f:facet name="header">
<h:outputText value="creator" />
</f:facet>
<h:link outcome="/useradmin/edit" value="#{entry.creator.user.nick}"> <h:link outcome="/useradmin/edit" value="#{entry.creator.user.nick}">
<f:param name="userid" value="#{entry.creator.user.id}" /> <f:param name="userid" value="#{entry.creator.user.id}" />
</h:link> </h:link>
</h:column> </p:column>
<h:column> <p:column headerText="Sort">
<f:facet name="header">
<h:outputText value="sort" />
</f:facet>
<h:inputText value="#{entry.sort}" size="4" /> <h:inputText value="#{entry.sort}" size="4" />
</h:column> </p:column>
<h:column> <p:column headerText="Vote total">
<f:facet name="header">
<h:outputText value="Vote total" />
</f:facet>
<h:outputText value="#{entry.votetotal}" /> <h:outputText value="#{entry.votetotal}" />
</h:column> </p:column>
<h:column> <p:column headerText="Vote count">
<f:facet name="header">
<h:outputText value="Vote count" />
</f:facet>
<h:outputText value="#{entry.votes.size()}" /> <h:outputText value="#{entry.votes.size()}" />
</h:column> </p:column>
<h:column> <p:column>
<h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}"> <h:link outcome="/voting/submitEntry" value="#{i18n['entry.edit']}">
<f:param name="entryId" value="#{entry.id}" /> <f:param name="entryId" value="#{entry.id}" />
</h:link> </h:link>
</h:column> </p:column>
</h:dataTable> </p:dataTable>
<h:commandButton action="#{compoMgmtView.saveSort}" value="#{i18n['compo.savesort']}" /> <h:commandButton action="#{compoMgmtView.saveSort}" value="#{i18n['compo.savesort']}" />
</h:form> </h:form>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!