Example usage for org.aspectj.lang ProceedingJoinPoint proceed

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

Introduction

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

Prototype

public Object proceed() throws Throwable;

Source Link

Document

Proceed with the next advice or target method invocation

Usage

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.aop.TenantActivationAspect.java

License:Open Source License

/**
 * Invokes a method and with an activated tenant. If no tenant is activated, the tenant set during initialization is
 * used./*from  ww w.jav  a  2s.  c o m*/
 * 
 * @param pjp
 *           proceeding join point
 * @return result of the invocation
 * @throws Throwable
 */
public Object execute(final ProceedingJoinPoint pjp) throws Throwable {
    if (Registry.hasCurrentTenant() && Registry.isCurrentTenant(currentTenant)) {
        return pjp.proceed();
    }

    // Thread does not have a tenant, setup our tenant on the thread
    Registry.setCurrentTenant(currentTenant);

    if (LOG.isInfoEnabled()) {
        LOG.info(String.format("Setting tenant %s on the current thread %s", currentTenant,
                Thread.currentThread()));
    }
    try {
        return pjp.proceed();
    } finally {
        Registry.unsetCurrentTenant();
    }
}

From source file:de.hybris.platform.acceleratorservices.dataimport.batch.aop.TimeMeasurementAspect.java

License:Open Source License

/**
 * Invokes a method and measures the execution time.
 * //from   ww w .j ava2 s .  com
 * @param pjp
 * @return result of the invocation
 * @throws Throwable
 */
