private void validateHookAttributeAvailability()

in flux/src/main/java/software/amazon/aws/clients/swf/flux/wf/graph/WorkflowGraphBuilder.java [659:715]


    private void validateHookAttributeAvailability(WorkflowStep hookedStep, WorkflowStepHook hook, StepHook.HookType hookType,
                                                   Map<String, Class<?>> availableAttributes, boolean allowPartitionAttributes) {
        Map<Method, StepHook> methods = WorkflowStepUtil.getAllMethodsWithAnnotation(hook.getClass(), StepHook.class);
        for (Entry<Method, StepHook> entry : methods.entrySet()) {
            StepHook config = entry.getValue();
            if (config.hookType() != hookType) {
                continue;
            }

            Map<String, Class<?>> hookAttributes = new HashMap<>(availableAttributes);
            hookAttributes.put(StepAttributes.ACTIVITY_NAME,
                               StepAttributes.getSpecialAttributeType(StepAttributes.ACTIVITY_NAME));
            hookAttributes.put(StepAttributes.ACTIVITY_INITIAL_ATTEMPT_TIME,
                               StepAttributes.getSpecialAttributeType(StepAttributes.ACTIVITY_INITIAL_ATTEMPT_TIME));
            hookAttributes.put(StepAttributes.RETRY_ATTEMPT,
                               StepAttributes.getSpecialAttributeType(StepAttributes.RETRY_ATTEMPT));
            if (allowPartitionAttributes) {
                hookAttributes.put(StepAttributes.PARTITION_ID,
                                   StepAttributes.getSpecialAttributeType(StepAttributes.PARTITION_ID));
                hookAttributes.put(StepAttributes.PARTITION_COUNT,
                                   StepAttributes.getSpecialAttributeType(StepAttributes.PARTITION_COUNT));
            }
            if (hookType == StepHook.HookType.POST) {
                hookAttributes.put(StepAttributes.RESULT_CODE,
                                   StepAttributes.getSpecialAttributeType(StepAttributes.RESULT_CODE));
                hookAttributes.put(StepAttributes.ACTIVITY_COMPLETION_MESSAGE,
                                   StepAttributes.getSpecialAttributeType(StepAttributes.ACTIVITY_COMPLETION_MESSAGE));
            }

            Method method = entry.getKey();
            for (Parameter param : method.getParameters()) {
                Class<?> paramType = param.getType();
                if (paramType.isAssignableFrom(MetricRecorder.class)) {
                    continue;
                }

                if (paramType == Date.class) {
                    // The step attribute encoding/decoding logic allows Date and Instant to be used
                    // interchangeably, so for the purposes of attribute availability,
                    // we'll coerce all Dates to Instants, to simplify the validation logic.
                    paramType = Instant.class;
                }

                Attribute attr = param.getAnnotation(Attribute.class);
                if (!allowPartitionAttributes && (StepAttributes.PARTITION_ID.equals(attr.value())
                                                  || StepAttributes.PARTITION_COUNT.equals(attr.value()))) {
                    String msg = String.format("%s.%s cannot request the PARTITION_ID or PARTITION_COUNT attributes for step %s.",
                                               hook.getClass().getSimpleName(), method.getName(),
                                               hookedStep.getClass().getSimpleName());
                    throw new WorkflowGraphBuildException(msg);
                }

                validateAttributeIdAndType(hook.getClass().getSimpleName(), method.getName(), attr.value(),
                                           paramType, attr.optional(), hookAttributes);
            }
        }
    }