Commit 720c5169 by Tuomas Riihimäki

Vähän taas silppuisaa.

Pieniä bottifiksejä.
Vippiasioiden generointi apin läpi.
Vippilistan paginointi (max 100 entryä kerrallaan). Chrome rendasi 1600 entryä ~5sekuntia
1 parent 0433705e
......@@ -4,6 +4,7 @@ import java.util.Set;
import javax.ejb.Local;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.iudex.utils.irc.IrcBot;
@Local
......@@ -11,6 +12,6 @@ public interface BotBeanLocal {
public void addBot(IrcBot bot);
Set<String> getIgnoreTypes();
Set<MoyaEventType> getIgnoreTypes();
}
......@@ -21,6 +21,7 @@ import fi.codecrew.moya.model.EventUser;
import fi.codecrew.moya.model.LanEvent;
import fi.codecrew.moya.model.User;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventMessage;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.iudex.utils.irc.IrcBot;
/**
......@@ -47,7 +48,7 @@ public class BotBean implements BotBeanLocal {
private UserFacade userfacade;
@EJB
private EventUserFacade eventuserfacade;
private final Set<String> ignoreTypes = ConcurrentHashMap.newKeySet();
private final Set<MoyaEventType> ignoreTypes = ConcurrentHashMap.newKeySet();
public void message(Message message) {
......@@ -90,7 +91,7 @@ public class BotBean implements BotBeanLocal {
}
@Override
public Set<String> getIgnoreTypes() {
public Set<MoyaEventType> getIgnoreTypes() {
return ignoreTypes;
}
......
......@@ -27,17 +27,13 @@ import fi.codecrew.moya.utilities.SearchResult;
@Stateless
@LocalBean
@DeclareRoles({
VipPermission.S_VIEW,
VipPermission.S_USAGE,
VipPermission.S_EDIT
})
@DeclareRoles({ VipPermission.S_VIEW, VipPermission.S_USAGE, VipPermission.S_EDIT })
public class VipBean implements VipBeanLocal {
private static final Logger log = LoggerFactory.getLogger(VipBean.class);
//@EJB
//private PermissionBeanLocal permissionBean;
// @EJB
// private PermissionBeanLocal permissionBean;
@EJB
private VipFacade vipFacade;
......@@ -89,10 +85,10 @@ public class VipBean implements VipBeanLocal {
}
private void checkEvent(Vip vip) {
if(!eventbean.getCurrentEvent().equals(vip.getEvent())){
if (!eventbean.getCurrentEvent().equals(vip.getEvent())) {
throw new EJBAccessException("VIP entry from wrong event!");
}
}
@Override
......@@ -104,11 +100,11 @@ public class VipBean implements VipBeanLocal {
return ret;
}
// @Override
// public SearchResult<Vip> search(SearchQuery sq) {
// // TODO Auto-generated method stub
// return null;
// }
// @Override
// public SearchResult<Vip> search(SearchQuery sq) {
// // TODO Auto-generated method stub
// return null;
// }
@Override
@RolesAllowed({ VipPermission.S_EDIT })
......
......@@ -134,7 +134,6 @@ public class SitePageFacade extends IntegerPkGenericFacade<SitePage> {
public List<PageContent> findContents(SitePage page, Date now, Locale locale) {
logger.info("Getting pageContents for locale {}", locale);
CriteriaBuilder cb = getEm().getCriteriaBuilder();
CriteriaQuery<PageContent> cq = cb.createQuery(PageContent.class);
......@@ -160,7 +159,6 @@ public class SitePageFacade extends IntegerPkGenericFacade<SitePage> {
// Show only if language equals or is null
Locale contLocale = content.getLocaleObject();
if (contLocale != null && !localeLang.equals(contLocale.getLanguage())) {
logger.info("Removing content with lang {} (comparing to {}) ", contLocale, locale);
contIter.remove();
}
}
......
......@@ -17,7 +17,7 @@
<br /><br />
<p:dataTable id="vipList" value="#{vipListView.viplist}" widgetVar="viplist" styleClass="moya_datatable4" var="vip" >
<p:dataTable paginator="true" rows="100" id="vipList" value="#{vipListView.viplist}" widgetVar="viplist" styleClass="moya_datatable4" var="vip" >
<f:facet name="header">
<p:outputPanel>
......@@ -29,8 +29,10 @@
<p:column headerText="#{i18n['vip.hostsName']}" filterBy="#{vip.host.wholeName}" filterMatchMode="contains" style="width: 140px;">
<!-- p:column headerText="#{i18n['vip.hostsName']}" style="width: 140px;" -->
<h:outputText id="viphostsname" value="#{vip.host.wholeName}" />
<p:tooltip id="viphostsnamephone" for="viphostsname" value="#{vip.host.phone}" />
<h:link outcome="/useradmin/edit" value="#{vip.host.wholeName}" >
<f:param name="id" value="#{vip.host.id}" />
</h:link>
<p:tooltip id="viphostsnamephone" for="viphostsname" value="#{vip.host.phone}" />
</p:column>
<p:column headerText="#{i18n['vip.description']}" filterBy="#{vip.shortDisplayDescr}" filterMatchMode="contains">
......
package fi.codecrew.moya.rest.v2;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
......@@ -16,10 +22,16 @@ import javax.ws.rs.core.Response;
import com.wordnik.swagger.annotations.Api;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.ProductBeanLocal;
import fi.codecrew.moya.beans.UserBeanLocal;
import fi.codecrew.moya.beans.VipBeanLocal;
import fi.codecrew.moya.model.AccountEvent;
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.ProductPojo;
import fi.codecrew.moya.rest.v2.pojo.VipProductPojo;
import fi.codecrew.moya.rest.v2.pojo.VipRestPojo;
import fi.codecrew.moya.utilities.SearchQuery;
import fi.codecrew.moya.utilities.SearchResult;
......@@ -34,6 +46,14 @@ public class VipRestView {
@EJB
private VipBeanLocal vipbean;
@EJB
private PermissionBeanLocal permbean;
@EJB
private UserBeanLocal userbean;
@EJB
private ProductBeanLocal prodbean;
@GET
@Path("/all")
public Response getAllVips() {
......@@ -52,4 +72,61 @@ public class VipRestView {
return Response.ok(ret).build();
}
@DELETE
@Path("/{id}")
public Response deleteEntry(@PathParam("id") Integer id) {
Vip vip = vipbean.find(id);
vipbean.delete(vip);
return Response.ok(VipRestPojo.create(vip)).build();
}
@GET
@Path("/{id}")
public Response findEntry(@PathParam("id") Integer id) {
Vip vip = vipbean.find(id);
return Response.ok(VipRestPojo.create(vip)).build();
}
@POST
@Path("/create")
@Produces({ MediaType.APPLICATION_JSON })
@Consumes(MediaType.APPLICATION_JSON)
public Response createEntry(VipRestPojo create) {
Vip vip = new Vip();
EventUser curruser = permbean.getCurrentUser();
EventUser eventuser = null;
if (create.eventuserId != null) {
eventuser = userbean.findByEventUserId(create.eventuserId);
}
EventUser host = curruser;
if (create.hostId != null) {
host = userbean.findByEventUserId(create.hostId);
}
vip.setDescription(create.description);
vip.setShortdescr(create.shortdescr);
vip.setCreated(new Date());
vip.setEvent(curruser.getEvent());
vip.setEventUser(eventuser);
vip.setCreator(curruser);
vip.setHost(host);
for (VipProductPojo p : create.products) {
VipProduct prod = new VipProduct(vip);
vip.getProducts().add(prod);
if (p.productId != null) {
prod.setProduct(prodbean.findById(p.productId));
} else {
prod.setName(p.name);
}
prod.setQuantity(p.quantity);
prod.setNotes(p.notes);
}
vipbean.create(vip);
return Response.ok(VipRestPojo.create(vip)).build();
}
}
......@@ -12,7 +12,7 @@ import fi.codecrew.moya.model.Vip;
import fi.codecrew.moya.model.VipProduct;
@XmlRootElement()
@ApiModel(description = "Product")
@ApiModel(description = "vip")
public class VipRestPojo {
public Integer id;
......@@ -27,27 +27,30 @@ public class VipRestPojo {
public static ArrayList<VipRestPojo> create(List<Vip> vips) {
ArrayList<VipRestPojo> ret = new ArrayList<>();
for (Vip v : vips) {
VipRestPojo r = new VipRestPojo();
ret.add(r);
r.id = v.getId();
r.description = v.getDescription();
r.shortdescr = v.getShortdescr();
r.created = v.getCreated();
if (v.getEventUser() != null) {
r.eventuserId = v.getEventUser().getId();
}
if (v.getCreator() != null) {
r.creatorId = v.getCreator().getId();
}
if (v.getHost() != null) {
r.hostId = v.getHost().getId();
}
for (VipProduct prod : v.getProducts()) {
r.products.add(VipProductPojo.create(prod));
}
ret.add(create(v));
}
return ret;
}
public static VipRestPojo create(Vip v) {
VipRestPojo r = new VipRestPojo();
r.id = v.getId();
r.description = v.getDescription();
r.shortdescr = v.getShortdescr();
r.created = v.getCreated();
if (v.getEventUser() != null) {
r.eventuserId = v.getEventUser().getId();
}
if (v.getCreator() != null) {
r.creatorId = v.getCreator().getId();
}
if (v.getHost() != null) {
r.hostId = v.getHost().getId();
}
for (VipProduct prod : v.getProducts()) {
r.products.add(VipProductPojo.create(prod));
}
return r;
}
}
......@@ -56,6 +56,7 @@ import fi.codecrew.moya.beans.EventBeanLocal;
import fi.codecrew.moya.beans.PermissionBeanLocal;
import fi.codecrew.moya.beans.PlaceBeanLocal;
import fi.codecrew.moya.utilities.SystemProperty;
import fi.codecrew.moya.utilities.moyamessage.MoyaEventType;
import fi.iudex.utils.irc.IrcBot;
import fi.iudex.utils.irc.IrcBotListener;
import net.sf.jerklib.Profile;
......@@ -126,8 +127,13 @@ public class IrcServlet extends HttpServlet {
@Override
public void executeIrc(IrcBot bot, String data) {
botbean.getIgnoreTypes().add(data);
bot.say("Added " + data + " as ignored message type");
try {
MoyaEventType d = MoyaEventType.valueOf(data);
botbean.getIgnoreTypes().add(d);
bot.say("Added " + data + " as ignored message type");
} catch (Exception e) {
bot.say("Unknown message type " + data);
}
}
}
......@@ -156,8 +162,8 @@ public class IrcServlet extends HttpServlet {
public void executeIrc(IrcBot bot, String data) {
StringBuilder sb = new StringBuilder();
sb.append("Ignored messagetypes: ");
for (String d : botbean.getIgnoreTypes()) {
sb.append(d).append(", ");
for (MoyaEventType d : botbean.getIgnoreTypes()) {
sb.append(d.name()).append(", ");
}
bot.say(sb.toString());
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!