Commit c8e39a5c by Tuukka Kivilahti

settings for placecode printing (print only own and use userid instead of placec…

…ode), fixed boolean eventsetting
1 parent 4d3b6587
...@@ -10,10 +10,10 @@ import javax.ejb.Stateless; ...@@ -10,10 +10,10 @@ import javax.ejb.Stateless;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import com.sun.xml.bind.v2.model.core.ID;
import fi.codecrew.moya.facade.PrintedCardFacade; import fi.codecrew.moya.facade.PrintedCardFacade;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils; import fi.codecrew.moya.utilities.BarcodeUtils;
/** /**
...@@ -23,12 +23,18 @@ import fi.codecrew.moya.utilities.BarcodeUtils; ...@@ -23,12 +23,18 @@ import fi.codecrew.moya.utilities.BarcodeUtils;
@LocalBean @LocalBean
public class BarcodeBean implements BarcodeBeanLocal { public class BarcodeBean implements BarcodeBeanLocal {
private static final String PRINTED_CARD_PREFIX = "277"; private static final String PRINTED_CARD_PREFIX = "277"; //2M
private static final String EVENTUSER_PREFIX = "279"; //2O
//private static final String NEXT_PREFIX = "289"; //2Y
//private static final String NEXT_PREFIX = "265"; //2A
private static final Logger logger = LoggerFactory.getLogger(BarcodeBean.class); private static final Logger logger = LoggerFactory.getLogger(BarcodeBean.class);
@EJB @EJB
PrintedCardFacade printedCardFacade; PrintedCardFacade printedCardFacade;
@EJB
UserBeanLocal userBean;
/** /**
* Default constructor. * Default constructor.
*/ */
...@@ -36,6 +42,21 @@ public class BarcodeBean implements BarcodeBeanLocal { ...@@ -36,6 +42,21 @@ public class BarcodeBean implements BarcodeBeanLocal {
// TODO Auto-generated constructor stub // TODO Auto-generated constructor stub
} }
public InputStream getUserBarcode(EventUser user) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(EVENTUSER_PREFIX);
String idStr = user.getId().toString();
for (int i = 12 - idStr.length() - sb.length(); i > 0; --i) {
sb.append("0");
}
sb.append(idStr);
String barcode = sb.toString();
logger.debug("Geneating barcode for user {} : {}", user, barcode);
return BarcodeUtils.getBarcodeEAN(barcode);
}
public InputStream getCardBarcode(PrintedCard printedCard) throws IOException { public InputStream getCardBarcode(PrintedCard printedCard) throws IOException {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append(PRINTED_CARD_PREFIX); sb.append(PRINTED_CARD_PREFIX);
...@@ -69,4 +90,22 @@ public class BarcodeBean implements BarcodeBeanLocal { ...@@ -69,4 +90,22 @@ public class BarcodeBean implements BarcodeBeanLocal {
return printedCardFacade.findByBarcode(barcode); return printedCardFacade.findByBarcode(barcode);
} }
public EventUser getUser(String barcode) {
if(barcode == null || barcode.isEmpty())
return null;
// it's our special front barcode
try {
if (barcode.startsWith(EVENTUSER_PREFIX)) {
int id = Integer.parseInt(barcode.substring(3));
EventUser user = userBean.findByEventUserId(id);
return user;
}
} catch (NumberFormatException x) {
}
return null;
}
} }
...@@ -21,21 +21,19 @@ import com.pdfjet.PDF; ...@@ -21,21 +21,19 @@ import com.pdfjet.PDF;
import com.pdfjet.Page; import com.pdfjet.Page;
import com.pdfjet.TextLine; import com.pdfjet.TextLine;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.facade.EventUserFacade; import fi.codecrew.moya.facade.EventUserFacade;
import fi.codecrew.moya.facade.GroupMembershipFacade; import fi.codecrew.moya.facade.GroupMembershipFacade;
import fi.codecrew.moya.facade.PlaceGroupFacade; import fi.codecrew.moya.facade.PlaceGroupFacade;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.LoggingBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
import fi.codecrew.moya.beans.SecurityLogType;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.SpecialPermission;
import fi.codecrew.moya.model.EventUser; import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership; import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.PlaceGroup; import fi.codecrew.moya.model.PlaceGroup;
import fi.codecrew.moya.model.User; import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.BarcodeUtils; import fi.codecrew.moya.utilities.BarcodeUtils;
import fi.codecrew.moya.utilities.I18n;
/** /**
* Session Bean implementation class PlaceGroupBean * Session Bean implementation class PlaceGroupBean
...@@ -50,6 +48,9 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal { ...@@ -50,6 +48,9 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
private EventBeanLocal eventbean; private EventBeanLocal eventbean;
@EJB @EJB
private BarcodeBeanLocal barcodeBean;
@EJB
private GroupMembershipFacade gmemfacade; private GroupMembershipFacade gmemfacade;
@EJB @EJB
private LoggingBeanLocal loggingbean; private LoggingBeanLocal loggingbean;
...@@ -134,6 +135,22 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal { ...@@ -134,6 +135,22 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
@RolesAllowed(SpecialPermission.S_USER) @RolesAllowed(SpecialPermission.S_USER)
public void getGroupMembershipPdf(EventUser usr, OutputStream ostream) { public void getGroupMembershipPdf(EventUser usr, OutputStream ostream) {
List<GroupMembership> memberships = getMembershipsAndCreations(usr); List<GroupMembership> memberships = getMembershipsAndCreations(usr);
LanEventProperty tmpProperty = eventbean.getProperty(LanEventPropertyKey.PLACECODE_FROM_USER);
boolean placecodeFromUser = false;
if (tmpProperty != null && tmpProperty.isBooleanValue())
{
placecodeFromUser = true;
}
tmpProperty = eventbean.getProperty(LanEventPropertyKey.PLACECODE_PRINT_ONLY_OWN);
boolean printOnlyOwn = false;
if (tmpProperty != null && tmpProperty.isBooleanValue())
{
printOnlyOwn = true;
}
try { try {
PDF pdf = new PDF(ostream); PDF pdf = new PDF(ostream);
Font font = new Font(pdf, CoreFont.TIMES_ROMAN); Font font = new Font(pdf, CoreFont.TIMES_ROMAN);
...@@ -149,15 +166,35 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal { ...@@ -149,15 +166,35 @@ public class PlaceGroupBean implements PlaceGroupBeanLocal {
y = YSTART; y = YSTART;
} }
if(printOnlyOwn && (membership.getUser() == null || !membership.getUser().equals(usr))) {
continue;
}
// //
// PNGImage jpeg = new // PNGImage jpeg = new
// PNGImage(BarcodeBean.getBarcode(membership.getInviteToken())); // PNGImage(BarcodeBean.getBarcode(membership.getInviteToken()));
// logger.debug("Jpeg: " + jpeg.getWidth() + " h. " + // logger.debug("Jpeg: " + jpeg.getWidth() + " h. " +
// jpeg.getHeight()); // jpeg.getHeight());
if(placecodeFromUser) {
if(membership.getUser() != null) {
Image image = new Image(pdf, barcodeBean.getUserBarcode(membership.getUser()), ImageType.PNG);
image.scaleBy(0.8);
image.setPosition(50, y);
image.drawOn(page);
} else {
TextLine nouser = new TextLine(bigfont, "EMPTY PLACE" );
nouser.setPosition(85, y+10);
nouser.drawOn(page);
}
} else {
Image image = new Image(pdf, BarcodeUtils.getBarcode(membership.getInviteToken()), ImageType.PNG); Image image = new Image(pdf, BarcodeUtils.getBarcode(membership.getInviteToken()), ImageType.PNG);
image.scaleBy(0.8); image.scaleBy(0.8);
image.setPosition(50, y); image.setPosition(50, y);
image.drawOn(page); image.drawOn(page);
}
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
if (membership.getPlaceReservation().getName() != null) if (membership.getPlaceReservation().getName() != null)
......
...@@ -5,12 +5,16 @@ import java.io.InputStream; ...@@ -5,12 +5,16 @@ import java.io.InputStream;
import javax.ejb.Local; import javax.ejb.Local;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.PrintedCard; import fi.codecrew.moya.model.PrintedCard;
@Local @Local
public interface BarcodeBeanLocal { public interface BarcodeBeanLocal {
public PrintedCard getPrintedCard(String barcode) ; public PrintedCard getPrintedCard(String barcode) ;
public EventUser getUser(String barcode);
public InputStream getUserBarcode(EventUser user) throws IOException;
public InputStream getCardBarcode(PrintedCard printedCard) throws IOException; public InputStream getCardBarcode(PrintedCard printedCard) throws IOException;
} }
...@@ -8,7 +8,10 @@ public enum LanEventPropertyKey { ...@@ -8,7 +8,10 @@ public enum LanEventPropertyKey {
PORTAL_EMAIL_NAME(Type.TEXT, "Streamparty intranet"), PORTAL_EMAIL_NAME(Type.TEXT, "Streamparty intranet"),
ADMIN_MAIL(Type.TEXT, "intra@streamparty.org"), ADMIN_MAIL(Type.TEXT, "intra@streamparty.org"),
EVENT_LAYOUT(Type.TEXT, "template1"), EVENT_LAYOUT(Type.TEXT, "template1"),
SHOP_DEFAULT_CASH(Type.BOOL, null), ; SHOP_DEFAULT_CASH(Type.BOOL, null),
PLACECODE_FROM_USER(Type.BOOL, null),
PLACECODE_PRINT_ONLY_OWN(Type.BOOL, null),
;
private enum Type { private enum Type {
TEXT, DATE, DATA, BOOL TEXT, DATE, DATA, BOOL
}; };
...@@ -29,7 +32,7 @@ public enum LanEventPropertyKey { ...@@ -29,7 +32,7 @@ public enum LanEventPropertyKey {
} }
public boolean isBoolean() { public boolean isBoolean() {
return Type.DATA.equals(type); return Type.BOOL.equals(type);
} }
private LanEventPropertyKey(Type t, String def) private LanEventPropertyKey(Type t, String def)
......
...@@ -77,6 +77,8 @@ ...@@ -77,6 +77,8 @@
<h:column> <h:column>
<f:facet name="header">#{i18n['lanEventProperty.value']}</f:facet> <f:facet name="header">#{i18n['lanEventProperty.value']}</f:facet>
<h:outputText rendered="#{prop.key.text}" value="#{prop.textvalue}" /> <h:outputText rendered="#{prop.key.text}" value="#{prop.textvalue}" />
<h:outputText rendered="#{prop.key.boolean and prop.booleanValue}" value="true" />
<h:outputText rendered="#{prop.key.boolean and not prop.booleanValue}" value="false" />
<h:outputText rendered="#{prop.key.date}" value="#{prop.dateValue}"> <h:outputText rendered="#{prop.key.date}" value="#{prop.dateValue}">
<f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" /> <f:convertDateTime pattern="#{sessionHandler.datetimeFormat}" timeZone="#{sessionHandler.timezone}" />
</h:outputText> </h:outputText>
...@@ -124,6 +126,10 @@ ...@@ -124,6 +126,10 @@
<p:calendar rendered="#{eventPropertyView.property.key.date}" value="#{eventPropertyView.property.dateValue}" pattern="#{sessionHandler.datetimeFormat}" /> <p:calendar rendered="#{eventPropertyView.property.key.date}" value="#{eventPropertyView.property.dateValue}" pattern="#{sessionHandler.datetimeFormat}" />
<h:message rendered="#{eventPropertyView.property.key.date}" for="textval" /> <h:message rendered="#{eventPropertyView.property.key.date}" for="textval" />
<h:outputLabel rendered="#{eventPropertyView.property.key.boolean}" for="booleanval" value="#{i18n['lanEventProperty.booleanValue']}" />
<h:selectBooleanCheckbox rendered="#{eventPropertyView.property.key.boolean}" id="booleanval" value="#{eventPropertyView.property.booleanValue}" />
<h:message rendered="#{eventPropertyView.property.key.boolean}" for="booleanval" />
</h:panelGrid> </h:panelGrid>
<h:commandButton action="#{eventPropertyView.saveProperty}" value="#{i18n['lanEventProperty.save']}" /> <h:commandButton action="#{eventPropertyView.saveProperty}" value="#{i18n['lanEventProperty.save']}" />
</h:form> </h:form>
......
...@@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse; ...@@ -12,6 +12,7 @@ import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal; import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceGroupBeanLocal; import fi.codecrew.moya.beans.PlaceGroupBeanLocal;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!