Search in sources :

Example 1 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project PhotoNoter by yydcdut.

the class PermissionAspect method aroundCheckAndRequestPermission.

@Around("pointcut2CheckAndRequestPermissions(aspectPermission)")
public void aroundCheckAndRequestPermission(ProceedingJoinPoint proceedingJoinPoint, AspectPermission aspectPermission) {
    if (aspectPermission == null) {
        return;
    }
    IPresenter iPresenter = (IPresenter) proceedingJoinPoint.getTarget();
    int value = aspectPermission.value();
    switch(value) {
        case PermissionUtils.CODE_CAMERA:
        case PermissionUtils.CODE_ADJUST_CAMERA:
            {
                if (hasPermission4Camera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_camera_init), PermissionUtils.PERMISSION_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_STORAGE:
            {
                if (hasPermission4Storage(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_storage_init), PermissionUtils.PERMISSION_STORAGE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_LOCATION_AND_CAMERA:
            {
                if (hasPermission4LocationAndCamera(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_location), PermissionUtils.PERMISSION_LOCATION_AND_CAMERA, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_AUDIO:
            {
                if (hasPermission4Audio(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_audio), PermissionUtils.PERMISSION_AUDIO, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
        case PermissionUtils.CODE_PHONE_STATE:
            {
                if (hasPermission4PhoneState(PermissionInstance.context)) {
                    try {
                        proceedingJoinPoint.proceed();
                    } catch (Throwable throwable) {
                        YLog.e(throwable);
                    }
                } else {
                    if (iPresenter.getContext() instanceof Activity) {
                        requestPermissions((Activity) iPresenter.getContext(), PermissionInstance.context.getString(R.string.permission_phone_state), PermissionUtils.PERMISSION_PHONE_STATE, value);
                    } else {
                        YLog.i(TAG, "iPresenter.getContext() instanceof Activity  -->   false");
                    }
                }
            }
            break;
    }
}
Also used : IPresenter(com.yydcdut.note.presenters.IPresenter) Activity(android.app.Activity) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 2 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project nifi by apache.

the class TestRemoteProcessGroupAuditor method updateProcessGroupConfiguration.

@SuppressWarnings("unchecked")
private Collection<Action> updateProcessGroupConfiguration(RemoteProcessGroupDTO inputRPGDTO, RemoteProcessGroup existingRPG) throws Throwable {
    final RemoteProcessGroupAuditor auditor = new RemoteProcessGroupAuditor();
    final ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
    final String remoteProcessGroupId = "remote-process-group-id";
    inputRPGDTO.setId(remoteProcessGroupId);
    final String targetUrl = "http://localhost:8080/nifi";
    when(existingRPG.getTargetUri()).thenReturn(targetUrl);
    final RemoteProcessGroupDAO remoteProcessGroupDAO = mock(RemoteProcessGroupDAO.class);
    when(remoteProcessGroupDAO.getRemoteProcessGroup(remoteProcessGroupId)).thenReturn(existingRPG);
    // Setup updatedRPG mock based on inputRPGDTO.
    final RemoteProcessGroup updatedRPG = mock(RemoteProcessGroup.class);
    when(updatedRPG.getIdentifier()).thenReturn(remoteProcessGroupId);
    when(updatedRPG.isTransmitting()).thenReturn(inputRPGDTO.isTransmitting());
    when(updatedRPG.getCommunicationsTimeout()).thenReturn(inputRPGDTO.getCommunicationsTimeout());
    when(updatedRPG.getYieldDuration()).thenReturn(inputRPGDTO.getYieldDuration());
    when(updatedRPG.getTransportProtocol()).thenReturn(SiteToSiteTransportProtocol.valueOf(inputRPGDTO.getTransportProtocol()));
    when(updatedRPG.getProxyHost()).thenReturn(inputRPGDTO.getProxyHost());
    when(updatedRPG.getProxyPort()).thenReturn(inputRPGDTO.getProxyPort());
    when(updatedRPG.getProxyUser()).thenReturn(inputRPGDTO.getProxyUser());
    when(updatedRPG.getProxyPassword()).thenReturn(inputRPGDTO.getProxyPassword());
    when(joinPoint.proceed()).thenReturn(updatedRPG);
    // Capture added actions so that those can be asserted later.
    final AuditService auditService = mock(AuditService.class);
    final AtomicReference<Collection<Action>> addedActions = new AtomicReference<>();
    doAnswer(invocation -> {
        Collection<Action> actions = invocation.getArgumentAt(0, Collection.class);
        addedActions.set(actions);
        return null;
    }).when(auditService).addActions(any());
    auditor.setAuditService(auditService);
    auditor.auditUpdateProcessGroupConfiguration(joinPoint, inputRPGDTO, remoteProcessGroupDAO);
    final Collection<Action> actions = addedActions.get();
    // Assert common action values.
    if (actions != null) {
        actions.forEach(action -> {
            assertEquals(remoteProcessGroupId, action.getSourceId());
            assertEquals("user-id", action.getUserIdentity());
            assertEquals(targetUrl, ((RemoteProcessGroupDetails) action.getComponentDetails()).getUri());
            assertNotNull(action.getTimestamp());
        });
    }
    return actions;
}
Also used : RemoteProcessGroup(org.apache.nifi.groups.RemoteProcessGroup) Action(org.apache.nifi.action.Action) Collection(java.util.Collection) AtomicReference(java.util.concurrent.atomic.AtomicReference) RemoteProcessGroupDAO(org.apache.nifi.web.dao.RemoteProcessGroupDAO) AuditService(org.apache.nifi.admin.service.AuditService) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 3 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project bamboobsc by billchen198318.

the class ServiceScriptExpressionUtils method getParameters.

private static Map<String, Object> getParameters(TbSysBeanHelpExpr beanHelpExpr, List<TbSysBeanHelpExprMap> beanHelpExprMaps, Object resultObj, ProceedingJoinPoint pjp) {
    Object[] args = pjp.getArgs();
    Map<String, Object> dataMap = new HashMap<String, Object>();
    for (TbSysBeanHelpExprMap map : beanHelpExprMaps) {
        Object value = null;
        if (YesNo.YES.equals(map.getMethodResultFlag())) {
            value = resultObj;
        } else {
            for (int i = 0; args != null && i < args.length; i++) {
                if (args[i] != null && args[i].getClass() != null && args[i].getClass().getName().equals(map.getMethodParamClass()) && map.getMethodParamIndex() == i) {
                    value = args[i];
                }
            }
        }
        dataMap.put(map.getVarName(), value);
    }
    return dataMap;
}
Also used : HashMap(java.util.HashMap) TbSysBeanHelpExprMap(com.netsteadfast.greenstep.po.hbm.TbSysBeanHelpExprMap) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 4 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project cuba by cuba-platform.

the class ServiceInterceptor method validateMethodResult.

protected void validateMethodResult(ProceedingJoinPoint ctx, ValidateServiceMethodContext validatedContext, Object methodResult) {
    if (validatedContext != null) {
        ExecutableValidator validator = validatedContext.getValidator();
        log.trace("Validating service call result: {}", ctx.getSignature());
        Class[] constraintGroups = validatedContext.getGroups();
        if (constraintGroups.length == 0) {
            constraintGroups = new Class[] { Default.class, ServiceResultChecks.class };
        }
        Set<ConstraintViolation<Object>> violations = validator.validateReturnValue(validatedContext.getTarget(), validatedContext.getMethod(), methodResult, constraintGroups);
        if (!violations.isEmpty()) {
            Class serviceInterface = ctx.getSignature().getDeclaringType();
            Set<ConstraintViolation<Object>> paramsViolations = violations.stream().map(violation -> new ServiceMethodConstraintViolation(serviceInterface, violation)).collect(Collectors.toSet());
            throw new MethodResultValidationException("Service method result validation failed", paramsViolations);
        }
    }
}
Also used : ServiceParametersChecks(com.haulmont.cuba.core.global.validation.groups.ServiceParametersChecks) Persistence(com.haulmont.cuba.core.Persistence) ServiceResultChecks(com.haulmont.cuba.core.global.validation.groups.ServiceResultChecks) LoggerFactory(org.slf4j.LoggerFactory) MethodResultValidationException(com.haulmont.cuba.core.global.validation.MethodResultValidationException) ServerConfig(com.haulmont.cuba.core.app.ServerConfig) ExecutableValidator(javax.validation.executable.ExecutableValidator) com.haulmont.cuba.core.global(com.haulmont.cuba.core.global) UserSession(com.haulmont.cuba.security.global.UserSession) ServiceMethodConstraintViolation(com.haulmont.cuba.core.global.validation.ServiceMethodConstraintViolation) MiddlewareStatisticsAccumulator(com.haulmont.cuba.core.app.MiddlewareStatisticsAccumulator) ConstraintViolation(javax.validation.ConstraintViolation) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Default(javax.validation.groups.Default) MethodInvocationProceedingJoinPoint(org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint) Validated(org.springframework.validation.annotation.Validated) Logger(org.slf4j.Logger) AnnotationUtils(org.springframework.core.annotation.AnnotationUtils) Set(java.util.Set) MethodParametersValidationException(com.haulmont.cuba.core.global.validation.MethodParametersValidationException) Collectors(java.util.stream.Collectors) NoUserSessionException(com.haulmont.cuba.security.global.NoUserSessionException) UserSessionsAPI(com.haulmont.cuba.security.app.UserSessionsAPI) MethodSignature(org.aspectj.lang.reflect.MethodSignature) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) ServiceMethodConstraintViolation(com.haulmont.cuba.core.global.validation.ServiceMethodConstraintViolation) ExecutableValidator(javax.validation.executable.ExecutableValidator) MethodResultValidationException(com.haulmont.cuba.core.global.validation.MethodResultValidationException) ServiceMethodConstraintViolation(com.haulmont.cuba.core.global.validation.ServiceMethodConstraintViolation) ConstraintViolation(javax.validation.ConstraintViolation)

Example 5 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project data-prep by Talend.

the class AnnotationUtils method getAnnotatedParameterIndex.

/**
 * Returns the id of the parameter annotated with <code>annotationClass</code> in all the <code>pjp</code>
 * arguments. If multiple parameters hold the annotation, returns the index of the <b>last</b> parameter.
 *
 * @param pjp The {@link ProceedingJoinPoint} to check for annotation in parameters.
 * @param annotationClass The annotation to look for.
 * @return The index of the annotated parameter or -1 if not found.
 */
public static int getAnnotatedParameterIndex(ProceedingJoinPoint pjp, Class<? extends Annotation> annotationClass) {
    MethodSignature ms = (MethodSignature) pjp.getSignature();
    Method m = ms.getMethod();
    Annotation[][] pa = m.getParameterAnnotations();
    int idParameterIndex = -1;
    int i = 0;
    for (Annotation[] annotations : pa) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType().equals(annotationClass)) {
                idParameterIndex = i;
            }
        }
        i++;
    }
    return idParameterIndex;
}
Also used : MethodSignature(org.aspectj.lang.reflect.MethodSignature) Method(java.lang.reflect.Method) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)76 Around (org.aspectj.lang.annotation.Around)32 MethodSignature (org.aspectj.lang.reflect.MethodSignature)15 Test (org.junit.Test)14 Method (java.lang.reflect.Method)13 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)10 SimpleDateFormat (java.text.SimpleDateFormat)8 ArrayList (java.util.ArrayList)8 JoinPoint (org.aspectj.lang.JoinPoint)8 FaseDTO (com.tomasio.projects.trainning.dto.FaseDTO)7 OrganizacaoDTO (com.tomasio.projects.trainning.dto.OrganizacaoDTO)7 PessoaDTO (com.tomasio.projects.trainning.dto.PessoaDTO)7 MockProceedingJoinPoint (org.finra.herd.core.MockProceedingJoinPoint)7 Annotation (java.lang.annotation.Annotation)5 CancelamentoMatriculaDTO (com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO)4 MatriculaDTO (com.tomasio.projects.trainning.dto.MatriculaDTO)4 Date (java.util.Date)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Action (org.apache.nifi.action.Action)4 MessageHeader (org.finra.herd.model.dto.MessageHeader)4