Commit 044491ba by Tuomas Riihimäki

Extract rest pojo classes from web project

This way pojo classes can be distributed separately to for example android project

 - Initially extract NetworkAssociation pojos and remove one reference to DB project
1 parent 9aaaffd3
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
<artifactId>moya-beans-client</artifactId> <artifactId>moya-beans-client</artifactId>
<build> <build>
<sourceDirectory>ejbModule</sourceDirectory> <sourceDirectory>ejbModule</sourceDirectory>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<module>../moya-authmodule</module> <module>../moya-authmodule</module>
<module>../moya-authmodule-client</module> <module>../moya-authmodule-client</module>
<module>../moya-database</module> <module>../moya-database</module>
<module>../moya-restpojo</module>
<module>../moya-beans-client</module> <module>../moya-beans-client</module>
<module>../moya-beans</module> <module>../moya-beans</module>
<module>../moya-web</module> <module>../moya-web</module>
......
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>moya-restpojo</artifactId>
<parent>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-parent</artifactId>
<version>1.0</version>
<relativePath>../moya-parent/pom.xml</relativePath>
</parent>
<!--
<dependencies>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-database</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies>
-->
</project>
\ No newline at end of file
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
......
...@@ -16,14 +16,10 @@ ...@@ -16,14 +16,10 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.Calendar;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.NetworkAssociation;
public class NetworkAssociationInfoPojo { public class NetworkAssociationInfoPojo {
private String createTime; private String createTime;
private String modifyTime; private String modifyTime;
...@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo { ...@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo {
private Integer placeId; private Integer placeId;
private Integer eventuserId; 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() { public NetworkAssociationInfoPojo() {
this.createTime = null; this.createTime = null;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
* future versions of the Software. * future versions of the Software.
* *
*/ */
package fi.codecrew.moya.rest.pojo; package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<configuration> <configuration>
<warSourceDirectory>WebContent</warSourceDirectory> <warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml> <failOnMissingWebXml>false</failOnMissingWebXml>
<packagingIncludes>WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*</packagingIncludes> <packagingIncludes>WEB-INF/lib/moya-restpojo*,WEB-INF/lib/javamelody-core*,WEB-INF/lib/primefaces*,WEB-INF/lib/*-1.0.8.jar,**/*.xml,**/*.xhtml,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,resources/*</packagingIncludes>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
...@@ -34,13 +34,18 @@ ...@@ -34,13 +34,18 @@
<artifactId>primefaces</artifactId> <artifactId>primefaces</artifactId>
<version>5.1</version> <version>5.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.primefaces.extensions</groupId> <groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId> <artifactId>all-themes</artifactId>
<version>1.0.8</version> <version>1.0.8</version>
<type>pom</type> <type>pom</type>
</dependency> </dependency>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-restpojo</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies> </dependencies>
<parent> <parent>
<groupId>fi.codecrew.moya</groupId> <groupId>fi.codecrew.moya</groupId>
......
...@@ -33,189 +33,206 @@ import javax.ws.rs.core.MediaType; ...@@ -33,189 +33,206 @@ import javax.ws.rs.core.MediaType;
import fi.codecrew.moya.beans.NetworkAssociationBeanLocal; import fi.codecrew.moya.beans.NetworkAssociationBeanLocal;
import fi.codecrew.moya.enums.NetworkAssociationStatus; import fi.codecrew.moya.enums.NetworkAssociationStatus;
import fi.codecrew.moya.model.NetworkAssociation; import fi.codecrew.moya.model.NetworkAssociation;
import fi.codecrew.moya.rest.pojo.NetworkAssociationActionPojo; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationActionPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoPojo; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfolistResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationResponseRoot; import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationResponseRoot;
@RequestScoped @RequestScoped
@Path("/networkassociation") @Path("/networkassociation")
public class NetworkAssociationRestView { public class NetworkAssociationRestView {
@EJB @EJB
private NetworkAssociationBeanLocal networkAssociationBean; private NetworkAssociationBeanLocal networkAssociationBean;
@POST @POST
@Path("/auth") @Path("/auth")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot auth( public NetworkAssociationResponseRoot auth(
@FormParam("username") String username, @FormParam("username") String username,
@FormParam("password") String password, @FormParam("password") String password,
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac, @FormParam("mac") String mac,
@FormParam("code") String code, @FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired @FormParam("coderequired") Boolean codeRequired
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
NetworkAssociation na = networkAssociationBean.tryAssociate( NetworkAssociation na = networkAssociationBean.tryAssociate(
username, password, ip, mac, code, codeRequired); username, password, ip, mac, code, codeRequired);
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) { if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
} else { } else {
resp.getResult().setMessage("UNKNOWN_ERROR"); resp.getResult().setMessage("UNKNOWN_ERROR");
} }
} }
return resp; return resp;
} }
@POST @POST
@Path("/codeauth") @Path("/codeauth")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot codeAuth( public NetworkAssociationResponseRoot codeAuth(
@FormParam("usercode") String usercode, @FormParam("usercode") String usercode,
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac, @FormParam("mac") String mac,
@FormParam("code") String code, @FormParam("code") String code,
@FormParam("coderequired") Boolean codeRequired @FormParam("coderequired") Boolean codeRequired
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
NetworkAssociation na = networkAssociationBean.tryAssociate( NetworkAssociation na = networkAssociationBean.tryAssociate(
usercode, ip, mac, code, codeRequired); usercode, ip, mac, code, codeRequired);
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE))
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
else else
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) { if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
} else { } else {
resp.getResult().setMessage("UNKNOWN_ERROR"); resp.getResult().setMessage("UNKNOWN_ERROR");
} }
} }
return resp; return resp;
} }
@GET @GET
@Path("/get_association_infos") @Path("/get_association_infos")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfolistResponseRoot getAssociationInfos() { public NetworkAssociationInfolistResponseRoot getAssociationInfos() {
NetworkAssociationInfolistResponseRoot nairr = new NetworkAssociationInfolistResponseRoot(); NetworkAssociationInfolistResponseRoot nairr = new NetworkAssociationInfolistResponseRoot();
for(NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) { for (NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) {
nairr.getAssociations().add(new NetworkAssociationInfoPojo(na)); nairr.getAssociations().add(initNetworkAssociationInfoPojo(na));
} }
return nairr; return nairr;
} }
@GET @GET
@Path("/get_association_info_by_ip/{ipAddress}") @Path("/get_association_info_by_ip/{ipAddress}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfoResponseRoot getAssociationInfos( public NetworkAssociationInfoResponseRoot getAssociationInfos(
@PathParam("ipAddress") String ipAddress @PathParam("ipAddress") String ipAddress
) { ) {
NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress); NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress);
NetworkAssociationInfoResponseRoot nairr; NetworkAssociationInfoResponseRoot nairr;
if(na != null) { if (na != null) {
nairr = new NetworkAssociationInfoResponseRoot( nairr = new NetworkAssociationInfoResponseRoot(
new NetworkAssociationInfoPojo(na) initNetworkAssociationInfoPojo(na)
); );
} else { } else {
nairr = new NetworkAssociationInfoResponseRoot(); nairr = new NetworkAssociationInfoResponseRoot();
} }
return nairr; return nairr;
} }
@GET @GET
@Path("/get_all/{activate}") @Path("/get_all/{activate}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAll( public NetworkAssociationResponseRoot getAll(
@PathParam("activate") Boolean activate @PathParam("activate") Boolean activate
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
if(activate == null) if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE"); throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate); List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate);
for(NetworkAssociation na : activeAssociations) { for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; return resp;
} }
} }
@GET @GET
@Path("/get_all/{horizon}/{activate}") @Path("/get_all/{horizon}/{activate}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAllByHorizon( public NetworkAssociationResponseRoot getAllByHorizon(
@PathParam("activate") Boolean activate, @PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon @PathParam("horizon") String horizon
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
if(activate == null) if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE"); throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon); List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon);
for(NetworkAssociation na : activeAssociations) { for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; return resp;
} }
} }
@POST @POST
@Path("/get_status_by_ip_mac") @Path("/get_status_by_ip_mac")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getChanges( public NetworkAssociationResponseRoot getChanges(
@FormParam("ip") String ip, @FormParam("ip") String ip,
@FormParam("mac") String mac @FormParam("mac") String mac
) { ) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot(); NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try { try {
for(NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) { for (NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) {
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) { if (na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} else if(na.getStatus().equals(NetworkAssociationStatus.PENDING)) { } else if (na.getStatus().equals(NetworkAssociationStatus.PENDING)) {
resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getPendings().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} else if(na.getStatus().equals(NetworkAssociationStatus.EXPIRED)) { } else if (na.getStatus().equals(NetworkAssociationStatus.EXPIRED)) {
resp.getRemovals().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC())); resp.getRemovals().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
} }
} }
return resp; return resp;
} catch(Exception e) { } catch (Exception e) {
resp.getResult().setResultCode(0); resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage()); resp.getResult().setMessage(e.getMessage());
return resp; return resp;
} }
} }
private NetworkAssociationInfoPojo initNetworkAssociationInfoPojo(NetworkAssociation na)
{
NetworkAssociationInfoPojo ret = new NetworkAssociationInfoPojo();
ret.setCreateTime(na.getCreateTime().getTime().toString());
ret.setModifyTime(na.getModifyTime().getTime().toString());
ret.setIpAddress(na.getIP());
ret.setMacAddress(na.getMAC());
Integer placeid = null;
if (na.getPlace() != null)
placeid = na.getPlace().getId();
ret.setPlaceId(placeid);
ret.setEventuserId(na.getEventUser().getId());
return ret;
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!