Example usage for org.aspectj.lang ProceedingJoinPoint getArgs

List of usage examples for org.aspectj.lang ProceedingJoinPoint getArgs

Introduction

In this page you can find the example usage for org.aspectj.lang ProceedingJoinPoint getArgs.

Prototype

Object[] getArgs();

Source Link

Usage

From source file:org.yes.cart.web.aspect.NewsletterAspect.java

License:Apache License

/**
 * Perform notification about newsletter registration.
 *
 * @param pjp join point/*  ww  w  .j  a v  a  2 s .c  o m*/
 *
 * @return inherited return
 *
 * @throws Throwable in case it was in underlying method
 */
protected Object notifyInternal(final ProceedingJoinPoint pjp) throws Throwable {
    final Object[] args = pjp.getArgs();

    final Shop shop = (Shop) args[0];
    final String email = (String) args[1];
    final Map<String, Object> registrationData = (Map<String, Object>) args[2];
    registrationData.put("email", email);

    final RegistrationMessage registrationMessage = new RegistrationMessageImpl();
    final ShoppingCart cart = ApplicationDirector.getShoppingCart();
    if (cart != null) {
        registrationMessage.setLocale(cart.getCurrentLocale());
    }

    registrationMessage.setMailTemplatePathChain(themeService.getMailTemplateChainByShopId(shop.getShopId()));

    registrationMessage.setTemplateName("adm-newsletter-request");

    final String emailTo = determineFromEmail(shop); // newsletter request to admin
    registrationMessage.setEmail(emailTo);
    registrationMessage.setShopMailFrom(emailTo);

    registrationMessage.setShopId(shop.getShopId());
    registrationMessage.setShopCode(shop.getCode());
    registrationMessage.setShopName(shop.getName());
    registrationMessage.setShopUrl(transformShopUrls(shop));

    registrationMessage.setAdditionalData(registrationData);

    sendNotification(registrationMessage);

    LOG.info("Newsletter message was send to queue {}", registrationMessage);

    return pjp.proceed();
}

From source file:org.yes.cart.web.aspect.PaymentAspect.java

License:Apache License

/**
 * Perform shopper notification, about payment authorize.
 *
 * @param pjp {@link ProceedingJoinPoint}
 * @return result of original operation.
 * @throws Throwable re throws exception
 *//*www .  j a v a2  s. c  om*/
@CacheEvict(value = { "skuWarehouseService-productOnWarehouse",
        "skuWarehouseService-productSkusOnWarehouse" }, allEntries = true)
@Around("execution(* org.yes.cart.service.payment.impl.PaymentProcessorImpl.authorize(..))")
public Object doAuthorize(final ProceedingJoinPoint pjp) throws Throwable {
    final String rez = (String) pjp.proceed();

    final HashMap<String, Object> map = new HashMap<String, Object>();

    fillParameters(pjp, map);

    final CustomerOrder customerOrder = (CustomerOrder) pjp.getArgs()[0];
    final Shop shop = shopService.getById(customerOrder.getShop().getShopId());
    map.put(StandardMessageListener.SHOP_CODE, shop.getCode());
    map.put(StandardMessageListener.CUSTOMER_EMAIL, customerOrder.getCustomer().getEmail());
    map.put(StandardMessageListener.RESULT, rez);
    map.put(StandardMessageListener.ROOT, customerOrder);
    map.put(StandardMessageListener.TEMPLATE_FOLDER,
            themeService.getMailTemplateChainByShopId(shop.getShopId()));

    map.put(StandardMessageListener.SHOP, shop);
    map.put(StandardMessageListener.CUSTOMER, customerOrder.getCustomer());
    map.put(StandardMessageListener.LOCALE, customerOrder.getLocale());

    final PaymentGatewayFeature feature = paymentModulesManager
            .getPaymentGateway(customerOrder.getPgLabel(), shop.getCode()).getPaymentGatewayFeatures();
    if (feature.isOnlineGateway()) {
        map.put(StandardMessageListener.TEMPLATE_NAME, "payment");
    } else {
        map.put(StandardMessageListener.TEMPLATE_NAME, "order-new");
    }

    map.put(StandardMessageListener.PAYMENT_GATEWAY_FEATURE, feature);

    sendNotification(map);

    reindex(customerOrder);

    return rez;
}

