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 0441bb8f
authored
Jun 04, 2013
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of codecrew.fi:bortal
2 parents
bcc3824a
7cf04205
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
101 additions
and
14 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BarcodeBean.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardPrintBean.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/BarcodeBeanLocal.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/BarcodeBean.java
View file @
0441bb8
...
@@ -96,6 +96,53 @@ public class BarcodeBean implements BarcodeBeanLocal {
...
@@ -96,6 +96,53 @@ public class BarcodeBean implements BarcodeBeanLocal {
return
hexcode
;
return
hexcode
;
}
}
public
String
getVrAuthCodeForCard
(
PrintedCard
printedCard
)
{
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
PRINTED_CARD_PREFIX
);
if
(
printedCard
==
null
)
return
""
;
String
idStr
=
printedCard
.
getId
().
toString
();
for
(
int
i
=
8
-
idStr
.
length
()
-
sb
.
length
();
i
>
0
;
--
i
)
{
sb
.
append
(
"0"
);
}
sb
.
append
(
idStr
);
String
code
=
sb
.
toString
();
String
hexcode
=
Integer
.
toHexString
(
Integer
.
parseInt
(
code
));
String
checksum
=
Integer
.
toHexString
(
hexcode
.
hashCode
());
checksum
=
checksum
.
substring
(
checksum
.
length
()
-
3
);
hexcode
+=
checksum
;
//hexcode = Integer.toString(hexcode.hashCode());
logger
.
debug
(
"Geneating VrAuthcode for card {} : {}"
,
printedCard
.
getId
(),
hexcode
);
return
hexcode
;
}
public
String
checkVrAuthCode
(
String
code
)
{
String
checksumNew
=
code
.
substring
(
code
.
length
()
-
3
);
code
=
code
.
substring
(
0
,
(
code
.
length
()-
3
));
String
checksumOld
=
Integer
.
toHexString
(
code
.
hashCode
());
checksumOld
=
checksumOld
.
substring
(
checksumOld
.
length
()
-
3
);
if
(
checksumNew
==
checksumOld
)
{
int
decimal
=
Integer
.
decode
(
code
);
code
=
Integer
.
toString
(
decimal
);
String
prefix
=
code
.
substring
(
0
,
2
);
int
id
=
Integer
.
parseInt
(
code
.
substring
(
3
,
code
.
length
()
-
1
));
if
(
prefix
==
PRINTED_CARD_PREFIX
&&
id
!=
0
)
{
PrintedCard
printedCard
=
printedCardFacade
.
find
(
id
);
if
(
printedCard
!=
null
)
return
printedCard
.
getUser
().
getNick
();
else
return
"Invalid"
;
}
}
else
{
return
"Invalid"
;
}
return
"Invalid"
;
}
@Override
@Override
public
Place
getPlaceFromHexcode
(
String
hexcode
)
{
public
Place
getPlaceFromHexcode
(
String
hexcode
)
{
...
...
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardPrintBean.java
View file @
0441bb8
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
import
java.awt.Color
;
import
java.awt.Font
;
import
java.awt.Font
;
import
java.awt.Graphics2D
;
import
java.awt.Graphics2D
;
import
java.awt.Paint
;
import
java.awt.RenderingHints
;
import
java.awt.geom.Point2D
;
import
java.awt.geom.Rectangle2D
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImageOp
;
import
java.awt.image.ColorModel
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
...
@@ -66,6 +73,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -66,6 +73,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
private
PrintedCardFacade
printedCardFacade
;
private
PrintedCardFacade
printedCardFacade
;
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CardPrintBean
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CardPrintBean
.
class
);
private
int
nick_x
=
0
;
private
int
nick_y
=
0
;
/**
/**
* Default constructor.
* Default constructor.
*/
*/
...
@@ -167,6 +177,7 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -167,6 +177,7 @@ public class CardPrintBean implements CardPrintBeanLocal {
Image
faceImage
=
new
Image
(
pdf
,
Image
faceImage
=
new
Image
(
pdf
,
convertBufferedImageToPng
(
faceBufferedImage
),
ImageType
.
PNG
);
convertBufferedImageToPng
(
faceBufferedImage
),
ImageType
.
PNG
);
faceImage
.
setPosition
(
15.5
,
67
);
faceImage
.
setPosition
(
15.5
,
67
);
//faceImage.setPosition(175, 222);
// faceImage.scaleBy(0.32);
// faceImage.scaleBy(0.32);
faceImage
.
scaleBy
(((
410.0
*
0.245
)
/
faceImage
.
getHeight
()));
faceImage
.
scaleBy
(((
410.0
*
0.245
)
/
faceImage
.
getHeight
()));
faceImage
.
drawOn
(
page
);
faceImage
.
drawOn
(
page
);
...
@@ -177,6 +188,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -177,6 +188,9 @@ public class CardPrintBean implements CardPrintBeanLocal {
nickFont
.
setSize
(
16.0
);
nickFont
.
setSize
(
16.0
);
// User nick text
// User nick text
TextLine
nickTextLine
=
new
TextLine
(
nickFont
);
TextLine
nickTextLine
=
new
TextLine
(
nickFont
);
nickTextLine
.
setText
(
user
.
getUser
().
getNick
());
nickTextLine
.
setText
(
user
.
getUser
().
getNick
());
nickTextLine
.
setPosition
(
19.0
,
193.0
);
nickTextLine
.
setPosition
(
19.0
,
193.0
);
...
@@ -247,14 +261,24 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -247,14 +261,24 @@ public class CardPrintBean implements CardPrintBeanLocal {
// g.drawImage(face, AffineTransform.getScaleInstance(0.31, 0.31),
// g.drawImage(face, AffineTransform.getScaleInstance(0.31, 0.31),
// null);
// null);
g
.
drawImage
(
face
,
60
,
300
,
320
,
400
,
null
);
//faceImage.scaleBy(((410.0 * 0.245) / faceImage.getHeight()));
g
.
drawImage
(
face
,
166
,
241
,
318
,
400
,
null
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
70
));
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
70
));
// g.drawString(nick, 595 -
Font
font
=
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
70
);
// g.getFontMetrics().charsWidth(nick.toCharArray(), 0, nick.length()),
int
nickWidth
=
g
.
getFontMetrics
(
font
).
stringWidth
(
user
.
getUser
().
getNick
());
// 840);
int
nickX
=
(
646
/
2
)
-
(
nickWidth
/
2
);
g
.
drawString
(
user
.
getUser
().
getNick
(),
50
,
810
);
int
nickY
=
750
;
//Color transparentWhite = new Color(255, 255, 255, 140);
//g.setColor(transparentWhite);
//g.fillRect(nickX - 20, nickY - 50, nickWidth + 40, 50);
g
.
setColor
(
Color
.
black
);
g
.
setFont
(
font
);
g
.
drawString
(
user
.
getUser
().
getNick
(),
nickX
,
nickY
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
45
));
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
45
));
...
@@ -268,14 +292,29 @@ public class CardPrintBean implements CardPrintBeanLocal {
...
@@ -268,14 +292,29 @@ public class CardPrintBean implements CardPrintBeanLocal {
//
//
// g.drawString(owner.getId().toString(), 60, 948);
// g.drawString(owner.getId().toString(), 60, 948);
g
.
drawString
(
wholeName
.
toString
(),
60
,
865
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
BOLD
,
40
));
g
.
drawString
(
card
.
getTemplate
().
getName
(),
60
,
915
);
g
.
drawString
(
wholeName
.
toString
(),
60
,
950
);
//g.drawString(card.getTemplate().getName(), 60, 915);
String
barcodeString
=
String
.
valueOf
(
user
.
getUser
().
getCreated
().
getTime
().
getTime
());
barcodeString
=
barcodeString
.
substring
(
barcodeString
.
length
()
-
12
);
PrintedCard
printedCard
=
cardTemplateBean
.
checkPrintedCard
(
user
);
BufferedImage
image
=
ImageIO
.
read
(
BarcodeUtils
.
getBarcodeEAN
(
barcodeString
));
g
.
drawImage
(
image
,
0
,
base
.
getHeight
()
-
120
,
base
.
getWidth
(),
120
,
null
);
g
.
setFont
(
new
Font
(
"Century gothic"
,
Font
.
PLAIN
,
30
));
g
.
setColor
(
Color
.
white
);
if
(
printedCard
!=
null
)
g
.
drawString
(
barcodeBean
.
getVrAuthCodeForCard
(
printedCard
),
445
,
905
);
BufferedImage
barCodeBufferedImage
=
ImageIO
.
read
(
barcodeBean
.
getCardBarcode
(
printedCard
));
//int barcodeX = (base.getWidth()/2) - (image.getWidth()/2);
int
barcodeX
=
(
base
.
getWidth
()
-
400
)/
2
;
int
barcodeY
=
base
.
getHeight
()
-
50
;
if
(
printedCard
!=
null
)
g
.
drawImage
(
barCodeBufferedImage
,
barcodeX
,
barcodeY
,
400
,
barCodeBufferedImage
.
getHeight
(),
null
);
g
.
setColor
(
Color
.
white
);
g
.
fillRect
(
0
,
base
.
getHeight
()-
20
,
base
.
getWidth
(),
base
.
getHeight
());
g
.
dispose
();
g
.
dispose
();
ByteArrayOutputStream
ostr
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
ostr
=
new
ByteArrayOutputStream
();
...
...
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/BarcodeBeanLocal.java
View file @
0441bb8
...
@@ -19,5 +19,6 @@ public interface BarcodeBeanLocal {
...
@@ -19,5 +19,6 @@ public interface BarcodeBeanLocal {
public
InputStream
getCardBarcode
(
PrintedCard
printedCard
)
throws
IOException
;
public
InputStream
getCardBarcode
(
PrintedCard
printedCard
)
throws
IOException
;
public
String
getPlaceHexcode
(
Place
place
);
public
String
getPlaceHexcode
(
Place
place
);
public
Place
getPlaceFromHexcode
(
String
hexcode
);
public
Place
getPlaceFromHexcode
(
String
hexcode
);
public
String
checkVrAuthCode
(
String
code
);
}
}
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