Commit 525c7345 by Antti Tönkyrä

functions to get user info by ip address & get all users

1 parent b3c51b46
...@@ -249,5 +249,17 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal { ...@@ -249,5 +249,17 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private Place resolvePlaceFromCode(String code) { private Place resolvePlaceFromCode(String code) {
if(code == null) return null; if(code == null) return null;
return barcodeBean.getPlaceFromTextCode(code); 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;
} }
} }
...@@ -23,4 +23,6 @@ public interface NetworkAssociationBeanLocal { ...@@ -23,4 +23,6 @@ public interface NetworkAssociationBeanLocal {
void dropAssociationById(Integer associd); void dropAssociationById(Integer associd);
NetworkAssociation getActiveAssociationByIP(String ipAddress);
} }
...@@ -16,6 +16,9 @@ import fi.codecrew.moya.beans.NetworkAssociationBeanLocal; ...@@ -16,6 +16,9 @@ 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.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.NetworkAssociationResponseRoot;
@RequestScoped @RequestScoped
...@@ -58,6 +61,36 @@ public class NetworkAssociationRestView { ...@@ -58,6 +61,36 @@ public class NetworkAssociationRestView {
} }
@GET @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}") @Path("/get_all/{activate}")
@Produces({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON })
public NetworkAssociationResponseRoot getAll( public NetworkAssociationResponseRoot getAll(
...@@ -65,6 +98,7 @@ public class NetworkAssociationRestView { ...@@ -65,6 +98,7 @@ 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");
......
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;
}
}
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;
}
}
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;
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!