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 4b6f3474
authored
Jun 02, 2014
by
Tuukka Kivilahti
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'networkassoc-features' into 'master'
Networkassoc features Vilkuillut
@tkfftk
2 parents
f028befe
10c72b2d
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
245 additions
and
1 deletions
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBean.java
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBeanLocal.java
code/MoyaWeb/WebContent/networkassociation/index.xhtml
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationRestView.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfoPojo.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfoResponseRoot.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfolistResponseRoot.java
code/MoyaBeans/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBean.java
View file @
4b6f347
...
...
@@ -19,6 +19,7 @@ import fi.codecrew.moya.model.EventUser;
import
fi.codecrew.moya.model.GroupMembership
;
import
fi.codecrew.moya.model.NetworkAssociation
;
import
fi.codecrew.moya.model.Place
;
import
fi.codecrew.moya.model.PrintedCard
;
import
fi.codecrew.moya.model.Role
;
/**
...
...
@@ -44,6 +45,9 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private
EventBean
eventBean
;
@EJB
private
CardTemplateBean
cardBean
;
@EJB
private
PermissionBean
permissionBean
;
public
NetworkAssociationBean
()
{}
...
...
@@ -83,6 +87,21 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
if
(
authUser
==
null
)
throw
new
Exception
(
"INVALID_USER_OR_PASSWORD"
);
return
tryAssociateInternal
(
authUser
,
ip
,
mac
,
code
,
codeRequired
);
}
@Override
@RolesAllowed
(
NetworkAssociationPermission
.
S_CAN_ADMINISTER_ASSOCIATIONS
)
public
NetworkAssociation
tryAssociate
(
String
usercode
,
String
ip
,
String
mac
,
String
code
,
Boolean
codeRequired
)
throws
Exception
{
EventUser
authUser
=
userBean
.
getUser
(
usercode
);
if
(
authUser
==
null
)
throw
new
Exception
(
"INVALID_USERCODE"
);
return
tryAssociateInternal
(
authUser
,
ip
,
mac
,
code
,
codeRequired
);
}
private
NetworkAssociation
tryAssociateInternal
(
EventUser
authUser
,
String
ip
,
String
mac
,
String
code
,
boolean
codeRequired
)
throws
Exception
{
NetworkAssociation
association
;
HashSet
<
IAppPermission
>
userPerms
=
buildPermsFor
(
authUser
);
...
...
@@ -249,5 +268,17 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private
Place
resolvePlaceFromCode
(
String
code
)
{
if
(
code
==
null
)
return
null
;
return
barcodeBean
.
getPlaceFromTextCode
(
code
);
}
}
@Override
@RolesAllowed
(
NetworkAssociationPermission
.
S_CAN_ADMINISTER_ASSOCIATIONS
)
public
NetworkAssociation
getActiveAssociationByIP
(
String
ipAddress
)
{
List
<
NetworkAssociation
>
na
=
this
.
networkAssociationFacade
.
findActiveAssociationsByIP
(
eventBean
.
getCurrentEvent
(),
ipAddress
);
if
(
na
.
size
()
>
0
)
return
na
.
get
(
0
);
else
return
null
;
}
}
code/MoyaBeansClient/ejbModule/fi/codecrew/moya/beans/NetworkAssociationBeanLocal.java
View file @
4b6f347
...
...
@@ -23,4 +23,9 @@ public interface NetworkAssociationBeanLocal {
void
dropAssociationById
(
Integer
associd
);
NetworkAssociation
getActiveAssociationByIP
(
String
ipAddress
);
NetworkAssociation
tryAssociate
(
String
usercode
,
String
ip
,
String
mac
,
String
code
,
Boolean
codeRequired
)
throws
Exception
;
}
code/MoyaWeb/WebContent/networkassociation/index.xhtml
View file @
4b6f347
...
...
@@ -12,6 +12,7 @@
</f:metadata>
<ui:define
name=
"content"
>
<h:form>
<p:commandButton
style=
"width: 0px; height: 0px;"
value=
"#{i18n['networkassociation.create_association']}"
action=
"#{networkAssociationView.createAssociation}"
update=
"@form"
/>
<p:messages
autoUpdate=
"true"
redisplay=
"false"
></p:messages>
<h1>
#{i18n['networkassociation.current_associations']}
</h1>
<p:dataTable
var=
"activeAssoc"
value=
"#{networkAssociationView.activeAssociations}"
>
...
...
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationRestView.java
View file @
4b6f347
...
...
@@ -16,6 +16,9 @@ import fi.codecrew.moya.beans.NetworkAssociationBeanLocal;
import
fi.codecrew.moya.enums.NetworkAssociationStatus
;
import
fi.codecrew.moya.model.NetworkAssociation
;
import
fi.codecrew.moya.rest.pojo.NetworkAssociationActionPojo
;
import
fi.codecrew.moya.rest.pojo.NetworkAssociationInfoPojo
;
import
fi.codecrew.moya.rest.pojo.NetworkAssociationInfoResponseRoot
;
import
fi.codecrew.moya.rest.pojo.NetworkAssociationInfolistResponseRoot
;
import
fi.codecrew.moya.rest.pojo.NetworkAssociationResponseRoot
;
@RequestScoped
...
...
@@ -57,6 +60,67 @@ public class NetworkAssociationRestView {
return
resp
;
}
@POST
@Path
(
"/codeauth"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationResponseRoot
codeAuth
(
@FormParam
(
"usercode"
)
String
usercode
,
@FormParam
(
"ip"
)
String
ip
,
@FormParam
(
"mac"
)
String
mac
,
@FormParam
(
"code"
)
String
code
,
@FormParam
(
"coderequired"
)
Boolean
codeRequired
)
{
NetworkAssociationResponseRoot
resp
=
new
NetworkAssociationResponseRoot
();
try
{
NetworkAssociation
na
=
networkAssociationBean
.
tryAssociate
(
usercode
,
ip
,
mac
,
code
,
codeRequired
);
if
(
na
.
getStatus
().
equals
(
NetworkAssociationStatus
.
ACTIVE
))
resp
.
getAdditions
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
else
resp
.
getPendings
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
catch
(
Exception
e
)
{
resp
.
getResult
().
setResultCode
(
0
);
if
(
e
.
getMessage
()
!=
null
&&
e
.
getMessage
()
!=
""
)
{
resp
.
getResult
().
setMessage
(
e
.
getMessage
());
}
else
{
resp
.
getResult
().
setMessage
(
"UNKNOWN_ERROR"
);
}
}
return
resp
;
}
@GET
@Path
(
"/get_association_infos"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationInfolistResponseRoot
getAssociationInfos
()
{
NetworkAssociationInfolistResponseRoot
nairr
=
new
NetworkAssociationInfolistResponseRoot
();
for
(
NetworkAssociation
na
:
networkAssociationBean
.
getActiveAssociations
(
false
))
{
nairr
.
getAssociations
().
add
(
new
NetworkAssociationInfoPojo
(
na
));
}
return
nairr
;
}
@GET
@Path
(
"/get_association_info_by_ip/{ipAddress}"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationInfoResponseRoot
getAssociationInfos
(
@PathParam
(
"ipAddress"
)
String
ipAddress
)
{
NetworkAssociation
na
=
networkAssociationBean
.
getActiveAssociationByIP
(
ipAddress
);
NetworkAssociationInfoResponseRoot
nairr
;
if
(
na
!=
null
)
{
nairr
=
new
NetworkAssociationInfoResponseRoot
(
new
NetworkAssociationInfoPojo
(
na
)
);
}
else
{
nairr
=
new
NetworkAssociationInfoResponseRoot
();
}
return
nairr
;
}
@GET
@Path
(
"/get_all/{activate}"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
...
...
@@ -65,6 +129,7 @@ public class NetworkAssociationRestView {
)
{
NetworkAssociationResponseRoot
resp
=
new
NetworkAssociationResponseRoot
();
try
{
if
(
activate
==
null
)
throw
new
Exception
(
"INVALID_PARAMETER_FOR_ACTIVATE"
);
...
...
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfoPojo.java
0 → 100644
View file @
4b6f347
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
java.util.Calendar
;
import
javax.xml.bind.annotation.XmlElement
;
import
fi.codecrew.moya.model.NetworkAssociation
;
public
class
NetworkAssociationInfoPojo
{
private
String
createTime
;
private
String
modifyTime
;
private
String
ipAddress
;
private
String
macAddress
;
private
Integer
placeId
;
private
Integer
eventuserId
;
public
NetworkAssociationInfoPojo
(
NetworkAssociation
na
)
{
this
.
createTime
=
na
.
getCreateTime
().
getTime
().
toString
();
this
.
modifyTime
=
na
.
getModifyTime
().
getTime
().
toString
();
this
.
ipAddress
=
na
.
getIP
();
this
.
macAddress
=
na
.
getMAC
();
if
(
na
.
getPlace
()
!=
null
)
this
.
placeId
=
na
.
getPlace
().
getId
();
else
this
.
placeId
=
null
;
this
.
eventuserId
=
na
.
getEventUser
().
getId
();
}
public
NetworkAssociationInfoPojo
()
{
this
.
createTime
=
null
;
this
.
modifyTime
=
null
;
this
.
ipAddress
=
null
;
this
.
macAddress
=
null
;
this
.
placeId
=
null
;
this
.
eventuserId
=
null
;
}
@XmlElement
(
name
=
"createTime"
)
public
String
getCreateTime
()
{
return
createTime
;
}
public
void
setCreateTime
(
String
createTime
)
{
this
.
createTime
=
createTime
;
}
@XmlElement
(
name
=
"modifyTime"
)
public
String
getModifyTime
()
{
return
modifyTime
;
}
public
void
setModifyTime
(
String
modifyTime
)
{
this
.
modifyTime
=
modifyTime
;
}
@XmlElement
(
name
=
"ipAddress"
)
public
String
getIpAddress
()
{
return
ipAddress
;
}
public
void
setIpAddress
(
String
ipAddress
)
{
this
.
ipAddress
=
ipAddress
;
}
@XmlElement
(
name
=
"macAddress"
)
public
String
getMacAddress
()
{
return
macAddress
;
}
public
void
setMacAddress
(
String
macAddress
)
{
this
.
macAddress
=
macAddress
;
}
@XmlElement
(
name
=
"placeId"
)
public
Integer
getPlaceId
()
{
return
placeId
;
}
public
void
setPlaceId
(
Integer
placeId
)
{
this
.
placeId
=
placeId
;
}
@XmlElement
(
name
=
"eventuserId"
)
public
Integer
getEventuserId
()
{
return
eventuserId
;
}
public
void
setEventuserId
(
Integer
eventuserId
)
{
this
.
eventuserId
=
eventuserId
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfoResponseRoot.java
0 → 100644
View file @
4b6f347
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
public
class
NetworkAssociationInfoResponseRoot
{
private
NetworkAssociationInfoPojo
association
;
public
NetworkAssociationInfoResponseRoot
(
NetworkAssociationInfoPojo
naip
)
{
this
.
association
=
naip
;
}
public
NetworkAssociationInfoResponseRoot
()
{
this
.
association
=
null
;
}
public
NetworkAssociationInfoPojo
getAssociation
()
{
return
association
;
}
public
void
setAssociation
(
NetworkAssociationInfoPojo
association
)
{
this
.
association
=
association
;
}
}
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationInfolistResponseRoot.java
0 → 100644
View file @
4b6f347
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
java.util.ArrayList
;
import
java.util.List
;
import
javax.xml.bind.annotation.XmlRootElement
;
@XmlRootElement
public
class
NetworkAssociationInfolistResponseRoot
{
private
List
<
NetworkAssociationInfoPojo
>
associations
;
public
NetworkAssociationInfolistResponseRoot
()
{
this
.
associations
=
new
ArrayList
<>();
}
public
List
<
NetworkAssociationInfoPojo
>
getAssociations
()
{
return
associations
;
}
public
void
setAssociations
(
List
<
NetworkAssociationInfoPojo
>
associations
)
{
this
.
associations
=
associations
;
}
}
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