Search in sources :

Example 1 with Introspection

use of com.bakdata.conquery.introspection.Introspection in project conquery by bakdata.

the class GroupHandler method handleField.

private void handleField(ClassInfo currentType, FieldInfo field) throws IOException {
    if (!isJSONSettableField(field)) {
        return;
    }
    Introspection introspec = Introspection.from(root, field.getClassInfo()).findField(field);
    String name = field.getName();
    TypeSignature typeSignature = field.getTypeSignatureOrTypeDescriptor();
    Ctx ctx = new Ctx().withField(field);
    String type;
    if (ID_REF.stream().anyMatch(field::hasAnnotation)) {
        type = ID_OF + printType(ctx.withIdOf(true), typeSignature);
    } else if (ID_REF_COL.stream().anyMatch(field::hasAnnotation)) {
        type = LIST_OF + ID_OF + StringUtils.removeStart(printType(ctx.withIdOf(true), typeSignature), LIST_OF);
    } else {
        type = printType(ctx, typeSignature);
    }
    out.table(editLink(introspec), name, type, findDefault(currentType, field), introspec.getExample(), introspec.getDescription());
}
Also used : BaseTypeSignature(io.github.classgraph.BaseTypeSignature) TypeSignature(io.github.classgraph.TypeSignature) ArrayTypeSignature(io.github.classgraph.ArrayTypeSignature) ClassRefTypeSignature(io.github.classgraph.ClassRefTypeSignature) Introspection(com.bakdata.conquery.introspection.Introspection)

Example 2 with Introspection

use of com.bakdata.conquery.introspection.Introspection in project conquery by bakdata.

the class GroupHandler method handleClass.

private void handleClass(String name, ClassInfo c) throws IOException {
    Introspection source = Introspection.from(root, c);
    try (Closeable details = details(name, c, source)) {
        if (c.getFieldInfo().stream().anyMatch(this::isJSONSettableField)) {
            out.line("Supported Fields:");
            out.tableHeader("", "Field", "Type", "Default", "Example", "Description");
            for (FieldInfo field : c.getFieldInfo().stream().sorted().collect(Collectors.toList())) {
                handleField(c, field);
            }
        } else {
            out.paragraph("No fields can be set for this type.");
        }
    }
}
Also used : Closeable(java.io.Closeable) Introspection(com.bakdata.conquery.introspection.Introspection) FieldInfo(io.github.classgraph.FieldInfo)

Example 3 with Introspection

use of com.bakdata.conquery.introspection.Introspection in project conquery by bakdata.

the class GroupHandler method handleEndpoint.

private void handleEndpoint(String url, MethodInfo method) throws IOException {
    Introspection introspec = Introspection.from(root, method.getClassInfo()).findMethod(method);
    try (Closeable details = details(getRestMethod(method) + "\u2001" + url, method.getClassInfo(), introspec)) {
        out.paragraph("Method: " + code(method.getName()));
        for (MethodParameterInfo param : method.getParameterInfo()) {
            if (param.hasAnnotation(PATH_PARAM) || param.hasAnnotation(AUTH) || param.hasAnnotation(CONTEXT)) {
                continue;
            }
            out.line("Expects: " + printType(new Ctx(), param.getTypeSignatureOrTypeDescriptor()));
        }
        out.paragraph("Returns: " + printType(new Ctx(), method.getTypeSignatureOrTypeDescriptor().getResultType()));
    }
}
Also used : Closeable(java.io.Closeable) Introspection(com.bakdata.conquery.introspection.Introspection) MethodParameterInfo(io.github.classgraph.MethodParameterInfo)

Example 4 with Introspection

use of com.bakdata.conquery.introspection.Introspection in project conquery by bakdata.

the class GroupHandler method handleMarkerInterface.

private void handleMarkerInterface(String name, ClassInfo c) throws IOException {
    Introspection source = Introspection.from(root, c);
    try (Closeable details = details(name, c, source)) {
        Set<String> values = new HashSet<>();
        for (Class<?> cl : group.getOtherClasses()) {
            if (c.loadClass().isAssignableFrom(cl)) {
                values.add("[" + cl.getSimpleName() + "](" + anchor(typeTitle(cl)) + ")");
            }
        }
        content.values().stream().filter(p -> c.loadClass().isAssignableFrom(p.getRight().loadClass())).forEach(p -> values.add("[" + p.getLeft().id() + "](" + anchor(p.getLeft().id()) + ")"));
        for (Class<?> cl : group.getMarkerInterfaces()) {
            if (c.loadClass().isAssignableFrom(cl) && !c.loadClass().equals(cl)) {
                values.add("[" + cl.getSimpleName() + "](" + anchor(typeTitle(cl)) + ")");
            }
        }
        if (!values.isEmpty()) {
            out.paragraph("A " + name + " is any of:\n* " + values.stream().sorted().collect(Collectors.joining("\n* ")));
        }
    }
}
Also used : Arrays(java.util.Arrays) BaseTypeSignature(io.github.classgraph.BaseTypeSignature) RequiredArgsConstructor(lombok.RequiredArgsConstructor) MethodInfo(io.github.classgraph.MethodInfo) IId(com.bakdata.conquery.models.identifiable.ids.IId) VariableDefaultValue(com.bakdata.conquery.util.VariableDefaultValue) StringUtils(org.apache.commons.lang3.StringUtils) HashMultimap(com.google.common.collect.HashMultimap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) UriBuilder(javax.ws.rs.core.UriBuilder) JsonNode(com.fasterxml.jackson.databind.JsonNode) Path(java.nio.file.Path) BiMap(com.google.common.collect.BiMap) CPSType(com.bakdata.conquery.io.cps.CPSType) MoreCollectors(com.google.common.collect.MoreCollectors) Set(java.util.Set) PrettyPrinter(com.bakdata.conquery.util.PrettyPrinter) MethodParameterInfo(io.github.classgraph.MethodParameterInfo) Collectors(java.util.stream.Collectors) Base(com.bakdata.conquery.model.Base) List(java.util.List) TypeSignature(io.github.classgraph.TypeSignature) Slf4j(lombok.extern.slf4j.Slf4j) JsonTypeInfo(com.fasterxml.jackson.annotation.JsonTypeInfo) Optional(java.util.Optional) Jackson(com.bakdata.conquery.io.jackson.Jackson) ArrayTypeSignature(io.github.classgraph.ArrayTypeSignature) FilenameUtils(org.apache.commons.io.FilenameUtils) TypeParameter(io.github.classgraph.TypeParameter) Constants(com.bakdata.conquery.Constants) Multimap(com.google.common.collect.Multimap) ClassRefTypeSignature(io.github.classgraph.ClassRefTypeSignature) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) ClassToInstanceMap(com.google.common.collect.ClassToInstanceMap) Group(com.bakdata.conquery.model.Group) Introspection(com.bakdata.conquery.introspection.Introspection) ScanResult(io.github.classgraph.ScanResult) FieldInfo(io.github.classgraph.FieldInfo) TypeVariableSignature(io.github.classgraph.TypeVariableSignature) ClassInfo(io.github.classgraph.ClassInfo) IOException(java.io.IOException) TypeArgument(io.github.classgraph.TypeArgument) File(java.io.File) Primitives(com.google.common.primitives.Primitives) Closeable(java.io.Closeable) Comparator(java.util.Comparator) Closeable(java.io.Closeable) Introspection(com.bakdata.conquery.introspection.Introspection) HashSet(java.util.HashSet)

Aggregations

Introspection (com.bakdata.conquery.introspection.Introspection)4 Closeable (java.io.Closeable)3 ArrayTypeSignature (io.github.classgraph.ArrayTypeSignature)2 BaseTypeSignature (io.github.classgraph.BaseTypeSignature)2 ClassRefTypeSignature (io.github.classgraph.ClassRefTypeSignature)2 FieldInfo (io.github.classgraph.FieldInfo)2 MethodParameterInfo (io.github.classgraph.MethodParameterInfo)2 TypeSignature (io.github.classgraph.TypeSignature)2 Constants (com.bakdata.conquery.Constants)1 CPSType (com.bakdata.conquery.io.cps.CPSType)1 Jackson (com.bakdata.conquery.io.jackson.Jackson)1 Base (com.bakdata.conquery.model.Base)1 Group (com.bakdata.conquery.model.Group)1 IId (com.bakdata.conquery.models.identifiable.ids.IId)1 PrettyPrinter (com.bakdata.conquery.util.PrettyPrinter)1 VariableDefaultValue (com.bakdata.conquery.util.VariableDefaultValue)1 JsonTypeInfo (com.fasterxml.jackson.annotation.JsonTypeInfo)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Strings (com.google.common.base.Strings)1 BiMap (com.google.common.collect.BiMap)1