Search in sources :

Example 21 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project trainning by fernandotomasio.

the class AtividadesEnsinoMailAdvice method removeMatriculaMethodInterceptor.

@Around("removeMatricula()")
public Object removeMatriculaMethodInterceptor(ProceedingJoinPoint joinPoint) throws Throwable {
    Object[] args = joinPoint.getArgs();
    Long matriculaId = (Long) args[0];
    MatriculaDTO matricula = atividadesEnsinoService.findMatricula(matriculaId);
    PessoaDTO pessoa = organizationalService.findPessoa(matricula.getPessoa().getId());
    String to = matricula.getIndicacao().getEmail();
    String subject = "SGC - EXCLUSÃO DE MATRICULA PARA CURSO";
    String textfase = "Fases:\n";
    int countfases = 1;
    for (FaseDTO fase : matricula.getTurma().getFases()) {
        textfase += "" + countfases + " - Modalidade: " + fase.getTipoFase() + " - Descrição: " + fase.getDescricao() + " - Local: " + fase.getLocal().getSigla() + " - Início: " + fase.getDataInicioFormatted() + " - Término: " + fase.getDataTerminoFormatted() + "\n";
        countfases++;
    }
    SimpleDateFormat dfExec = new SimpleDateFormat("yyyy");
    String exercicio = dfExec.format(matricula.getTurma().getExercicio());
    OrganizacaoDTO OMGEstor = organizationalService.findOrganizacao(matricula.getTurma().getOrganizacaoGestoraId());
    OrganizacaoDTO OMResp = organizationalService.findOrganizacao(matricula.getTurma().getResponsavelId());
    String text = "Prezado(a), " + pessoa.getTargetaCompletaOM() + "\n\n" + "Sua MATRICULA para participar do seguinte curso foi EXCLUÍDA no SGC:\n\n" + "Curso: " + matricula.getTurma().getCurso().getCodigo() + " - " + matricula.getTurma().getCurso().getDescricao() + "\n" + "Turma: " + matricula.getTurma().getNumeroTurma() + " / " + exercicio + "\n" + "Organização Responsável: " + OMResp.getNome() + " (" + OMResp.getSigla() + ")\n" + "Quantidade de Vagas: " + matricula.getTurma().getQuantidadeVagas() + "\n" + "Data de Início: " + matricula.getTurma().getDataInicioFormatted() + "\n" + "Data de Término: " + matricula.getTurma().getDataTerminoFormatted() + "\n" + "Local: " + matricula.getTurma().getLocal() + "\n" + "Modalidade: " + matricula.getTurma().getTipoTurma() + "\n\n" + textfase + "\n\n==> CABE RESSALTAR QUE ESTE E-MAIL POSSUI CARATER MERAMENTE INFORMATIVO. O DOCUMENTO QUE OFICIALIZA A MATRÍCULA NO CURSO É A PUBLICAÇÃO OFICIAL DA OM GESTORA DA CAPACITAÇÃO. <==\n" + "\nAcesse o Portal da Capacitação para mais informações.\n" + "\nEm caso de dúvidas entre em contato com o setor de capacitação de sua OM " + "ou com a Organização Gestora desta capacitação (" + OMGEstor.getSigla() + ") " + "para verificar a veracidade desta informação.\n\n" + "----------------------------------------------------\n" + "Esse e-mail foi enviado de forma automática para " + to + ", NÃO RESPONDA ESTE E-MAIL.\n" + "Este é um serviço prestado pelo SGC - Sistema de Gerenciamento da Capacitação.\n";
    systemService.sendMail(to, subject, text);
    // }
    return joinPoint.proceed();
}
Also used : MatriculaDTO(com.tomasio.projects.trainning.dto.MatriculaDTO) CancelamentoMatriculaDTO(com.tomasio.projects.trainning.dto.CancelamentoMatriculaDTO) PessoaDTO(com.tomasio.projects.trainning.dto.PessoaDTO) OrganizacaoDTO(com.tomasio.projects.trainning.dto.OrganizacaoDTO) SimpleDateFormat(java.text.SimpleDateFormat) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) FaseDTO(com.tomasio.projects.trainning.dto.FaseDTO) Around(org.aspectj.lang.annotation.Around)

