Commit 59613c7e by Tuomas Riihimäki

Add placecode generation

1 parent 817c4562
......@@ -31,21 +31,32 @@ import fi.codecrew.moya.model.Product;
@Local
public interface BarcodeBeanLocal {
public PrintedCard getPrintedCard(String barcode) ;
static final String TEXTCODE_CHARACTER_MAP = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
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 String getPlaceTextCode(Place place);
public Place getPlaceFromTextCode(String hexcode);
public String checkVrAuthCode(String code);
public String getUserTextCode(EventUser user);
public EventUser getUserFromTextCode(String textcode);
public String getUserLongTextCode(EventUser user);
public EventUser getUserFromLongTextCode(String textcode);
public Product getProduct(String barcode);
public Place getPlaceFromBarcode(String barcode);
}
......@@ -54,7 +54,6 @@ public class BarcodeBean implements BarcodeBeanLocal {
// DO NOT ACCIDENTLY ADD '=' -char to this list
private static final String TEXTCODE_CHARACTER_MAP = "23456789ABCDEFGHJKLMNPQRSTUVWXYZ";
private static final int TEXTCODE_ROTATE_COUNT = 500;
//private static final String NEXT_PREFIX = "265"; //2A
......
package fi.codecrew.moya.rest.placemap.v1;
import javax.xml.bind.annotation.XmlRootElement;
import com.wordnik.swagger.annotations.ApiModel;
import fi.codecrew.moya.model.Place;
@XmlRootElement()
@ApiModel(description = "PlaceCode")
public class PlaceCodePojo {
public PlaceCodePojo() {
}
public PlaceCodePojo(Place place) {
this.type = place.getProduct().getName();
this.id = place.getId();
this.name = place.getName();
this.code = place.getCode();
}
private Integer id;
private String name;
private String type;
private String code;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
......@@ -2,7 +2,9 @@ package fi.codecrew.moya.rest.placemap.v1;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
......@@ -20,18 +22,23 @@ import javax.ws.rs.core.Response.ResponseBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fi.codecrew.moya.beans.BarcodeBeanLocal;
import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.beans.map.QueueBeanLocal;
import fi.codecrew.moya.enums.apps.MapPermission;
import fi.codecrew.moya.enums.apps.UserPermission;
import fi.codecrew.moya.model.EventMap;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.rest.PojoUtils;
import fi.codecrew.moya.rest.pojo.placemap.v1.IntegerRoot;
import fi.codecrew.moya.rest.pojo.placemap.v1.PlacemapMapRootPojo;
import fi.codecrew.moya.rest.pojo.placemap.v1.SimplePlacelistRoot;
import fi.codecrew.moya.utilities.PasswordFunctions;
import fi.codecrew.moya.web.cdiview.user.UserView;
@RequestScoped
......@@ -54,6 +61,11 @@ public class PlacemapRestViewV1 {
private QueueBeanLocal quebean;
@EJB
private UserBeanLocal userbean;
@EJB
private EventBeanLocal eventbean;
@EJB
private BarcodeBeanLocal barcodebean;
// @GET
// @Path("/maps")
......@@ -98,17 +110,17 @@ public class PlacemapRestViewV1 {
{
EventMap map = placebean.findMap(mapId);
if(!permbean.hasPermission(UserPermission.VIEW_ALL)) {
if (!permbean.hasPermission(UserPermission.VIEW_ALL)) {
return Response.status(Response.Status.FORBIDDEN).entity("Try to login first!").build();
}
EventUser user = userbean.findByUserId(userId,false);
EventUser user = userbean.findByUserId(userId, false);
if (user == null) {
return Response.status(Response.Status.BAD_REQUEST).entity("No User found for id: "+userId).build();
return Response.status(Response.Status.BAD_REQUEST).entity("No User found for id: " + userId).build();
}
return Response.ok(PojoUtils.parseSimplePlaces(map.getPlaces(), user, permbean.hasPermission(UserPermission.VIEW_ALL), true)).build();
return Response.ok(PojoUtils.parseSimplePlaces(map.getPlaces(), user, permbean.hasPermission(UserPermission.VIEW_ALL), true)).build();
}
@GET
......@@ -192,4 +204,76 @@ public class PlacemapRestViewV1 {
}
return resp.build();
}
@GET
@Path("/{id}/placecodes")
public Response getPlaceCodes(@PathParam("id") Integer mapId) {
if (!permbean.hasPermission(MapPermission.MANAGE_MAPS)) {
return Response
.status(Response.Status.FORBIDDEN)
.entity("No enough permissions!")
.build();
}
EventMap map = placebean.findMap(mapId);
LanEvent event = eventbean.getCurrentEvent();
if (!event.equals(map.getEvent())) {
return Response
.status(Response.Status.FORBIDDEN)
.entity("Wrong event!")
.build();
}
ArrayList<PlaceCodePojo> ret = new ArrayList<PlaceCodePojo>();
for (Place p : map.getPlaces()) {
if (p.getCode() == null || p.getCode().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity("Error fetching code for place " + p.getName()).build();
}
ret.add(new PlaceCodePojo(p));
}
return Response.ok(ret).build();
}
@GET
@Path("/{id}/gencodes")
public Response getGencodes(@PathParam("id") Integer mapId) {
if (!permbean.hasPermission(MapPermission.MANAGE_MAPS)) {
return Response
.status(Response.Status.FORBIDDEN)
.entity("No enough permissions!")
.build();
}
EventMap map = placebean.findMap(mapId);
LanEvent event = eventbean.getCurrentEvent();
if (!event.equals(map.getEvent())) {
return Response
.status(Response.Status.FORBIDDEN)
.entity("Wrong event!")
.build();
}
Set<String> oldcodes = new HashSet<>();
for (Place p : map.getPlaces()) {
if (p.getCode() != null && !p.getCode().isEmpty()) {
oldcodes.add(p.getCode());
}
}
for (Place p : map.getPlaces()) {
String code = null;
do {
code = PasswordFunctions.generateRandomString(12, BarcodeBeanLocal.TEXTCODE_CHARACTER_MAP);
} while (oldcodes.contains(code));
if (p.getCode() == null || p.getCode().isEmpty()) {
p.setCode(code);
p = placebean.mergeChanges(p);
logger.info("Updating place {} with code {}", p.getName(), p.getCode());
}
}
return Response.ok().entity("Ok").build();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!