public Object measure(final ProceedingJoinPoint pjp) throws Throwable {
    final String methodName = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
    final Object[] args = pjp.getArgs();
    final long start = System.currentTimeMillis();
    final Object result = pjp.proceed();
    if (LOG.isInfoEnabled()) {
        final BatchHeader header = AspectUtils.getHeader(args);
        LOG.info("Processed " + methodName + (header == null ? "" : " [header=" + header + "]") + " in "
                + (System.currentTimeMillis() - start) + "ms");
    }
    return result;
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.checkout.steps.validation.CheckoutStepValidationAspect.java

License:Open Source License

public Object validateCheckoutStep(final ProceedingJoinPoint pjp) throws Throwable {
    final MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
    final PreValidateCheckoutStep preValidateCheckoutStep = methodSignature.getMethod()
            .getAnnotation(PreValidateCheckoutStep.class);
    final CheckoutGroup checkoutGroup = getCheckoutFlowGroupMap()
            .get(getCheckoutFacade().getCheckoutFlowGroupForCheckout());
    final CheckoutStep checkoutStepBean = checkoutGroup.getCheckoutStepMap()
            .get(preValidateCheckoutStep.checkoutStep());

    final ValidationResults validationResults = checkoutStepBean
            .validate((RedirectAttributesModelMap) pjp.getArgs()[1]);

    if (checkoutStepBean.checkIfValidationErrors(validationResults)) {
        return checkoutStepBean.onValidation(validationResults);
    }/*  w ww .ja va2 s  . c o  m*/
    return pjp.proceed();
}

From source file:de.hybris.platform.acceleratorstorefrontcommons.checkout.steps.validation.QuoteCheckoutStepValidationAspect.java

License:Open Source License

public Object validateQuoteCheckoutStep(final ProceedingJoinPoint pjp) throws Throwable // NOSONAR
{
    if (getCartFacade().hasSessionCart()) {
        final QuoteData quoteData = getCartFacade().getSessionCart().getQuoteData();
        if (quoteData != null && !getQuoteFacade().isQuoteSessionCartValidForCheckout()) {
            getQuoteFacade().removeQuoteCart(quoteData.getCode());
            GlobalMessages.addFlashMessage((RedirectAttributesModelMap) pjp.getArgs()[1],
                    GlobalMessages.ERROR_MESSAGES_HOLDER, "quote.cart.checkout.error");
            return String.format(REDIRECT_QUOTE_DETAILS, quoteData.getCode());
        }//from  w w w. j  a v  a 2  s. com
    }

    return pjp.proceed();
}

From source file:de.hybris.platform.assistedservicestorefront.aspect.ChannelDecisionAspect.java

License:Open Source License

/**
 * Around advice for the decide method of classes in the org.springframework.security.web.access.channel package,
 * forcing HTTPS for all requests./*from  w  w  w  .  j  a  v  a  2s .c  o m*/
 * 
 * @param joinPoint
 *           the join point
 * @throws Throwable
 *            any exceptions thrown during advice execution
 */
@Around("execution(public void org.springframework.security.web.access.channel.*.decide(..))")
public void decideAround(final ProceedingJoinPoint joinPoint) throws Throwable {
    if (isAssistedServiceMode(joinPoint)) {
        if (joinPoint.getTarget() instanceof SecureChannelProcessor) {
            processSecureChannelProcessor(joinPoint);
        } else if (joinPoint.getTarget() instanceof InsecureChannelProcessor) {
            // do nothing - we don't want the insecure processor to redirect to HTTP
        } else if (joinPoint.getTarget() instanceof ChannelDecisionManagerImpl) {
            processChannelDecisionManager(joinPoint);
        } else {
            joinPoint.proceed();
        }
    } else {
        // if the assisted service mode is off just call the regular logic
        joinPoint.proceed();
    }
}

From source file:de.hybris.platform.mpintgordermanagement.aspects.ConsignmentActionAspect.java

License:Open Source License

/**
 * Perform around advice.//  w  w  w . jav  a 2s .  com
 *
 * @param joinPoint
 *           - the join point
 * @return the remaining cancellation entries to be cancelled; never <tt>null</tt>
 * @throws Throwable
 *            when an exception occurs that has been cleared to be rethrown.
 */
public Collection<CancellationEntry> advise(final ProceedingJoinPoint joinPoint) throws Throwable {
    Collection<CancellationEntry> remainingEntries = Collections.emptyList();
    final ConsignmentModel consignment = getConsignment(joinPoint);
    LOGGER.debug("Running consignment action aspect for consignment with code: " + consignment.getCode());
    try {
        getConsignmentBusinessProcessService().triggerChoiceEvent(consignment,
                MpintgordermanagementConstants.CONSIGNMENT_ACTION_EVENT_NAME, getChoice());
        remainingEntries = (Collection<CancellationEntry>) joinPoint.proceed();
        triggerAfter(consignment);
    } catch (final BusinessProcessException e) {
        throw e;
    } catch (final Throwable e) {
        triggerAfter(consignment);
        if (getExceptionsToRethrow().stream().anyMatch(clazz -> (e.getClass().equals(clazz)))) {
            throw e;
        }
        LOGGER.info(String.format(EXCEPTION_MESSAGE, consignment.getCode()));
    }
    return remainingEntries;
}

From source file:de.hybris.platform.security.captcha.ReCaptchaAspect.java

License:Open Source License

public Object prepare(final ProceedingJoinPoint joinPoint) throws Throwable {
    final List<Object> args = Arrays.asList(joinPoint.getArgs());
    final HttpServletRequest request = (HttpServletRequest) CollectionUtils.find(args,
            PredicateUtils.instanceofPredicate(HttpServletRequest.class));

    if (request != null) {
        final boolean captcaEnabledForCurrentStore = isCaptcaEnabledForCurrentStore();
        request.setAttribute("captcaEnabledForCurrentStore", Boolean.valueOf(captcaEnabledForCurrentStore));
        if (captcaEnabledForCurrentStore) {
            request.setAttribute("recaptchaPublicKey",
                    getSiteConfigService().getProperty(RECAPTCHA_PUBLIC_KEY_PROPERTY));
        }/*from  w  w w.j  a v  a  2s .  c om*/
    }
    return joinPoint.proceed();
}

From source file:de.hybris.platform.security.captcha.ReCaptchaAspect.java

License:Open Source License

public Object advise(final ProceedingJoinPoint joinPoint) throws Throwable {

    final boolean captcaEnabledForCurrentStore = isCaptcaEnabledForCurrentStore();
    if (captcaEnabledForCurrentStore) {
        final List<Object> args = Arrays.asList(joinPoint.getArgs());
        HttpServletRequest request = (HttpServletRequest) CollectionUtils.find(args,
                PredicateUtils.instanceofPredicate(HttpServletRequest.class));

        if (request == null
                && RequestContextHolder.getRequestAttributes() instanceof ServletRequestAttributes) {
            final ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
                    .getRequestAttributes();
            request = requestAttributes.getRequest();
        }//  w w  w . j a  v a2  s. co m

        if (request != null) {
            request.setAttribute("captcaEnabledForCurrentStore", Boolean.valueOf(captcaEnabledForCurrentStore));
            request.setAttribute("recaptchaPublicKey",
                    getSiteConfigService().getProperty(RECAPTCHA_PUBLIC_KEY_PROPERTY));
            final String challengeFieldValue = request.getParameter(RECAPTCHA_CHALLENGE_FIELD_PARAM);
            final String responseFieldValue = request.getParameter(RECAPTCHA_RESPONSE_FIELD_PARAM);
            if ((StringUtils.isBlank(challengeFieldValue) || StringUtils.isBlank(responseFieldValue))
                    || !checkAnswer(request, challengeFieldValue, responseFieldValue)) {
                // if there is an error add a message to binding result.
                final BindingResult bindingResult = (BindingResult) CollectionUtils.find(args,
                        PredicateUtils.instanceofPredicate(BindingResult.class));
                if (bindingResult != null) {
                    bindingResult.reject("recaptcha.challenge.field.invalid", "Challenge Answer is invalid.");
                }
                request.setAttribute("recaptchaChallangeAnswered", Boolean.FALSE);
            }
        }
    }
    return joinPoint.proceed();
}

From source file:de.iteratec.iteraplan.businesslogic.common.SubscriptionsAdvice.java

License:Open Source License

/**
 * Intercepts the {@link de.iteratec.iteraplan.presentation.dialog.BuildingBlockFrontendService#saveComponentModel(MemBean, Integer, org.springframework.webflow.execution.RequestContext, org.springframework.webflow.execution.FlowExecutionContext)}
 * method and sends the notification email.
 * //from   w w  w.  j a  v a2  s  .  c  o  m
 * @param pjp the ProceedingJoinPoint, which exposes the proceed(..) method in order to support around advice in aspects
 * @return the result of the intercepted method
 * @throws Throwable if any exceptions occurs executing method
 */
public Object saveComponentModelAdvice(ProceedingJoinPoint pjp) throws Throwable {
    if (!activated) {
        return pjp.proceed();
    }

    Object[] args = pjp.getArgs();
    BuildingBlock bb = getEntity(args[0]);

    if (bb == null || bb.getSubscribedUsers().isEmpty()) {
        return pjp.proceed();
    }

    BuildingBlock buildingBlockClone = cloneBb(bb);
    Map<String, List<TimeseriesEntry>> oldTimeseriesEntries = getTimeseriesEntriesForBb(buildingBlockClone);

    final Object retVal = pjp.proceed();

    if (buildingBlockClone != null) {
        BuildingBlock buildingBlock = load(buildingBlockClone);
        List<String> changedTimeseries = determineChangedTimeseries(oldTimeseriesEntries, buildingBlock);

        String messageKey = GENERIC + UPDATED;
        sendEmail(buildingBlockClone, buildingBlock, changedTimeseries, messageKey,
                buildingBlock.getSubscribedUsers());
    }

    return retVal;
}

From source file:de.iteratec.iteraplan.businesslogic.common.SubscriptionsAdvice.java

License:Open Source License

/**
 * Intercepts the {@link de.iteratec.iteraplan.presentation.dialog.BuildingBlockFrontendService#saveComponentModel(MemBean, Integer, org.springframework.webflow.execution.RequestContext, org.springframework.webflow.execution.FlowExecutionContext)}
 * method and sends the notification email.
 * // w w w  . ja v  a  2s.c om
 * @param pjp the ProceedingJoinPoint, which exposes the proceed(..) method in order to support around advice in aspects
 * @return the result of the intercepted method
 * @throws Throwable if any exceptions occurs executing method
 */
public Object saveNewComponentModelAdvice(ProceedingJoinPoint pjp) throws Throwable {
    if (!activated) {
        return pjp.proceed();
    }

    Object[] args = pjp.getArgs();

    final Object retVal = pjp.proceed();

    if (retVal != null) {
        BuildingBlock buildingBlock = getEntity(args[0]);

        if (buildingBlock != null && BBT_TO_MESSAGE_KEY.containsKey(buildingBlock.getTypeOfBuildingBlock())) {
            buildingBlock = load(buildingBlock);
            List<String> changedTimeseries = determineChangedTimeseries(
                    Maps.<String, List<TimeseriesEntry>>newHashMap(), buildingBlock);

            String messageKey = GENERIC + CREATED;
            sendEmail(null, buildingBlock, changedTimeseries, messageKey,
                    buildingBlock.getBuildingBlockType().getSubscribedUsers());
        }
    }

    return retVal;
}