Search in sources :

Example 76 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class ThymeleafMetadata method getShowInlineMethod.

/**
 * This method provides the "showInline" method using Thymeleaf view response type
 *
 * @return MethodMetadata
 */
private MethodMetadata getShowInlineMethod() {
    // Define methodName
    final JavaSymbolName methodName = SHOW_INLINE_METHOD_NAME;
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(this.entity, ANN_METADATA_MODEL_ATTRIBUTE));
    parameterTypes.add(MODEL_PARAM);
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName(entityItemName));
    parameterNames.add(MODEL_PARAM_NAME);
    // Adding annotations
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Adding @RequestMapping annotation
    AnnotationMetadataBuilder getMappingAnnotation = new AnnotationMetadataBuilder(GET_MAPPING);
    getMappingAnnotation.addStringAttribute("value", "/inline");
    getMappingAnnotation.addStringAttribute("name", methodName.getSymbolName());
    annotations.add(getMappingAnnotation);
    // Generate body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // model.addAttribute("entity", entityParam)
    bodyBuilder.appendFormalLine("model.addAttribute(\"%s\", %s);", entityItemName, entityItemName);
    // return new ModelAndView("customers/showInline :: inline-content");
    bodyBuilder.appendFormalLine("return new %s(\"%s/showInline :: inline-content\");", getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), viewsPath);
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, SpringJavaType.MODEL_AND_VIEW, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    return methodBuilder.build();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 77 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class ThymeleafMetadata method getEditFormMethod.

/**
 * This method provides the "edit" form method using Thymeleaf view response
 * type
 *
 * @return MethodMetadata
 */
private MethodMetadata getEditFormMethod() {
    // Define methodName
    final JavaSymbolName methodName = EDIT_FORM_METHOD_NAME;
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(this.entity, ANN_METADATA_MODEL_ATTRIBUTE));
    parameterTypes.add(MODEL_PARAM);
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName(entityItemName));
    parameterNames.add(MODEL_PARAM_NAME);
    // Adding annotations
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Adding @GetMapping annotation
    final AnnotationMetadataBuilder getMapping = new AnnotationMetadataBuilder(GET_MAPPING);
    getMapping.addStringAttribute("value", "/edit-form");
    getMapping.addStringAttribute("name", methodName.getSymbolName());
    annotations.add(getMapping);
    this.mvcMethodNames.put(methodName.getSymbolName(), methodName.getSymbolName());
    // Generate body
    final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // populateFormats(model);
    bodyBuilder.appendFormalLine("%s(model);", populateFormMethod.getMethodName());
    bodyBuilder.newLine();
    // model.addAttribute("entity", entityParam)
    bodyBuilder.appendFormalLine("model.addAttribute(\"%s\", %s);", entityItemName, entityItemName);
    // return new ModelAndView("customers/edit");
    bodyBuilder.appendFormalLine("return new %s(\"%s/edit\");", getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), viewsPath);
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, SpringJavaType.MODEL_AND_VIEW, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    return methodBuilder.build();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Example 78 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class ThymeleafMetadata method getAddColumnToReportBuilderMethod.

/* Jasper Export Methods */
/**
 * Generates a method to add columns to DynamicJasper report builder.
 *
 * @return MethodMetadata
 */
