Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Linnea Samila
/
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 ed593358
authored
Nov 09, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add map property fetching via rest
1 parent
2c9e4f1a
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
3 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/EventMapFacade.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-web/src/main/java/fi/codecrew/moya/rest/pojo/ProductRestPojo.java
code/moya-web/src/main/java/fi/codecrew/moya/servlet/PlaceMapServlet.java
code/moya-beans-client/ejbModule/fi/codecrew/moya/beans/PlaceBeanLocal.java
View file @
ed59335
...
...
@@ -34,6 +34,7 @@ import fi.codecrew.moya.model.EventUser;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.PlaceGroup
;
import
fi.codecrew.moya.model.Product
;
/**
*
...
...
@@ -98,4 +99,20 @@ public interface PlaceBeanLocal {
public
EventMap
getActiveMap
();
/**
* Get all maps
*
* @return
*/
List
<
EventMap
>
getMaps
();
/**
* Get all products used in map;
* @param map
*
* @return
*/
List
<
Product
>
getMapProducts
(
EventMap
map
);
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
ed59335
...
...
@@ -686,4 +686,14 @@ public class PlaceBean implements PlaceBeanLocal {
return
null
;
}
@Override
public
List
<
EventMap
>
getMaps
()
{
return
eventMapFacade
.
getMaps
();
}
@Override
public
List
<
Product
>
getMapProducts
(
EventMap
map
)
{
return
placeFacade
.
getMapProducts
(
map
);
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/EventMapFacade.java
View file @
ed59335
...
...
@@ -18,10 +18,18 @@
*/
package
fi
.
codecrew
.
moya
.
facade
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.ejb.LocalBean
;
import
javax.ejb.Stateless
;
import
javax.persistence.criteria.CriteriaBuilder
;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Root
;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventMap_
;
@Stateless
@LocalBean
...
...
@@ -31,4 +39,16 @@ public class EventMapFacade extends IntegerPkGenericFacade<EventMap> {
super
(
EventMap
.
class
);
}
@EJB
private
EventBeanLocal
eventbean
;
public
List
<
EventMap
>
getMaps
()
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
EventMap
>
cq
=
cb
.
createQuery
(
EventMap
.
class
);
Root
<
EventMap
>
root
=
cq
.
from
(
EventMap
.
class
);
cq
.
where
(
cb
.
equal
(
root
.
get
(
EventMap_
.
event
),
eventbean
.
getCurrentEvent
()),
cb
.
isTrue
(
root
.
get
(
EventMap_
.
active
)));
return
getEm
().
createQuery
(
cq
).
getResultList
();
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
ed59335
...
...
@@ -29,6 +29,7 @@ import javax.persistence.criteria.CriteriaBuilder;
import
javax.persistence.criteria.CriteriaQuery
;
import
javax.persistence.criteria.Path
;
import
javax.persistence.criteria.Root
;
import
javax.persistence.criteria.Subquery
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
...
...
@@ -41,6 +42,7 @@ import fi.codecrew.moya.model.LanEvent;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.Place_
;
import
fi.codecrew.moya.model.Product
;
import
fi.codecrew.moya.model.Product_
;
@Stateless
@LocalBean
...
...
@@ -208,4 +210,21 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
return
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
public
List
<
Product
>
getMapProducts
(
EventMap
map
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
Product
>
cq
=
cb
.
createQuery
(
Product
.
class
);
Root
<
Product
>
root
=
cq
.
from
(
Product
.
class
);
Subquery
<
Integer
>
subq
=
cq
.
subquery
(
Integer
.
class
);
Root
<
Place
>
subroot
=
subq
.
from
(
Place
.
class
);
subq
.
select
(
subroot
.
get
(
Place_
.
product
).
get
(
Product_
.
id
));
subq
.
distinct
(
true
);
subq
.
where
(
cb
.
equal
(
subroot
.
get
(
Place_
.
map
),
map
));
cq
.
where
(
root
.
get
(
Product_
.
id
).
in
(
subq
));
return
getEm
().
createQuery
(
cq
).
getResultList
();
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
View file @
ed59335
package
fi
.
codecrew
.
moya
.
rest
.
placemap
.
v1
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
...
...
@@ -14,6 +15,7 @@ import javax.ws.rs.core.MediaType;
import
fi.codecrew.moya.beans.PlaceBeanLocal
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.rest.pojo.placemap.PlacemapMapRootPojo
;
import
fi.codecrew.moya.rest.pojo.placemap.SimplePlacePojo
;
import
fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot
;
...
...
@@ -26,6 +28,25 @@ public class PlacemapRestViewV1 {
@EJB
private
PlaceBeanLocal
placebean
;
// @GET
// @Path("/maps")
// public PlacemapMapRootPojo getMaps()
// {
// List<EventMap> maps = placebean.getMaps();
// placebean.getAllMapProducts();
// new PlacemapMapRootPojo();
// }
@GET
@Path
(
"/{id}"
)
public
PlacemapMapRootPojo
getMap
(
@PathParam
(
"id"
)
Integer
id
)
{
PlacemapMapRootPojo
ret
=
new
PlacemapMapRootPojo
();
EventMap
map
=
placebean
.
findMap
(
id
);
ret
.
setMap
(
map
);
ret
.
setRawProducts
(
placebean
.
getMapProducts
(
map
));
return
ret
;
}
@GET
@Path
(
"{id}/places"
)
public
SimplePlacelistRoot
getPlaces
(
@PathParam
(
"id"
)
Integer
mapId
)
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/ProductRestPojo.java
0 → 100644
View file @
ed59335
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
java.math.BigDecimal
;
import
javax.xml.bind.annotation.XmlElement
;
import
fi.codecrew.moya.model.Product
;
public
class
ProductRestPojo
{
private
Product
prod
;
public
ProductRestPojo
()
{
}
public
ProductRestPojo
(
Product
p
)
{
this
.
prod
=
p
;
}
@XmlElement
(
name
=
"id"
)
public
Integer
getId
()
{
return
prod
.
getId
();
}
@XmlElement
(
name
=
"name"
)
public
String
getName
()
{
return
prod
.
getName
();
}
@XmlElement
(
name
=
"price"
)
public
String
getPrice
()
{
return
prod
.
getPrice
().
setScale
(
2
,
BigDecimal
.
ROUND_HALF_UP
).
toString
();
}
@XmlElement
(
name
=
"description"
)
public
String
getDescription
()
{
return
prod
.
getDescription
();
}
}
code/moya-web/src/main/java/fi/codecrew/moya/servlet/PlaceMapServlet.java
View file @
ed59335
...
...
@@ -60,10 +60,9 @@ import fi.codecrew.moya.model.Place;
* @author tuukka
*/
@WebServlet
(
"/PlaceMap"
)
public
class
PlaceMap
extends
HttpServlet
{
public
class
PlaceMap
Servlet
extends
HttpServlet
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlaceMap
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlaceMapServlet
.
class
);
private
static
final
long
serialVersionUID
=
8769688627918936258L
;
@EJB
...
...
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