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 @@
<artifactId>moya-beans-client</artifactId>
<build>
<sourceDirectory>ejbModule</sourceDirectory>
</build>
<dependencies>
<dependency>
......
......@@ -10,6 +10,7 @@
<module>../moya-authmodule</module>
<module>../moya-authmodule-client</module>
<module>../moya-database</module>
<module>../moya-restpojo</module>
<module>../moya-beans-client</module>
<module>../moya-beans</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 @@
* 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;
......
......@@ -16,14 +16,10 @@
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo;
import java.util.Calendar;
package fi.codecrew.moya.rest.pojo.network.v1;
import javax.xml.bind.annotation.XmlElement;
import fi.codecrew.moya.model.NetworkAssociation;
public class NetworkAssociationInfoPojo {
private String createTime;
private String modifyTime;
......@@ -32,18 +28,7 @@ public class NetworkAssociationInfoPojo {
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;
......
......@@ -16,7 +16,7 @@
* 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.List;
......
......@@ -16,7 +16,7 @@
* 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.List;
......
......@@ -16,7 +16,7 @@
* 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.List;
......
......@@ -16,7 +16,7 @@
* 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;
......
......@@ -12,7 +12,7 @@
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<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>
</plugin>
</plugins>
......@@ -34,13 +34,18 @@
<artifactId>primefaces</artifactId>
<version>5.1</version>
</dependency>
<dependency>
<groupId>org.primefaces.extensions</groupId>
<artifactId>all-themes</artifactId>
<version>1.0.8</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-restpojo</artifactId>
<version>${moya.version}</version>
</dependency>
</dependencies>
<parent>
<groupId>fi.codecrew.moya</groupId>
......
......@@ -33,189 +33,206 @@ 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.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.NetworkAssociationResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationActionPojo;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoPojo;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfoResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationInfolistResponseRoot;
import fi.codecrew.moya.rest.pojo.network.v1.NetworkAssociationResponseRoot;
@RequestScoped
@Path("/networkassociation")
public class NetworkAssociationRestView {
@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
) {
@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))
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) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) {
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
resp.getResult().setMessage(e.getMessage());
} else {
resp.getResult().setMessage("UNKNOWN_ERROR");
}
}
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
) {
@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))
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) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
if(e.getMessage() != null && !e.getMessage().isEmpty()) {
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
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));
for (NetworkAssociation na : networkAssociationBean.getActiveAssociations(false)) {
nairr.getAssociations().add(initNetworkAssociationInfoPojo(na));
}
return nairr;
}
@GET
@Path("/get_association_info_by_ip/{ipAddress}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationInfoResponseRoot getAssociationInfos(
@PathParam("ipAddress") String ipAddress
) {
@PathParam("ipAddress") String ipAddress
) {
NetworkAssociation na = networkAssociationBean.getActiveAssociationByIP(ipAddress);
NetworkAssociationInfoResponseRoot nairr;
if(na != null) {
if (na != null) {
nairr = new NetworkAssociationInfoResponseRoot(
new NetworkAssociationInfoPojo(na)
);
initNetworkAssociationInfoPojo(na)
);
} else {
nairr = new NetworkAssociationInfoResponseRoot();
}
return nairr;
}
@GET
@Path("/get_all/{activate}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAll(
@PathParam("activate") Boolean activate
) {
@PathParam("activate") Boolean activate
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
if(activate == null)
if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociations(activate);
for(NetworkAssociation na : activeAssociations) {
for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
return resp;
}
}
@GET
@Path("/get_all/{horizon}/{activate}")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAllByHorizon(
@PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon
) {
@PathParam("activate") Boolean activate,
@PathParam("horizon") String horizon
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
if(activate == null)
if (activate == null)
throw new Exception("INVALID_PARAMETER_FOR_ACTIVATE");
List<NetworkAssociation> activeAssociations = networkAssociationBean.getActiveAssociationsByHorizon(activate, horizon);
for(NetworkAssociation na : activeAssociations) {
for (NetworkAssociation na : activeAssociations) {
resp.getAdditions().add(new NetworkAssociationActionPojo(na.getIP(), na.getMAC()));
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
return resp;
}
}
@POST
@Path("/get_status_by_ip_mac")
@Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getChanges(
@FormParam("ip") String ip,
@FormParam("mac") String mac
) {
@FormParam("ip") String ip,
@FormParam("mac") String mac
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
for(NetworkAssociation na : networkAssociationBean.getStatusByIPAndMAC(ip, mac)) {
if(na.getStatus().equals(NetworkAssociationStatus.ACTIVE)) {
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)) {
} else if (na.getStatus().equals(NetworkAssociationStatus.PENDING)) {
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()));
}
}
return resp;
} catch(Exception e) {
} catch (Exception e) {
resp.getResult().setResultCode(0);
resp.getResult().setMessage(e.getMessage());
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!