Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Max Mecklin
/
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 62c53559
authored
May 11, 2014
by
Antti Tönkyrä
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
front-end implementation for network assoc
1 parent
f8f8fcfa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
239 additions
and
0 deletions
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationView.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationActionPojo.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationResponseRoot.java
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/RESTCallResultPojo.java
code/MoyaWeb/src/fi/codecrew/moya/rest/NetworkAssociationView.java
0 → 100644
View file @
62c5355
package
fi
.
codecrew
.
moya
.
rest
;
import
java.util.List
;
import
javax.ejb.EJB
;
import
javax.enterprise.context.RequestScoped
;
import
javax.ws.rs.FormParam
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.POST
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
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.NetworkAssociationResponseRoot
;
@RequestScoped
@Path
(
"/networkassociation"
)
public
class
NetworkAssociationView
{
@EJB
private
NetworkAssociationBeanLocal
networkAssociationBean
;
@POST
@Path
(
"/auth"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationResponseRoot
auth
(
@FormParam
(
"username"
)
String
username
,
@FormParam
(
"password"
)
String
password
,
@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
(
username
,
password
,
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_all/{activate}"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationResponseRoot
getAll
(
@PathParam
(
"activate"
)
Boolean
activate
)
{
NetworkAssociationResponseRoot
resp
=
new
NetworkAssociationResponseRoot
();
try
{
if
(
activate
==
null
)
throw
new
Exception
(
"INVALID_PARAMETER_FOR_ACTIVATE"
);
if
(
activate
)
System
.
out
.
println
(
"TRUE TRUE"
);
else
System
.
out
.
println
(
"SUPER FALSE"
);
List
<
NetworkAssociation
>
activeAssociations
=
networkAssociationBean
.
getActiveAssociations
(
activate
);
for
(
NetworkAssociation
na
:
activeAssociations
)
{
resp
.
getAdditions
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
return
resp
;
}
catch
(
Exception
e
)
{
resp
.
getResult
().
setResultCode
(
0
);
resp
.
getResult
().
setMessage
(
e
.
getMessage
());
return
resp
;
}
}
@GET
@Path
(
"/get_status_by_ip_mac/{ip}/{mac}"
)
@Produces
({
MediaType
.
APPLICATION_JSON
})
public
NetworkAssociationResponseRoot
getChanges
(
@PathParam
(
"ip"
)
String
ip
,
@PathParam
(
"mac"
)
String
mac
)
{
NetworkAssociationResponseRoot
resp
=
new
NetworkAssociationResponseRoot
();
try
{
for
(
NetworkAssociation
na
:
networkAssociationBean
.
getStatusByIPAndMAC
(
ip
,
mac
))
{
if
(
na
.
getStatus
().
equals
(
NetworkAssociationStatus
.
ACTIVE
))
{
resp
.
getAdditions
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
else
if
(
na
.
getStatus
().
equals
(
NetworkAssociationStatus
.
PENDING
))
{
resp
.
getPendings
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
else
if
(
na
.
getStatus
().
equals
(
NetworkAssociationStatus
.
EXPIRED
))
{
resp
.
getRemovals
().
add
(
new
NetworkAssociationActionPojo
(
na
.
getIP
(),
na
.
getMAC
()));
}
}
return
resp
;
}
catch
(
Exception
e
)
{
resp
.
getResult
().
setResultCode
(
0
);
resp
.
getResult
().
setMessage
(
e
.
getMessage
());
return
resp
;
}
}
}
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationActionPojo.java
0 → 100644
View file @
62c5355
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
javax.xml.bind.annotation.XmlElement
;
public
class
NetworkAssociationActionPojo
{
private
String
ip
;
private
String
mac
;
public
NetworkAssociationActionPojo
()
{
this
.
ip
=
""
;
this
.
mac
=
""
;
}
public
NetworkAssociationActionPojo
(
String
ip
,
String
mac
)
{
this
.
ip
=
ip
;
this
.
mac
=
mac
;
}
@XmlElement
(
name
=
"ip"
)
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
@XmlElement
(
name
=
"mac"
)
public
String
getMac
()
{
return
mac
;
}
public
void
setMac
(
String
mac
)
{
this
.
mac
=
mac
;
}
}
\ No newline at end of file
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/NetworkAssociationResponseRoot.java
0 → 100644
View file @
62c5355
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
NetworkAssociationResponseRoot
{
private
RESTCallResultPojo
result
;
private
List
<
NetworkAssociationActionPojo
>
additions
;
private
List
<
NetworkAssociationActionPojo
>
removals
;
private
List
<
NetworkAssociationActionPojo
>
pendings
;
public
NetworkAssociationResponseRoot
()
{
this
.
result
=
new
RESTCallResultPojo
();
this
.
setAdditions
(
new
ArrayList
<
NetworkAssociationActionPojo
>());
this
.
setRemovals
(
new
ArrayList
<
NetworkAssociationActionPojo
>());
this
.
setPendings
(
new
ArrayList
<
NetworkAssociationActionPojo
>());
}
public
RESTCallResultPojo
getResult
()
{
return
result
;
}
public
void
setResult
(
RESTCallResultPojo
result
)
{
this
.
result
=
result
;
}
public
List
<
NetworkAssociationActionPojo
>
getAdditions
()
{
return
additions
;
}
public
void
setAdditions
(
List
<
NetworkAssociationActionPojo
>
additions
)
{
this
.
additions
=
additions
;
}
public
List
<
NetworkAssociationActionPojo
>
getRemovals
()
{
return
removals
;
}
public
void
setRemovals
(
List
<
NetworkAssociationActionPojo
>
removals
)
{
this
.
removals
=
removals
;
}
public
List
<
NetworkAssociationActionPojo
>
getPendings
()
{
return
pendings
;
}
public
void
setPendings
(
List
<
NetworkAssociationActionPojo
>
pendings
)
{
this
.
pendings
=
pendings
;
}
}
\ No newline at end of file
code/MoyaWeb/src/fi/codecrew/moya/rest/pojo/RESTCallResultPojo.java
0 → 100644
View file @
62c5355
package
fi
.
codecrew
.
moya
.
rest
.
pojo
;
import
javax.xml.bind.annotation.XmlElement
;
public
class
RESTCallResultPojo
{
private
Integer
resultCode
;
private
String
resultMessage
;
@XmlElement
(
name
=
"code"
)
public
Integer
getResultCode
()
{
return
resultCode
;
}
public
void
setResultCode
(
Integer
resultCode
)
{
this
.
resultCode
=
resultCode
;
}
@XmlElement
(
name
=
"message"
)
public
String
getMessage
()
{
return
this
.
resultMessage
;
}
public
void
setMessage
(
String
message
)
{
this
.
resultMessage
=
message
;
}
public
RESTCallResultPojo
(
Integer
code
,
String
result
)
{
this
.
resultCode
=
code
;
this
.
resultMessage
=
result
;
}
public
RESTCallResultPojo
()
{
this
.
resultCode
=
1
;
this
.
resultMessage
=
"ok"
;
}
}
\ No newline at end of file
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