Commit 662b4629 by Tuomas Riihimäki

Randomfixes

1 parent 9e4535ec
/*
* Copyright Codecrew Ry
*
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest.pojo.userinfo.v1;
......@@ -25,16 +25,18 @@ import javax.xml.bind.annotation.XmlElement;
@ApiModel
public class UserPermissionRestPojo {
@XmlElement()
private EventUserRestPojo user;
@XmlElement()
private boolean accessGranted = false;
public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted)
{
public UserPermissionRestPojo(EventUserRestPojo eventUserRestPojo, boolean granted) {
this();
this.user = eventUserRestPojo;
this.accessGranted = granted;
}
public UserPermissionRestPojo()
{
public UserPermissionRestPojo() {
super();
}
......@@ -54,9 +56,5 @@ public class UserPermissionRestPojo {
this.user = user;
}
@XmlElement()
private EventUserRestPojo user;
@XmlElement()
private boolean accessGranted = false;
}
package fi.codecrew.moya.rest.pojo.vip.v2;
import java.math.BigDecimal;
import java.util.Date;
public class VipProductDeliveryPojo {
public Integer id;
public Integer delivererId;
public BigDecimal quantity;
public Date deliveryTime;
public String notes;
}
package fi.codecrew.moya.rest.v2.pojo;
package fi.codecrew.moya.rest.pojo.vip.v2;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import fi.codecrew.moya.model.VipProduct;
public class VipProductPojo {
public Integer id;
......@@ -14,20 +12,7 @@ public class VipProductPojo {
public String notes;
public BigDecimal quantity;
public BigDecimal delivered;
public List<VipProductDeliveryPojo> deliveries = new ArrayList<>();
public List<VipProductDeliveryPojo> deliveries = new ArrayList<VipProductDeliveryPojo>();
public static VipProductPojo create(VipProduct prod) {
VipProductPojo ret = new VipProductPojo();
ret.id = prod.getId();
ret.name = prod.getProductName();
if (prod.getProduct() != null) {
ret.productId = prod.getProduct().getId();
}
ret.notes = prod.getNotes();
ret.quantity = prod.getQuantity();
ret.delivered = prod.getDelivered();
ret.deliveries = VipProductDeliveryPojo.create(prod.getDeliveries());
return ret;
}
}
package fi.codecrew.moya.rest.pojo.vip.v2;
import io.swagger.annotations.ApiModel;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@XmlRootElement()
@ApiModel(description = "vip")
public class VipRestPojo {
public Integer id;
public String description;
public String shortdescr;
public Date created;
public Integer eventuserId;
public Integer creatorId;
public Integer hostId;
public List<VipProductPojo> products = new ArrayList<VipProductPojo>();
}
......@@ -12,10 +12,12 @@
</f:metadata>
<ui:define name="title">
<h1>#{i18n['etickets.title']}</h1>
<h1>#{standaloneEticketView.user.event.name}</h1>
</ui:define>
<ui:define name="content">
<h2>#{i18n['etickets.title']}</h2>
<h:form id="etickets">
......
......@@ -39,6 +39,7 @@ import javax.servlet.http.HttpSession;
import fi.codecrew.moya.beans.*;
import fi.codecrew.moya.utilities.UserLoginUtils;
import org.apache.commons.codec.Charsets;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
......@@ -181,9 +182,10 @@ public class HostnameFilter implements Filter {
|| "/dydata".equals(httpRequest.getServletPath())) {
authtype = AuthType.REST;
if (!restAuth(httpRequest, response)) {
if (!restAuth(httpRequest, response) && RestApplicationEntrypoint.REST_PATH.equals(httpRequest.getServletPath())) {
response.reset();
response.getOutputStream().write("Rest auth failed! ".getBytes(UTF8));
response.getOutputStream().write("Rest auth failed! ".getBytes( Charsets.UTF_8));
if (response instanceof HttpServletResponse) {
HttpServletResponse httpResp = (HttpServletResponse) response;
......@@ -192,7 +194,9 @@ public class HostnameFilter implements Filter {
// Rest auth failed. Go away!
return;
}
} else {
}
if(httpRequest.getUserPrincipal() == null) {
try {
authtype = AuthType.ANON;
httpRequest.login(User.ANONYMOUS_LOGINNAME + '@' + hostname, null);
......@@ -200,6 +204,7 @@ public class HostnameFilter implements Filter {
logger.warn("Error logging in as anonymous... ignoring.. ", t);
}
}
} else if (!httpRequest.getUserPrincipal().getName().equals(User.ANONYMOUS_LOGINNAME + '@' + hostname)) {
authtype = AuthType.USER;
sessionmgmt.updateSessionUser(httpRequest.getSession().getId(), httpRequest.getUserPrincipal().getName());
......@@ -273,6 +278,9 @@ public class HostnameFilter implements Filter {
hashBuilder.append(httpRequest.getParameter("appmac")).append(":");
hashBuilder.append(httpRequest.getPathInfo());
restAuthStr = hashBuilder.toString();
} else {
// If no rest authentication is even tried, allow, anon login
return true;
}
boolean ret = true;
......
/*
* Copyright Codecrew Ry
*
*
* All rights reserved.
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*
* This license applies to any software containing a notice placed by the
* copyright holder. Such software is herein referred to as the Software.
* This license covers modification, distribution and use of the Software.
*
* Any distribution and use in source and binary forms, with or without
* modification is not permitted without explicit written permission from the
* copyright owner.
*
* A non-exclusive royalty-free right is granted to the copyright owner of the
* Software to use, modify and distribute all modifications to the Software in
* future versions of the Software.
*
*/
package fi.codecrew.moya.rest;
......@@ -38,8 +38,8 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPermissionRestPojo;
@RequestScoped
@Path("/reader")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON + "; charset=UTF-8"})
public class ReaderRestView {
@EJB
......@@ -93,8 +93,7 @@ public class ReaderRestView {
@GET
@Path("/LastEventusers")
public ReaderEventRestRoot getLastEventusers()
{
public ReaderEventRestRoot getLastEventusers() {
return new ReaderEventRestRoot(PojoUtils.parseReaderEvents(readerbean.getLastReaderEvents()));
}
......@@ -108,10 +107,10 @@ public class ReaderRestView {
@GET
@Path("/EventRole/{reader}/{tagId}/{roleid}")
public Response isTaguserInRole(
@PathParam("reader") String reader,
@PathParam("tagId") String tag,
@PathParam("roleid") Integer roleId
) {
@PathParam("reader") String reader,
@PathParam("tagId") String tag,
@PathParam("roleid") Integer roleId
) {
ReaderEvent ret = readerbean.checkCode(reader, tag);
ResponseBuilder builder = null;
if (roleId == null || roleId.equals(0)) {
......@@ -119,23 +118,20 @@ public class ReaderRestView {
builder.entity("role ID is required!");
builder.type(MediaType.TEXT_PLAIN);
}
if (builder == null) {
if (ret == null || ret.getPrintedCard() == null) {
builder = Response.status(Status.NOT_ACCEPTABLE);
builder.entity("No card found for uid.");
builder.type(MediaType.TEXT_PLAIN);
} else if (ret.getPrintedCard() == null) {
builder = Response.status(Status.NOT_ACCEPTABLE);
builder.entity("No card found for uid.");
builder.type(MediaType.TEXT_PLAIN);
} else {
EventUser user = ret.getPrintedCard().getUser();
boolean found = userbean.isUserInRole(user, roleId);
if (found) {
builder = Response.status(Status.OK);
} else {
EventUser user = ret.getPrintedCard().getUser();
boolean found = userbean.isUserInRole(user, roleId);
if (found) {
builder = Response.status(Status.OK);
} else {
builder = Response.status(Status.FORBIDDEN);
}
builder.entity(new UserPermissionRestPojo(PojoUtils.initEventUserRestPojo(user), found));
builder = Response.status(Status.FORBIDDEN);
}
builder.entity(new UserPermissionRestPojo(PojoUtils.initEventUserRestPojo(user), found));
}
return builder.build();
......
package fi.codecrew.moya.rest.v2;
import java.util.ArrayList;
import java.util.Date;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import io.swagger.annotations.Api;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
......@@ -25,16 +7,28 @@ import fi.codecrew.moya.beans.VipBeanLocal;
import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.Vip;
import fi.codecrew.moya.model.VipProduct;
import fi.codecrew.moya.rest.v2.pojo.VipProductPojo;
import fi.codecrew.moya.rest.v2.pojo.VipRestPojo;
import fi.codecrew.moya.rest.pojo.vip.v2.VipProductPojo;
import fi.codecrew.moya.rest.pojo.vip.v2.VipRestPojo;
import fi.codecrew.moya.rest.v2.pojo.VipPojoUtils;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
import io.swagger.annotations.Api;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@RequestScoped
@Path("/v2/vip")
@Api(value = "/v2/vip", description = "Vip list operations")
@Produces({ MediaType.APPLICATION_JSON + "; charset=UTF-8" })
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON + "; charset=UTF-8"})
@Consumes({MediaType.APPLICATION_JSON})
public class VipRestView {
@EJB
......@@ -51,8 +45,8 @@ public class VipRestView {
@GET
@Path("/all")
public Response getAllVips() {
ArrayList<VipRestPojo> ret = VipRestPojo.create(vipbean.getAvailableVips());
return Response.ok(ret).build();
ArrayList<VipRestPojo> ret = VipPojoUtils.createVipList(vipbean.getAvailableVips());
return Response.ok(new GenericEntity<ArrayList<VipRestPojo>>(ret){}).build();
}
@GET
......@@ -62,7 +56,7 @@ public class VipRestView {
sq.setSearch(search);
sq.setPagesize(0);
SearchResult<Vip> result = vipbean.search(sq);
ArrayList<VipRestPojo> ret = VipRestPojo.create(result.getResults());
ArrayList<VipRestPojo> ret = VipPojoUtils.createVipList(result.getResults());
GenericEntity<ArrayList<VipRestPojo>> list = new GenericEntity<ArrayList<VipRestPojo>>(ret) {
};
......@@ -74,19 +68,19 @@ public class VipRestView {
public Response deleteEntry(@PathParam("id") Integer id) {
Vip vip = vipbean.find(id);
vipbean.delete(vip);
return Response.ok(VipRestPojo.create(vip)).build();
return Response.ok(VipPojoUtils.createVip(vip)).build();
}
@GET
@Path("/{id}")
public Response findEntry(@PathParam("id") Integer id) {
Vip vip = vipbean.find(id);
return Response.ok(VipRestPojo.create(vip)).build();
return Response.ok(VipPojoUtils.createVip(vip)).build();
}
@POST
@Path("/create")
@Produces({ MediaType.APPLICATION_JSON })
@Produces({MediaType.APPLICATION_JSON})
@Consumes(MediaType.APPLICATION_JSON)
public Response createEntry(VipRestPojo create) {
......@@ -123,7 +117,8 @@ public class VipRestView {
vipbean.create(vip);
return Response.ok(VipRestPojo.create(vip)).build();
return Response.ok(VipPojoUtils.createVip(vip)).build();
}
}
package fi.codecrew.moya.rest.v2.pojo;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import io.swagger.annotations.ApiModel;
import fi.codecrew.moya.model.Vip;
import fi.codecrew.moya.model.VipProduct;
import fi.codecrew.moya.model.VipProductDelivery;
import fi.codecrew.moya.rest.pojo.vip.v2.VipProductDeliveryPojo;
import fi.codecrew.moya.rest.pojo.vip.v2.VipProductPojo;
import fi.codecrew.moya.rest.pojo.vip.v2.VipRestPojo;
@XmlRootElement()
@ApiModel(description = "vip")
public class VipRestPojo {
import java.util.ArrayList;
import java.util.List;
public Integer id;
public String description;
public String shortdescr;
public Date created;
public Integer eventuserId;
public Integer creatorId;
public Integer hostId;
public List<VipProductPojo> products = new ArrayList<>();
public class VipPojoUtils {
public static VipProductPojo createVipProduct(VipProduct prod) {
VipProductPojo ret = new VipProductPojo();
ret.id = prod.getId();
ret.name = prod.getProductName();
if (prod.getProduct() != null) {
ret.productId = prod.getProduct().getId();
}
ret.notes = prod.getNotes();
ret.quantity = prod.getQuantity();
ret.delivered = prod.getDelivered();
ret.deliveries = createDeliveryList(prod.getDeliveries());
return ret;
}
public static ArrayList<VipRestPojo> create(List<Vip> vips) {
public static ArrayList<VipRestPojo> createVipList(List<Vip> vips) {
ArrayList<VipRestPojo> ret = new ArrayList<>();
for (Vip v : vips) {
ret.add(create(v));
ret.add(createVip(v));
}
return ret;
}
public static VipRestPojo create(Vip v) {
public static VipRestPojo createVip(Vip v) {
VipRestPojo r = new VipRestPojo();
r.id = v.getId();
r.description = v.getDescription();
......@@ -49,8 +51,27 @@ public class VipRestPojo {
r.hostId = v.getHost().getId();
}
for (VipProduct prod : v.getProducts()) {
r.products.add(VipProductPojo.create(prod));
r.products.add(createVipProduct(prod));
}
return r;
}
public static List<VipProductDeliveryPojo> createDeliveryList(List<VipProductDelivery> deliveries) {
List<VipProductDeliveryPojo> ret = new ArrayList<>();
if (deliveries != null) {
for (VipProductDelivery d : deliveries) {
VipProductDeliveryPojo delivery = new VipProductDeliveryPojo();
ret.add(delivery);
if (d.getDeliverer() != null) {
delivery.delivererId = d.getDeliverer().getId();
}
delivery.id = d.getId();
delivery.deliveryTime = d.getDeliveryTime();
delivery.quantity = d.getQuantity();
delivery.notes = d.getNotes();
}
}
return ret;
}
}
package fi.codecrew.moya.rest.v2.pojo;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import fi.codecrew.moya.model.VipProductDelivery;
public class VipProductDeliveryPojo {
public Integer id;
public Integer delivererId;
public BigDecimal quantity;
public Date deliveryTime;
public String notes;
public static List<VipProductDeliveryPojo> create(List<VipProductDelivery> deliveries) {
List<VipProductDeliveryPojo> ret = new ArrayList<>();
if (deliveries != null) {
for (VipProductDelivery d : deliveries) {
VipProductDeliveryPojo delivery = new VipProductDeliveryPojo();
ret.add(delivery);
if (d.getDeliverer() != null) {
delivery.delivererId = d.getDeliverer().getId();
}
delivery.id= d.getId();
delivery.deliveryTime = d.getDeliveryTime();
delivery.quantity = d.getQuantity();
delivery.notes = d.getNotes();
}
}
return ret;
}
}
<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
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fi.codecrew.moya</groupId>
......@@ -52,7 +52,7 @@
<url>http://codecrew.fi</url>
</organization>
<scm>
<connection>scm:git:https://gitlab.codecrew.fi/codecrew/moya.git</connection>
<connection>scm:git:https://gitlab.codecrew.fi/codecrew/moya.git</connection>
<developerConnection>scm:git:git@gitlab.codecrew.fi:codecrew/moya.git</developerConnection>
<url>https://gitlab.codecrew.fi/codecrew/moya</url>
</scm>
......@@ -60,6 +60,15 @@
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin-version}</version>
......@@ -75,7 +84,6 @@
</build>
<repositories>
<repository>
<id>prime-repo</id>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!