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 950a912f
authored
Jan 31, 2018
by
Tuomas Riihimäki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drd apis
1 parent
fe5aa708
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
243 additions
and
113 deletions
code/moya-beans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ReaderBean.java
code/moya-beans/ejbModule/fi/codecrew/moya/facade/ApiApplicationInstanceFacade.java
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/reader/v1/ReaderEventRestPojo.java
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/userinfo/v1/PrintedCardUpdateCodePojo.java
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/userinfo/v1/UserPwdPojo.java
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/JsonUtils.java
code/moya-web/pom.xml
code/moya-web/src/main/java/fi/codecrew/moya/rest/PojoUtils.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/ReaderRestView.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/UserRestView.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/apiapp/v1/ApiAppRestViewV1.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/appconfig/v1/EventInfoV1.java
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/UserRestViewV2.java
code/moya-beans/ejbModule/fi/codecrew/moya/beans/CardTemplateBean.java
View file @
950a912
...
@@ -65,13 +65,10 @@ import fi.codecrew.moya.util.MailMessage;
...
@@ -65,13 +65,10 @@ import fi.codecrew.moya.util.MailMessage;
*/
*/
@Stateless
@Stateless
@LocalBean
@LocalBean
@DeclareRoles
({
UserPermission
.
S_WRITE_ROLES
})
@DeclareRoles
({
UserPermission
.
S_WRITE_ROLES
})
public
class
CardTemplateBean
implements
CardTemplateBeanLocal
{
public
class
CardTemplateBean
implements
CardTemplateBeanLocal
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CardTemplateBean
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
CardTemplateBean
.
class
);
/**
/**
...
@@ -114,7 +111,6 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -114,7 +111,6 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
private
CardCodeFacade
cardCodeFacade
;
private
CardCodeFacade
cardCodeFacade
;
// @Override
// @Override
// @RolesAllowed("USER_MANAGEMENT/WRITE")
// @RolesAllowed("USER_MANAGEMENT/WRITE")
// public List<CardTemplate> findAll() {
// public List<CardTemplate> findAll() {
...
@@ -126,8 +122,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -126,8 +122,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
public
void
create
(
CardTemplate
card
)
{
public
void
create
(
CardTemplate
card
)
{
LanEvent
currEv
=
eventBean
.
getCurrentEvent
();
LanEvent
currEv
=
eventBean
.
getCurrentEvent
();
if
(
currEv
.
getCardTemplates
()
==
null
)
if
(
currEv
.
getCardTemplates
()
==
null
)
{
{
currEv
.
setCardTemplates
(
new
ArrayList
<
CardTemplate
>());
currEv
.
setCardTemplates
(
new
ArrayList
<
CardTemplate
>());
}
}
card
.
setEvent
(
currEv
);
card
.
setEvent
(
currEv
);
...
@@ -169,20 +164,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -169,20 +164,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
logger
.
info
(
"Checking printed card"
);
logger
.
info
(
"Checking printed card"
);
user
=
eventUserFacade
.
reload
(
user
);
user
=
eventUserFacade
.
reload
(
user
);
if
(
user
==
null
)
return
null
;
LanEvent
currEvent
=
eventBean
.
getCurrentEvent
();
LanEvent
currEvent
=
eventBean
.
getCurrentEvent
();
List
<
PrintedCard
>
myCards
=
printedcardfacade
.
getCards
(
user
);
List
<
PrintedCard
>
myCards
=
printedcardfacade
.
getCards
(
user
);
PrintedCard
biggestCard
=
null
;
PrintedCard
biggestCard
=
null
;
for
(
PrintedCard
card
:
myCards
)
{
for
(
PrintedCard
card
:
myCards
)
{
if
(
card
.
getEnabled
())
{
if
(
card
.
getEnabled
()
&&
biggestCard
==
null
||
biggestCard
.
getTemplate
().
getPower
()
<
card
.
getTemplate
().
getPower
())
{
if
(
biggestCard
==
null
||
biggestCard
.
getTemplate
().
getPower
()
<
card
.
getTemplate
().
getPower
())
{
// The biggest card should be the only one enabled.
// The biggest card should be the only one enabled.
if
(
biggestCard
!=
null
)
{
if
(
biggestCard
!=
null
)
{
biggestCard
.
setEnabled
(
false
);
biggestCard
.
setEnabled
(
false
);
}
}
biggestCard
=
card
;
biggestCard
=
card
;
}
}
}
}
}
...
@@ -211,12 +206,11 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -211,12 +206,11 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
user
.
getPrintedCards
().
add
(
pc
);
user
.
getPrintedCards
().
add
(
pc
);
// printedcardfacade.create(pc);
// printedcardfacade.create(pc);
biggestCard
=
pc
;
biggestCard
=
pc
;
logger
.
info
(
"User {} has too little power old role {} New role {}"
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
logger
.
info
(
"User {} has too little power old role {} New role {}"
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
}
else
if
(
existingPower
>
newPower
)
{
}
else
if
(
existingPower
>
newPower
)
{
MailMessage
msg
=
new
MailMessage
();
MailMessage
msg
=
new
MailMessage
();
LanEventProperty
value
=
eventPropertyFacade
.
find
(
eventBean
.
getCurrentEvent
(),
LanEventPropertyKey
.
ADMIN_MAIL
);
LanEventProperty
value
=
eventPropertyFacade
.
find
(
eventBean
.
getCurrentEvent
(),
LanEventPropertyKey
.
ADMIN_MAIL
);
if
(
value
!=
null
&&
value
.
getTextvalue
()
!=
null
&&
!
value
.
getTextvalue
().
isEmpty
())
if
(
value
!=
null
&&
value
.
getTextvalue
()
!=
null
&&
!
value
.
getTextvalue
().
isEmpty
())
{
{
msg
.
setFromAddress
(
value
.
getTextvalue
());
msg
.
setFromAddress
(
value
.
getTextvalue
());
msg
.
setFromName
(
"Lippukauppa"
);
msg
.
setFromName
(
"Lippukauppa"
);
...
@@ -226,12 +220,12 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -226,12 +220,12 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
mailbean
.
sendMail
(
msg
);
mailbean
.
sendMail
(
msg
);
}
}
logger
.
info
(
"User {} has too much power old role {} New role {}, old card revoked."
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
logger
.
info
(
"User {} has too much power old role {} New role {}, old card revoked."
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
biggestCard
.
setEnabled
(
false
);
biggestCard
.
setEnabled
(
false
);
return
this
.
checkPrintedCard
(
user
);
return
this
.
checkPrintedCard
(
user
);
}
else
{
}
else
{
logger
.
info
(
"User {} has power {} and roles has power {}"
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
logger
.
info
(
"User {} has power {} and roles has power {}"
,
new
Object
[]
{
user
.
getUser
().
getLogin
(),
existingPower
,
newPower
});
}
}
return
biggestCard
;
return
biggestCard
;
...
@@ -361,8 +355,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -361,8 +355,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override
@Override
public
PrintedCard
setCardState
(
Integer
cardId
,
CardState
state
)
throws
Exception
{
public
PrintedCard
setCardState
(
Integer
cardId
,
CardState
state
)
throws
Exception
{
PrintedCard
card
=
printedcardfacade
.
find
(
cardId
);
PrintedCard
card
=
printedcardfacade
.
find
(
cardId
);
switch
(
state
)
switch
(
state
)
{
{
case
PRINTED:
case
PRINTED:
card
.
setPrintCount
(
card
.
getPrintCount
()
+
1
);
card
.
setPrintCount
(
card
.
getPrintCount
()
+
1
);
card
.
setPrintTime
(
Calendar
.
getInstance
());
card
.
setPrintTime
(
Calendar
.
getInstance
());
...
@@ -384,10 +377,6 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -384,10 +377,6 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
}
}
@Override
@Override
public
EventUser
giveCard
(
EventUser
user
,
boolean
markUserPlacesDelivered
)
{
public
EventUser
giveCard
(
EventUser
user
,
boolean
markUserPlacesDelivered
)
{
...
@@ -414,7 +403,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -414,7 +403,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
public
void
removeCardCode
(
CardCode
code
)
{
public
void
removeCardCode
(
CardCode
code
)
{
code
=
cardCodeFacade
.
reload
(
code
);
code
=
cardCodeFacade
.
reload
(
code
);
if
(
code
.
getPrintedCard
().
getCardCodes
().
contains
(
code
))
{
if
(
code
.
getPrintedCard
().
getCardCodes
().
contains
(
code
))
{
code
.
getPrintedCard
().
getCardCodes
().
remove
(
code
);
code
.
getPrintedCard
().
getCardCodes
().
remove
(
code
);
}
}
...
@@ -454,6 +443,4 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -454,6 +443,4 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
}
}
}
}
code/moya-beans/ejbModule/fi/codecrew/moya/beans/ReaderBean.java
View file @
950a912
...
@@ -138,8 +138,8 @@ public class ReaderBean implements ReaderBeanLocal {
...
@@ -138,8 +138,8 @@ public class ReaderBean implements ReaderBeanLocal {
if
(
lastevent
.
getValue
().
equals
(
event
.
getValue
())
&&
(
lastevent
.
getUpdatetime
().
getTime
()
+
60000
l
)
>
event
.
getTime
().
getTime
())
{
if
(
lastevent
.
getValue
().
equals
(
event
.
getValue
())
&&
(
lastevent
.
getUpdatetime
().
getTime
()
+
60000
l
)
>
event
.
getTime
().
getTime
())
{
lastevent
=
readerEventFacade
.
reload
(
lastevent
);
//
lastevent = readerEventFacade.reload(lastevent);
lastevent
=
readerEventFacade
.
merge
(
lastevent
);
//
lastevent = readerEventFacade.merge(lastevent);
return
lastevent
;
// todo: update lastevent bfore return
return
lastevent
;
// todo: update lastevent bfore return
}
}
...
@@ -210,8 +210,9 @@ public class ReaderBean implements ReaderBeanLocal {
...
@@ -210,8 +210,9 @@ public class ReaderBean implements ReaderBeanLocal {
cardCodeFacade
.
create
(
code
);
cardCodeFacade
.
create
(
code
);
card
.
getCardCodes
().
add
(
code
);
card
.
getCardCodes
().
add
(
code
);
cardCodeFacade
.
flush
();
return
readerEvent
;
return
checkCode
(
readerEvent
.
getReader
(),
readerEvent
.
getValue
())
;
}
}
@Override
@Override
...
...
code/moya-beans/ejbModule/fi/codecrew/moya/facade/ApiApplicationInstanceFacade.java
View file @
950a912
...
@@ -45,4 +45,16 @@ public class ApiApplicationInstanceFacade extends IntegerPkGenericFacade<ApiAppl
...
@@ -45,4 +45,16 @@ public class ApiApplicationInstanceFacade extends IntegerPkGenericFacade<ApiAppl
return
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
return
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
}
}
public
ApiApplicationInstance
findInstance
(
String
appkey
,
String
userId
,
LanEvent
event
)
{
CriteriaBuilder
cb
=
getEm
().
getCriteriaBuilder
();
CriteriaQuery
<
ApiApplicationInstance
>
q
=
cb
.
createQuery
(
ApiApplicationInstance
.
class
);
Root
<
ApiApplicationInstance
>
root
=
q
.
from
(
ApiApplicationInstance
.
class
);
q
.
where
(
cb
.
equal
(
root
.
get
(
ApiApplicationInstance_
.
application
).
get
(
ApiApplication_
.
applicationKey
),
appkey
),
cb
.
equal
(
root
.
get
(
ApiApplicationInstance_
.
authname
),
userId
),
cb
.
equal
(
root
.
get
(
ApiApplicationInstance_
.
eventuser
).
get
(
EventUser_
.
event
),
event
));
return
super
.
getSingleNullableResult
(
getEm
().
createQuery
(
q
));
}
}
}
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/reader/v1/ReaderEventRestPojo.java
View file @
950a912
...
@@ -28,6 +28,7 @@ import io.swagger.annotations.ApiModel;
...
@@ -28,6 +28,7 @@ import io.swagger.annotations.ApiModel;
@ApiModel
@ApiModel
public
class
ReaderEventRestPojo
{
public
class
ReaderEventRestPojo
{
private
EventUserRestPojo
eventUser
;
private
EventUserRestPojo
eventUser
;
private
PrintedCardRestPojo
printedCard
;
private
PrintedCardRestPojo
printedCard
;
...
@@ -40,32 +41,32 @@ public class ReaderEventRestPojo {
...
@@ -40,32 +41,32 @@ public class ReaderEventRestPojo {
public
ReaderEventRestPojo
()
{
public
ReaderEventRestPojo
()
{
}
}
@XmlElement
(
name
=
"eventuser"
)
@XmlElement
(
name
=
"eventuser"
,
nillable
=
true
)
public
EventUserRestPojo
getEventuser
()
{
public
EventUserRestPojo
getEventuser
()
{
return
eventUser
;
return
eventUser
;
}
}
@XmlElement
(
name
=
"readerEventId"
)
@XmlElement
(
name
=
"readerEventId"
,
nillable
=
false
)
public
Integer
getEventId
()
{
public
Integer
getEventId
()
{
return
readerEventId
;
return
readerEventId
;
}
}
@XmlElement
(
name
=
"readerEventTime"
)
@XmlElement
(
name
=
"readerEventTime"
,
nillable
=
true
)
public
Date
getReaderEventTime
()
{
public
Date
getReaderEventTime
()
{
return
readerEventTime
;
return
readerEventTime
;
}
}
@XmlElement
(
name
=
"readerId"
)
@XmlElement
(
name
=
"readerId"
,
nillable
=
false
)
public
Integer
getReaderId
()
{
public
Integer
getReaderId
()
{
return
readerId
;
return
readerId
;
}
}
@XmlElement
(
name
=
"printedCardId"
)
@XmlElement
(
name
=
"printedCardId"
,
nillable
=
true
)
public
Integer
getPrintedCardId
()
{
public
Integer
getPrintedCardId
()
{
return
printedCardId
;
return
printedCardId
;
}
}
@XmlElement
(
name
=
"printedCardState"
)
@XmlElement
(
name
=
"printedCardState"
,
nillable
=
true
)
public
String
getPrintedCardState
()
{
public
String
getPrintedCardState
()
{
return
printedCardState
;
return
printedCardState
;
}
}
...
...
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/userinfo/v1/PrintedCardUpdateCodePojo.java
0 → 100644
View file @
950a912
package
fi
.
codecrew
.
moya
.
rest
.
pojo
.
userinfo
.
v1
;
public
class
PrintedCardUpdateCodePojo
{
private
String
readerName
;
private
String
code
;
public
PrintedCardUpdateCodePojo
(
String
readerName
,
String
code
)
{
this
.
readerName
=
readerName
;
this
.
code
=
code
;
}
public
PrintedCardUpdateCodePojo
()
{
super
();
}
public
String
getReaderName
()
{
return
readerName
;
}
public
void
setReaderName
(
String
readerName
)
{
this
.
readerName
=
readerName
;
}
public
String
getCode
()
{
return
code
;
}
public
void
setCode
(
String
code
)
{
this
.
code
=
code
;
}
}
code/moya-restpojo/src/main/java/fi/codecrew/moya/rest/pojo/userinfo/v1/UserPwdPojo.java
View file @
950a912
...
@@ -3,10 +3,22 @@ package fi.codecrew.moya.rest.pojo.userinfo.v1;
...
@@ -3,10 +3,22 @@ package fi.codecrew.moya.rest.pojo.userinfo.v1;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.Date
;
public
class
UserPwdPojo
implements
Serializable
{
public
class
UserPwdPojo
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
public
UserPwdPojo
()
{
super
();
}
public
UserPwdPojo
(
String
username
,
String
password
,
Date
submitTime
)
{
this
();
this
.
username
=
username
;
this
.
password
=
password
;
this
.
submitTime
=
submitTime
;
}
private
String
username
;
private
String
username
;
private
String
password
;
private
String
password
;
private
Date
submitTime
;
private
Date
submitTime
;
...
@@ -14,18 +26,23 @@ public class UserPwdPojo implements Serializable{
...
@@ -14,18 +26,23 @@ public class UserPwdPojo implements Serializable{
public
String
getUsername
()
{
public
String
getUsername
()
{
return
username
;
return
username
;
}
}
public
void
setUsername
(
String
username
)
{
public
void
setUsername
(
String
username
)
{
this
.
username
=
username
;
this
.
username
=
username
;
}
}
public
String
getPassword
()
{
public
String
getPassword
()
{
return
password
;
return
password
;
}
}
public
void
setPassword
(
String
password
)
{
public
void
setPassword
(
String
password
)
{
this
.
password
=
password
;
this
.
password
=
password
;
}
}
public
Date
getSubmitTime
()
{
public
Date
getSubmitTime
()
{
return
submitTime
;
return
submitTime
;
}
}
public
void
setSubmitTime
(
Date
submitTime
)
{
public
void
setSubmitTime
(
Date
submitTime
)
{
this
.
submitTime
=
submitTime
;
this
.
submitTime
=
submitTime
;
}
}
...
...
code/moya-utils/src/main/java/fi/codecrew/moya/utilities/JsonUtils.java
View file @
950a912
...
@@ -37,18 +37,18 @@ public class JsonUtils {
...
@@ -37,18 +37,18 @@ public class JsonUtils {
* @param path
* @param path
* @return
* @return
*/
*/
public
static
JsonValue
getSubObject
(
JsonObject
jsonObject
,
public
static
JsonValue
getSubObject
(
JsonObject
jsonObject
,
List
<
String
>
path
)
{
List
<
String
>
path
)
{
JsonValue
sub
=
jsonObject
;
JsonValue
sub
=
jsonObject
;
// Burrow into object hierarchy
// Burrow into object hierarchy
for
(
String
s
:
path
)
{
for
(
String
s
:
path
)
{
if
(
sub
.
getValueType
()
==
ValueType
.
OBJECT
)
{
if
(
sub
!=
null
&&
sub
.
getValueType
()
==
ValueType
.
OBJECT
)
{
JsonObject
subObject
=
(
JsonObject
)
sub
;
JsonObject
subObject
=
(
JsonObject
)
sub
;
sub
=
subObject
.
get
(
s
);
sub
=
subObject
.
get
(
s
);
}
else
{
}
else
{
// Trying to get sub-object of something not an object. Bad.
// Trying to get sub-object of something not an object. Bad.
return
null
;
sub
=
null
;
break
;
}
}
}
}
...
@@ -64,14 +64,11 @@ public class JsonUtils {
...
@@ -64,14 +64,11 @@ public class JsonUtils {
* Adds or alters one key in JsonObject
* Adds or alters one key in JsonObject
*
*
* @param jsonObject
* @param jsonObject
* @param key
* @param key which key to add/alter
* which key to add/alter
* @param value The value associate to the key
* @param value
* The value associate to the key
* @return JsonObject with the key:value pair added
* @return JsonObject with the key:value pair added
*/
*/
public
static
JsonObject
assocJsonObject
(
JsonObject
jsonObject
,
String
key
,
public
static
JsonObject
assocJsonObject
(
JsonObject
jsonObject
,
String
key
,
JsonValue
value
)
{
JsonValue
value
)
{
JsonObjectBuilder
builder
=
Json
.
createObjectBuilder
();
JsonObjectBuilder
builder
=
Json
.
createObjectBuilder
();
// Copy all non conflicting json entries
// Copy all non conflicting json entries
...
@@ -92,13 +89,11 @@ public class JsonUtils {
...
@@ -92,13 +89,11 @@ public class JsonUtils {
* ["foo", "bar"], "{\"a\":\"b\"}") => {\"foo\":{\"bar\":{\"a\":\"b\"}}}
* ["foo", "bar"], "{\"a\":\"b\"}") => {\"foo\":{\"bar\":{\"a\":\"b\"}}}
*
*
* @param jsonObject
* @param jsonObject
* @param keys
* @param keys path inside key hierarchy
* path inside key hierarchy
* @param value
* @param value
* @return JsonObject with the value added
* @return JsonObject with the value added
*/
*/
public
static
JsonObject
assocInJsonObject
(
JsonObject
jsonObject
,
public
static
JsonObject
assocInJsonObject
(
JsonObject
jsonObject
,
List
<
String
>
keys
,
JsonValue
value
)
{
List
<
String
>
keys
,
JsonValue
value
)
{
// Recurse?
// Recurse?
if
(
keys
.
size
()
>
1
)
{
if
(
keys
.
size
()
>
1
)
{
...
@@ -114,9 +109,7 @@ public class JsonUtils {
...
@@ -114,9 +109,7 @@ public class JsonUtils {
return
assocJsonObject
(
jsonObject
,
firstKey
,
value
);
return
assocJsonObject
(
jsonObject
,
firstKey
,
value
);
}
}
public
static
JsonObject
alterSubObject
(
JsonObject
jsonObject
,
public
static
JsonObject
alterSubObject
(
JsonObject
jsonObject
,
List
<
String
>
path
,
JsonObject
subObject
)
{
List
<
String
>
path
,
JsonObject
subObject
)
{
return
assocInJsonObject
(
jsonObject
,
path
,
subObject
);
return
assocInJsonObject
(
jsonObject
,
path
,
subObject
);
}
}
}
}
code/moya-web/pom.xml
View file @
950a912
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
<dependency>
<dependency>
<groupId>
fi.codecrew.moya
</groupId>
<groupId>
fi.codecrew.moya
</groupId>
<artifactId>
moya-restpojo
</artifactId>
<artifactId>
moya-restpojo
</artifactId>
<version>
1.2.
1
</version>
<version>
1.2.
4
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
org.glassfish.jersey.media
</groupId>
<groupId>
org.glassfish.jersey.media
</groupId>
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/PojoUtils.java
View file @
950a912
...
@@ -27,8 +27,7 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserReservationPlacePojo;
...
@@ -27,8 +27,7 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserReservationPlacePojo;
import
fi.codecrew.moya.rest.pojo.util.v1.ErrorRoot
;
import
fi.codecrew.moya.rest.pojo.util.v1.ErrorRoot
;
public
class
PojoUtils
{
public
class
PojoUtils
{
public
static
EventUserRestPojo
initEventUserRestPojo
(
EventUser
user
)
public
static
EventUserRestPojo
initEventUserRestPojo
(
EventUser
user
)
{
{
EventUserRestPojo
ret
=
new
EventUserRestPojo
();
EventUserRestPojo
ret
=
new
EventUserRestPojo
();
ret
.
setNick
(
user
.
getUser
().
getNick
());
ret
.
setNick
(
user
.
getUser
().
getNick
());
ret
.
setLogin
(
user
.
getUser
().
getLogin
());
ret
.
setLogin
(
user
.
getUser
().
getLogin
());
...
@@ -49,8 +48,7 @@ public class PojoUtils {
...
@@ -49,8 +48,7 @@ public class PojoUtils {
}
}
public
static
PrintedCardRestPojo
initPrintedCardRestPojo
(
PrintedCard
card
)
public
static
PrintedCardRestPojo
initPrintedCardRestPojo
(
PrintedCard
card
)
{
{
PrintedCardRestPojo
ret
=
new
PrintedCardRestPojo
();
PrintedCardRestPojo
ret
=
new
PrintedCardRestPojo
();
ret
.
setEventuserId
(
card
.
getUser
().
getId
());
ret
.
setEventuserId
(
card
.
getUser
().
getId
());
ret
.
setId
(
card
.
getId
());
ret
.
setId
(
card
.
getId
());
...
@@ -66,8 +64,7 @@ public class PojoUtils {
...
@@ -66,8 +64,7 @@ public class PojoUtils {
return
ret
;
return
ret
;
}
}
public
static
CardRoot
parsePrintedCards
(
List
<
PrintedCard
>
cards
)
public
static
CardRoot
parsePrintedCards
(
List
<
PrintedCard
>
cards
)
{
{
ArrayList
<
PrintedCardRestPojo
>
ret
=
new
ArrayList
<
PrintedCardRestPojo
>();
ArrayList
<
PrintedCardRestPojo
>
ret
=
new
ArrayList
<
PrintedCardRestPojo
>();
for
(
PrintedCard
c
:
cards
)
{
for
(
PrintedCard
c
:
cards
)
{
ret
.
add
(
initPrintedCardRestPojo
(
c
));
ret
.
add
(
initPrintedCardRestPojo
(
c
));
...
@@ -98,19 +95,17 @@ public class PojoUtils {
...
@@ -98,19 +95,17 @@ public class PojoUtils {
ret
.
setDisabled
(
place
.
isDisabled
());
ret
.
setDisabled
(
place
.
isDisabled
());
// I cannot change REST -api without making new version, so let's simulate this ReleaseTime -feature from reserveTime
// I cannot change REST -api without making new version, so let's simulate this ReleaseTime -feature from reserveTime
Calendar
relTime
=
Calendar
.
getInstance
();
Calendar
relTime
=
Calendar
.
getInstance
();
relTime
.
add
(
relTime
.
HOUR
,
4
);
relTime
.
add
(
relTime
.
HOUR
,
4
);
if
(
place
.
getReserveTime
()
!=
null
)
if
(
place
.
getReserveTime
()
!=
null
)
ret
.
setReleaseTime
(
relTime
);
ret
.
setReleaseTime
(
relTime
);
else
else
ret
.
setReleaseTime
(
null
);
ret
.
setReleaseTime
(
null
);
if
(
place
.
getMap
()
!=
null
)
{
if
(
place
.
getMap
()
!=
null
)
{
ret
.
setMapId
(
place
.
getMap
().
getId
());
ret
.
setMapId
(
place
.
getMap
().
getId
());
}
}
...
@@ -156,7 +151,7 @@ public class PojoUtils {
...
@@ -156,7 +151,7 @@ public class PojoUtils {
public
static
ReaderEventRestPojo
initReaderEventRestPojo
(
ReaderEvent
event
)
{
public
static
ReaderEventRestPojo
initReaderEventRestPojo
(
ReaderEvent
event
)
{
ReaderEventRestPojo
ret
=
new
ReaderEventRestPojo
();
ReaderEventRestPojo
ret
=
new
ReaderEventRestPojo
();
if
(
event
.
getPrintedCard
()
!=
null
)
{
if
(
event
.
getPrintedCard
()
!=
null
)
{
if
(
event
.
getPrintedCard
().
getUser
()
!=
null
)
{
if
(
event
.
getPrintedCard
().
getUser
()
!=
null
)
{
ret
.
setEventUser
(
PojoUtils
.
initEventUserRestPojo
(
event
.
getPrintedCard
().
getUser
()));
ret
.
setEventUser
(
PojoUtils
.
initEventUserRestPojo
(
event
.
getPrintedCard
().
getUser
()));
}
}
...
@@ -186,8 +181,7 @@ public class PojoUtils {
...
@@ -186,8 +181,7 @@ public class PojoUtils {
return
ret
;
return
ret
;
}
}
public
static
ReaderRestPojo
initReaderRestPojo
(
Reader
reader
)
public
static
ReaderRestPojo
initReaderRestPojo
(
Reader
reader
)
{
{
ReaderRestPojo
ret
=
new
ReaderRestPojo
();
ReaderRestPojo
ret
=
new
ReaderRestPojo
();
ret
.
setReaderId
(
reader
.
getId
());
ret
.
setReaderId
(
reader
.
getId
());
ret
.
setIdentification
(
reader
.
getIdentification
());
ret
.
setIdentification
(
reader
.
getIdentification
());
...
@@ -217,8 +211,7 @@ public class PojoUtils {
...
@@ -217,8 +211,7 @@ public class PojoUtils {
return
ret
;
return
ret
;
}
}
public
static
ProductRestPojo
initProductRestPojo
(
Product
product
)
public
static
ProductRestPojo
initProductRestPojo
(
Product
product
)
{
{
ProductRestPojo
ret
=
new
ProductRestPojo
();
ProductRestPojo
ret
=
new
ProductRestPojo
();
ret
.
setId
(
product
.
getId
());
ret
.
setId
(
product
.
getId
());
ret
.
setName
(
product
.
getName
());
ret
.
setName
(
product
.
getName
());
...
@@ -233,8 +226,7 @@ public class PojoUtils {
...
@@ -233,8 +226,7 @@ public class PojoUtils {
return
parseSimplePlaces
(
places
,
user
,
hasPermissionViewAllusers
,
false
);
return
parseSimplePlaces
(
places
,
user
,
hasPermissionViewAllusers
,
false
);
}
}
public
static
SimplePlacelistRoot
parseSimplePlaces
(
List
<
Place
>
places
,
EventUser
user
,
boolean
hasPermissionViewAllusers
,
boolean
onlyHilightPlaces
)
public
static
SimplePlacelistRoot
parseSimplePlaces
(
List
<
Place
>
places
,
EventUser
user
,
boolean
hasPermissionViewAllusers
,
boolean
onlyHilightPlaces
)
{
{
SimplePlacelistRoot
ret
=
new
SimplePlacelistRoot
();
SimplePlacelistRoot
ret
=
new
SimplePlacelistRoot
();
ArrayList
<
SimplePlacePojo
>
placeList
=
new
ArrayList
<>();
ArrayList
<
SimplePlacePojo
>
placeList
=
new
ArrayList
<>();
ret
.
setPlaces
(
placeList
);
ret
.
setPlaces
(
placeList
);
...
@@ -251,41 +243,40 @@ public class PojoUtils {
...
@@ -251,41 +243,40 @@ public class PojoUtils {
ret
.
setName
(
p
.
getName
());
ret
.
setName
(
p
.
getName
());
String
state
=
null
;
String
state
=
null
;
if
(
hasPermissionViewAllusers
)
{
if
(
hasPermissionViewAllusers
)
{
if
(
p
.
getPlaceReserver
()
!=
null
)
{
if
(
p
.
getPlaceReserver
()
!=
null
)
{
if
(
p
.
getPlaceReserver
().
getUser
()
!=
null
)
{
if
(
p
.
getPlaceReserver
().
getUser
()
!=
null
)
{
ret
.
setUserDescription
(
p
.
getPlaceReserver
().
getUser
().
getUser
().
getShortUserDescriptor
());
ret
.
setUserDescription
(
p
.
getPlaceReserver
().
getUser
().
getUser
().
getShortUserDescriptor
());
}
else
if
(
p
.
getPlaceReserver
().
getPlaceGroup
()
!=
null
&&
p
.
getPlaceReserver
().
getPlaceGroup
().
getCreator
()
!=
null
)
{
}
else
if
(
p
.
getPlaceReserver
().
getPlaceGroup
()
!=
null
&&
p
.
getPlaceReserver
().
getPlaceGroup
().
getCreator
()
!=
null
)
{
ret
.
setUserDescription
(
p
.
getPlaceReserver
().
getPlaceGroup
().
getCreator
().
getUser
().
getShortUserDescriptor
());
ret
.
setUserDescription
(
p
.
getPlaceReserver
().
getPlaceGroup
().
getCreator
().
getUser
().
getShortUserDescriptor
());
}
}
}
}
}
}
switch
(
p
.
getState
(
user
))
switch
(
p
.
getState
(
user
))
{
{
case
DISABLED:
case
DISABLED:
state
=
(
onlyHilightPlaces
)
?
"F"
:
"D"
;
state
=
(
onlyHilightPlaces
)
?
"F"
:
"D"
;
break
;
break
;
case
FREE:
case
FREE:
state
=
"F"
;
state
=
"F"
;
break
;
break
;
case
LOCKED:
case
LOCKED:
state
=
(
onlyHilightPlaces
)
?
"F"
:
"L"
;
state
=
(
onlyHilightPlaces
)
?
"F"
:
"L"
;
break
;
break
;
case
MY_PLACE:
case
MY_PLACE:
state
=
"P"
;
state
=
"P"
;
break
;
break
;
case
RESERVED:
case
RESERVED:
state
=
(
onlyHilightPlaces
)
?
"F"
:
"R"
;
state
=
(
onlyHilightPlaces
)
?
"F"
:
"R"
;
break
;
break
;
case
TEMP_RESERVED_FORME:
case
TEMP_RESERVED_FORME:
state
=
(
onlyHilightPlaces
)
?
"F"
:
"T"
;
state
=
(
onlyHilightPlaces
)
?
"F"
:
"T"
;
break
;
break
;
default
:
default
:
break
;
break
;
}
}
if
(
onlyHilightPlaces
)
{
if
(
onlyHilightPlaces
)
{
}
}
...
@@ -321,15 +312,10 @@ public class PojoUtils {
...
@@ -321,15 +312,10 @@ public class PojoUtils {
return
ur
;
return
ur
;
}
}
public
static
EventRoot
parseEvents
(
List
<
LanEvent
>
events
)
{
public
static
EventPojo
parseEvent
(
LanEvent
event
)
{
EventRoot
root
=
new
EventRoot
();
ArrayList
<
EventPojo
>
eventPojos
=
new
ArrayList
<>();
for
(
LanEvent
event
:
events
)
{
ArrayList
<
String
>
urls
=
new
ArrayList
<>();
ArrayList
<
String
>
urls
=
new
ArrayList
<>();
for
(
LanEventDomain
domain
:
event
.
getDomains
())
{
for
(
LanEventDomain
domain
:
event
.
getDomains
())
{
urls
.
add
(
domain
.
getDomain
());
urls
.
add
(
domain
.
getDomain
());
}
}
...
@@ -338,7 +324,16 @@ public class PojoUtils {
...
@@ -338,7 +324,16 @@ public class PojoUtils {
pojo
.
setLanEventId
(
event
.
getId
());
pojo
.
setLanEventId
(
event
.
getId
());
pojo
.
setUrls
(
urls
);
pojo
.
setUrls
(
urls
);
pojo
.
setStartTime
(
event
.
getStartTime
());
pojo
.
setStartTime
(
event
.
getStartTime
());
eventPojos
.
add
(
pojo
);
return
pojo
;
}
public
static
EventRoot
parseEvents
(
List
<
LanEvent
>
events
)
{
EventRoot
root
=
new
EventRoot
();
ArrayList
<
EventPojo
>
eventPojos
=
new
ArrayList
<>();
for
(
LanEvent
event
:
events
)
{
eventPojos
.
add
(
parseEvent
(
event
));
}
}
root
.
setEvents
(
eventPojos
);
root
.
setEvents
(
eventPojos
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/ReaderRestView.java
View file @
950a912
...
@@ -22,11 +22,7 @@ import java.util.List;
...
@@ -22,11 +22,7 @@ import java.util.List;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
import
javax.enterprise.context.RequestScoped
;
import
javax.ws.rs.Consumes
;
import
javax.ws.rs.*
;
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
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response.ResponseBuilder
;
import
javax.ws.rs.core.Response.ResponseBuilder
;
...
@@ -86,6 +82,15 @@ public class ReaderRestView {
...
@@ -86,6 +82,15 @@ public class ReaderRestView {
return
Response
.
ok
().
build
();
return
Response
.
ok
().
build
();
}
}
@POST
@Path
(
"/createevent/{reader}/{code}"
)
public
Response
createReaderEvent
(
@PathParam
(
"reader"
)
String
readerName
,
@PathParam
(
"code"
)
String
readerCode
)
{
ReaderEvent
readerEvent
=
readerbean
.
checkCode
(
readerName
,
readerCode
);
return
Response
.
ok
(
PojoUtils
.
initReaderEventRestPojo
(
readerEvent
)).
build
();
}
@GET
@GET
@Path
(
"/LastEventusers"
)
@Path
(
"/LastEventusers"
)
public
ReaderEventRestRoot
getLastEventusers
()
public
ReaderEventRestRoot
getLastEventusers
()
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/UserRestView.java
View file @
950a912
...
@@ -150,6 +150,7 @@ public class UserRestView {
...
@@ -150,6 +150,7 @@ public class UserRestView {
try
{
try
{
EventUser
curruser
=
permbean
.
getCurrentUser
();
EventUser
curruser
=
permbean
.
getCurrentUser
();
ReaderEvent
revent
=
readerbean
.
checkCode
(
"restapi: "
+
curruser
.
getLogin
(),
code
);
ReaderEvent
revent
=
readerbean
.
checkCode
(
"restapi: "
+
curruser
.
getLogin
(),
code
);
if
(
revent
!=
null
&&
revent
.
getUser
()
!=
null
)
{
if
(
revent
!=
null
&&
revent
.
getUser
()
!=
null
)
{
...
@@ -263,6 +264,7 @@ public class UserRestView {
...
@@ -263,6 +264,7 @@ public class UserRestView {
EventUser
user
=
userbean
.
findByEventUserId
(
eventuserid
);
EventUser
user
=
userbean
.
findByEventUserId
(
eventuserid
);
logger
.
warn
(
"users card for user: {}"
,
user
);
logger
.
warn
(
"users card for user: {}"
,
user
);
PrintedCard
card
=
cardbean
.
checkPrintedCard
(
user
);
PrintedCard
card
=
cardbean
.
checkPrintedCard
(
user
);
if
(
card
==
null
)
{
if
(
card
==
null
)
{
return
null
;
return
null
;
}
}
...
@@ -403,4 +405,19 @@ public class UserRestView {
...
@@ -403,4 +405,19 @@ public class UserRestView {
}
}
}
}
@GET
@Path
(
"/{userid}/image"
)
public
Response
fetchUserImage
(
@PathParam
(
"userid"
)
Integer
userid
)
{
EventUser
eventuser
=
userbean
.
findByUserId
(
userid
,
false
);
if
(
eventuser
==
null
)
{
return
Response
.
status
(
Status
.
NOT_FOUND
).
entity
(
"No user found with id"
).
build
();
}
UserImage
currimage
=
eventuser
.
getUser
().
getCurrentImage
();
if
(
currimage
==
null
)
{
return
Response
.
noContent
().
build
();
}
return
Response
.
ok
(
currimage
.
getImageData
(),
currimage
.
getMimeType
()).
build
();
}
}
}
code/moya-web/src/main/java/fi/codecrew/moya/rest/apiapp/v1/ApiAppRestViewV1.java
View file @
950a912
package
fi
.
codecrew
.
moya
.
rest
.
apiapp
.
v1
;
package
fi
.
codecrew
.
moya
.
rest
.
apiapp
.
v1
;
import
java.nio.charset.Charset
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.util.Base64
;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
import
javax.enterprise.context.RequestScoped
;
...
@@ -36,22 +38,32 @@ public class ApiAppRestViewV1 {
...
@@ -36,22 +38,32 @@ public class ApiAppRestViewV1 {
@EJB
@EJB
private
ApiApplicationBeanLocal
apibean
;
private
ApiApplicationBeanLocal
apibean
;
private
static
final
String
AUTH_HEADER
=
"authorization"
;
private
static
final
String
AUTH_PREFIX
=
"Basic "
;
@POST
@POST
@Path
(
"/createInstance/{appKey}"
)
@Path
(
"/createInstance/{appKey}"
)
public
Response
createApiInstance
(
@PathParam
(
"appKey"
)
String
appKey
,
@QueryParam
(
"username"
)
String
username
,
@QueryParam
(
"password"
)
String
password
,
@QueryParam
(
"nonce"
)
Long
timestamp
)
{
//public Response createApiInstance(@PathParam("appKey") String appKey, @QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("nonce") Long timestamp) {
public
Response
createApiInstance
(
@PathParam
(
"appKey"
)
String
appKey
)
{
try
{
try
{
Principal
principal
=
servletRequest
.
getUserPrincipal
();
Principal
principal
=
servletRequest
.
getUserPrincipal
();
// ensure logged out user
// ensure logged out user
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
servletRequest
.
logout
();
servletRequest
.
logout
();
principal
=
null
;
principal
=
null
;
}
}
servletRequest
.
getSession
(
true
);
servletRequest
.
getSession
(
true
);
String
domain
=
servletRequest
.
getHeader
(
"host"
);
String
domain
=
servletRequest
.
getHeader
(
"host"
);
String
authHeader
=
servletRequest
.
getHeader
(
AUTH_HEADER
);
logger
.
info
(
"Got auth header {}"
,
authHeader
);
if
(!
authHeader
.
startsWith
(
AUTH_PREFIX
))
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
).
entity
(
"No basic auth provided"
).
build
();
}
String
[]
splitAuth
=
new
String
(
Base64
.
getDecoder
().
decode
(
authHeader
.
substring
(
AUTH_PREFIX
.
length
()))).
split
(
":"
,
2
);
servletRequest
.
login
(
username
+
"@"
+
domain
,
password
);
servletRequest
.
login
(
splitAuth
[
0
]
+
"@"
+
domain
,
splitAuth
[
1
]
);
ApiApplication
app
=
apibean
.
findApplication
(
appKey
);
ApiApplication
app
=
apibean
.
findApplication
(
appKey
);
ApiApplicationInstance
apiInstance
=
apibean
.
createApplicationInstance
(
app
);
ApiApplicationInstance
apiInstance
=
apibean
.
createApplicationInstance
(
app
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/appconfig/v1/EventInfoV1.java
View file @
950a912
package
fi
.
codecrew
.
moya
.
rest
.
appconfig
.
v1
;
package
fi
.
codecrew
.
moya
.
rest
.
appconfig
.
v1
;
import
java.security.Principal
;
import
java.security.Principal
;
import
java.util.Base64
;
import
java.util.Date
;
import
java.util.Date
;
import
javax.ejb.EJB
;
import
javax.ejb.EJB
;
...
@@ -12,6 +13,7 @@ import javax.ws.rs.core.Context;
...
@@ -12,6 +13,7 @@ import javax.ws.rs.core.Context;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.MediaType
;
import
javax.ws.rs.core.Response
;
import
javax.ws.rs.core.Response
;
import
jdk.nashorn.internal.objects.annotations.Getter
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -38,6 +40,8 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPwdPojo;
...
@@ -38,6 +40,8 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPwdPojo;
public
class
EventInfoV1
{
public
class
EventInfoV1
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EventInfoV1
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
EventInfoV1
.
class
);
private
static
final
String
AUTH_HEADER
=
"authorization"
;
private
static
final
String
AUTH_PREFIX
=
"Basic "
;
@Context
@Context
private
HttpServletRequest
servletRequest
;
private
HttpServletRequest
servletRequest
;
...
@@ -49,13 +53,25 @@ public class EventInfoV1 {
...
@@ -49,13 +53,25 @@ public class EventInfoV1 {
private
EventBeanLocal
eventBean
;
private
EventBeanLocal
eventBean
;
@GET
@GET
@Path
(
"/current"
)
public
Response
getCurrentEventInfo
()
{
return
Response
.
ok
(
PojoUtils
.
parseEvent
(
eventBean
.
getCurrentEvent
())).
build
();
}
@GET
@Path
(
"/allevents"
)
@Path
(
"/allevents"
)
public
Response
getEventsForUser
(
@QueryParam
(
"username"
)
String
username
,
@QueryParam
(
"password"
)
String
password
,
@QueryParam
(
"timestamp"
)
Long
timestamp
)
{
public
Response
getEventsForUser
()
{
try
{
try
{
if
(
username
!=
null
)
{
String
authHeader
=
servletRequest
.
getHeader
(
AUTH_HEADER
);
Principal
principal
=
servletRequest
.
getUserPrincipal
();
if
(
authHeader
==
null
||
!
authHeader
.
startsWith
(
AUTH_PREFIX
))
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
).
entity
(
"No basic auth provided"
).
build
();
}
String
authStr
=
new
String
(
Base64
.
getDecoder
().
decode
(
authHeader
.
substring
(
AUTH_PREFIX
.
length
())));
String
[]
splitAuth
=
authStr
.
split
(
":"
,
2
);
Principal
principal
=
servletRequest
.
getUserPrincipal
();
// ensure logged out user
// ensure logged out user
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
servletRequest
.
logout
();
servletRequest
.
logout
();
...
@@ -63,8 +79,8 @@ public class EventInfoV1 {
...
@@ -63,8 +79,8 @@ public class EventInfoV1 {
String
domain
=
servletRequest
.
getHeader
(
"host"
);
String
domain
=
servletRequest
.
getHeader
(
"host"
);
servletRequest
.
getSession
(
true
);
servletRequest
.
getSession
(
true
);
servletRequest
.
login
(
username
+
"@"
+
domain
,
password
);
servletRequest
.
login
(
splitAuth
[
0
]
+
"@"
+
domain
,
splitAuth
[
1
]
);
}
return
Response
.
ok
(
PojoUtils
.
parseEvents
(
eventBean
.
findAllEventsForCurrentUser
())).
build
();
return
Response
.
ok
(
PojoUtils
.
parseEvents
(
eventBean
.
findAllEventsForCurrentUser
())).
build
();
}
catch
(
ServletException
e
)
{
}
catch
(
ServletException
e
)
{
logger
.
warn
(
"Error logging in while creating ApiApplication instance"
);
logger
.
warn
(
"Error logging in while creating ApiApplication instance"
);
...
...
code/moya-web/src/main/java/fi/codecrew/moya/rest/v2/UserRestViewV2.java
View file @
950a912
package
fi
.
codecrew
.
moya
.
rest
.
v2
;
package
fi
.
codecrew
.
moya
.
rest
.
v2
;
import
fi.codecrew.moya.beans.EventBeanLocal
;
import
fi.codecrew.moya.beans.*
;
import
fi.codecrew.moya.beans.PermissionBeanLocal
;
import
fi.codecrew.moya.beans.UserBeanLocal
;
import
fi.codecrew.moya.enums.Gender
;
import
fi.codecrew.moya.enums.Gender
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
import
fi.codecrew.moya.enums.apps.UserPermission
;
import
fi.codecrew.moya.model.EventUser
;
import
fi.codecrew.moya.model.*
;
import
fi.codecrew.moya.model.User
;
import
fi.codecrew.moya.model.UserImage
;
import
fi.codecrew.moya.rest.PojoUtils
;
import
fi.codecrew.moya.rest.PojoUtils
;
import
fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo
;
import
fi.codecrew.moya.rest.pojo.userinfo.v1.EventUserRestPojo
;
import
fi.codecrew.moya.rest.pojo.userinfo.v1.PrintedCardUpdateCodePojo
;
import
fi.codecrew.moya.rest.v2.pojo.UserPojo
;
import
fi.codecrew.moya.rest.v2.pojo.UserPojo
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
io.swagger.annotations.ApiOperation
;
...
@@ -39,11 +36,17 @@ public class UserRestViewV2 {
...
@@ -39,11 +36,17 @@ public class UserRestViewV2 {
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserRestViewV2
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
UserRestViewV2
.
class
);
@EJB
@EJB
EventBeanLocal
eventBean
;
private
EventBeanLocal
eventBean
;
@EJB
@EJB
PermissionBeanLocal
permissionBean
;
private
PermissionBeanLocal
permissionBean
;
@EJB
@EJB
UserBeanLocal
userBean
;
private
UserBeanLocal
userBean
;
@EJB
private
ReaderBeanLocal
readerbean
;
@EJB
private
CardTemplateBeanLocal
cardBean
;
@Inject
@Inject
PojoFactoryV2
pojoFactory
;
PojoFactoryV2
pojoFactory
;
...
@@ -78,9 +81,23 @@ public class UserRestViewV2 {
...
@@ -78,9 +81,23 @@ public class UserRestViewV2 {
}
}
}
}
@GET
@Path
(
"/current"
)
@Produces
(
MediaType
.
APPLICATION_JSON
)
@ApiOperation
(
value
=
"Fetch current user"
,
response
=
EventUserRestPojo
.
class
)
public
Response
getCurrentUser
()
{
EventUser
usr
=
permissionBean
.
getCurrentUser
();
logger
.
info
(
"Got current user {} "
,
usr
);
/*if (usr == null || usr.isAnonymous()) {
return Response.status(Response.Status.NOT_FOUND).entity("User not found, or not logged in").build();
}*/
return
Response
.
ok
(
pojoFactory
.
createUserPojo
(
usr
)).
build
();
}
@POST
@POST
@Path
(
"/create"
)
@Path
(
"/create"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
@Produces
({
MediaType
.
APPLICATION_JSON
})
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@Consumes
(
MediaType
.
APPLICATION_JSON
)
@ApiOperation
(
value
=
"Create user"
,
response
=
UserPojo
.
class
)
@ApiOperation
(
value
=
"Create user"
,
response
=
UserPojo
.
class
)
public
Response
createUser
(
UserPojo
userPojo
)
{
public
Response
createUser
(
UserPojo
userPojo
)
{
...
@@ -111,14 +128,39 @@ public class UserRestViewV2 {
...
@@ -111,14 +128,39 @@ public class UserRestViewV2 {
userBean
.
createNewUser
(
eventUser
,
userPojo
.
password
);
userBean
.
createNewUser
(
eventUser
,
userPojo
.
password
);
return
Response
.
ok
(
pojoFactory
.
createUserPojo
(
eventUser
)).
build
();
return
Response
.
ok
(
pojoFactory
.
createUserPojo
(
eventUser
)).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"Creating user failed"
,
e
);
logger
.
error
(
"Creating user failed"
,
e
);
return
Response
.
serverError
().
entity
(
PojoUtils
.
initErrorPojo
(
e
.
getMessage
())).
build
();
return
Response
.
serverError
().
entity
(
PojoUtils
.
initErrorPojo
(
e
.
getMessage
())).
build
();
}
}
}
}
@PUT
@ApiOperation
(
value
=
"Update code "
)
@Path
(
"/{userid}/cardcode"
)
public
Response
updateUserCard
(
PrintedCardUpdateCodePojo
codepojo
,
@PathParam
(
"userid"
)
Integer
userid
)
{
ReaderEvent
event
=
readerbean
.
checkCode
(
codepojo
.
getReaderName
(),
codepojo
.
getCode
());
// If tag is not associated, try to add it to the user.
if
(
event
.
getPrintedCard
()
==
null
)
{
PrintedCard
card
=
cardBean
.
checkPrintedCard
(
userBean
.
findByUserId
(
userid
,
false
));
logger
.
info
(
"Updating card {} to event {} "
,
card
,
event
);
if
(
card
!=
null
)
{
event
=
readerbean
.
assocCodeToCard
(
event
,
card
);
return
Response
.
ok
(
PojoUtils
.
initReaderEventRestPojo
(
event
)).
build
();
}
}
Response
.
Status
status
=
Response
.
Status
.
CONFLICT
;
if
(
event
.
getPrintedCard
()
!=
null
&&
event
.
getUser
().
getEvent
().
equals
(
eventBean
.
getCurrentEvent
())
&&
event
.
getUser
().
getUser
().
getId
().
equals
(
userid
))
{
status
=
Response
.
Status
.
OK
;
}
return
Response
.
status
(
status
).
entity
(
PojoUtils
.
initReaderEventRestPojo
(
event
)).
build
();
}
/**
/**
* Post forma parameter "image" with the image data in it.
* Post forma parameter "image" with the image data in it.
*
* @param request
* @param request
* @param userId
* @param userId
* @return
* @return
...
@@ -154,6 +196,7 @@ public class UserRestViewV2 {
...
@@ -154,6 +196,7 @@ public class UserRestViewV2 {
/**
/**
* Get user image
* Get user image
*
* @param userId
* @param userId
* @return
* @return
*/
*/
...
@@ -183,7 +226,7 @@ public class UserRestViewV2 {
...
@@ -183,7 +226,7 @@ public class UserRestViewV2 {
}
}
return
Response
.
ok
(
image
.
getImageData
(),
mimeType
).
build
();
return
Response
.
ok
(
image
.
getImageData
(),
mimeType
).
build
();
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
logger
.
error
(
"Getting image failed"
,
e
);
logger
.
error
(
"Getting image failed"
,
e
);
return
Response
.
serverError
().
entity
(
PojoUtils
.
initErrorPojo
(
e
.
getMessage
())).
build
();
return
Response
.
serverError
().
entity
(
PojoUtils
.
initErrorPojo
(
e
.
getMessage
())).
build
();
}
}
...
...
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