Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Codecrew
/
Moya
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
30
Merge Requests
2
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit dc5dd3ac
authored
Jul 22, 2015
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge placecode generation to fetching class
1 parent
885340b6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
42 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 @
dc5dd3a
...
@@ -111,6 +111,7 @@ public interface PlaceBeanLocal {
...
@@ -111,6 +111,7 @@ public interface PlaceBeanLocal {
/**
/**
* Get all products used in map;
* Get all products used in map;
*
* @param map
* @param map
*
*
* @return
* @return
...
@@ -133,4 +134,6 @@ public interface PlaceBeanLocal {
...
@@ -133,4 +134,6 @@ public interface PlaceBeanLocal {
EventMap
copyMap
(
EventMap
sourceMap
,
EventMap
map
);
EventMap
copyMap
(
EventMap
sourceMap
,
EventMap
map
);
Place
findByCode
(
String
code
,
EventMap
map
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
dc5dd3a
...
@@ -802,4 +802,9 @@ public class PlaceBean implements PlaceBeanLocal {
...
@@ -802,4 +802,9 @@ public class PlaceBean implements PlaceBeanLocal {
return
dst
;
return
dst
;
}
}
@Override
public
Place
findByCode
(
String
code
,
EventMap
map
)
{
return
placeFacade
.
findByCode
(
code
,
map
);
}
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
dc5dd3a
...
@@ -309,4 +309,12 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
...
@@ -309,4 +309,12 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return
getEm
().
createQuery
(
cq
).
getResultList
();
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
));
}
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
View file @
dc5dd3a
...
@@ -226,7 +226,13 @@ public class PlacemapRestViewV1 {
...
@@ -226,7 +226,13 @@ public class PlacemapRestViewV1 {
ArrayList
<
PlaceCodePojo
>
ret
=
new
ArrayList
<
PlaceCodePojo
>();
ArrayList
<
PlaceCodePojo
>
ret
=
new
ArrayList
<
PlaceCodePojo
>();
for
(
Place
p
:
map
.
getPlaces
())
{
for
(
Place
p
:
map
.
getPlaces
())
{
if
(
p
.
getCode
()
==
null
||
p
.
getCode
().
isEmpty
())
{
if
(
p
.
getCode
()
==
null
||
p
.
getCode
().
isEmpty
())
{
return
Response
.
status
(
Response
.
Status
.
NOT_FOUND
).
entity
(
"Error fetching code for place "
+
p
.
getName
()).
build
();
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
));
ret
.
add
(
new
PlaceCodePojo
(
p
));
}
}
...
@@ -235,45 +241,4 @@ public class PlacemapRestViewV1 {
...
@@ -235,45 +241,4 @@ public class PlacemapRestViewV1 {
}
}
@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
();
}
}
}
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