private MethodMetadata getAddColumnToReportBuilderMethod() {
    JavaSymbolName methodName = ADD_COLUMN_TO_REPORT_BUILDER_METHOD_NAME;
    // Including parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(STRING_PARAM);
    parameterTypes.add(new AnnotatedJavaType(FAST_REPORT_BUILDER));
    parameterTypes.add(LOCALE_PARAM);
    parameterTypes.add(STRING_PARAM);
    // Check method existence
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    // Including parameter names
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    final JavaSymbolName columnName = new JavaSymbolName("columnName");
    parameterNames.add(columnName);
    final JavaSymbolName reportBuilder = new JavaSymbolName("builder");
    parameterNames.add(reportBuilder);
    parameterNames.add(LOCALE_PARAM_NAME);
    parameterNames.add(FILE_NAME_PARAM_NAME);
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // try {
    bodyBuilder.appendFormalLine("try {");
    for (int i = 0; i < this.entityValidFields.size(); i++) {
        FieldMetadata fieldMetadata = this.entityValidFields.get(i);
        String fieldName = fieldMetadata.getFieldName().getSymbolName();
        if (i == 0) {
            // if (columnName.equals("FIELD")) {
            bodyBuilder.appendFormalLine("if (columnName.equals(\"%s\")) {", fieldName);
        } else {
            // else if (columnName.equals("FIELD")) {
            bodyBuilder.appendFormalLine("else if (columnName.equals(\"%s\")) {", fieldName);
        }
        bodyBuilder.indent();
        JavaType fieldType = fieldMetadata.getFieldType();
        if (fieldMetadata.getFieldName().equals(this.entityMetadata.getCurrentIndentifierField().getFieldName())) {
            // 50);
            if (fieldType.isPrimitive()) {
                // Print SimpleTypeName of JavaType when it is a primitive
                bodyBuilder.appendFormalLine("builder.addColumn(%s().getMessage(\"%s_%s\", null, \"%s\", locale), \"%s\", %s.class.getName(), 50);", getAccessorMethod(this.messageSourceField).getMethodName(), this.entityLabel, fieldName.toLowerCase(), getFieldDefaultLabelValue(fieldName), fieldName, fieldType.getSimpleTypeName());
                // assure import of fielType is in aj
                getNameOfJavaType(fieldType);
            } else {
                bodyBuilder.appendFormalLine("builder.addColumn(%s().getMessage(\"%s_%s\", null, \"%s\", locale), \"%s\", %s.class.getName(), 50);", getAccessorMethod(this.messageSourceField).getMethodName(), this.entityLabel, fieldName.toLowerCase(), getFieldDefaultLabelValue(fieldName), fieldName, getNameOfJavaType(fieldType.withoutParameters()));
            }
        } else {
            // 100);
            if (fieldType.isPrimitive()) {
                bodyBuilder.appendFormalLine("builder.addColumn(%s().getMessage(\"%s_%s\", null, \"%s\", locale), \"%s\", %s.class.getName(), 100);", getAccessorMethod(this.messageSourceField).getMethodName(), this.entityLabel, fieldName.toLowerCase(), getFieldDefaultLabelValue(fieldName), fieldName, fieldType.getSimpleTypeName());
                // assure import of fielType is in aj
                getNameOfJavaType(fieldType);
            } else {
                bodyBuilder.appendFormalLine("builder.addColumn(%s().getMessage(\"%s_%s\", null, \"%s\", locale), \"%s\", %s.class.getName(), 100);", getAccessorMethod(this.messageSourceField).getMethodName(), this.entityLabel, fieldName.toLowerCase(), getFieldDefaultLabelValue(fieldName), fieldName, getNameOfJavaType(fieldType.withoutParameters()));
            }
        }
        bodyBuilder.indentRemove();
        bodyBuilder.appendFormalLine("}");
    }
    // }
    bodyBuilder.appendFormalLine("}");
    // Build catch blocks
    buildExportCatchBlock(bodyBuilder, COLUMN_BUILDER_EXCEPTION);
    buildExportCatchBlock(bodyBuilder, CLASS_NOT_FOUND_EXCEPTION);
    // Build method
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, JavaType.VOID_PRIMITIVE, parameterTypes, parameterNames, bodyBuilder);
    // Add Javadoc to method
    CommentStructure commentStructure = new CommentStructure();
    String description = "This method contains all the entity fields that are able to be displayed in a ".concat(IOUtils.LINE_SEPARATOR).concat("report. The developer could add a new column to the report builder providing the ").concat(IOUtils.LINE_SEPARATOR).concat("field name and the builder where the new field will be added as column.");
    List<String> paramInfo = new ArrayList<String>();
    paramInfo.add("columnName the field name to show as column");
    paramInfo.add("builder The builder where the new field will be added as column.");
    commentStructure.addComment(new JavadocComment(description, paramInfo, null, null), CommentLocation.BEGINNING);
    methodBuilder.setCommentStructure(commentStructure);
    return methodBuilder.build();
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) CommentStructure(org.springframework.roo.classpath.details.comments.CommentStructure) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) Jsr303JavaType(org.springframework.roo.model.Jsr303JavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JavaType(org.springframework.roo.model.JavaType) JavadocComment(org.springframework.roo.classpath.details.comments.JavadocComment) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 79 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class ThymeleafMetadata method getPdfExportMethod.

/**
 * Generates a method to export data to PDF using DynamicJasper.
 *
 * @return MethodMetadata
 */
private MethodMetadata getPdfExportMethod() {
    if (jasperReportsMap.get("JasperReportsPdfExporter") != null) {
        final String exporterMethodInvocation = String.format("new %s()", getNameOfJavaType(jasperReportsMap.get("JasperReportsPdfExporter")));
        final String fileName = String.format("%s_report.pdf", StringUtils.uncapitalize(this.entityPlural));
        final JavaSymbolName methodName = EXPORT_PDF_METHOD_NAME;
        return buildExportTypeMethod(exporterMethodInvocation, fileName, methodName, "exportPdf", "/export/pdf", "PDF");
    }
    return null;
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName)

Example 80 with JavaSymbolName

use of org.springframework.roo.model.JavaSymbolName in project spring-roo by spring-projects.

the class ThymeleafMetadata method getShowDetailInlineMethod.

/**
 * This method provides the "showInline" detail method using Thymeleaf view
 * response type
 *
 * @return MethodMetadata
 */
private MethodMetadata getShowDetailInlineMethod() {
    // Define methodName
    final JavaSymbolName methodName = SHOW_INLINE_METHOD_NAME;
    final RelationInfoExtended info = controllerMetadata.getLastDetailsInfo();
    final JavaType parentEntity = info.entityType;
    final JavaType entity = info.childType;
    final String entityItemName = StringUtils.uncapitalize(entity.getSimpleTypeName());
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(new AnnotatedJavaType(parentEntity, ANN_METADATA_MODEL_ATTRIBUTE));
    parameterTypes.add(new AnnotatedJavaType(entity, ANN_METADATA_MODEL_ATTRIBUTE));
    parameterTypes.add(MODEL_PARAM);
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(parentEntity.getSimpleTypeName())));
    parameterNames.add(new JavaSymbolName(entityItemName));
    parameterNames.add(MODEL_PARAM_NAME);
    // Adding annotations
    final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
    // Adding @RequestMapping annotation
    AnnotationMetadataBuilder getMappingAnnotation = new AnnotationMetadataBuilder(GET_MAPPING);
    getMappingAnnotation.addStringAttribute("value", "/inline");
    getMappingAnnotation.addStringAttribute("name", methodName.getSymbolName());
    annotations.add(getMappingAnnotation);
    // Generate body
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    // model.addAttribute("entity", entityParam)
    bodyBuilder.appendFormalLine("model.addAttribute(\"%s\", %s);", entityItemName, entityItemName);
    // return new ModelAndView("customerorders/details/showInline :: inline-content");
    bodyBuilder.appendFormalLine("return new %s(\"%s/%s/showInline :: inline-content\");", getNameOfJavaType(SpringJavaType.MODEL_AND_VIEW), viewsPath, controllerMetadata.getDetailsPathAsString("/"));
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, methodName, SpringJavaType.MODEL_AND_VIEW, parameterTypes, parameterNames, bodyBuilder);
    methodBuilder.setAnnotations(annotations);
    return methodBuilder.build();
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) Jsr303JavaType(org.springframework.roo.model.Jsr303JavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JavaType(org.springframework.roo.model.JavaType) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) RelationInfoExtended(org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder) AnnotationMetadataBuilder(org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)

Aggregations

JavaSymbolName (org.springframework.roo.model.JavaSymbolName)317 ArrayList (java.util.ArrayList)186 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)155 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)143 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)142 JavaType (org.springframework.roo.model.JavaType)133 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)121 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)119 SpringJavaType (org.springframework.roo.model.SpringJavaType)61 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)59 JdkJavaType (org.springframework.roo.model.JdkJavaType)59 FieldMetadataBuilder (org.springframework.roo.classpath.details.FieldMetadataBuilder)48 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)47 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)45 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)39 AnnotationAttributeValue (org.springframework.roo.classpath.details.annotations.AnnotationAttributeValue)36 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)29 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)29 StringAttributeValue (org.springframework.roo.classpath.details.annotations.StringAttributeValue)27 EnumDetails (org.springframework.roo.model.EnumDetails)25