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 fd170d66
authored
May 12, 2013
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tarratulostusta, paikat
1 parent
26c197b6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
164 additions
and
10 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BarcodeBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/BarcodeBeanLocal.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/PlaceBeanLocal.java
code/MoyaDatabase/src/fi/codecrew/moya/model/Place.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BarcodeBean.java
View file @
fd170d6
...
@@ -10,10 +10,11 @@ import javax.ejb.Stateless;
...
@@ -10,10 +10,11 @@ import javax.ejb.Stateless;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.facade.PlaceFacade
;
import
fi.codecrew.moya.facade.PrintedCardFacade
;
import
fi.codecrew.moya.facade.PrintedCardFacade
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.PrintedCard
;
import
fi.codecrew.moya.model.PrintedCard
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.utilities.BarcodeUtils
;
import
fi.codecrew.moya.utilities.BarcodeUtils
;
/**
/**
...
@@ -24,15 +25,19 @@ import fi.codecrew.moya.utilities.BarcodeUtils;
...
@@ -24,15 +25,19 @@ import fi.codecrew.moya.utilities.BarcodeUtils;
public
class
BarcodeBean
implements
BarcodeBeanLocal
{
public
class
BarcodeBean
implements
BarcodeBeanLocal
{
private
static
final
String
PRINTED_CARD_PREFIX
=
"277"
;
//2M
private
static
final
String
PRINTED_CARD_PREFIX
=
"277"
;
//2M
private
static
final
String
EVENTUSER_PREFIX
=
"279"
;
//2O
private
static
final
String
EVENTUSER_PREFIX
=
"279"
;
//2O
//private static final String NEXT
_PREFIX = "289"; //2Y
private
static
final
String
PLACE
_PREFIX
=
"289"
;
//2Y
//private static final String NEXT_PREFIX = "265"; //2A
//private static final String NEXT_PREFIX = "265"; //2A
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BarcodeBean
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BarcodeBean
.
class
);
@EJB
@EJB
PrintedCardFacade
printedCardFacade
;
PrintedCardFacade
printedCardFacade
;
@EJB
@EJB
PlaceFacade
placeFacade
;
@EJB
UserBeanLocal
userBean
;
UserBeanLocal
userBean
;
/**
/**
...
@@ -71,6 +76,43 @@ public class BarcodeBean implements BarcodeBeanLocal {
...
@@ -71,6 +76,43 @@ public class BarcodeBean implements BarcodeBeanLocal {
return
BarcodeUtils
.
getBarcodeEAN
(
barcode
);
return
BarcodeUtils
.
getBarcodeEAN
(
barcode
);
}
}
public
String
getPlaceHexcode
(
Place
place
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
PLACE_PREFIX
);
String
idStr
=
place
.
getId
().
toString
();
for
(
int
i
=
12
-
idStr
.
length
()
-
sb
.
length
();
i
>
0
;
--
i
)
{
sb
.
append
(
"0"
);
}
sb
.
append
(
idStr
);
String
barcode
=
sb
.
toString
();
String
hexcode
=
Integer
.
toHexString
(
Integer
.
parseInt
(
barcode
));
logger
.
debug
(
"Geneating hexcode for place {} : {}"
,
place
.
getId
(),
hexcode
);
return
hexcode
;
}
@Override
public
Place
getPlaceFromHexcode
(
String
hexcode
)
{
String
barcode
=
""
+
Integer
.
parseInt
(
hexcode
,
16
);
try
{
if
(
barcode
.
startsWith
(
PLACE_PREFIX
))
{
int
id
=
Integer
.
parseInt
(
barcode
.
substring
(
3
,
barcode
.
length
()-
1
));
Place
place
=
placeFacade
.
find
(
id
);
return
place
;
}
}
catch
(
NumberFormatException
x
)
{
}
return
null
;
}
public
PrintedCard
getPrintedCard
(
String
barcode
)
{
public
PrintedCard
getPrintedCard
(
String
barcode
)
{
if
(
barcode
==
null
||
barcode
.
isEmpty
())
if
(
barcode
==
null
||
barcode
.
isEmpty
())
...
@@ -110,4 +152,6 @@ public class BarcodeBean implements BarcodeBeanLocal {
...
@@ -110,4 +152,6 @@ public class BarcodeBean implements BarcodeBeanLocal {
return
null
;
return
null
;
}
}
}
}
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/PlaceBean.java
View file @
fd170d6
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.io.ByteArrayOutputStream
;
import
java.math.BigDecimal
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
...
@@ -31,6 +32,11 @@ import javax.ejb.TimerService;
...
@@ -31,6 +32,11 @@ import javax.ejb.TimerService;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
com.pdfjet.CoreFont
;
import
com.pdfjet.PDF
;
import
com.pdfjet.Page
;
import
com.pdfjet.TextLine
;
import
fi.codecrew.moya.enums.apps.MapPermission
;
import
fi.codecrew.moya.enums.apps.MapPermission
;
import
fi.codecrew.moya.enums.apps.SpecialPermission
;
import
fi.codecrew.moya.enums.apps.SpecialPermission
;
import
fi.codecrew.moya.exceptions.BortalCatchableException
;
import
fi.codecrew.moya.exceptions.BortalCatchableException
;
...
@@ -99,6 +105,9 @@ public class PlaceBean implements PlaceBeanLocal {
...
@@ -99,6 +105,9 @@ public class PlaceBean implements PlaceBeanLocal {
@EJB
@EJB
private
ProductPBean
productPBean
;
private
ProductPBean
productPBean
;
@EJB
private
BarcodeBeanLocal
barcodeBean
;
@Override
@Override
@RolesAllowed
(
MapPermission
.
S_MANAGE_MAPS
)
@RolesAllowed
(
MapPermission
.
S_MANAGE_MAPS
)
public
Place
mergeChanges
(
Place
place
)
{
public
Place
mergeChanges
(
Place
place
)
{
...
@@ -506,4 +515,79 @@ public class PlaceBean implements PlaceBeanLocal {
...
@@ -506,4 +515,79 @@ public class PlaceBean implements PlaceBeanLocal {
}
}
return
place
;
return
place
;
}
}
private
byte
[]
generatePlacesPdf
(
double
width
,
double
height
,
double
font1
,
double
font2
,
List
<
Place
>
places
)
throws
Exception
{
ByteArrayOutputStream
outputStream
=
new
ByteArrayOutputStream
();
PDF
pdf
=
new
PDF
(
outputStream
);
pdf
.
setTitle
(
"Place"
);
double
pointInMillim
=
(
25.4
/
72.0
);
// 1 point is 1/72 inches. 1 inch = 25.4mm
double
pagex
=
width
/
pointInMillim
;
double
pagey
=
height
/
pointInMillim
;
for
(
Place
place
:
places
)
{
Page
page
=
new
Page
(
pdf
,
new
double
[]
{
pagex
,
pagey
});
// place code
com
.
pdfjet
.
Font
font
=
new
com
.
pdfjet
.
Font
(
pdf
,
CoreFont
.
HELVETICA
);
font
.
setSize
(
font1
);
TextLine
textLine
=
new
TextLine
(
font
);
textLine
.
setText
(
place
.
getCode
());
textLine
.
setPosition
(
3
,
3
);
textLine
.
setColor
(
new
double
[]
{
0
,
0
,
0
});
textLine
.
drawOn
(
page
);
double
currentX
=
font1
*
4
;
// nick
if
(
place
.
getPlaceReserver
()
!=
null
&&
place
.
getPlaceReserver
().
getUser
()
!=
null
)
{
font
=
new
com
.
pdfjet
.
Font
(
pdf
,
CoreFont
.
HELVETICA
);
font
.
setSize
(
font2
);
textLine
=
new
TextLine
(
font
);
textLine
.
setText
(
place
.
getPlaceReserver
().
getUser
().
getNick
());
textLine
.
setPosition
(
currentX
,
3
);
textLine
.
setColor
(
new
double
[]
{
0
,
0
,
0
});
textLine
.
drawOn
(
page
);
}
// place hex code
font
=
new
com
.
pdfjet
.
Font
(
pdf
,
CoreFont
.
HELVETICA
);
font
.
setSize
(
font2
);
textLine
=
new
TextLine
(
font
);
textLine
.
setText
(
barcodeBean
.
getPlaceHexcode
(
place
));
textLine
.
setPosition
(
currentX
,
(
height
/
2
));
textLine
.
setColor
(
new
double
[]
{
0
,
0
,
0
});
textLine
.
drawOn
(
page
);
}
pdf
.
flush
();
outputStream
.
close
();
return
outputStream
.
toByteArray
();
}
@Override
public
byte
[]
generatePlacesPdf
(
double
width
,
double
height
,
double
font1
,
double
font2
)
{
try
{
return
generatePlacesPdf
(
width
,
height
,
font1
,
font1
,
placeFacade
.
findAll
());
}
catch
(
Exception
e
)
{
logger
.
error
(
"Exception from place pdf generation."
,
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
code/MoyaBeans/ejbModule/fi/codecrew/moya/facade/PlaceFacade.java
View file @
fd170d6
...
@@ -3,6 +3,7 @@ package fi.codecrew.moya.facade;
...
@@ -3,6 +3,7 @@ package fi.codecrew.moya.facade;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.List
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.ejb.LocalBean
;
import
javax.ejb.LocalBean
;
import
javax.ejb.Stateless
;
import
javax.ejb.Stateless
;
import
javax.persistence.TypedQuery
;
import
javax.persistence.TypedQuery
;
...
@@ -14,18 +15,22 @@ import javax.persistence.criteria.Root;
...
@@ -14,18 +15,22 @@ import javax.persistence.criteria.Root;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
fi.codecrew.moya.model.EventMap_
;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.model.Place_
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventMap
;
import
fi.codecrew.moya.model.EventMap_
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.LanEvent
;
import
fi.codecrew.moya.model.LanEvent
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.Place_
;
@Stateless
@Stateless
@LocalBean
@LocalBean
public
class
PlaceFacade
extends
IntegerPkGenericFacade
<
Place
>
{
public
class
PlaceFacade
extends
IntegerPkGenericFacade
<
Place
>
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlaceFacade
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PlaceFacade
.
class
);
@EJB
EventBeanLocal
eventBean
;
public
PlaceFacade
()
{
public
PlaceFacade
()
{
...
@@ -122,4 +127,17 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
...
@@ -122,4 +127,17 @@ public class PlaceFacade extends IntegerPkGenericFacade<Place> {
);
);
return
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
return
getSingleNullableResult
(
getEm
().
createQuery
(
cq
));
}
}
public
List
<
Place
>
findAll
()
{
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
).
get
(
EventMap_
.
event
),
eventBean
.
getCurrentEvent
()));
return
getEm
().
createQuery
(
cq
).
getResultList
();
}
}
}
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/BarcodeBeanLocal.java
View file @
fd170d6
...
@@ -6,6 +6,7 @@ import java.io.InputStream;
...
@@ -6,6 +6,7 @@ import java.io.InputStream;
import
javax.ejb.Local
;
import
javax.ejb.Local
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.PrintedCard
;
import
fi.codecrew.moya.model.PrintedCard
;
@Local
@Local
...
@@ -16,5 +17,7 @@ public interface BarcodeBeanLocal {
...
@@ -16,5 +17,7 @@ public interface BarcodeBeanLocal {
public
InputStream
getUserBarcode
(
EventUser
user
)
throws
IOException
;
public
InputStream
getUserBarcode
(
EventUser
user
)
throws
IOException
;
public
InputStream
getCardBarcode
(
PrintedCard
printedCard
)
throws
IOException
;
public
InputStream
getCardBarcode
(
PrintedCard
printedCard
)
throws
IOException
;
public
String
getPlaceHexcode
(
Place
place
);
public
Place
getPlaceFromHexcode
(
String
hexcode
);
}
}
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/PlaceBeanLocal.java
View file @
fd170d6
...
@@ -46,5 +46,15 @@ public interface PlaceBeanLocal {
...
@@ -46,5 +46,15 @@ public interface PlaceBeanLocal {
BigDecimal
getTotalReservationPrice
(
EventUser
user
,
Place
newPlace
);
BigDecimal
getTotalReservationPrice
(
EventUser
user
,
Place
newPlace
);
BigDecimal
getTotalReservationPrice
(
Place
newPlace
);
BigDecimal
getTotalReservationPrice
(
Place
newPlace
);
/**
*
* @param width page width in millimeters
* @param height page height in millimeters
* @param font1 font 1 size
* @param font2 font 2 size
* @return
*/
public
byte
[]
generatePlacesPdf
(
double
width
,
double
height
,
double
font1
,
double
font2
);
}
}
code/MoyaDatabase/src/fi/codecrew/moya/model/Place.java
View file @
fd170d6
package
fi
.
codecrew
.
moya
.
model
;
package
fi
.
codecrew
.
moya
.
model
;
import
java.util.ArrayList
;
import
java.util.Calendar
;
import
java.util.Calendar
;
import
java.util.List
;
import
javax.persistence.CascadeType
;
import
javax.persistence.CascadeType
;
import
javax.persistence.Column
;
import
javax.persistence.Column
;
import
javax.persistence.Entity
;
import
javax.persistence.Entity
;
import
javax.persistence.FetchType
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.JoinColumn
;
import
javax.persistence.Lob
;
import
javax.persistence.Lob
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.ManyToOne
;
import
javax.persistence.OneToMany
;
import
javax.persistence.OneToOne
;
import
javax.persistence.OneToOne
;
import
javax.persistence.OrderBy
;
import
javax.persistence.Table
;
import
javax.persistence.Table
;
import
javax.persistence.Temporal
;
import
javax.persistence.Temporal
;
import
javax.persistence.TemporalType
;
import
javax.persistence.TemporalType
;
...
...
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