Commit 4b6f3474 by Tuukka Kivilahti

Merge branch 'networkassoc-features' into 'master'

Networkassoc features

Vilkuillut @tkfftk
2 parents f028befe 10c72b2d
......@@ -19,6 +19,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.GroupMembership;
import fi.codecrew.moya.model.NetworkAssociation;
import fi.codecrew.moya.model.Place;
import fi.codecrew.moya.model.PrintedCard;
import fi.codecrew.moya.model.Role;
/**
......@@ -44,6 +45,9 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private EventBean eventBean;
@EJB
private CardTemplateBean cardBean;
@EJB
private PermissionBean permissionBean;
public NetworkAssociationBean() {}
......@@ -83,6 +87,21 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
if(authUser == null)
throw new Exception("INVALID_USER_OR_PASSWORD");
return tryAssociateInternal(authUser, ip, mac, code, codeRequired);
}
@Override
@RolesAllowed(NetworkAssociationPermission.S_CAN_ADMINISTER_ASSOCIATIONS)
public NetworkAssociation tryAssociate(String usercode, String ip, String mac, String code, Boolean codeRequired) throws Exception {
EventUser authUser = userBean.getUser(usercode);
if(authUser == null)
throw new Exception("INVALID_USERCODE");
return tryAssociateInternal(authUser, ip, mac, code, codeRequired);
}
private NetworkAssociation tryAssociateInternal(EventUser authUser, String ip, String mac, String code, boolean codeRequired) throws Exception {
NetworkAssociation association;
HashSet<IAppPermission> userPerms = buildPermsFor(authUser);
......@@ -249,5 +268,17 @@ public class NetworkAssociationBean implements NetworkAssociationBeanLocal {
private Place resolvePlaceFromCode(String code) {
if(code == null) return null;
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,9 @@ public interface NetworkAssociationBeanLocal {
void dropAssociationById(Integer associd);
NetworkAssociation getActiveAssociationByIP(String ipAddress);
NetworkAssociation tryAssociate(String usercode, String ip, String mac,
String code, Boolean codeRequired) throws Exception;
}
......@@ -12,6 +12,7 @@
</f:metadata>
<ui:define name="content">
<h:form>
<p:commandButton style="width: 0px; height: 0px;" value="#{i18n['networkassociation.create_association']}" action="#{networkAssociationView.createAssociation}" update="@form"/>
<p:messages autoUpdate="true" redisplay="false"></p:messages>
<h1>#{i18n['networkassociation.current_associations']}</h1>
<p:dataTable var="activeAssoc" value="#{networkAssociationView.activeAssociations}">
......
......@@ -16,6 +16,9 @@ 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;
@RequestScoped
......@@ -57,6 +60,67 @@ public class NetworkAssociationRestView {
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
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
NetworkAssociation na = networkAssociationBean.tryAssociate(
usercode, 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_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}")
@Produces({ MediaType.APPLICATION_JSON })
......@@ -65,6 +129,7 @@ public class NetworkAssociationRestView {
) {
NetworkAssociationResponseRoot resp = new NetworkAssociationResponseRoot();
try {
if(activate == null)
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!