From source file:org.yes.cart.web.aspect.PaymentAspect.java

License:Apache License

/**
 * Perform shopper notification, about payment authorize.
 *
 * @param pjp {@link ProceedingJoinPoint}
 * @return result of original operation.
 * @throws Throwable re throws exception
 *///from  ww  w .  ja v  a2  s  . co m
@CacheEvict(value = { "skuWarehouseService-productOnWarehouse",
        "skuWarehouseService-productSkusOnWarehouse" }, allEntries = true)
@Around("execution(* org.yes.cart.service.payment.impl.PaymentProcessorImpl.shipmentComplete(..))")
public Object doShipmentComplete(final ProceedingJoinPoint pjp) throws Throwable {

    final String rez = (String) pjp.proceed();

    final HashMap<String, Object> map = new HashMap<String, Object>();

    fillParameters(pjp, map);

    final CustomerOrder customerOrder = (CustomerOrder) pjp.getArgs()[0];
    final Shop shop = shopService.getById(customerOrder.getShop().getShopId());
    map.put(StandardMessageListener.SHOP_CODE, shop.getCode());
    map.put(StandardMessageListener.CUSTOMER_EMAIL, customerOrder.getCustomer().getEmail());
    map.put(StandardMessageListener.RESULT, rez);
    map.put(StandardMessageListener.ROOT, customerOrder);
    map.put(StandardMessageListener.TEMPLATE_FOLDER,
            themeService.getMailTemplateChainByShopId(shop.getShopId()));

    map.put(StandardMessageListener.SHOP, shop);
    map.put(StandardMessageListener.CUSTOMER, customerOrder.getCustomer());
    map.put(StandardMessageListener.LOCALE, customerOrder.getLocale());

    map.put(StandardMessageListener.TEMPLATE_NAME, "shipment-complete");

    sendNotification(map);

    reindex(customerOrder);

    return rez;

}

From source file:org.zhangmz.pickles.helper.aop.AuthorityHelperAOP.java

License:Apache License

@Around("adminActionMethod()")
public Object adminAuthorityAroundService(ProceedingJoinPoint joinpoint) throws Throwable {
    ModelAndView result = null;/*from www  .ja  v a2 s  .  com*/
    try {
        // ? begin
        // long start = System.currentTimeMillis();

        // ????TOKEN
        Object[] args = joinpoint.getArgs();

        if (args.length > 0 && authorityHelper.isAdmin((String) args[0])) {
            // ???? TOKEN/mainInfo
            // return joinpoint.proceed();
            result = ((ModelAndView) joinpoint.proceed()).addObject("TOKEN", args[0]);
        } else {
            result = new ModelAndView(AdminUrl.loginPage);
            result.addObject("message", Messages.USER_NOT_ADMIN);
        }

        // long end = System.currentTimeMillis();
        // System.out.println("end! performance took " + (end-start) + " milliseconds");
        // ? end
    } catch (Throwable e) {
        e.printStackTrace();
        result = new ModelAndView(AdminUrl.loginPage);
        result.addObject("message", Messages.AOP_HAS_ERROR);
    }

    return result;
}

From source file:org.zhangmz.pickles.helper.aop.AuthorityHelperAOP.java

License:Apache License

@Around("userActionMethod()")
public Object userAuthorityAroundService(ProceedingJoinPoint joinpoint) throws Throwable {
    ModelAndView result = null;/*from ww  w . jav a 2s.co m*/
    try {
        // ? begin
        // long start = System.currentTimeMillis();

        // ????TOKEN
        Object[] args = joinpoint.getArgs();

        if (args.length > 0 && authorityHelper.isLogin((String) args[0])) {
            // ???? TOKEN/mainInfo
            // return joinpoint.proceed();
            result = ((ModelAndView) joinpoint.proceed()).addObject("TOKEN", args[0]);
        } else {
            result = new ModelAndView(UserUrl.loginPage);
            result.addObject("message", Messages.USER_NOT_USER);
        }

        // long end = System.currentTimeMillis();
        // System.out.println("end! performance took " + (end-start) + " milliseconds");
        // ? end
    } catch (Throwable e) {
        e.printStackTrace();
        result = new ModelAndView(UserUrl.loginPage);
        result.addObject("message", Messages.AOP_HAS_ERROR);
    }

    return result;
}

