use of org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition in project drools by kiegroup.
the class DMNDeclaredField method annotateFieldWithOAS.
private void annotateFieldWithOAS(List<AnnotationDefinition> annotations) {
if (getObjectType().equals("java.lang.String") && fieldDMNType.getAllowedValues() != null && !fieldDMNType.getAllowedValues().isEmpty()) {
annotateFieldWithOASEnumValues(annotations);
} else {
boolean isTemporal = DMNTypeUtils.isFEELBuiltInType(fieldDMNType) && DMNAllTypesIndex.TEMPORALS.contains(DMNTypeUtils.getFEELBuiltInType(fieldDMNType));
boolean isTemporalCollection = fieldDMNType.isCollection() && DMNTypeUtils.isFEELBuiltInType(DMNTypeUtils.genericOfCollection(fieldDMNType)) && DMNAllTypesIndex.TEMPORALS.contains(DMNTypeUtils.getFEELBuiltInType(DMNTypeUtils.genericOfCollection(fieldDMNType)));
if (isTemporal || isTemporalCollection) {
DMNType temporal = isTemporalCollection ? DMNTypeUtils.genericOfCollection(fieldDMNType) : fieldDMNType;
Class<?> clazz = index.getJacksonDeserializeAs(temporal).orElseThrow(IllegalStateException::new);
// intentionally use DMNType name
String temporalName = temporal.getName();
if (codeGenConfig.isWithMPOpenApiAnnotation()) {
AnnotationDefinition annDef = createOASAnnotationForTemporal("org.eclipse.microprofile.openapi.annotations.media.Schema", clazz, temporalName);
if (isTemporalCollection) {
annDef.addValue("type", "org.eclipse.microprofile.openapi.annotations.enums.SchemaType.ARRAY");
}
annotations.add(annDef);
}
if (codeGenConfig.isWithIOSwaggerOASv3Annotation()) {
AnnotationDefinition annDef = createOASAnnotationForTemporal("io.swagger.v3.oas.annotations.media.Schema", clazz, temporalName);
if (isTemporalCollection) {
annDef.addValue("type", "\"array\"");
}
annotations.add(annDef);
}
}
}
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition in project drools by kiegroup.
the class DescrFieldDefinition method addPositionAnnotation.
public void addPositionAnnotation(int position) {
AnnotationDefinition annotationDefinition = DescrAnnotationDefinition.createPositionAnnotation(position);
annotations.put(annotationDefinition.getName(), annotationDefinition);
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition in project drools by kiegroup.
the class GeneratedClassDeclaration method addMethod.
private void addMethod(MethodDefinition methodDefinition) {
List<Modifier.Keyword> modifiers = new ArrayList<>();
if (methodDefinition.isStatic()) {
modifiers.add(Modifier.Keyword.STATIC);
}
if (methodDefinition.isPublic()) {
modifiers.add(Modifier.Keyword.PUBLIC);
}
MethodDeclaration methodDeclaration = generatedClass.addMethod(methodDefinition.getMethodName(), modifiers.toArray(new Modifier.Keyword[0]));
methodDeclaration.setType(methodDefinition.getReturnType());
for (MethodParameter mp : methodDefinition.parameters()) {
methodDeclaration.addParameter(mp.getType(), mp.getName());
}
for (AnnotationDefinition a : methodDefinition.getAnnotations()) {
methodDeclaration.addAnnotation(createSimpleAnnotation(a.getName()));
}
methodDeclaration.setBody(StaticJavaParser.parseBlock(methodDefinition.getBody()));
}
use of org.drools.modelcompiler.builder.generator.declaredtype.api.AnnotationDefinition in project drools by kiegroup.
the class DMNDeclaredField method getFieldAnnotations.
@Override
public List<AnnotationDefinition> getFieldAnnotations() {
List<AnnotationDefinition> annotations = new ArrayList<>();
if (codeGenConfig.isWithJacksonAnnotation()) {
boolean isCollection = fieldDMNType.isCollection();
DMNType narrowTypeHint = isCollection ? DMNTypeUtils.getRootBaseTypeOfCollection(fieldDMNType) : fieldDMNType;
Optional<Class<?>> as = index.getJacksonDeserializeAs(narrowTypeHint);
as.ifPresent(asClass -> annotations.add(new SimpleAnnotationDefinition("com.fasterxml.jackson.databind.annotation.JsonDeserialize").addValue(isCollection ? "contentAs" : "as", asClass.getCanonicalName() + ".class")));
}
if (codeGenConfig.isWithMPOpenApiAnnotation() || codeGenConfig.isWithIOSwaggerOASv3Annotation()) {
annotateFieldWithOAS(annotations);
}
return annotations;
}
Aggregations