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 fae6cee2
authored
May 11, 2013
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added mutex for printque
1 parent
8e9138de
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
6 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/CardTemplateBeanLocal.java
code/MoyaUtilities/src/fi/codecrew/moya/enums/CardState.java
code/MoyaWeb/src/fi/codecrew/moya/rest/PrinterRestView.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
View file @
fae6cee
...
@@ -271,4 +271,27 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -271,4 +271,27 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
return
printedcardfacade
.
findByState
(
state
);
return
printedcardfacade
.
findByState
(
state
);
}
}
@Override
public
PrintedCard
setCardState
(
int
cardId
,
CardState
state
)
throws
Exception
{
PrintedCard
card
=
printedcardfacade
.
find
(
cardId
);
switch
(
state
)
{
case
PRINTED:
card
.
setPrintCount
(
card
.
getPrintCount
()
+
1
);
break
;
case
PRINTING_IN_PROGRESS:
if
(
card
.
getCardState
().
equals
(
CardState
.
PRINTING_IN_PROGRESS
)
||
card
.
getCardState
().
equals
(
CardState
.
PRINTED
))
{
String
response
=
"Unable to change type to PRINTING_IN_PROGRESS value is already {}"
+
card
.
getCardState
();
logger
.
warn
(
response
);
throw
new
Exception
(
response
);
}
break
;
default
:
break
;
}
card
.
setCardState
(
state
);
return
card
;
}
}
}
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/CardTemplateBeanLocal.java
View file @
fae6cee
...
@@ -44,4 +44,6 @@ public interface CardTemplateBeanLocal extends EntityFinderBean<CardTemplate> {
...
@@ -44,4 +44,6 @@ public interface CardTemplateBeanLocal extends EntityFinderBean<CardTemplate> {
List
<
PrintedCard
>
getCardsByState
(
CardState
...
pendingPrint
);
List
<
PrintedCard
>
getCardsByState
(
CardState
...
pendingPrint
);
PrintedCard
setCardState
(
int
cardId
,
CardState
printed
)
throws
Exception
;
}
}
code/MoyaUtilities/src/fi/codecrew/moya/enums/CardState.java
View file @
fae6cee
...
@@ -8,7 +8,6 @@ public enum CardState {
...
@@ -8,7 +8,6 @@ public enum CardState {
PENDING_VALIDATION
,
PENDING_VALIDATION
,
REJECTED
,
REJECTED
,
VALIDATED
,
VALIDATED
,
PENDING_PRINT
,
PRINTING_IN_PROGRESS
,
PRINTING_IN_PROGRESS
,
PRINTED
;
PRINTED
;
...
...
code/MoyaWeb/src/fi/codecrew/moya/rest/PrinterRestView.java
View file @
fae6cee
...
@@ -39,12 +39,35 @@ public class PrinterRestView {
...
@@ -39,12 +39,35 @@ public class PrinterRestView {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PrinterRestView
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
PrinterRestView
.
class
);
@GET
@GET
@Path
(
"/Reserve/{id}/"
)
public
Response
reserveCardForPrinting
(
@PathParam
(
"id"
)
int
cardId
,
@QueryParam
(
"key"
)
String
hash
)
throws
Exception
{
ResponseBuilder
ret
=
null
;
try
{
PrintedCard
card
=
cardbean
.
setCardState
(
cardId
,
CardState
.
PRINTING_IN_PROGRESS
);
if
(
card
.
getCardState
().
equals
(
CardState
.
PRINTING_IN_PROGRESS
))
{
ret
=
Response
.
ok
(
new
PrintedCardRestPojo
(
card
));
}
}
catch
(
Exception
e
)
{
ret
=
null
;
logger
.
warn
(
"Caught exception while reserving card for printing"
+
cardId
,
e
);
}
if
(
ret
==
null
)
{
ret
=
Response
.
status
(
Response
.
Status
.
CONFLICT
);
}
return
ret
.
build
();
}
@GET
@Path
(
"/Printed/{id}/"
)
@Path
(
"/Printed/{id}/"
)
public
PrintedCardRestPojo
setCardPrinted
(
@PathParam
(
"id"
)
int
cardId
,
@QueryParam
(
"key"
)
String
hash
)
throws
Exception
{
public
PrintedCardRestPojo
setCardPrinted
(
@PathParam
(
"id"
)
int
cardId
,
@QueryParam
(
"key"
)
String
hash
)
throws
Exception
{
PrintedCard
card
=
cardbean
.
findCard
(
cardId
);
return
new
PrintedCardRestPojo
(
cardbean
.
setCardState
(
cardId
,
CardState
.
PRINTED
));
card
.
setCardState
(
CardState
.
PRINTED
);
// PrintedCard card = cardbean.findCard(cardId);
card
=
cardbean
.
saveCard
(
card
);
// card.setCardState(CardState.PRINTED);
return
new
PrintedCardRestPojo
(
card
);
// card.setPrintCount(card.getPrintCount() + 1);
// card = cardbean.saveCard(card);
// return new PrintedCardRestPojo(card);
}
}
@GET
@GET
...
@@ -76,7 +99,7 @@ public class PrinterRestView {
...
@@ -76,7 +99,7 @@ public class PrinterRestView {
@GET
@GET
@Path
(
"/ListUnprinted"
)
@Path
(
"/ListUnprinted"
)
public
List
<
PrintedCardRestPojo
>
getUserCard
(
@QueryParam
(
"key"
)
String
key
)
throws
Exception
{
public
List
<
PrintedCardRestPojo
>
getUserCard
(
@QueryParam
(
"key"
)
String
key
)
throws
Exception
{
List
<
PrintedCardRestPojo
>
ret
=
PrintedCardRestPojo
.
parseCards
(
cardbean
.
getCardsByState
(
CardState
.
PENDING_PRINT
));
List
<
PrintedCardRestPojo
>
ret
=
PrintedCardRestPojo
.
parseCards
(
cardbean
.
getCardsByState
(
CardState
.
VALIDATED
));
logger
.
info
(
"Returning card pojos: {} for key {}"
,
ret
,
key
);
logger
.
info
(
"Returning card pojos: {} for key {}"
,
ret
,
key
);
return
ret
;
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