Commit 239bfb74 by Juho Juopperi

Merge branch 'placecodegen' into 'master'

Placecodefetching for all places

Create rest view for fetching all places, including entrytickets which do not have an associated map, from event.

See merge request !294
2 parents 8c29bd6a c67a40b6
...@@ -134,6 +134,13 @@ public interface PlaceBeanLocal { ...@@ -134,6 +134,13 @@ public interface PlaceBeanLocal {
EventMap copyMap(EventMap sourceMap, EventMap map); EventMap copyMap(EventMap sourceMap, EventMap map);
Place findByCode(String code, EventMap map); Place findByCode(String code);
/**
* Find all places, including places without a map
*
* @return
*/
List<Place> findAllForEvent();
} }
...@@ -803,8 +803,15 @@ public class PlaceBean implements PlaceBeanLocal { ...@@ -803,8 +803,15 @@ public class PlaceBean implements PlaceBeanLocal {
} }
@Override @Override
public Place findByCode(String code, EventMap map) { public Place findByCode(String code) {
return placeFacade.findByCode(code, map); LanEvent event = eventBean.getCurrentEvent();
return placeFacade.findByCode(code, event);
} }
@Override
public List<Place> findAllForEvent() {
LanEvent event = eventBean.getCurrentEvent();
List<Place> ret = placeFacade.findAllForEvent(event);
return ret;
}
} }
...@@ -310,11 +310,22 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> { ...@@ -310,11 +310,22 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return getEm().createQuery(cq).getResultList(); return getEm().createQuery(cq).getResultList();
} }
public Place findByCode(String code, EventMap map) { public Place findByCode(String code, LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder(); CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<Place> cq = cb.createQuery(Place.class); CriteriaQuery<Place> cq = cb.createQuery(Place.class);
Root<Place> root = cq.from(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));
cq.where(cb.equal(root.get(Place_.product).get(Product_.event), event), cb.equal(root.get(Place_.code), code));
return super.getSingleNullableResult(getEm().createQuery(cq)); return super.getSingleNullableResult(getEm().createQuery(cq));
} }
public List<Place> findAllForEvent(LanEvent event) {
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_.product).get(Product_.event), event));
return getEm().createQuery(cq).getResultList();
}
} }
...@@ -206,6 +206,20 @@ public class PlacemapRestViewV1 { ...@@ -206,6 +206,20 @@ public class PlacemapRestViewV1 {
} }
@GET @GET
@Path("/all/placecodes")
public Response getAllPlacecodes() {
if (!permbean.hasPermission(MapPermission.MANAGE_MAPS)) {
return Response
.status(Response.Status.FORBIDDEN)
.entity("No enough permissions!")
.build();
}
List<PlaceCodePojo> ret = makePlaceCodePojos(placebean.findAllForEvent());
return Response.ok(ret).build();
}
@GET
@Path("/{id}/placecodes") @Path("/{id}/placecodes")
public Response getPlaceCodes(@PathParam("id") Integer mapId) { public Response getPlaceCodes(@PathParam("id") Integer mapId) {
if (!permbean.hasPermission(MapPermission.MANAGE_MAPS)) { if (!permbean.hasPermission(MapPermission.MANAGE_MAPS)) {
...@@ -223,22 +237,27 @@ public class PlacemapRestViewV1 { ...@@ -223,22 +237,27 @@ public class PlacemapRestViewV1 {
.build(); .build();
} }
ArrayList<PlaceCodePojo> ret = makePlaceCodePojos(map.getPlaces());
return Response.ok(ret).build();
}
private ArrayList<PlaceCodePojo> makePlaceCodePojos(List<Place> places) {
ArrayList<PlaceCodePojo> ret = new ArrayList<PlaceCodePojo>(); ArrayList<PlaceCodePojo> ret = new ArrayList<PlaceCodePojo>();
for (Place p : map.getPlaces()) { for (Place p : places) {
if (p.getCode() == null || p.getCode().isEmpty()) { if (p.getCode() == null || p.getCode().isEmpty()) {
String newcode = null; String newcode = null;
do { do {
newcode = PasswordFunctions.generateRandomString(12, BarcodeBeanLocal.TEXTCODE_CHARACTER_MAP); newcode = PasswordFunctions.generateRandomString(12, BarcodeBeanLocal.TEXTCODE_CHARACTER_MAP);
} while (placebean.findByCode(newcode, map) != null); } while (placebean.findByCode(newcode) != null);
p.setCode(newcode); p.setCode(newcode);
p = placebean.mergeChanges(p); p = placebean.mergeChanges(p);
logger.info("Updating place {} with code {} in map {}", p.getName(), p.getCode(), map); logger.info("Updating place {} with code {} in map {}", p.getName(), p.getCode());
} }
ret.add(new PlaceCodePojo(p)); ret.add(new PlaceCodePojo(p));
} }
return ret;
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!