Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Antti Väyrynen
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit c67a40b6
authored
Jul 25, 2015
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add possibility to fetch all placecodes from event
1 parent
8c29bd6a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
11 deletions
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/PlaceBeanLocal.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/PlaceBeanLocal.java
View file @
c67a40b
...
...
@@ -134,6 +134,13 @@ public interface PlaceBeanLocal {
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
();
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
c67a40b
...
...
@@ -803,8 +803,15 @@ public class PlaceBean implements PlaceBeanLocal {
}
@Override
public
Place
findByCode
(
String
code
,
EventMap
map
)
{
return
placeFacade
.
findByCode
(
code
,
map
);
public
Place
findByCode
(
String
code
)
{
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
;
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
c67a40b
...
...
@@ -310,11 +310,22 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return
getEm
().
createQuery
(
cq
).
getResultList
();
}
public
Place
findByCode
(
String
code
,
EventMap
map
)
{
public
Place
findByCode
(
String
code
,
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_
.
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
));
}
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
();
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
View file @
c67a40b
...
...
@@ -206,6 +206,20 @@ public class PlacemapRestViewV1 {
}
@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"
)
public
Response
getPlaceCodes
(
@PathParam
(
"id"
)
Integer
mapId
)
{
if
(!
permbean
.
hasPermission
(
MapPermission
.
MANAGE_MAPS
))
{
...
...
@@ -223,22 +237,27 @@ public class PlacemapRestViewV1 {
.
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
>();
for
(
Place
p
:
map
.
getPlaces
()
)
{
for
(
Place
p
:
places
)
{
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
);
}
while
(
placebean
.
findByCode
(
newcode
)
!=
null
);
p
.
setCode
(
newcode
);
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
));
}
return
Response
.
ok
(
ret
).
build
();
return
ret
;
}
}
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment