use of org.javlo.service.ContentService in project javlo by Javlo.
the class DynamicComponentCreator method getViewXHTMLCode.
@Override
public String getViewXHTMLCode(ContentContext ctx) throws Exception {
if (ctx.getCurrentUser() == null) {
return "";
}
ctx.getRequest().setAttribute(REQUEST_KEY, true);
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
PrintStream out = new PrintStream(outStream);
RequestService rs = RequestService.getInstance(ctx.getRequest());
out.println("<form action=\"" + URLHelper.createURL(ctx) + "\" method=\"post\" enctype=\"multipart/form-data\">");
I18nAccess i18nAccess = I18nAccess.getInstance(ctx.getRequest());
if (rs.getParameter("new", null) == null && rs.getParameter("id", null) == null && rs.getParameter("edit", null) == null || rs.getParameter("valid", null) != null || rs.getParameter("cancel", null) != null || rs.getParameter("delete", null) != null) {
out.println("<div class=\"form-group\">");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"new\">" + i18nAccess.getViewText("global.create") + ' ' + getValue() + "</button>");
out.println("</div>");
} else if (rs.getParameter("new", null) != null || rs.getParameter("edit", null) != null) {
ContentService contentService = ContentService.getInstance(ctx.getRequest());
DynamicComponent compDef = (DynamicComponent) contentService.getComponent(ctx, rs.getParameter("id", null));
String id = StringHelper.getRandomId();
if (compDef == null) {
compDef = (DynamicComponent) ComponentFactory.getComponentWithType(ctx, getValue());
if (compDef == null) {
return "<div class=\"alert alert-danger\" role=\"alert\">technical error : '" + getValue() + "' not found.</div>";
}
} else {
id = compDef.getId();
}
compDef.getComponentBean().setId(id);
out.println("<div class=\"card\"><div class=\"card-body\"><h4 class=\"card-title\">" + i18nAccess.getViewText("global.new") + "</h4>");
ContentContext editCtx = new ContentContext(ctx);
i18nAccess.forceReloadEdit(ctx.getGlobalContext(), ctx.getRequest().getSession(), ctx.getRequestContentLanguage());
editCtx.setContextRequestLanguage(ctx.getRequestContentLanguage());
editCtx.setRenderMode(ContentContext.EDIT_MODE);
out.println(compDef.getEditXHTMLCode(editCtx));
i18nAccess.resetForceEditLg();
out.println("<div><input type=\"hidden\" name=\"type\" value=\"" + getValue() + "\" />");
out.println("<input type=\"hidden\" name=\"id\" value=\"" + id + "\" />");
out.println("<input type=\"hidden\" name=\"webaction\" value=\"" + getActionGroupName() + ".createcomponent\" />");
out.println("</div>");
out.println("<div class=\"form-group pull-right\">");
out.println("<button class=\"btn btn-primary\" type=\"submit\" name=\"create\">" + i18nAccess.getViewText("global.ok") + "</button>");
out.println("<button class=\"btn btn-warning\" type=\"submit\" name=\"delete\" value=\"1\">" + i18nAccess.getViewText("global.delete") + "</button>");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"cancel\">" + i18nAccess.getViewText("global.cancel") + "</button>");
out.println("</div></div>");
} else if (rs.getParameter("id", null) != null) {
ContentService contentService = ContentService.getInstance(ctx.getRequest());
IContentVisualComponent comp = contentService.getComponent(ctx, rs.getParameter("id", null));
if (comp == null) {
logger.severe("component not found : " + rs.getParameter("id", null));
return "component not found : " + rs.getParameter("id", null);
}
ctx.getRequest().setAttribute(EDIT_KEY, true);
out.println(comp.getXHTMLCode(ctx));
ctx.getRequest().removeAttribute(EDIT_KEY);
out.println("<div class=\"form-group\">");
out.println("<input type=\"hidden\" name=\"id\" value=\"" + rs.getParameter("id", null) + "\" />");
out.println("<button class=\"btn btn-primary\" type=\"submit\" name=\"valid\">" + i18nAccess.getViewText("global.ok") + "</button>");
out.println("<button class=\"btn btn-default\" type=\"submit\" name=\"edit\" >" + i18nAccess.getViewText("global.edit") + "</button>");
out.println("</div>");
}
out.println("</form>");
out.close();
return new String(outStream.toByteArray());
}
use of org.javlo.service.ContentService in project javlo by Javlo.
the class StripeOrderComponent method performWebhook.
public static String performWebhook(ContentContext ctx, RequestService rs) throws Exception {
ctx.setStopRendering(true);
String payload = IOUtils.toString(ctx.getRequest().getReader());
if (StringHelper.isEmpty(payload)) {
ctx.getResponse().setStatus(400);
logger.warning("body not found.");
return "body not found.";
}
Event event = null;
try {
event = ApiResource.GSON.fromJson(payload, Event.class);
} catch (JsonSyntaxException e) {
logger.warning("invalid payload : " + e.getMessage());
// Invalid payload
ctx.getResponse().setStatus(400);
return "";
}
// Deserialize the nested object inside the event
EventDataObjectDeserializer dataObjectDeserializer = event.getDataObjectDeserializer();
StripeObject stripeObject = null;
if (dataObjectDeserializer.getObject().isPresent()) {
stripeObject = dataObjectDeserializer.getObject().get();
} else {
logger.severe("Deserialization failed");
// Deserialization failed, probably due to an API version mismatch.
// Refer to the Javadoc documentation on `EventDataObjectDeserializer` for
// instructions on how to handle this case, or return an error here.
}
// Handle the event
switch(event.getType()) {
case "charge.succeeded":
// case "payment_intent.succeeded":
Charge charge = (Charge) stripeObject;
Basket basket = BasketPersistenceService.getInstance(ctx.getGlobalContext()).getBasketByPaymentIndent(charge.getPaymentIntent());
if (basket == null) {
logger.severe("basket not found : " + charge.getPaymentIntent());
IEcomListner ecomListner = ctx.getGlobalContext().getStaticConfig().getEcomLister();
EcomStatus status = ecomListner.onPaymentProcessorEvent(ctx, new EcomEvent(charge.getPaymentIntent(), true, null));
if (status.isError()) {
ctx.getResponse().setStatus(400);
}
return "";
}
ctx.setAllLanguage(basket.getLanguage());
EcomStatus status = basket.payAll(ctx);
logger.info("webhook basket status : " + status);
if (!status.isError()) {
I18nAccess i18nAccess = I18nAccess.getInstance(ctx);
AbstractOrderComponent comp = null;
if (basket.getComponentId() != null) {
ContentService content = ContentService.getInstance(ctx.getRequest());
comp = (AbstractOrderComponent) content.getComponent(ctx, (basket.getComponentId()));
}
if (comp == null) {
logger.severe("comp id not found : " + basket.getComponentId());
}
String msg = XHTMLHelper.textToXHTML(comp.getConfirmationEmail(ctx, basket));
msg = "<p>" + i18nAccess.getViewText("ecom.basket-confirmed") + "</p><p>" + msg + "</p>";
// comp.sendConfirmationEmail(ctx, basket);
ctx.getRequest().setAttribute("msg", msg);
NetHelper.sendMailToAdministrator(ctx.getGlobalContext(), "basket confirmed with stripe : " + ctx.getGlobalContext().getContextKey(), basket.getAdministratorEmail(ctx));
basket.setStatus(Basket.STATUS_VALIDED);
basket.setStep(Basket.FINAL_STEP);
Basket.setInstance(ctx, basket);
BasketPersistenceService.getInstance(ctx.getGlobalContext()).storeBasket(basket);
comp.sendConfirmationEmail(ctx, basket);
logger.info("stripe basket valided : " + basket);
} else {
NetHelper.sendMailToAdministrator(ctx.getGlobalContext(), "ERROR: basket NOT confirmed with stripe : " + ctx.getGlobalContext().getContextKey(), basket.getAdministratorEmail(ctx));
}
break;
default:
System.out.println("Unhandled event type: " + event.getType());
}
ctx.getResponse().setStatus(200);
return "";
}
use of org.javlo.service.ContentService in project javlo by Javlo.
the class ComponentFactory method getAllDynamicComponents.
public static List<DynamicComponent> getAllDynamicComponents(ContentContext ctx) throws Exception {
ContentContext noAreaCtx = ctx.getContextWithArea(null);
List<DynamicComponent> outComps = new LinkedList<DynamicComponent>();
ContentService content = ContentService.getInstance(ctx.getGlobalContext());
MenuElement root = content.getNavigation(noAreaCtx);
ContentElementList pageContent = root.getContent(noAreaCtx);
/*
* while (pageContent.hasNext(noAreaCtx)) { IContentVisualComponent comp
* = pageContent.next(noAreaCtx); if (comp instanceof DynamicComponent)
* { outComps.add((DynamicComponent)comp); } }
*/
for (MenuElement page : root.getAllChildrenList()) {
pageContent = page.getContent(noAreaCtx);
while (pageContent.hasNext(noAreaCtx)) {
IContentVisualComponent comp = pageContent.next(noAreaCtx);
if (comp instanceof DynamicComponent) {
outComps.add((DynamicComponent) comp);
}
}
}
return outComps;
}
use of org.javlo.service.ContentService in project javlo by Javlo.
the class ComponentFactory method getDynamicComponents.
public static DynamicComponent getDynamicComponents(ContentContext ctx, String type) throws Exception {
ContentContext noAreaCtx = ctx.getContextWithArea(null);
ContentService content = ContentService.getInstance(ctx.getGlobalContext());
MenuElement root = content.getNavigation(noAreaCtx);
ContentElementList pageContent = root.getContent(noAreaCtx);
for (MenuElement page : root.getAllChildrenList()) {
pageContent = page.getContent(noAreaCtx);
while (pageContent.hasNext(noAreaCtx)) {
IContentVisualComponent comp = pageContent.next(noAreaCtx);
if (comp instanceof DynamicComponent && comp.getType().equals(type)) {
return (DynamicComponent) comp;
}
}
}
return null;
}
use of org.javlo.service.ContentService in project javlo by Javlo.
the class ProductComponent method prepareView.
@Override
public void prepareView(ContentContext ctx) throws Exception {
super.prepareView(ctx);
ctx.getRequest().setAttribute("productName", getName());
String action;
if (getBasketPage().trim().length() > 0) {
ContentService content = ContentService.getInstance(ctx.getRequest());
MenuElement page = content.getNavigation(ctx).searchChildFromName(getBasketPage());
if (page != null) {
action = URLHelper.createURL(ctx, page);
} else {
action = URLHelper.createURL(ctx);
}
} else {
action = URLHelper.createURL(ctx);
}
ProductComponent refComp = (ProductComponent) getReferenceComponent(ctx);
if (refComp != null) {
ctx.getRequest().setAttribute("action", action);
ctx.getRequest().setAttribute("price", refComp.getPrice());
ctx.getRequest().setAttribute("priceDisplay", StringHelper.renderDouble(refComp.getPrice(), 2));
ctx.getRequest().setAttribute("currency", refComp.getCurrency());
ctx.getRequest().setAttribute("currencyDisplay", getCurrencyHtml(refComp.getCurrency()));
if (!StringHelper.isEmpty(getDescription())) {
ctx.getRequest().setAttribute("description", XHTMLHelper.textToXHTML(getDescription()));
}
ctx.getRequest().setAttribute("virtualStock", getVirtualStock(ctx));
ctx.getRequest().setAttribute("offset", refComp.getOffset(ctx));
if (!StringHelper.isEmpty(refComp.getSpecialLink())) {
String link = refComp.getSpecialLink();
link = XHTMLHelper.replaceJSTLData(ctx, link);
link = XHTMLHelper.replaceLinks(ctx, link);
ctx.getRequest().setAttribute("specialLink", link);
}
}
}
Aggregations