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>
...@@ -41,6 +41,11 @@ ...@@ -41,6 +41,11 @@
<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,11 +33,11 @@ import javax.ws.rs.core.MediaType; ...@@ -33,11 +33,11 @@ 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")
...@@ -62,13 +62,13 @@ public class NetworkAssociationRestView { ...@@ -62,13 +62,13 @@ public class NetworkAssociationRestView {
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");
...@@ -93,13 +93,13 @@ public class NetworkAssociationRestView { ...@@ -93,13 +93,13 @@ public class NetworkAssociationRestView {
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");
...@@ -114,8 +114,8 @@ public class NetworkAssociationRestView { ...@@ -114,8 +114,8 @@ public class NetworkAssociationRestView {
@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;
...@@ -129,9 +129,9 @@ public class NetworkAssociationRestView { ...@@ -129,9 +129,9 @@ public class NetworkAssociationRestView {
) { ) {
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();
...@@ -148,17 +148,17 @@ public class NetworkAssociationRestView { ...@@ -148,17 +148,17 @@ public class NetworkAssociationRestView {
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;
...@@ -175,17 +175,17 @@ public class NetworkAssociationRestView { ...@@ -175,17 +175,17 @@ public class NetworkAssociationRestView {
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;
...@@ -201,21 +201,38 @@ public class NetworkAssociationRestView { ...@@ -201,21 +201,38 @@ public class NetworkAssociationRestView {
) { ) {
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!