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 8f96083b
authored
Nov 08, 2014
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial version of placemap rest api
1 parent
608b617d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
431 additions
and
243 deletions
code/moya-database/src/main/java/fi/codecrew/moya/model/Place.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/placemap/SimplePlacePojo.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/placemap/SimplePlacelistRoot.java
code/moya-database/src/main/java/fi/codecrew/moya/model/Place.java
View file @
8f96083
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
*/
*/
package
fi
.
codecrew
.
moya
.
model
;
package
fi
.
codecrew
.
moya
.
model
;
import
java.awt.Color
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
javax.persistence.CascadeType
;
import
javax.persistence.CascadeType
;
...
@@ -41,260 +42,293 @@ import fi.codecrew.moya.utilities.NumericStringComparator;
...
@@ -41,260 +42,293 @@ import fi.codecrew.moya.utilities.NumericStringComparator;
@Table
(
name
=
"places"
)
@Table
(
name
=
"places"
)
public
class
Place
extends
GenericEntity
implements
Comparable
<
Place
>
{
public
class
Place
extends
GenericEntity
implements
Comparable
<
Place
>
{
/**
/**
*
*
*/
*/
private
static
final
long
serialVersionUID
=
-
5314851260772328611L
;
private
static
final
long
serialVersionUID
=
-
5314851260772328611L
;
@Lob
@Lob
@Column
(
name
=
"place_description"
)
@Column
(
name
=
"place_description"
)
private
String
description
;
private
String
description
;
@Column
(
name
=
"place_name"
)
@Column
(
name
=
"place_name"
)
private
String
name
;
private
String
name
;
@Column
(
name
=
"map_x"
)
@Column
(
name
=
"map_x"
)
private
int
mapX
=
0
;
private
int
mapX
=
0
;
@Column
(
name
=
"map_y"
)
@Column
(
name
=
"map_y"
)
private
int
mapY
=
0
;
private
int
mapY
=
0
;
@Column
(
name
=
"width"
)
@Column
(
name
=
"width"
)
private
int
width
=
0
;
private
int
width
=
0
;
@Column
(
name
=
"height"
)
@Column
(
name
=
"height"
)
private
int
height
=
0
;
private
int
height
=
0
;
@Column
(
name
=
"release_time"
)
@Column
(
name
=
"release_time"
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
@Temporal
(
TemporalType
.
TIMESTAMP
)
private
Calendar
releaseTime
;
private
Calendar
releaseTime
;
@Column
(
name
=
"place_details"
)
@Column
(
name
=
"place_details"
)
@Lob
@Lob
private
String
details
=
""
;
private
String
details
=
""
;
@Column
(
name
=
"place_code"
)
@Column
(
name
=
"place_code"
)
private
String
code
=
""
;
private
String
code
=
""
;
@OneToOne
(
mappedBy
=
"placeReservation"
)
@OneToOne
(
mappedBy
=
"placeReservation"
)
private
GroupMembership
placeReserver
;
private
GroupMembership
placeReserver
;
@Column
(
name
=
"buyable"
,
nullable
=
false
)
@Column
(
name
=
"buyable"
,
nullable
=
false
)
private
boolean
buyable
=
true
;
private
boolean
buyable
=
true
;
@Column
(
nullable
=
false
)
@Column
(
nullable
=
false
)
private
boolean
disabled
=
false
;
private
boolean
disabled
=
false
;
/**
/**
* Which group has bought the place
* Which group has bought the place
*/
*/
@ManyToOne
@ManyToOne
@JoinColumn
(
name
=
"group_id"
,
referencedColumnName
=
"id"
)
@JoinColumn
(
name
=
"group_id"
,
referencedColumnName
=
"id"
)
private
PlaceGroup
group
;
private
PlaceGroup
group
;
@ManyToOne
@JoinColumn
(
name
=
"provided_role_id"
,
referencedColumnName
=
Role
.
ID_COLUMN
)
private
Role
providesRole
;
@JoinColumn
(
name
=
"map_id"
,
referencedColumnName
=
EventMap
.
ID_COLUMN
,
nullable
=
true
)
@ManyToOne
(
optional
=
true
,
cascade
=
CascadeType
.
ALL
)
private
EventMap
map
;
/**
* Which ticket type is this place sold as
*/
@JoinColumn
(
name
=
"products_id"
,
referencedColumnName
=
Product
.
ID_COLUMN
)
@ManyToOne
()
private
Product
product
;
/**
* Who is the current currentUser (mapped with code printed on the place) of
* the place. Used in Vectorama currentUser tracking.
*/
@JoinColumn
(
name
=
"current_eventuser_id"
,
referencedColumnName
=
EventUser
.
ID_COLUMN
)
@ManyToOne
private
EventUser
currentUser
;
public
Place
()
{
super
();
}
public
Place
(
EventMap
eventMap
)
{
super
();
this
.
map
=
eventMap
;
}
public
String
getDescription
()
{
return
description
;
}
public
void
setDescription
(
String
placeDescription
)
{
this
.
description
=
placeDescription
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
placeName
)
{
this
.
name
=
placeName
;
}
public
Integer
getMapX
()
{
return
mapX
;
}
public
void
setMapX
(
Integer
mapX
)
{
this
.
mapX
=
mapX
;
}
public
Integer
getMapY
()
{
return
mapY
;
}
public
void
setMapY
(
Integer
mapY
)
{
this
.
mapY
=
mapY
;
}
public
String
getDetails
()
{
return
details
;
}
public
void
setDetails
(
String
placeDetails
)
{
this
.
details
=
placeDetails
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
placeCode
)
{
this
.
code
=
placeCode
;
}
public
PlaceGroup
getGroup
()
{
return
group
;
}
public
void
setGroup
(
PlaceGroup
group
)
{
if
(
group
!=
null
&&
map
!=
null
&&
!
group
.
getEvent
().
equals
(
map
.
getEvent
()))
{
throw
new
RuntimeException
(
"Can not set Group from different Event to Place!"
);
}
this
.
group
=
group
;
}
public
EventMap
getMap
()
{
return
map
;
}
public
void
setMap
(
EventMap
map
)
{
this
.
map
=
map
;
}
public
Product
getProduct
()
{
return
product
;
}
public
void
setProduct
(
Product
productsId
)
{
this
.
product
=
productsId
;
}
public
EventUser
getCurrentUser
()
{
return
currentUser
;
}
public
void
setCurrentUser
(
EventUser
usersId
)
{
this
.
currentUser
=
usersId
;
}
public
void
setPlaceReserver
(
GroupMembership
placeReserver
)
{
this
.
placeReserver
=
placeReserver
;
}
public
GroupMembership
getPlaceReserver
()
{
return
placeReserver
;
}
/**
@ManyToOne
* @return the height
@JoinColumn
(
name
=
"provided_role_id"
,
referencedColumnName
=
Role
.
ID_COLUMN
)
*/
private
Role
providesRole
;
public
Integer
getHeight
()
{
return
height
;
}
/**
@JoinColumn
(
name
=
"map_id"
,
referencedColumnName
=
EventMap
.
ID_COLUMN
,
nullable
=
true
)
* @param height
@ManyToOne
(
optional
=
true
,
cascade
=
CascadeType
.
ALL
)
* the height to set
private
EventMap
map
;
*/
/**
public
void
setHeight
(
Integer
height
)
{
* Which ticket type is this place sold as
this
.
height
=
height
;
*/
}
@JoinColumn
(
name
=
"products_id"
,
referencedColumnName
=
Product
.
ID_COLUMN
)
@ManyToOne
()
private
Product
product
;
/**
* Who is the current currentUser (mapped with code printed on the place) of
* the place. Used in Vectorama currentUser tracking.
*/
@JoinColumn
(
name
=
"current_eventuser_id"
,
referencedColumnName
=
EventUser
.
ID_COLUMN
)
@ManyToOne
private
EventUser
currentUser
;
/**
public
static
enum
PlaceState
{
* @return the width
FREE
,
DISABLED
,
LOCKED
,
TEMP_RESERVED_FORME
,
*/
MY_PLACE
,
RESERVED
public
Integer
getWidth
()
{
}
return
width
;
}
/**
public
PlaceState
getState
(
EventUser
user
)
* @param width
{
* the width to set
PlaceState
ret
=
PlaceState
.
FREE
;
*/
if
(
isDisabled
())
{
public
void
setWidth
(
Integer
width
)
{
ret
=
PlaceState
.
DISABLED
;
this
.
width
=
width
;
}
else
{
}
public
boolean
isTaken
()
{
if
(!
isBuyable
())
{
ret
=
PlaceState
.
LOCKED
;
}
if
(
isTaken
())
{
ret
=
PlaceState
.
RESERVED
;
// logger.debug("Setting place Reserved {}", p);
}
}
if
(
user
!=
null
)
{
if
(
isReservedFor
(
user
))
{
ret
=
PlaceState
.
TEMP_RESERVED_FORME
;
}
else
if
(
user
.
equals
(
getCurrentUser
())
||
(
getGroup
()
!=
null
&&
user
.
equals
(
getGroup
().
getCreator
()))
||
(
getPlaceReserver
()
!=
null
&&
user
.
equals
(
getPlaceReserver
().
getUser
())))
{
ret
=
PlaceState
.
MY_PLACE
;
return
(
getReleaseTime
()
!=
null
||
getGroup
()
!=
null
);
}
}
}
/**
return
ret
;
*
}
* @return Is the place reserved ( not bought for user)
*/
public
boolean
isReservedFor
(
EventUser
u
)
{
return
(
u
.
equals
(
getCurrentUser
())
&&
getGroup
()
==
null
);
}
/**
public
Place
()
{
* Check if the places releasetime has expired and it should be released for
super
();
* shopping
}
*
* @return If the status of thie entity changed and it should be merged.
public
Place
(
EventMap
eventMap
)
{
*/
super
();
public
boolean
checkReleased
()
{
this
.
map
=
eventMap
;
boolean
ret
=
false
;
}
if
(
getGroup
()
==
null
&&
getReleaseTime
()
!=
null
&&
Calendar
.
getInstance
().
after
(
getReleaseTime
()))
{
setCurrentUser
(
null
);
public
String
getDescription
()
{
setReleaseTime
(
null
);
return
description
;
ret
=
true
;
}
}
return
ret
;
public
void
setDescription
(
String
placeDescription
)
{
}
this
.
description
=
placeDescription
;
}
public
void
setBuyable
(
boolean
buyable
)
{
this
.
buyable
=
buyable
;
public
String
getName
()
{
}
return
name
;
}
public
boolean
isBuyable
()
{
return
buyable
;
public
void
setName
(
String
placeName
)
{
}
this
.
name
=
placeName
;
}
public
void
setReleaseTime
(
Calendar
releaseTime
)
{
this
.
releaseTime
=
releaseTime
;
public
Integer
getMapX
()
{
}
return
mapX
;
}
public
Calendar
getReleaseTime
()
{
return
releaseTime
;
public
void
setMapX
(
Integer
mapX
)
{
}
this
.
mapX
=
mapX
;
}
public
void
setProvidesRole
(
Role
providesRole
)
{
this
.
providesRole
=
providesRole
;
public
Integer
getMapY
()
{
}
return
mapY
;
}
public
Role
getProvidesRole
()
{
return
providesRole
;
public
void
setMapY
(
Integer
mapY
)
{
}
this
.
mapY
=
mapY
;
}
public
boolean
isDisabled
()
{
return
disabled
;
public
String
getDetails
()
{
}
return
details
;
}
public
void
setDisabled
(
boolean
disabled
)
{
this
.
disabled
=
disabled
;
public
void
setDetails
(
String
placeDetails
)
{
}
this
.
details
=
placeDetails
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
placeCode
)
{
this
.
code
=
placeCode
;
}
public
PlaceGroup
getGroup
()
{
return
group
;
}
public
void
setGroup
(
PlaceGroup
group
)
{
if
(
group
!=
null
&&
map
!=
null
&&
!
group
.
getEvent
().
equals
(
map
.
getEvent
()))
{
throw
new
RuntimeException
(
"Can not set Group from different Event to Place!"
);
}
this
.
group
=
group
;
}
public
EventMap
getMap
()
{
return
map
;
}
public
void
setMap
(
EventMap
map
)
{
this
.
map
=
map
;
}
public
Product
getProduct
()
{
return
product
;
}
public
void
setProduct
(
Product
productsId
)
{
this
.
product
=
productsId
;
}
public
EventUser
getCurrentUser
()
{
return
currentUser
;
}
public
void
setCurrentUser
(
EventUser
usersId
)
{
this
.
currentUser
=
usersId
;
}
public
void
setPlaceReserver
(
GroupMembership
placeReserver
)
{
this
.
placeReserver
=
placeReserver
;
}
public
GroupMembership
getPlaceReserver
()
{
return
placeReserver
;
}
/**
* @return the height
*/
public
Integer
getHeight
()
{
return
height
;
}
/**
* @param height
* the height to set
*/
public
void
setHeight
(
Integer
height
)
{
this
.
height
=
height
;
}
/**
* @return the width
*/
public
Integer
getWidth
()
{
return
width
;
}
/**
* @param width
* the width to set
*/
public
void
setWidth
(
Integer
width
)
{
this
.
width
=
width
;
}
public
boolean
isTaken
()
{
return
(
getReleaseTime
()
!=
null
||
getGroup
()
!=
null
);
}
/**
*
* @return Is the place reserved ( not bought for user)
*/
public
boolean
isReservedFor
(
EventUser
u
)
{
return
(
u
.
equals
(
getCurrentUser
())
&&
getGroup
()
==
null
);
}
/**
* Check if the places releasetime has expired and it should be released for
* shopping
*
* @return If the status of thie entity changed and it should be merged.
*/
public
boolean
checkReleased
()
{
boolean
ret
=
false
;
if
(
getGroup
()
==
null
&&
getReleaseTime
()
!=
null
&&
Calendar
.
getInstance
().
after
(
getReleaseTime
()))
{
setCurrentUser
(
null
);
setReleaseTime
(
null
);
ret
=
true
;
}
return
ret
;
}
public
void
setBuyable
(
boolean
buyable
)
{
this
.
buyable
=
buyable
;
}
public
boolean
isBuyable
()
{
return
buyable
;
}
public
void
setReleaseTime
(
Calendar
releaseTime
)
{
this
.
releaseTime
=
releaseTime
;
}
public
Calendar
getReleaseTime
()
{
return
releaseTime
;
}
public
void
setProvidesRole
(
Role
providesRole
)
{
this
.
providesRole
=
providesRole
;
}
public
Role
getProvidesRole
()
{
return
providesRole
;
}
public
boolean
isDisabled
()
{
return
disabled
;
}
public
void
setDisabled
(
boolean
disabled
)
{
this
.
disabled
=
disabled
;
}
/**
/**
* Note: this class has a natural ordering that is inconsistent with equals.
* Note: this class has a natural ordering that is inconsistent with equals.
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/placemap/v1/PlacemapRestViewV1.java
0 → 100644
View file @
8f96083
package
fi
.
codecrew
.
moya
.
rest
.
placemap
.
v1
;
import
java.util.ArrayList
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
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.SimplePlacePojo
;
import
fi.codecrew.moya.rest.pojo.placemap.SimplePlacelistRoot
;
@RequestScoped
@Path
(
"/placemap/v1"
)
@Consumes
({
MediaType
.
APPLICATION_JSON
})
@Produces
({
MediaType
.
APPLICATION_JSON
+
"; charset=UTF-8"
})
public
class
PlacemapRestViewV1
{
@EJB
private
PlaceBeanLocal
placebean
;
@GET
@Path
(
"{id}/places"
)
public
SimplePlacelistRoot
getPlaces
(
@PathParam
(
"id"
)
Integer
mapId
)
{
EventMap
map
=
placebean
.
findMap
(
mapId
);
return
SimplePlacelistRoot
.
wrap
(
map
.
getPlaces
(),
null
);
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/placemap/SimplePlacePojo.java
0 → 100644
View file @
8f96083
package
fi
.
codecrew
.
moya
.
rest
.
pojo
.
placemap
;
import
javax.xml.bind.annotation.XmlElement
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Place
;
public
class
SimplePlacePojo
{
private
Place
place
;
private
EventUser
user
;
public
SimplePlacePojo
(
Place
place
,
EventUser
user
)
{
super
();
this
.
place
=
place
;
this
.
user
=
user
;
}
public
SimplePlacePojo
()
{
super
();
}
@XmlElement
(
name
=
"id"
)
public
Integer
getId
()
{
return
place
.
getId
();
}
@XmlElement
(
name
=
"name"
)
public
String
getName
()
{
return
place
.
getName
();
}
@XmlElement
(
name
=
"state"
)
public
String
getState
()
{
String
ret
=
null
;
switch
(
place
.
getState
(
user
))
{
case
DISABLED:
ret
=
"D"
;
break
;
case
FREE:
ret
=
"F"
;
break
;
case
LOCKED:
ret
=
"L"
;
break
;
case
MY_PLACE:
ret
=
"P"
;
break
;
case
RESERVED:
ret
=
"R"
;
break
;
case
TEMP_RESERVED_FORME:
ret
=
"T"
;
break
;
default
:
break
;
}
return
ret
;
}
@XmlElement
(
name
=
"x"
)
public
Integer
getX
()
{
return
place
.
getMapX
();
}
@XmlElement
(
name
=
"y"
)
public
Integer
getY
()
{
return
place
.
getMapY
();
}
@XmlElement
(
name
=
"w"
)
public
Integer
getWidth
()
{
return
place
.
getWidth
();
}
@XmlElement
(
name
=
"h"
)
public
Integer
getHeight
()
{
return
place
.
getHeight
();
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/pojo/placemap/SimplePlacelistRoot.java
0 → 100644
View file @
8f96083
package
fi
.
codecrew
.
moya
.
rest
.
pojo
.
placemap
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlRootElement
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Place
;
@XmlRootElement
public
class
SimplePlacelistRoot
{
private
List
<
SimplePlacePojo
>
places
;
public
List
<
SimplePlacePojo
>
getPlaces
()
{
return
places
;
}
public
void
setPlaces
(
List
<
SimplePlacePojo
>
places
)
{
this
.
places
=
places
;
}
public
static
SimplePlacelistRoot
wrap
(
List
<
Place
>
places
,
EventUser
user
)
{
SimplePlacelistRoot
ret
=
new
SimplePlacelistRoot
();
ArrayList
<
SimplePlacePojo
>
placeList
=
new
ArrayList
<
SimplePlacePojo
>();
ret
.
setPlaces
(
placeList
);
for
(
Place
p
:
places
)
{
placeList
.
add
(
new
SimplePlacePojo
(
p
,
user
));
}
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