Search in sources :

Example 6 with UseCaseEntry

use of com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry in project sechub by mercedes-benz.

the class UseCaseModelDataCollector 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 Step) {
                    String location = "method `" + method.getName() + "` in class `" + method.getDeclaringClass().getName() + "`";
                    useCaseEntry.addStep((Step) value, rolesAllowed, location);
                }
            } catch (Exception e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : RolesAllowed(javax.annotation.security.RolesAllowed) UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry) Method(java.lang.reflect.Method) Step(com.mercedesbenz.sechub.sharedkernel.Step)

Example 7 with UseCaseEntry

use of com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry in project sechub by mercedes-benz.

the class UseCaseRestDocModelAsciiDocGenerator method createEntriesForGroup.

private void createEntriesForGroup(UseCaseRestDocModel model, Context context, List<List<UseCaseRestDocEntry>> found, SortedSet<UseCaseEntry> entriesForGroup, StringBuilder linksToRestDocs) {
    for (UseCaseEntry entry : entriesForGroup) {
        if (!context.usecasesToInspect.contains(entry.getIdentifierEnumName())) {
            continue;
        }
        entry.getIdentifierEnumName();
        List<UseCaseRestDocEntry> restDocEntries = model.getRestDocEntries(entry);
        if (restDocEntries == null || restDocEntries.isEmpty()) {
            continue;
        /* use case has no rest doc so ignore */
        }
        linksToRestDocs.append("- " + UseCaseAsciiDocFactory.createLinkToUseCaseRestDoc(entry, "REST API for " + entry.getId() + "-" + entry.getTitle()) + "\n");
        found.add(restDocEntries);
    }
}
Also used : UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry)

Aggregations

UseCaseEntry (com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry)7 Method (java.lang.reflect.Method)3 RolesAllowed (javax.annotation.security.RolesAllowed)2 PDSStep (com.mercedesbenz.sechub.pds.usecase.PDSStep)1 Step (com.mercedesbenz.sechub.sharedkernel.Step)1 UseCaseGroup (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseGroup)1 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1