Example 22 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project commons by craftercms.

the class HasPermissionAnnotationHandler method getAnnotatedSecuredObject.

protected Object getAnnotatedSecuredObject(Method method, ProceedingJoinPoint pjp) {
    Annotation[][] paramAnnotations = method.getParameterAnnotations();
    Object[] params = pjp.getArgs();
    for (int i = 0; i < paramAnnotations.length; i++) {
        for (Annotation a : paramAnnotations[i]) {
            if (a instanceof SecuredObject) {
                return params[i];
            }
        }
    }
    return null;
}
Also used : ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Annotation(java.lang.annotation.Annotation)

Example 23 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project trafficController by amitkhosla.

the class AnnotationSupportImpl method addToTaskChainAsCalledFromParallel.

/**
 * Add to task chain when Controlled called from parallel flow.
 * @param joinPoint Join point
 * @param controlled Controlled
 * @param task Parallel Task
 * @param taskExecutorPresent Is task executor present
 * @param nameForTheTaskExecutor Name of task executor
 * @param taskExecutor Task executor
 * @return Task executor
 */
protected TaskExecutor addToTaskChainAsCalledFromParallel(ProceedingJoinPoint joinPoint, Controlled controlled, Task task, boolean taskExecutorPresent, String nameForTheTaskExecutor, TaskExecutor taskExecutor) {
    int taskId = parallelJoinHelper.getObjectKeyForParalleldTask();
    int parallelTaskId = ParallelJoinHelper.getParallelId();
    logger.fine("already from same executor..so will be processed directly via different task.");
    RunnableToBeExecuted runnableToBeExecuted = () -> {
        ParallelJoinHelper.putObject(parallelTaskId, taskId, joinPoint.proceed());
    };
    // / TODO - IS this check required?
    if (taskExecutorPresent) {
        taskExecutor = task.getTaskExecutor();
    } else {
        runnableToBeExecuted = () -> {
            try {
                TaskExecutorsInUseThreadLocal.setTaskExecutor(nameForTheTaskExecutor);
                Object result = joinPoint.proceed();
                if (Objects.nonNull(result)) {
                    ParallelJoinHelper.putObject(parallelTaskId, taskId, result);
                }
            } finally {
                TaskExecutorsInUseThreadLocal.removeTaskExecutor(nameForTheTaskExecutor);
            }
        };
    }
    String name = "ParallelId:" + parallelTaskId + " taskId:" + taskId + " " + getTaskNameFromJoinPoint(joinPoint);
    org.ak.trafficController.Task.TaskType taskType = convertAnnotationTaskTypeToFrameworkTaskType(controlled.taskType());
    Task thisTask;
    if (taskType == org.ak.trafficController.Task.TaskType.NORMAL) {
        thisTask = taskExecutor.of(runnableToBeExecuted);
    } else {
        thisTask = taskExecutor.slowOf(runnableToBeExecuted);
    }
    ((ParallelTask) task).addTask(thisTask);
    setThreadingDetailsIfAny(thisTask, controlled.threadDetailsDataExtractClass(), controlled.threadDetailsDataExtractMethodName(), controlled.threadDetailsProcessorClass(), controlled.threadDetailsProcessorMethodName(), controlled.threadDetailsCleanerClass(), controlled.threadDetailsCleanerMethodName());
    return taskExecutor;
}
Also used : RunnableToBeExecuted(org.ak.trafficController.RunnableToBeExecuted) ParallelTask(org.ak.trafficController.ParallelTask) ParallelExecutingTask(org.ak.trafficController.ParallelExecutingTask) ExecutableTask(org.ak.trafficController.ExecutableTask) Task(org.ak.trafficController.Task) UnlinkedTask(org.ak.trafficController.UnlinkedTask) ParallelTask(org.ak.trafficController.ParallelTask) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Example 24 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project trafficController by amitkhosla.

the class AnnotationSupportImpl method runParallel.

