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
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
287 additions
and
200 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
/*
/*
* Copyright Codecrew Ry
* Copyright Codecrew Ry
*
*
* All rights reserved.
* All rights reserved.
*
*
* This license applies to any software containing a notice placed by the
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
* This license covers modification, distribution and use of the Software.
*
*
* Any distribution and use in source and binary forms, with or without
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* modification is not permitted without explicit written permission from the
* copyright owner.
* copyright owner.
*
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
* future versions of the Software.
*
*
*/
*/
package
fi
.
codecrew
.
moya
.
beans
;
package
fi
.
codecrew
.
moya
.
beans
;
...
@@ -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
);
...
@@ -161,7 +156,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -161,7 +156,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
/**
/**
* Checks users printed card roles and return the biggestCard
* Checks users printed card roles and return the biggestCard
*
*
* @throws PermissionDeniedException
* @throws PermissionDeniedException
*/
*/
@Override
@Override
...
@@ -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,40 +355,35 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -361,40 +355,35 @@ 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
());
break
;
break
;
case
PRINTING_IN_PROGRESS:
case
PRINTING_IN_PROGRESS:
if
(
card
.
getCardState
().
equals
(
CardState
.
PRINTING_IN_PROGRESS
)
if
(
card
.
getCardState
().
equals
(
CardState
.
PRINTING_IN_PROGRESS
)
||
card
.
getCardState
().
equals
(
CardState
.
PRINTED
))
{
||
card
.
getCardState
().
equals
(
CardState
.
PRINTED
))
{
String
response
=
"Unable to change type to PRINTING_IN_PROGRESS value is already {}"
+
card
.
getCardState
();
String
response
=
"Unable to change type to PRINTING_IN_PROGRESS value is already {}"
+
card
.
getCardState
();
logger
.
warn
(
response
);
logger
.
warn
(
response
);
throw
new
Exception
(
response
);
throw
new
Exception
(
response
);
}
}
break
;
break
;
default
:
default
:
break
;
break
;
}
}
card
.
setCardState
(
state
);
card
.
setCardState
(
state
);
return
card
;
return
card
;
}
}
@Override
@Override
public
EventUser
giveCard
(
EventUser
user
,
boolean
markUserPlacesDelivered
)
{
public
EventUser
giveCard
(
EventUser
user
,
boolean
markUserPlacesDelivered
)
{
user
=
eventUserFacade
.
reload
(
user
);
user
=
eventUserFacade
.
reload
(
user
);
PrintedCard
card
=
checkPrintedCard
(
user
);
PrintedCard
card
=
checkPrintedCard
(
user
);
if
(
card
.
getCardState
()
!=
CardState
.
DELIVERED
)
{
if
(
card
.
getCardState
()
!=
CardState
.
DELIVERED
)
{
card
.
setCardState
(
CardState
.
DELIVERED
);
card
.
setCardState
(
CardState
.
DELIVERED
);
}
else
{
}
else
{
...
@@ -413,24 +402,24 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
...
@@ -413,24 +402,24 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override
@Override
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
);
}
}
cardCodeFacade
.
remove
(
code
);
cardCodeFacade
.
remove
(
code
);
}
}
@Override
@Override
public
CardTemplate
removeCardTextData
(
CardTextData
data
)
{
public
CardTemplate
removeCardTextData
(
CardTextData
data
)
{
data
=
ctdFacade
.
reload
(
data
);
data
=
ctdFacade
.
reload
(
data
);
CardTemplate
template
=
data
.
getCardTemplate
();
CardTemplate
template
=
data
.
getCardTemplate
();
ctdFacade
.
remove
(
data
);
ctdFacade
.
remove
(
data
);
return
template
;
return
template
;
}
}
@Override
@Override
public
CardTemplate
removeCardObjectData
(
CardObjectData
data
)
{
public
CardTemplate
removeCardObjectData
(
CardObjectData
data
)
{
data
=
codFacade
.
reload
(
data
);
data
=
codFacade
.
reload
(
data
);
...
@@ -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
...
@@ -107,7 +107,7 @@ public class ReaderBean implements ReaderBeanLocal {
...
@@ -107,7 +107,7 @@ public class ReaderBean implements ReaderBeanLocal {
/**
/**
* Some of rfid-readers adds zeros to start, some to end
* Some of rfid-readers adds zeros to start, some to end
*
*
* Also, under 16 char -rdid (the smaller one) should be 16 character
* Also, under
16 char -rdid (the smaller one) should be 16 character
* long, with zeros on beginning.
* long, with zeros on beginning.
*/
*/
if
(
ReaderType
.
RFID
.
equals
(
reader
.
getType
()))
{
if
(
ReaderType
.
RFID
.
equals
(
reader
.
getType
()))
{
...
@@ -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
/*
/*
* Copyright Codecrew Ry
* Copyright Codecrew Ry
*
*
* All rights reserved.
* All rights reserved.
*
*
* This license applies to any software containing a notice placed by the
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
* This license covers modification, distribution and use of the Software.
*
*
* Any distribution and use in source and binary forms, with or without
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* modification is not permitted without explicit written permission from the
* copyright owner.
* copyright owner.
*
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
* future versions of the Software.
*
*
*/
*/
package
fi
.
codecrew
.
moya
.
facade
;
package
fi
.
codecrew
.
moya
.
facade
;
...
@@ -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,31 +3,48 @@ package fi.codecrew.moya.rest.pojo.userinfo.v1;
...
@@ -3,31 +3,48 @@ 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
;
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
/*
/*
* Copyright Codecrew Ry
* Copyright Codecrew Ry
*
*
* All rights reserved.
* All rights reserved.
*
*
* This license applies to any software containing a notice placed by the
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
* This license covers modification, distribution and use of the Software.
*
*
* Any distribution and use in source and binary forms, with or without
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* modification is not permitted without explicit written permission from the
* copyright owner.
* copyright owner.
*
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
* future versions of the Software.
*
*
*/
*/
package
fi
.
codecrew
.
moya
.
utilities
;
package
fi
.
codecrew
.
moya
.
utilities
;
...
@@ -32,23 +32,23 @@ public class JsonUtils {
...
@@ -32,23 +32,23 @@ public class JsonUtils {
/**
/**
* Gets a sub object from a JsonObject. Returns an empty object if not
* Gets a sub object from a JsonObject. Returns an empty object if not
* found.
* found.
*
*
* @param jsonObject
* @param jsonObject
* @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
;
}
}
}
}
...
@@ -62,16 +62,13 @@ public class JsonUtils {
...
@@ -62,16 +62,13 @@ 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
...
@@ -90,15 +87,13 @@ public class JsonUtils {
...
@@ -90,15 +87,13 @@ public class JsonUtils {
/**
/**
* Goes into a json object and sets subobject assocInJsonObject("{}",
* Goes into a json object and sets subobject assocInJsonObject("{}",
* ["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
)
{
...
@@ -106,7 +101,7 @@ public class JsonUtils {
...
@@ -106,7 +101,7 @@ public class JsonUtils {
List
<
String
>
restKeys
=
keys
.
subList
(
1
,
keys
.
size
());
List
<
String
>
restKeys
=
keys
.
subList
(
1
,
keys
.
size
());
JsonObject
subObj
=
jsonObject
.
getJsonObject
(
firstKey
);
JsonObject
subObj
=
jsonObject
.
getJsonObject
(
firstKey
);
return
assocJsonObject
(
jsonObject
,
firstKey
,
return
assocJsonObject
(
jsonObject
,
firstKey
,
assocInJsonObject
(
subObj
,
restKeys
,
value
));
assocInJsonObject
(
subObj
,
restKeys
,
value
));
}
}
// End?
// End?
...
@@ -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,17 +95,15 @@ public class PojoUtils {
...
@@ -98,17 +95,15 @@ 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
Calendar
relTime
=
Calendar
.
getInstance
();
// I cannot change REST -api without making new version, so let's simulate this ReleaseTime -feature from reserveTime
relTime
.
add
(
relTime
.
HOUR
,
4
);
Calendar
relTime
=
Calendar
.
getInstance
();
relTime
.
add
(
relTime
.
HOUR
,
4
);
if
(
place
.
getReserveTime
()
!=
null
)
ret
.
setReleaseTime
(
relTime
);
else
ret
.
setReleaseTime
(
null
);
if
(
place
.
getReserveTime
()
!=
null
)
ret
.
setReleaseTime
(
relTime
);
else
ret
.
setReleaseTime
(
null
);
if
(
place
.
getMap
()
!=
null
)
{
if
(
place
.
getMap
()
!=
null
)
{
...
@@ -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,24 +312,28 @@ public class PojoUtils {
...
@@ -321,24 +312,28 @@ public class PojoUtils {
return
ur
;
return
ur
;
}
}
public
static
EventPojo
parseEvent
(
LanEvent
event
)
{
ArrayList
<
String
>
urls
=
new
ArrayList
<>();
for
(
LanEventDomain
domain
:
event
.
getDomains
())
{
urls
.
add
(
domain
.
getDomain
());
}
EventPojo
pojo
=
new
EventPojo
();
pojo
.
setName
(
event
.
getName
());
pojo
.
setLanEventId
(
event
.
getId
());
pojo
.
setUrls
(
urls
);
pojo
.
setStartTime
(
event
.
getStartTime
());
return
pojo
;
}
public
static
EventRoot
parseEvents
(
List
<
LanEvent
>
events
)
{
public
static
EventRoot
parseEvents
(
List
<
LanEvent
>
events
)
{
EventRoot
root
=
new
EventRoot
();
EventRoot
root
=
new
EventRoot
();
ArrayList
<
EventPojo
>
eventPojos
=
new
ArrayList
<>();
ArrayList
<
EventPojo
>
eventPojos
=
new
ArrayList
<>();
for
(
LanEvent
event
:
events
)
{
for
(
LanEvent
event
:
events
)
{
ArrayList
<
String
>
urls
=
new
ArrayList
<>();
eventPojos
.
add
(
parseEvent
(
event
));
for
(
LanEventDomain
domain
:
event
.
getDomains
())
{
urls
.
add
(
domain
.
getDomain
());
}
EventPojo
pojo
=
new
EventPojo
();
pojo
.
setName
(
event
.
getName
());
pojo
.
setLanEventId
(
event
.
getId
());
pojo
.
setUrls
(
urls
);
pojo
.
setStartTime
(
event
.
getStartTime
());
eventPojos
.
add
(
pojo
);
}
}
root
.
setEvents
(
eventPojos
);
root
.
setEvents
(
eventPojos
);
...
@@ -357,11 +352,11 @@ public class PojoUtils {
...
@@ -357,11 +352,11 @@ public class PojoUtils {
return
pojo
;
return
pojo
;
}
}
public
static
ErrorRoot
initErrorPojo
(
String
errorMessage
)
{
public
static
ErrorRoot
initErrorPojo
(
String
errorMessage
)
{
ErrorRoot
errorRoot
=
new
ErrorRoot
();
ErrorRoot
errorRoot
=
new
ErrorRoot
();
errorRoot
.
setError
(
errorMessage
);
errorRoot
.
setError
(
errorMessage
);
return
errorRoot
;
return
errorRoot
;
}
}
}
}
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,22 +53,34 @@ public class EventInfoV1 {
...
@@ -49,22 +53,34 @@ 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
();
// ensure logged out user
if
(
authHeader
==
null
||
!
authHeader
.
startsWith
(
AUTH_PREFIX
))
{
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
return
Response
.
status
(
Response
.
Status
.
FORBIDDEN
).
entity
(
"No basic auth provided"
).
build
();
servletRequest
.
logout
();
}
}
String
authStr
=
new
String
(
Base64
.
getDecoder
().
decode
(
authHeader
.
substring
(
AUTH_PREFIX
.
length
())));
String
domain
=
servletRequest
.
getHeader
(
"host"
);
String
[]
splitAuth
=
authStr
.
split
(
":"
,
2
);
servletRequest
.
getSession
(
true
);
Principal
principal
=
servletRequest
.
getUserPrincipal
();
servletRequest
.
login
(
username
+
"@"
+
domain
,
password
);
// ensure logged out user
if
(
principal
!=
null
&&
principal
.
getName
()
!=
null
)
{
servletRequest
.
logout
();
}
}
String
domain
=
servletRequest
.
getHeader
(
"host"
);
servletRequest
.
getSession
(
true
);
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
This diff is collapsed.
Click to expand it.
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