use of com.mercedesbenz.sechub.pds.usecase.PDSStep in project sechub by mercedes-benz.
the class PDSUseCaseModelDataCollector method collectAnnotationInfo.
private <T extends Annotation> void collectAnnotationInfo(UseCaseModel model, Class<T> useCaseAnnotationClazz) {
if (DEBUG) {
LOG.info("start collecting annotation info:{}", useCaseAnnotationClazz);
}
Set<Method> methodsAnnotated = reflections.getMethodsAnnotatedWith(useCaseAnnotationClazz);
if (DEBUG) {
LOG.info("found methods annotated with:{} - {}", useCaseAnnotationClazz, methodsAnnotated);
}
for (Method method : methodsAnnotated) {
List<RolesAllowed> rolesAllowed = fetchAllAllowedRoles(method);
T[] annosFound = method.getAnnotationsByType(useCaseAnnotationClazz);
if (DEBUG) {
LOG.info("inspect method:{}\n - roles found:{}\n - annos found:{}", method, rolesAllowed, annosFound);
}
for (T anno : annosFound) {
UseCaseEntry useCaseEntry = model.ensureUseCase(anno.getClass());
try {
Method valueMethod = anno.getClass().getMethod("value");
Object value = valueMethod.invoke(anno);
if (value instanceof PDSStep) {
String location = "method `" + method.getName() + "` in class `" + method.getDeclaringClass().getName() + "`";
useCaseEntry.addStep((PDSStep) value, rolesAllowed, location);
}
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
}
}
Aggregations