Commit 8c29bd6a by Tuukka Kivilahti

Merge branch 'placecodegen' into 'master'

Placecode generation

Add rest calls for generating and fetching placecodes

See merge request !293
2 parents 817c4562 dc5dd3ac
......@@ -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);
}
......@@ -111,7 +111,8 @@ public interface PlaceBeanLocal {
/**
* Get all products used in map;
* @param map
*
* @param map
*
* @return
*/
......@@ -133,4 +134,6 @@ public interface PlaceBeanLocal {
EventMap copyMap(EventMap sourceMap, EventMap map);
Place findByCode(String code, EventMap map);
}
......@@ -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
......
......@@ -183,7 +183,7 @@ public class OrgRoleBean implements OrgRoleBeanLocal {
orgRole.setEventRoles(new ArrayList<>());
}
if (!orgRole.getEventRoles().contains(orgRole)) {
if (!orgRole.getEventRoles().contains(eventRole)) {
orgRole.getEventRoles().add(eventRole);
}
......
......@@ -802,4 +802,9 @@ public class PlaceBean implements PlaceBeanLocal {
return dst;
}
@Override
public Place findByCode(String code, EventMap map) {
return placeFacade.findByCode(code, map);
}
}
......@@ -309,4 +309,12 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return getEm().createQuery(cq).getResultList();
}
public Place findByCode(String code, EventMap map) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(Place.class);
cq.where(cb.equal(root.get(Place_.map), map), cb.equal(root.get(Place_.code), code));
return super.getSingleNullableResult(getEm().createQuery(cq));
}
}
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,41 @@ 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()) {
String newcode = null;
do {
newcode = PasswordFunctions.generateRandomString(12, BarcodeBeanLocal.TEXTCODE_CHARACTER_MAP);
} while (placebean.findByCode(newcode, map) != null);
p.setCode(newcode);
p = placebean.mergeChanges(p);
logger.info("Updating place {} with code {} in map {}", p.getName(), p.getCode(), map);
}
ret.add(new PlaceCodePojo(p));
}
return Response.ok(ret).build();
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!