Commit 950a912f by Tuomas Riihimäki

drd apis

1 parent fe5aa708
/*
* 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.beans;
......@@ -65,13 +65,10 @@ import fi.codecrew.moya.util.MailMessage;
*/
@Stateless
@LocalBean
@DeclareRoles({ UserPermission.S_WRITE_ROLES })
@DeclareRoles({UserPermission.S_WRITE_ROLES})
public class CardTemplateBean implements CardTemplateBeanLocal {
private static final Logger logger = LoggerFactory.getLogger(CardTemplateBean.class);
/**
......@@ -114,7 +111,6 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
private CardCodeFacade cardCodeFacade;
// @Override
// @RolesAllowed("USER_MANAGEMENT/WRITE")
// public List<CardTemplate> findAll() {
......@@ -126,8 +122,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
public void create(CardTemplate card) {
LanEvent currEv = eventBean.getCurrentEvent();
if (currEv.getCardTemplates() == null)
{
if (currEv.getCardTemplates() == null) {
currEv.setCardTemplates(new ArrayList<CardTemplate>());
}
card.setEvent(currEv);
......@@ -161,7 +156,7 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
/**
* Checks users printed card roles and return the biggestCard
*
*
* @throws PermissionDeniedException
*/
@Override
......@@ -169,20 +164,20 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
logger.info("Checking printed card");
user = eventUserFacade.reload(user);
if (user == null)
return null;
LanEvent currEvent = eventBean.getCurrentEvent();
List<PrintedCard> myCards = printedcardfacade.getCards(user);
PrintedCard biggestCard = null;
for (PrintedCard card : myCards) {
if (card.getEnabled()) {
if (biggestCard == null || biggestCard.getTemplate().getPower() < card.getTemplate().getPower()) {
// The biggest card should be the only one enabled.
if (biggestCard != null) {
biggestCard.setEnabled(false);
}
biggestCard = card;
if (card.getEnabled() && biggestCard == null || biggestCard.getTemplate().getPower() < card.getTemplate().getPower()) {
// The biggest card should be the only one enabled.
if (biggestCard != null) {
biggestCard.setEnabled(false);
}
biggestCard = card;
}
}
......@@ -211,12 +206,11 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
user.getPrintedCards().add(pc);
// printedcardfacade.create(pc);
biggestCard = pc;
logger.info("User {} has too little power old role {} New role {}", new Object[] { user.getUser().getLogin(), existingPower, newPower });
logger.info("User {} has too little power old role {} New role {}", new Object[]{user.getUser().getLogin(), existingPower, newPower});
} else if (existingPower > newPower) {
MailMessage msg = new MailMessage();
LanEventProperty value = eventPropertyFacade.find(eventBean.getCurrentEvent(), LanEventPropertyKey.ADMIN_MAIL);
if (value != null && value.getTextvalue() != null && !value.getTextvalue().isEmpty())
{
if (value != null && value.getTextvalue() != null && !value.getTextvalue().isEmpty()) {
msg.setFromAddress(value.getTextvalue());
msg.setFromName("Lippukauppa");
......@@ -226,12 +220,12 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
mailbean.sendMail(msg);
}
logger.info("User {} has too much power old role {} New role {}, old card revoked.", new Object[] { user.getUser().getLogin(), existingPower, newPower });
logger.info("User {} has too much power old role {} New role {}, old card revoked.", new Object[]{user.getUser().getLogin(), existingPower, newPower});
biggestCard.setEnabled(false);
return this.checkPrintedCard(user);
} else {
logger.info("User {} has power {} and roles has power {}", new Object[] { user.getUser().getLogin(), existingPower, newPower });
logger.info("User {} has power {} and roles has power {}", new Object[]{user.getUser().getLogin(), existingPower, newPower});
}
return biggestCard;
......@@ -361,40 +355,35 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override
public PrintedCard setCardState(Integer cardId, CardState state) throws Exception {
PrintedCard card = printedcardfacade.find(cardId);
switch (state)
{
case PRINTED:
card.setPrintCount(card.getPrintCount() + 1);
card.setPrintTime(Calendar.getInstance());
break;
case PRINTING_IN_PROGRESS:
if (card.getCardState().equals(CardState.PRINTING_IN_PROGRESS)
switch (state) {
case PRINTED:
card.setPrintCount(card.getPrintCount() + 1);
card.setPrintTime(Calendar.getInstance());
break;
case PRINTING_IN_PROGRESS:
if (card.getCardState().equals(CardState.PRINTING_IN_PROGRESS)
|| card.getCardState().equals(CardState.PRINTED)) {
String response = "Unable to change type to PRINTING_IN_PROGRESS value is already {}" + card.getCardState();
logger.warn(response);
throw new Exception(response);
}
break;
default:
break;
String response = "Unable to change type to PRINTING_IN_PROGRESS value is already {}" + card.getCardState();
logger.warn(response);
throw new Exception(response);
}
break;
default:
break;
}
card.setCardState(state);
return card;
}
@Override
public EventUser giveCard(EventUser user, boolean markUserPlacesDelivered) {
user = eventUserFacade.reload(user);
PrintedCard card = checkPrintedCard(user);
if (card.getCardState() != CardState.DELIVERED) {
card.setCardState(CardState.DELIVERED);
} else {
......@@ -413,24 +402,24 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
@Override
public void removeCardCode(CardCode code) {
code = cardCodeFacade.reload(code);
if(code.getPrintedCard().getCardCodes().contains(code)) {
if (code.getPrintedCard().getCardCodes().contains(code)) {
code.getPrintedCard().getCardCodes().remove(code);
}
cardCodeFacade.remove(code);
}
}
@Override
public CardTemplate removeCardTextData(CardTextData data) {
data = ctdFacade.reload(data);
CardTemplate template = data.getCardTemplate();
ctdFacade.remove(data);
return template;
}
@Override
public CardTemplate removeCardObjectData(CardObjectData data) {
data = codFacade.reload(data);
......@@ -454,6 +443,4 @@ public class CardTemplateBean implements CardTemplateBeanLocal {
}
}
......@@ -107,7 +107,7 @@ public class ReaderBean implements ReaderBeanLocal {
/**
* Some of rfid-readers adds zeros to start, some to end
*
* Also, under 16 char -rdid (the smaller one) should be 16 character
* Also, under 16 char -rdid (the smaller one) should be 16 character
* long, with zeros on beginning.
*/
if (ReaderType.RFID.equals(reader.getType())) {
......@@ -138,8 +138,8 @@ public class ReaderBean implements ReaderBeanLocal {
if (lastevent.getValue().equals(event.getValue()) && (lastevent.getUpdatetime().getTime() + 60000l) > event.getTime().getTime()) {
lastevent = readerEventFacade.reload(lastevent);
lastevent = readerEventFacade.merge(lastevent);
//lastevent = readerEventFacade.reload(lastevent);
//lastevent = readerEventFacade.merge(lastevent);
return lastevent; // todo: update lastevent bfore return
}
......@@ -210,8 +210,9 @@ public class ReaderBean implements ReaderBeanLocal {
cardCodeFacade.create(code);
card.getCardCodes().add(code);
cardCodeFacade.flush();
return readerEvent;
return checkCode(readerEvent.getReader(), readerEvent.getValue());
}
@Override
......
/*
* 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.facade;
......@@ -45,4 +45,16 @@ public class ApiApplicationInstanceFacade extends IntegerPkGenericFacade<ApiAppl
return super.getSingleNullableResult(getEm().createQuery(q));
}
public ApiApplicationInstance findInstance(String appkey, String userId, LanEvent event) {
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<ApiApplicationInstance> q = cb.createQuery(ApiApplicationInstance.class);
Root<ApiApplicationInstance> root = q.from(ApiApplicationInstance.class);
q.where(cb.equal(root.get(ApiApplicationInstance_.application).get(ApiApplication_.applicationKey), appkey),
cb.equal(root.get(ApiApplicationInstance_.authname), userId),
cb.equal(root.get(ApiApplicationInstance_.eventuser).get(EventUser_.event), event));
return super.getSingleNullableResult(getEm().createQuery(q));
}
}
......@@ -28,6 +28,7 @@ import io.swagger.annotations.ApiModel;
@ApiModel
public class ReaderEventRestPojo {
private EventUserRestPojo eventUser;
private PrintedCardRestPojo printedCard;
......@@ -40,32 +41,32 @@ public class ReaderEventRestPojo {
public ReaderEventRestPojo() {
}
@XmlElement(name = "eventuser")
@XmlElement(name = "eventuser", nillable = true)
public EventUserRestPojo getEventuser() {
return eventUser;
}
@XmlElement(name = "readerEventId")
@XmlElement(name = "readerEventId", nillable = false)
public Integer getEventId() {
return readerEventId;
}
@XmlElement(name = "readerEventTime")
@XmlElement(name = "readerEventTime", nillable = true)
public Date getReaderEventTime() {
return readerEventTime;
}
@XmlElement(name = "readerId")
@XmlElement(name = "readerId", nillable = false)
public Integer getReaderId() {
return readerId;
}
@XmlElement(name = "printedCardId")
@XmlElement(name = "printedCardId", nillable = true)
public Integer getPrintedCardId() {
return printedCardId;
}
@XmlElement(name = "printedCardState")
@XmlElement(name = "printedCardState", nillable = true)
public String getPrintedCardState() {
return printedCardState;
}
......
package fi.codecrew.moya.rest.pojo.userinfo.v1;
public class PrintedCardUpdateCodePojo {
private String readerName;
private String code;
public PrintedCardUpdateCodePojo(String readerName, String code) {
this.readerName = readerName;
this.code = code;
}
public PrintedCardUpdateCodePojo() {
super();
}
public String getReaderName() {
return readerName;
}
public void setReaderName(String readerName) {
this.readerName = readerName;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
......@@ -3,31 +3,48 @@ package fi.codecrew.moya.rest.pojo.userinfo.v1;
import java.io.Serializable;
import java.util.Date;
public class UserPwdPojo implements Serializable{
public class UserPwdPojo implements Serializable {
private static final long serialVersionUID = 1L;
public UserPwdPojo() {
super();
}
public UserPwdPojo(String username, String password, Date submitTime) {
this();
this.username = username;
this.password = password;
this.submitTime = submitTime;
}
private String username;
private String password;
private Date submitTime;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Date getSubmitTime() {
return submitTime;
}
public void setSubmitTime(Date submitTime) {
this.submitTime = submitTime;
}
}
/*
* 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.utilities;
......@@ -32,23 +32,23 @@ public class JsonUtils {
/**
* Gets a sub object from a JsonObject. Returns an empty object if not
* found.
*
*
* @param jsonObject
* @param path
* @return
*/
public static JsonValue getSubObject(JsonObject jsonObject,
List<String> path) {
public static JsonValue getSubObject(JsonObject jsonObject, List<String> path) {
JsonValue sub = jsonObject;
// Burrow into object hierarchy
for (String s : path) {
if (sub.getValueType() == ValueType.OBJECT) {
if (sub != null && sub.getValueType() == ValueType.OBJECT) {
JsonObject subObject = (JsonObject) sub;
sub = subObject.get(s);
} else {
// Trying to get sub-object of something not an object. Bad.
return null;
sub = null;
break;
}
}
......@@ -62,16 +62,13 @@ public class JsonUtils {
/**
* Adds or alters one key in JsonObject
*
*
* @param jsonObject
* @param key
* which key to add/alter
* @param value
* The value associate to the key
* @param key which key to add/alter
* @param value The value associate to the key
* @return JsonObject with the key:value pair added
*/
public static JsonObject assocJsonObject(JsonObject jsonObject, String key,
JsonValue value) {
public static JsonObject assocJsonObject(JsonObject jsonObject, String key, JsonValue value) {
JsonObjectBuilder builder = Json.createObjectBuilder();
// Copy all non conflicting json entries
......@@ -90,15 +87,13 @@ public class JsonUtils {
/**
* Goes into a json object and sets subobject assocInJsonObject("{}",
* ["foo", "bar"], "{\"a\":\"b\"}") => {\"foo\":{\"bar\":{\"a\":\"b\"}}}
*
*
* @param jsonObject
* @param keys
* path inside key hierarchy
* @param keys path inside key hierarchy
* @param value
* @return JsonObject with the value added
*/
public static JsonObject assocInJsonObject(JsonObject jsonObject,
List<String> keys, JsonValue value) {
public static JsonObject assocInJsonObject(JsonObject jsonObject, List<String> keys, JsonValue value) {
// Recurse?
if (keys.size() > 1) {
......@@ -106,7 +101,7 @@ public class JsonUtils {
List<String> restKeys = keys.subList(1, keys.size());
JsonObject subObj = jsonObject.getJsonObject(firstKey);
return assocJsonObject(jsonObject, firstKey,
assocInJsonObject(subObj, restKeys, value));
assocInJsonObject(subObj, restKeys, value));
}
// End?
......@@ -114,9 +109,7 @@ public class JsonUtils {
return assocJsonObject(jsonObject, firstKey, value);
}
public static JsonObject alterSubObject(JsonObject jsonObject,
List<String> path, JsonObject subObject) {
public static JsonObject alterSubObject(JsonObject jsonObject, List<String> path, JsonObject subObject) {
return assocInJsonObject(jsonObject, path, subObject);
}
}
......@@ -44,7 +44,7 @@
<dependency>
<groupId>fi.codecrew.moya</groupId>
<artifactId>moya-restpojo</artifactId>
<version>1.2.1</version>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
......
......@@ -27,8 +27,7 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserReservationPlacePojo;
import fi.codecrew.moya.rest.pojo.util.v1.ErrorRoot;
public class PojoUtils {
public static EventUserRestPojo initEventUserRestPojo(EventUser user)
{
public static EventUserRestPojo initEventUserRestPojo(EventUser user) {
EventUserRestPojo ret = new EventUserRestPojo();
ret.setNick(user.getUser().getNick());
ret.setLogin(user.getUser().getLogin());
......@@ -49,8 +48,7 @@ public class PojoUtils {
}
public static PrintedCardRestPojo initPrintedCardRestPojo(PrintedCard card)
{
public static PrintedCardRestPojo initPrintedCardRestPojo(PrintedCard card) {
PrintedCardRestPojo ret = new PrintedCardRestPojo();
ret.setEventuserId(card.getUser().getId());
ret.setId(card.getId());
......@@ -66,8 +64,7 @@ public class PojoUtils {
return ret;
}
public static CardRoot parsePrintedCards(List<PrintedCard> cards)
{
public static CardRoot parsePrintedCards(List<PrintedCard> cards) {
ArrayList<PrintedCardRestPojo> ret = new ArrayList<PrintedCardRestPojo>();
for (PrintedCard c : cards) {
ret.add(initPrintedCardRestPojo(c));
......@@ -98,17 +95,15 @@ public class PojoUtils {
ret.setDisabled(place.isDisabled());
// I cannot change REST -api without making new version, so let's simulate this ReleaseTime -feature from reserveTime
Calendar relTime = Calendar.getInstance();
// I cannot change REST -api without making new version, so let's simulate this ReleaseTime -feature from reserveTime
Calendar relTime = Calendar.getInstance();
relTime.add(relTime.HOUR, 4);
if(place.getReserveTime() != null)
ret.setReleaseTime(relTime);
else
ret.setReleaseTime(null);
relTime.add(relTime.HOUR, 4);
if (place.getReserveTime() != null)
ret.setReleaseTime(relTime);
else
ret.setReleaseTime(null);
if (place.getMap() != null) {
......@@ -156,7 +151,7 @@ public class PojoUtils {
public static ReaderEventRestPojo initReaderEventRestPojo(ReaderEvent event) {
ReaderEventRestPojo ret = new ReaderEventRestPojo();
if ( event.getPrintedCard() != null) {
if (event.getPrintedCard() != null) {
if (event.getPrintedCard().getUser() != null) {
ret.setEventUser(PojoUtils.initEventUserRestPojo(event.getPrintedCard().getUser()));
}
......@@ -186,8 +181,7 @@ public class PojoUtils {
return ret;
}
public static ReaderRestPojo initReaderRestPojo(Reader reader)
{
public static ReaderRestPojo initReaderRestPojo(Reader reader) {
ReaderRestPojo ret = new ReaderRestPojo();
ret.setReaderId(reader.getId());
ret.setIdentification(reader.getIdentification());
......@@ -217,8 +211,7 @@ public class PojoUtils {
return ret;
}
public static ProductRestPojo initProductRestPojo(Product product)
{
public static ProductRestPojo initProductRestPojo(Product product) {
ProductRestPojo ret = new ProductRestPojo();
ret.setId(product.getId());
ret.setName(product.getName());
......@@ -233,8 +226,7 @@ public class PojoUtils {
return parseSimplePlaces(places, user, hasPermissionViewAllusers, false);
}
public static SimplePlacelistRoot parseSimplePlaces(List<Place> places, EventUser user, boolean hasPermissionViewAllusers, boolean onlyHilightPlaces)
{
public static SimplePlacelistRoot parseSimplePlaces(List<Place> places, EventUser user, boolean hasPermissionViewAllusers, boolean onlyHilightPlaces) {
SimplePlacelistRoot ret = new SimplePlacelistRoot();
ArrayList<SimplePlacePojo> placeList = new ArrayList<>();
ret.setPlaces(placeList);
......@@ -251,41 +243,40 @@ public class PojoUtils {
ret.setName(p.getName());
String state = null;
if(hasPermissionViewAllusers) {
if(p.getPlaceReserver() != null) {
if(p.getPlaceReserver().getUser() != null) {
if (hasPermissionViewAllusers) {
if (p.getPlaceReserver() != null) {
if (p.getPlaceReserver().getUser() != null) {
ret.setUserDescription(p.getPlaceReserver().getUser().getUser().getShortUserDescriptor());
} else if(p.getPlaceReserver().getPlaceGroup() != null && p.getPlaceReserver().getPlaceGroup().getCreator() != null) {
} else if (p.getPlaceReserver().getPlaceGroup() != null && p.getPlaceReserver().getPlaceGroup().getCreator() != null) {
ret.setUserDescription(p.getPlaceReserver().getPlaceGroup().getCreator().getUser().getShortUserDescriptor());
}
}
}
switch (p.getState(user))
{
switch (p.getState(user)) {
case DISABLED:
state = (onlyHilightPlaces)?"F":"D";
state = (onlyHilightPlaces) ? "F" : "D";
break;
case FREE:
state = "F";
break;
case LOCKED:
state = (onlyHilightPlaces)?"F":"L";
state = (onlyHilightPlaces) ? "F" : "L";
break;
case MY_PLACE:
state = "P";
break;
case RESERVED:
state = (onlyHilightPlaces)?"F":"R";
state = (onlyHilightPlaces) ? "F" : "R";
break;
case TEMP_RESERVED_FORME:
state = (onlyHilightPlaces)?"F":"T";
state = (onlyHilightPlaces) ? "F" : "T";
break;
default:
break;
}
if(onlyHilightPlaces) {
if (onlyHilightPlaces) {
}
......@@ -321,24 +312,28 @@ public class PojoUtils {
return ur;
}
public static EventPojo parseEvent(LanEvent event) {
ArrayList<String> urls = new ArrayList<>();
for (LanEventDomain domain : event.getDomains()) {
urls.add(domain.getDomain());
}
EventPojo pojo = new EventPojo();
pojo.setName(event.getName());
pojo.setLanEventId(event.getId());
pojo.setUrls(urls);
pojo.setStartTime(event.getStartTime());
return pojo;
}
public static EventRoot parseEvents(List<LanEvent> events) {
EventRoot root = new EventRoot();
ArrayList<EventPojo> eventPojos = new ArrayList<>();
for(LanEvent event : events) {
ArrayList<String> urls = new ArrayList<>();
for(LanEventDomain domain : event.getDomains()) {
urls.add(domain.getDomain());
}
EventPojo pojo = new EventPojo();
pojo.setName(event.getName());
pojo.setLanEventId(event.getId());
pojo.setUrls(urls);
pojo.setStartTime(event.getStartTime());
eventPojos.add(pojo);
for (LanEvent event : events) {
eventPojos.add(parseEvent(event));
}
root.setEvents(eventPojos);
......@@ -357,11 +352,11 @@ public class PojoUtils {
return pojo;
}
public static ErrorRoot initErrorPojo(String errorMessage) {
ErrorRoot errorRoot = new ErrorRoot();
errorRoot.setError(errorMessage);
return errorRoot;
}
public static ErrorRoot initErrorPojo(String errorMessage) {
ErrorRoot errorRoot = new ErrorRoot();
errorRoot.setError(errorMessage);
return errorRoot;
}
}
......@@ -22,11 +22,7 @@ import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
......@@ -86,6 +82,15 @@ public class ReaderRestView {
return Response.ok().build();
}
@POST
@Path("/createevent/{reader}/{code}")
public Response createReaderEvent(@PathParam("reader") String readerName, @PathParam("code") String readerCode) {
ReaderEvent readerEvent = readerbean.checkCode(readerName, readerCode);
return Response.ok(PojoUtils.initReaderEventRestPojo(readerEvent)).build();
}
@GET
@Path("/LastEventusers")
public ReaderEventRestRoot getLastEventusers()
......
......@@ -150,6 +150,7 @@ public class UserRestView {
try {
EventUser curruser = permbean.getCurrentUser();
ReaderEvent revent = readerbean.checkCode("restapi: " + curruser.getLogin(), code);
if (revent != null && revent.getUser() != null) {
......@@ -263,6 +264,7 @@ public class UserRestView {
EventUser user = userbean.findByEventUserId(eventuserid);
logger.warn("users card for user: {}", user);
PrintedCard card = cardbean.checkPrintedCard(user);
if (card == null) {
return null;
}
......@@ -403,4 +405,19 @@ public class UserRestView {
}
}
@GET
@Path("/{userid}/image")
public Response fetchUserImage(@PathParam("userid") Integer userid) {
EventUser eventuser = userbean.findByUserId(userid, false);
if (eventuser == null) {
return Response.status(Status.NOT_FOUND).entity("No user found with id").build();
}
UserImage currimage = eventuser.getUser().getCurrentImage();
if (currimage == null) {
return Response.noContent().build();
}
return Response.ok(currimage.getImageData(), currimage.getMimeType()).build();
}
}
package fi.codecrew.moya.rest.apiapp.v1;
import java.nio.charset.Charset;
import java.security.Principal;
import java.util.Base64;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
......@@ -36,22 +38,32 @@ public class ApiAppRestViewV1 {
@EJB
private ApiApplicationBeanLocal apibean;
private static final String AUTH_HEADER = "authorization";
private static final String AUTH_PREFIX = "Basic ";
@POST
@Path("/createInstance/{appKey}")
public Response createApiInstance(@PathParam("appKey") String appKey, @QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("nonce") Long timestamp) {
//public Response createApiInstance(@PathParam("appKey") String appKey, @QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("nonce") Long timestamp) {
public Response createApiInstance(@PathParam("appKey") String appKey) {
try {
Principal principal = servletRequest.getUserPrincipal();
// ensure logged out user
if (principal != null && principal.getName() != null) {
servletRequest.logout();
principal = null;
}
servletRequest.getSession(true);
String domain = servletRequest.getHeader("host");
String authHeader = servletRequest.getHeader(AUTH_HEADER);
logger.info("Got auth header {}", authHeader);
if (!authHeader.startsWith(AUTH_PREFIX)) {
return Response.status(Response.Status.FORBIDDEN).entity("No basic auth provided").build();
}
String[] splitAuth = new String(Base64.getDecoder().decode(authHeader.substring(AUTH_PREFIX.length()))).split(":", 2);
servletRequest.login(username + "@" + domain, password);
servletRequest.login(splitAuth[0] + "@" + domain, splitAuth[1]);
ApiApplication app = apibean.findApplication(appKey);
ApiApplicationInstance apiInstance = apibean.createApplicationInstance(app);
......
package fi.codecrew.moya.rest.appconfig.v1;
import java.security.Principal;
import java.util.Base64;
import java.util.Date;
import javax.ejb.EJB;
......@@ -12,6 +13,7 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -38,6 +40,8 @@ import fi.codecrew.moya.rest.pojo.userinfo.v1.UserPwdPojo;
public class EventInfoV1 {
private static final Logger logger = LoggerFactory.getLogger(EventInfoV1.class);
private static final String AUTH_HEADER = "authorization";
private static final String AUTH_PREFIX = "Basic ";
@Context
private HttpServletRequest servletRequest;
......@@ -49,22 +53,34 @@ public class EventInfoV1 {
private EventBeanLocal eventBean;
@GET
@Path("/current")
public Response getCurrentEventInfo() {
return Response.ok(PojoUtils.parseEvent(eventBean.getCurrentEvent())).build();
}
@GET
@Path("/allevents")
public Response getEventsForUser(@QueryParam("username") String username, @QueryParam("password") String password, @QueryParam("timestamp") Long timestamp) {
public Response getEventsForUser() {
try {
if (username != null) {
Principal principal = servletRequest.getUserPrincipal();
String authHeader = servletRequest.getHeader(AUTH_HEADER);
// ensure logged out user
if (principal != null && principal.getName() != null) {
servletRequest.logout();
}
String domain = servletRequest.getHeader("host");
if (authHeader == null || !authHeader.startsWith(AUTH_PREFIX)) {
return Response.status(Response.Status.FORBIDDEN).entity("No basic auth provided").build();
}
String authStr = new String(Base64.getDecoder().decode(authHeader.substring(AUTH_PREFIX.length())));
String[] splitAuth = authStr.split(":", 2);
servletRequest.getSession(true);
servletRequest.login(username + "@"+domain, password);
Principal principal = servletRequest.getUserPrincipal();
// ensure logged out user
if (principal != null && principal.getName() != null) {
servletRequest.logout();
}
String domain = servletRequest.getHeader("host");
servletRequest.getSession(true);
servletRequest.login(splitAuth[0] + "@" + domain, splitAuth[1]);
return Response.ok(PojoUtils.parseEvents(eventBean.findAllEventsForCurrentUser())).build();
} catch (ServletException e) {
logger.warn("Error logging in while creating ApiApplication instance");
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!