/**
 * Handles Parallel annotated methods.
 * Parallel if annotated, all method calls to Controlled annotated methods is made in parallel. Join annotated method joins back the the result created by controlled annotated methods.
 * It first execute the annotated method and creates task chain to be run in parallel followed by a joiner method which will join these results.
 * Parallel should be used only where we are calling different methods annotated with controlled and in different class to allow AOP play its work.
 * Output returned will be the output from Join operation or the last operation.
 * @param joinPoint Join point
 * @param parallel Parallel
 * @return Return output of the operation
 * @throws Throwable In case of any exception in processing
 */
@Around("execution(@org.ak.trafficController.annotations.api.Parallel * *(..)) && @annotation(parallel)")
public Object runParallel(ProceedingJoinPoint joinPoint, Parallel parallel) throws Throwable {
    int currentParallelId = parallelId.incrementAndGet();
    parallelJoinHelper.map.put(currentParallelId, new ConcurrentHashMap<>());
    AtomicInteger taskId = new AtomicInteger(0);
    AtomicInteger earlierParallelTaskId = new AtomicInteger(0);
    Task originalTask = parallelJoinHelper.getTask();
    boolean isSubParallelTask = originalTask != null;
    if (isSubParallelTask) {
        // this task is one task of parallel tasks.
        taskId.set(parallelJoinHelper.getObjectKeyForParalleldTask());
        earlierParallelTaskId.set(parallelJoinHelper.getParallelId());
    }
    ParallelJoinHelper.setParallelTaskId(currentParallelId);
    // if (!isSubParallelTask) {
    ExecutableTask thisParallelTask = TaskExecutor.getInstance().of(() -> {
    });
    setThreadingDetailsIfAny(thisParallelTask, parallel.threadDetailsDataExtractClass(), parallel.threadDetailsDataExtractMethodName(), parallel.threadDetailsProcessorClass(), parallel.threadDetailsProcessorMethodName(), parallel.threadDetailsCleanerClass(), parallel.threadDetailsCleanerMethodName());
    thisParallelTask.setName("ParallelTask" + currentParallelId);
    ParallelExecutingTask<Object> thenParallel = thisParallelTask.thenParallel(() -> {
    });
    thenParallel.setName("ParallelTaskName:" + currentParallelId);
    // set dummy task
    parallelJoinHelper.setTask(thenParallel);
    // }
    if (!isSubParallelTask) {
        Object val = directParallelTaskHandling(joinPoint, currentParallelId, parallel);
        return val;
    } else {
        joinPoint.proceed();
        if (originalTask instanceof ParallelTask) {
            subProcessHandling(currentParallelId, taskId, earlierParallelTaskId, originalTask, thisParallelTask);
        }
        return null;
    }
}
Also used : ParallelTask(org.ak.trafficController.ParallelTask) ParallelExecutingTask(org.ak.trafficController.ParallelExecutingTask) ExecutableTask(org.ak.trafficController.ExecutableTask) Task(org.ak.trafficController.Task) UnlinkedTask(org.ak.trafficController.UnlinkedTask) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutableTask(org.ak.trafficController.ExecutableTask) ParallelTask(org.ak.trafficController.ParallelTask) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Around(org.aspectj.lang.annotation.Around)

Example 25 with ProceedingJoinPoint

use of org.aspectj.lang.ProceedingJoinPoint in project trafficController by amitkhosla.

the class TaskHelper method getTaskExecutorBasedOnAsyncProps.

/**
 * Get task executor for submit.
 * This method creates task executor with max consumer details.
 * @param async Submit
 * @param joinPoint Join point
 * @return Task executor for required inputs
 */
protected TaskExecutor getTaskExecutorBasedOnAsyncProps(Submit async, ProceedingJoinPoint joinPoint) {
    int maxConsumers = getConsumers(async.maxConsumer(), joinPoint);
    int maxSlowConsumers = getConsumers(async.maxSlowConsumer(), joinPoint);
    return getTaskExecutorForConsumersDetails(maxConsumers, maxSlowConsumers);
}
Also used : ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint)

Aggregations

ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)78 Around (org.aspectj.lang.annotation.Around)33 MethodSignature (org.aspectj.lang.reflect.MethodSignature)16 Method (java.lang.reflect.Method)14 Test (org.junit.Test)14 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