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 18458a23
authored
Oct 24, 2012
by
Riku Silvola
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of codecrew.fi:bortal
2 parents
000deb8c
ad84ff38
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
112 additions
and
22 deletions
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/CardPrintBean.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/MenuBean.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/CardPrintBeanLocal.java
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/util/MassPrintResult.java
code/LanBortalWeb/WebContent/WEB-INF/faces-config.xml
code/LanBortalWeb/WebContent/card/massprint.xhtml
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/card/CardMassPrintView.java
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/CardPrintBean.java
View file @
18458a2
...
...
@@ -23,6 +23,7 @@ import fi.insomnia.bortal.facade.EventUserFacade;
import
fi.insomnia.bortal.model.CardTemplate
;
import
fi.insomnia.bortal.model.EventUser
;
import
fi.insomnia.bortal.model.PrintedCard
;
import
fi.insomnia.bortal.util.MassPrintResult
;
import
fi.insomnia.bortal.utilities.BarcodeUtils
;
/**
...
...
@@ -45,27 +46,33 @@ public class CardPrintBean implements CardPrintBeanLocal {
//TODO: Roles?
public
byte
[]
getUserCardsAsPrintablePdf
(
List
<
Integer
>
userIdList
)
throws
Exception
{
public
MassPrintResult
getUserCardsAsPrintablePdf
(
List
<
Integer
>
userIdList
)
throws
Exception
{
ArrayList
<
EventUser
>
listOfEventUsers
=
new
ArrayList
<
EventUser
>();
for
(
Integer
userId
:
userIdList
)
{
listOfEventUsers
.
add
(
eventUserFacade
.
find
(
userId
));
}
byte
[]
pdfData
=
constructPdf
(
listOfEventUsers
);
return
pdfData
;
return
constructPdf
(
listOfEventUsers
);
}
public
byte
[]
getUserCardAsPrintablePdf
(
Integer
userId
)
throws
Exception
{
public
MassPrintResult
getUserCardAsPrintablePdf
(
Integer
userId
)
throws
Exception
{
ArrayList
<
EventUser
>
listOfEventUsers
=
new
ArrayList
<
EventUser
>();
listOfEventUsers
.
add
(
eventUserFacade
.
find
(
userId
));
byte
[]
pdfData
=
constructPdf
(
listOfEventUsers
);
return
pdfData
;
return
constructPdf
(
listOfEventUsers
);
}
private
byte
[]
constructPdf
(
List
<
EventUser
>
users
)
throws
Exception
{
public
void
acceptMassPrintResult
(
MassPrintResult
mpr
)
{
for
(
EventUser
eu
:
mpr
.
getAffectedUsers
())
{
PrintedCard
printedCard
=
cardTemplateBean
.
checkPrintedCard
(
eu
);
printedCard
.
setPrintCount
(
printedCard
.
getPrintCount
()+
1
);
System
.
out
.
println
(
"Print count "
+
printedCard
.
getPrintCount
());
}
}
private
MassPrintResult
constructPdf
(
List
<
EventUser
>
users
)
throws
Exception
{
// double[] pageSize = new double[] { cardBackground.getWidth(),
// cardBackground.getHeight() };
...
...
@@ -78,13 +85,14 @@ public class CardPrintBean implements CardPrintBeanLocal {
double
pagex
=
155.52
;
// 54,0 mm
double
pagey
=
243.84
;
// 85,5 mm
int
numCards
=
0
;
MassPrintResult
mpr
=
new
MassPrintResult
()
;
for
(
EventUser
user
:
users
)
{
PrintedCard
printedCard
=
cardTemplateBean
.
checkPrintedCard
(
user
);
if
(
printedCard
==
null
)
continue
;
else
numCards
++;
if
(
printedCard
==
null
)
continue
;
CardTemplate
cardTemplate
=
printedCard
.
getTemplate
();
...
...
@@ -154,14 +162,15 @@ public class CardPrintBean implements CardPrintBeanLocal {
barCodeImage
.
setPosition
(
0.0
,
243.5
);
barCodeImage
.
scaleBy
(
0.7
);
barCodeImage
.
drawOn
(
page
);
mpr
.
getAffectedUsers
().
add
(
user
);
}
pdf
.
flush
();
outputStream
.
close
();
if
(
numCards
==
0
)
throw
new
Exception
(
"No cards generated"
);
return
outputStream
.
toByteArray
()
;
if
(
mpr
.
getAffectedUsers
().
size
()
==
0
)
throw
new
Exception
(
"No cards generated"
);
mpr
.
setPdf
(
outputStream
.
toByteArray
());
return
mpr
;
}
private
ByteArrayInputStream
convertBufferedImageToPng
(
BufferedImage
img
)
...
...
code/LanBortalBeans/ejbModule/fi/insomnia/bortal/beans/MenuBean.java
View file @
18458a2
...
...
@@ -82,6 +82,8 @@ public class MenuBean implements MenuBeanLocal {
frontTopnavi
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/auth/passwordChanged"
),
null
).
setVisible
(
false
);
frontTopnavi
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/auth/notauthorized"
),
null
).
setVisible
(
false
);
MenuNavigation
userTopnavi
=
usernavi
.
addPage
(
null
,
null
);
userTopnavi
.
setKey
(
"topnavi.user"
);
userTopnavi
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/user/edit"
),
UserPermission
.
VIEW_SELF
).
setHeader
(
"submenu.user.userlinks"
);
...
...
@@ -93,6 +95,10 @@ public class MenuBean implements MenuBeanLocal {
MenuNavigation
placemapTopmenu
=
usernavi
.
addPage
(
null
,
null
);
placemapTopmenu
.
setKey
(
"topnavi.placemap"
);
placemapTopmenu
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/place/placemap"
),
MapPermission
.
VIEW
);
MenuNavigation
actionlogTopmenu
=
usernavi
.
addPage
(
null
,
null
);
actionlogTopmenu
.
setKey
(
"topnavi.actionlog"
);
actionlogTopmenu
.
addPage
(
menuitemfacade
.
findOrCreate
(
"/actionlog/messagelist"
),
ContentPermission
.
MANAGE_ACTIONLOG
);
MenuNavigation
shopTopmenu
=
usernavi
.
addPage
(
null
,
null
);
shopTopmenu
.
setKey
(
"topnavi.shop"
);
...
...
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/beans/CardPrintBeanLocal.java
View file @
18458a2
...
...
@@ -4,8 +4,11 @@ import java.util.List;
import
javax.ejb.Local
;
import
fi.insomnia.bortal.util.MassPrintResult
;
@Local
public
interface
CardPrintBeanLocal
{
public
byte
[]
getUserCardsAsPrintablePdf
(
List
<
Integer
>
userIdList
)
throws
Exception
;
public
byte
[]
getUserCardAsPrintablePdf
(
Integer
userId
)
throws
Exception
;
public
MassPrintResult
getUserCardsAsPrintablePdf
(
List
<
Integer
>
userIdList
)
throws
Exception
;
public
MassPrintResult
getUserCardAsPrintablePdf
(
Integer
userId
)
throws
Exception
;
public
void
acceptMassPrintResult
(
MassPrintResult
mpr
);
}
code/LanBortalBeansClient/ejbModule/fi/insomnia/bortal/util/MassPrintResult.java
0 → 100755
View file @
18458a2
package
fi
.
insomnia
.
bortal
.
util
;
import
java.util.ArrayList
;
import
java.util.List
;
import
fi.insomnia.bortal.model.EventUser
;
public
class
MassPrintResult
{
private
byte
[]
pdf
;
private
List
<
EventUser
>
affectedUsers
=
new
ArrayList
<
EventUser
>();
public
byte
[]
getPdf
()
{
return
pdf
;
}
public
void
setPdf
(
byte
[]
pdf
)
{
this
.
pdf
=
pdf
;
}
public
List
<
EventUser
>
getAffectedUsers
()
{
return
affectedUsers
;
}
public
void
setAffectedUsers
(
List
<
EventUser
>
affectedUsers
)
{
this
.
affectedUsers
=
affectedUsers
;
}
}
code/LanBortalWeb/WebContent/WEB-INF/faces-config.xml
View file @
18458a2
...
...
@@ -123,6 +123,15 @@
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>
card/massprint
</display-name>
<from-view-id>
/card/massprint.xhtml
</from-view-id>
<navigation-case>
<from-outcome>
accepted
</from-outcome>
<to-view-id>
/useradmin/list.xhtml
</to-view-id>
<redirect
/>
</navigation-case>
</navigation-rule>
<navigation-rule>
<display-name>
voting/create
</display-name>
<from-view-id>
/voting/create.xhtml
</from-view-id>
<navigation-case>
...
...
code/LanBortalWeb/WebContent/card/massprint.xhtml
View file @
18458a2
...
...
@@ -14,10 +14,12 @@
<h1>
#{i18n['card.massprint.title']}
</h1>
</ui:define>
<ui:define
name=
"content"
>
<h:form>
<p:commandButton
rendered=
"#{cardMassPrintView.file!=null}"
id=
"downloadLink"
value=
"Download"
ajax=
"false"
onclick=
"PrimeFaces.monitorDownload(start, stop)"
icon=
"ui-icon-arrowthichk-s"
>
<p:fileDownload
value=
"#{cardMassPrintView.
f
ile}"
/>
<h:form
rendered=
"#{cardMassPrintView.file!=null}"
>
<p:commandButton
id=
"downloadLink"
value=
"Download"
ajax=
"false"
onclick=
"PrimeFaces.monitorDownload(start, stop)"
icon=
"ui-icon-arrowthichk-s"
>
<p:fileDownload
value=
"#{cardMassPrintView.
streamedF
ile}"
/>
</p:commandButton>
<p:commandButton
value=
"Accept printout"
action=
"#{cardMassPrintView.acceptPrintout()}"
rendered=
"#{cardMassPrintView.waitForAcceptance}"
/>
</h:form>
</ui:define>
</ui:composition>
...
...
code/LanBortalWeb/src/fi/insomnia/bortal/web/cdiview/card/CardMassPrintView.java
View file @
18458a2
...
...
@@ -8,8 +8,13 @@ import javax.faces.context.FacesContext;
import
javax.inject.Inject
;
import
javax.inject.Named
;
import
org.primefaces.model.DefaultStreamedContent
;
import
org.primefaces.model.StreamedContent
;
import
fi.insomnia.bortal.beans.CardPrintBeanLocal
;
import
fi.insomnia.bortal.model.EventUser
;
import
fi.insomnia.bortal.util.MassPrintResult
;
import
fi.insomnia.bortal.web.cdiview.GenericCDIView
;
import
fi.insomnia.bortal.web.cdiview.user.UserCartView
;
import
java.io.File
;
...
...
@@ -22,13 +27,17 @@ import java.util.List;
@Named
@ConversationScoped
public
class
CardMassPrintView
implements
Serializable
{
public
class
CardMassPrintView
extends
GenericCDIView
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
1017243588290663967L
;
@Inject
private
UserCartView
userCartView
;
@EJB
private
CardPrintBeanLocal
cardPrintBean
;
private
File
file
;
private
StreamedContent
streamedFile
;
private
MassPrintResult
mpr
=
null
;
private
boolean
waitForAcceptance
=
true
;
public
CardMassPrintView
()
{
// TODO Auto-generated constructor stub
...
...
@@ -44,16 +53,30 @@ public class CardMassPrintView implements Serializable {
file
=
null
;
try
{
byte
[]
printout
=
cardPrintBean
.
getUserCardsAsPrintablePdf
(
userIdList
);
mpr
=
cardPrintBean
.
getUserCardsAsPrintablePdf
(
userIdList
);
waitForAcceptance
=
true
;
file
=
File
.
createTempFile
(
"cardprintout"
,
null
);
FileOutputStream
fostream
=
new
FileOutputStream
(
file
);
fostream
.
write
(
printout
);
fostream
.
write
(
mpr
.
getPdf
()
);
fostream
.
close
();
setStreamedFile
(
new
DefaultStreamedContent
(
new
FileInputStream
(
this
.
file
)));
}
catch
(
Exception
e
)
{
FacesContext
.
getCurrentInstance
().
addMessage
(
null
,
new
FacesMessage
(
e
.
getMessage
()));
}
}
public
String
acceptPrintout
()
{
if
(
mpr
!=
null
&&
waitForAcceptance
)
{
waitForAcceptance
=
false
;
cardPrintBean
.
acceptMassPrintResult
(
mpr
);
}
userCartView
.
setUsercart
(
new
ArrayList
<
EventUser
>());
return
"accepted"
;
}
public
UserCartView
getUserCartView
()
{
return
userCartView
;
}
...
...
@@ -69,4 +92,20 @@ public class CardMassPrintView implements Serializable {
public
void
setFile
(
File
file
)
{
this
.
file
=
file
;
}
public
StreamedContent
getStreamedFile
()
{
return
streamedFile
;
}
public
void
setStreamedFile
(
StreamedContent
streamedFile
)
{
this
.
streamedFile
=
streamedFile
;
}
public
boolean
isWaitForAcceptance
()
{
return
waitForAcceptance
;
}
public
void
setWaitForAcceptance
(
boolean
waitForAcceptance
)
{
this
.
waitForAcceptance
=
waitForAcceptance
;
}
}
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