Search in sources :

Example 1 with UseCaseEntry

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

the class UseCaseAsciiDocGenerator method generateGroupUseCaseLinks.

private void generateGroupUseCaseLinks(Context context, int h, UseCaseDefGroup group) {
    SortedSet<UseCaseEntry> entries = group.getUseCases();
    if (entries.isEmpty()) {
        return;
    }
    context.addLine(headline(h + 1) + group.title);
    context.addLine(group.description);
    context.addLine("");
    for (UseCaseEntry entry : entries) {
        context.addLine("- <<" + UseCaseAsciiDocFactory.createLinkId(entry) + "," + entry.getId() + "-" + entry.getTitle() + ">>\n");
    }
    context.addLine("");
}
Also used : UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry)

Example 2 with UseCaseEntry

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

the class UseCaseRestDocModelAsciiDocGenerator method generateOverview.

private List<List<UseCaseRestDocEntry>> generateOverview(UseCaseRestDocModel model, Context context, int h) {
    context.addLine(headline(h) + "Overview");
    List<List<UseCaseRestDocEntry>> found = new ArrayList<>();
    for (UseCaseGroup group : UseCaseGroup.values()) {
        SortedSet<UseCaseEntry> entriesForGroup = model.getUseCaseModel().getGroup(group).getUseCases();
        if (entriesForGroup.isEmpty()) {
            continue;
        }
        StringBuilder linksToRestDocs = new StringBuilder();
        createEntriesForGroup(model, context, found, entriesForGroup, linksToRestDocs);
        boolean foundAtLeastOneRestDocForGroup = linksToRestDocs.length() > 0;
        if (!foundAtLeastOneRestDocForGroup) {
            continue;
        }
        context.addLine(headline(h + 1) + group.getTitle());
        context.addLine(group.getDescription());
        context.addLine("");
        context.addLine(linksToRestDocs.toString());
        context.addLine("");
    }
    return found;
}
Also used : ArrayList(java.util.ArrayList) UseCaseGroup(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseGroup) UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with UseCaseEntry

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

the class UseCaseRestDocModelDataCollector method collect.

public UseCaseRestDocModel collect(UseCaseModel useCaseModel) {
    if (DEBUG) {
        LOG.info("start collecting");
    }
    UseCaseRestDocModel model = new UseCaseRestDocModel(useCaseModel);
    Set<Method> annotatedMethods = reflections.getMethodsAnnotatedWith(UseCaseRestDoc.class);
    if (annotatedMethods.size() == 0) {
        throw new IllegalStateException("Criticial:Cannot generate REST documentation!\n" + "Reflections did not find any method annotated with @UseCaseRestDoc!\n" + "- If you started the collector from your IDE, please do not start directly, but instead start `AsciidocGeneratorManualTest.java`.\n" + "  Doing this, the classpath will contain automatically all necessary resources.\n" + "- If you are inside a gradle build this is a criticial problem, because the documentation would not be generated correctly! ");
    }
    if (DEBUG) {
        LOG.info("> will collect for:{} - {}", annotatedMethods.size(), annotatedMethods);
    }
    for (Method method : annotatedMethods) {
        UseCaseRestDoc[] annos = method.getAnnotationsByType(UseCaseRestDoc.class);
        if (annos.length == 0) {
            continue;
        }
        if (annos.length > 1) {
            throw new IllegalStateException("UseCaseRestDoc annotation may only added one time to test method!");
        }
        UseCaseRestDoc restDoc = annos[0];
        Class<? extends Annotation> useCaseClass = restDoc.useCase();
        if (DEBUG) {
            LOG.info("inspect method:{}\n - usecase found:{}", method, useCaseClass);
        }
        UseCaseEntry useCaseEntry = useCaseModel.ensureUseCase(useCaseClass);
        /* create and prepare rest doc entry */
        UseCaseRestDocEntry restDocEntry = new UseCaseRestDocEntry();
        restDocEntry.variantOriginValue = restDoc.variant();
        restDocEntry.variantId = RestDocFactory.createVariantId(restDocEntry.variantOriginValue);
        restDocEntry.usecaseEntry = useCaseEntry;
        String path = RestDocFactory.createPath(useCaseClass, restDocEntry.variantId);
        restDocEntry.identifier = RestDocFactory.createIdentifier(useCaseClass);
        restDocEntry.path = path;
        File projectRestDocGenFolder = scanForSpringRestDocGenFolder(restDocEntry);
        restDocEntry.copiedRestDocFolder = copyToDocumentationProject(projectRestDocGenFolder, path);
        restDocEntry.wanted = restDoc.wanted();
        model.add(restDocEntry);
        /* connect with usecase */
        useCaseEntry.addLinkToRestDoc(restDocEntry);
    }
    return model;
}
Also used : UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry) Method(java.lang.reflect.Method) File(java.io.File)

Example 4 with UseCaseEntry

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

the class PDSUseCaseAsciiDocGenerator method generateGroupUseCaseLinks.

private void generateGroupUseCaseLinks(Context context, int headlineLevel, UseCaseDefGroup group) {
    SortedSet<UseCaseEntry> entries = group.getUseCases();
    if (entries.isEmpty()) {
        return;
    }
    context.addLine(headline(headlineLevel + 1) + group.title);
    context.addLine(group.description);
    context.addLine("");
    for (UseCaseEntry entry : entries) {
        context.addLine("- <<" + UseCaseAsciiDocFactory.createLinkId(entry) + "," + entry.getId() + "-" + entry.getTitle() + ">>\n");
    }
    context.addLine("");
}
Also used : UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry)

Example 5 with UseCaseEntry

use of com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry 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);
            }
        }
    }
}
Also used : RolesAllowed(javax.annotation.security.RolesAllowed) UseCaseEntry(com.mercedesbenz.sechub.docgen.usecase.UseCaseModel.UseCaseEntry) Method(java.lang.reflect.Method) PDSStep(com.mercedesbenz.sechub.pds.usecase.PDSStep)

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