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;
}
}
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;
}
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;
}
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);
}
}
}
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;
}
Aggregations