From source file:pe.gob.sunat.tecnologia3.arquitectura.framework.desktop.auditoria.aspect.LoggerAspectj.java

@Around("(execution(* pe.gob.sunat.tecnologia3.arquitectura.framework.desktop..*(..)) && @annotation(logAnnotation))")
public Object auditarMetodo(final ProceedingJoinPoint joinPoint, LoggerAnnotation logAnnotation)
        throws Throwable {

    long start = System.nanoTime();

    Signature signature = joinPoint.getSignature();
    String methodName = signature.getName();
    //Class object = joinPoint.getClass();

    String arguments = StringUtils.join(joinPoint.getArgs());

    Object result = joinPoint.proceed();
    long last = System.nanoTime() - start;

    String modulo = logAnnotation.modulo();
    LogHelper.log(last, methodName, arguments, modulo);

    return result;
}

From source file:podd.dataaccess.hibernate.DeadlockInterceptor.java

License:Open Source License

private void logRetry(ProceedingJoinPoint pjp, int numRetries, HibernateException throwable) {
    StringBuffer buffer = new StringBuffer();
    buffer.append("Operation ").append(pjp.toShortString()).append(" failed on ").append(throwable.getClass())
            .append(" with parameters: [");
    final Object[] arguments = pjp.getArgs();
    for (Object obj : arguments) {
        if (null != obj) {
            buffer.append(obj.toString()).append(", ");
        }/*  w  w  w  .  ja v  a2s  . c o m*/
    }
    final int start = buffer.lastIndexOf(", ");
    if (start >= 0) {
        buffer.delete(start, start + 2);
    }
    buffer.append("]. Retrying ").append(numRetries).append(" out of ").append(retry).append(" times.");
    logger.warn(buffer.toString());
}

From source file:prospring3.ch6.CompositeAdvice.java

public Object deassociate(ProceedingJoinPoint pjp, Deassociate deassociate) throws Throwable {
    System.out.println("[BEFORE] RemoveScheduledPostsAdvice.around");
    final String name = pjp.getSignature().getName();
    final DeassociateTarget deassociateTarget = deassociate.target();
    System.out.println("deassociateTarget = " + deassociateTarget);
    System.out.println("signature name = " + name);
    System.out.println("this.getClass().getCanonicalName() = " + this.getClass().getCanonicalName());

    for (IDeassociation advice : deassociateAdvices) {
        advice.deassociate(pjp, deassociate);
    }/*from  w w w  .j a  v  a 2s  .  c  om*/

    final Object ret = pjp.proceed(pjp.getArgs());

    System.out.println("this.getClass().getCanonicalName() = " + this.getClass().getCanonicalName());
    System.out.println("[AFTER] RemoveScheduledPostsAdvice.around");
    return ret;
}

From source file:quanlyhocvu.api.mongodb.DAO.AOP.GiaoVienAOP.java

@Around("execution(* quanlyhocvu.api.mongodb.DAO.GiaoVienDAO.*(..))")
public Object LookTestAOP(ProceedingJoinPoint joinPoint) throws Throwable {
    boolean result = true;
    for (Object obj : joinPoint.getArgs()) {
        if (obj instanceof GiaoVienDTO) {
            if (!checkGiaoVienData((GiaoVienDTO) obj)) {
                result = false;//from  w ww  .j  a v  a 2  s.  com
                break;
            }
        }
    }
    if (!result) {
        throw new Exception("Sai thng tin gio vin");
    } else {
        return joinPoint.proceed();
    }
}

From source file:quanlyhocvu.api.mongodb.DAO.AOP.HocSinhAOP.java

@Around("execution(* quanlyhocvu.api.mongodb.DAO.HocSinhDAO.*(..))")
public Object LookTestAOP(ProceedingJoinPoint joinPoint) throws Throwable {
    boolean result = true;
    for (Object obj : joinPoint.getArgs()) {
        if (obj instanceof HocSinhDTO) {
            if (!checkHocSinhData((HocSinhDTO) obj)) {
                result = false;//from   w w w. j  ava 2  s  .c o  m
                break;
            }
        }
    }
    if (!result) {
        throw new Exception("Sai thng tin h?c sinh");
    } else {
        return joinPoint.proceed();
    }
}