Search in sources :

Example 16 with MethodMetadata

use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.

the class JpaEntityMetadata method getAddValueMethod.

/**
 * Create add method to handle referenced relation
 *
 * @param addMethodName
 * @param field
 * @param cardinality
 * @param childType
 * @param mappedBy
 * @param removeMethodName
 * @param importResolver
 * @return method metadata or null if method already in class
 */
private MethodMetadata getAddValueMethod(final JavaSymbolName addMethodName, final FieldMetadata field, final Cardinality cardinality, final JavaType childType, final String mappedBy, final JavaSymbolName removeMethodName, ImportRegistrationResolver importResolver) {
    // Identify parameters type and name
    final List<JavaType> parameterTypes = new ArrayList<JavaType>(1);
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(1);
    if (cardinality == Cardinality.ONE_TO_ONE) {
        parameterTypes.add(childType);
        parameterNames.add(field.getFieldName());
    } else {
        parameterTypes.add(JavaType.iterableOf(childType));
        parameterNames.add(new JavaSymbolName(field.getFieldName().getSymbolName() + ADD_PARAMETER_SUFFIX));
    }
    // See if the type itself declared the method
    MethodMetadata existingMethod = getGovernorMethod(addMethodName, parameterTypes);
    if (existingMethod != null) {
        return existingMethod;
    }
    final InvocableMemberBodyBuilder builder = new InvocableMemberBodyBuilder();
    if (cardinality == Cardinality.ONE_TO_ONE) {
        buildAddOneToOneBody(field, mappedBy, parameterNames.get(0), childType, removeMethodName, builder);
    } else if (cardinality == Cardinality.ONE_TO_MANY) {
        buildAddOneToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver);
    } else {
        buildAddManyToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver);
    }
    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, addMethodName, JavaType.VOID_PRIMITIVE, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, builder).build();
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 17 with MethodMetadata

use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.

the class JpaEntityMetadata method getRemoveMethod.

/**
 * Create remove method to handle referenced relation
 *
 * @param removeMethodName
 * @param field
 * @param cardinality
 * @param childType
 * @param mappedBy
 * @param importResolver
 * @return method metadata or null if method already in class
 */
private MethodMetadata getRemoveMethod(final JavaSymbolName removeMethodName, final FieldMetadata field, final Cardinality cardinality, final JavaType childType, final String mappedBy, ImportRegistrationResolver importResolver) {
    // Identify parameters types and names (if any)
    final List<JavaType> parameterTypes = new ArrayList<JavaType>(1);
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>(1);
    if (cardinality != Cardinality.ONE_TO_ONE) {
        parameterTypes.add(JavaType.iterableOf(childType));
        parameterNames.add(new JavaSymbolName(field.getFieldName().getSymbolName() + REMOVE_PARAMETER_SUFFIX));
    }
    // See if the type itself declared the method
    MethodMetadata existingMethod = getGovernorMethod(removeMethodName, parameterTypes);
    if (existingMethod != null) {
        return existingMethod;
    }
    final InvocableMemberBodyBuilder builder = new InvocableMemberBodyBuilder();
    if (cardinality == Cardinality.ONE_TO_ONE) {
        buildRemoveOneToOneBody(field, mappedBy, builder);
    } else if (cardinality == Cardinality.ONE_TO_MANY) {
        buildRemoveOneToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver);
    } else {
        // ManyToMany
        buildRemoveManyToManyBody(field, mappedBy, parameterNames.get(0), childType, builder, importResolver);
    }
    return new MethodMetadataBuilder(getId(), Modifier.PUBLIC, removeMethodName, JavaType.VOID_PRIMITIVE, AnnotatedJavaType.convertFromJavaTypes(parameterTypes), parameterNames, builder).build();
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) MethodMetadataBuilder(org.springframework.roo.classpath.details.MethodMetadataBuilder) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) InvocableMemberBodyBuilder(org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)

Example 18 with MethodMetadata

use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.

the class SeiImplMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Getting annotated class details
    ClassOrInterfaceTypeDetails endpoint = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
    AnnotationMetadata seiImplAnnotation = endpoint.getAnnotation(ROO_SEI_IMPL);
    AnnotationAttributeValue<?> seiAttr = seiImplAnnotation.getAttribute(new JavaSymbolName("sei"));
    Validate.notNull(seiAttr, "ERROR: You must provide a valid SEI to be able to generate a Endpoint.");
    // Getting SEI from annotation
    JavaType seiType = (JavaType) seiAttr.getValue();
    // Getting SEI details
    ClassOrInterfaceTypeDetails seiTypeDetails = getTypeLocationService().getTypeDetails(seiType);
    // Getting SEI Metadata
    final String seiMetadataId = SeiMetadata.createIdentifier(seiTypeDetails.getType(), PhysicalTypeIdentifier.getPath(seiTypeDetails.getDeclaredByMetadataId()));
    final SeiMetadata seiMetadata = (SeiMetadata) getMetadataService().get(seiMetadataId);
    // Getting SEI methods from service and save it
    Map<MethodMetadata, MethodMetadata> seiMethods = seiMetadata.getSeiMethods();
    // Registering dependency between SeiMetadata and this one, to be able to
    // update Endpoint if SEI changes
    final String seiMetadataKey = SeiMetadata.createIdentifier(seiTypeDetails);
    registerDependency(seiMetadataKey, metadataIdentificationString);
    return new SeiImplMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, getProjectOperations().getTopLevelPackage(""), endpoint, seiType, seiMetadata.getService(), seiMethods);
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata)

Example 19 with MethodMetadata

use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.

the class JaxbEntityMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Getting the annotated entity type
    JavaType annotatedEntity = governorPhysicalTypeMetadata.getType();
    // Getting the entity details
    ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(annotatedEntity);
    // Getting the plural
    String entityPlural = getPluralService().getPlural(entityDetails);
    // Getting JavaBean Metadata
    String javaBeanMetadataKey = JavaBeanMetadata.createIdentifier(entityDetails);
    JavaBeanMetadata javaBeanMetadata = getMetadataService().get(javaBeanMetadataKey);
    // Getting JpaEntity Metadata
    String jpaEntityMetadataKey = JpaEntityMetadata.createIdentifier(entityDetails);
    JpaEntityMetadata jpaEntityMetadata = getMetadataService().get(jpaEntityMetadataKey);
    if (javaBeanMetadata == null) {
        // Not ready for this metadata
        return null;
    }
    // Getting the @OneToMany and @ManyToOne getters
    Map<String, String> entityNames = new HashMap<String, String>();
    List<MethodMetadata> oneToManyGetters = new ArrayList<MethodMetadata>();
    List<MethodMetadata> manyToOneGetters = new ArrayList<MethodMetadata>();
    for (FieldMetadata field : entityDetails.getDeclaredFields()) {
        // Getting getter for the oneToMany field
        MethodMetadata getter = javaBeanMetadata.getAccesorMethod(field);
        if (getter != null && (field.getAnnotation(JpaJavaType.ONE_TO_MANY) != null || field.getAnnotation(JpaJavaType.MANY_TO_MANY) != null)) {
            String getterTypeName = getter.getReturnType().getBaseType().getSimpleTypeName().toLowerCase();
            oneToManyGetters.add(getter);
            entityNames.put(getterTypeName, getPluralService().getPlural(getterTypeName));
        } else if (getter != null && field.getAnnotation(JpaJavaType.MANY_TO_ONE) != null) {
            String getterTypeName = getter.getReturnType().getSimpleTypeName().toLowerCase();
            manyToOneGetters.add(getter);
            entityNames.put(getterTypeName, getPluralService().getPlural(getterTypeName));
        }
    }
    // Getting the identifier accessor only if the annotated class doesn't have
    // parent
    MethodMetadata identifierAccessor = null;
    if (jpaEntityMetadata != null && jpaEntityMetadata.getParent() == null) {
        identifierAccessor = jpaEntityMetadata.getCurrentIdentifierAccessor();
    }
    return new JaxbEntityMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, getProjectOperations().getTopLevelPackage(""), annotatedEntity, entityPlural, identifierAccessor, oneToManyGetters, manyToOneGetters, entityNames);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) JavaBeanMetadata(org.springframework.roo.addon.javabean.addon.JavaBeanMetadata) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)

Example 20 with MethodMetadata

use of org.springframework.roo.classpath.details.MethodMetadata in project spring-roo by spring-projects.

the class JspMetadataListener method get.

public MetadataItem get(final String jspMetadataId) {
    // Work out the MIDs of the other metadata we depend on
    // NB: The JavaType and Path are to the corresponding web scaffold
    // controller class
    final String webScaffoldMetadataKey = WebScaffoldMetadata.createIdentifier(JspMetadata.getJavaType(jspMetadataId), JspMetadata.getPath(jspMetadataId));
    final WebScaffoldMetadata webScaffoldMetadata = (WebScaffoldMetadata) getMetadataService().get(webScaffoldMetadataKey);
    if (webScaffoldMetadata == null || !webScaffoldMetadata.isValid()) {
        // to manage any JSPs at this time
        return null;
    }
    final JavaType formBackingType = webScaffoldMetadata.getAnnotationValues().getFormBackingObject();
    final MemberDetails memberDetails = getWebMetadataService().getMemberDetails(formBackingType);
    final JavaTypeMetadataDetails formBackingTypeMetadataDetails = getWebMetadataService().getJavaTypeMetadataDetails(formBackingType, memberDetails, jspMetadataId);
    Validate.notNull(formBackingTypeMetadataDetails, "Unable to obtain metadata for type %s", formBackingType.getFullyQualifiedTypeName());
    formBackingObjectTypesToLocalMids.put(formBackingType, jspMetadataId);
    final SortedMap<JavaType, JavaTypeMetadataDetails> relatedTypeMd = getWebMetadataService().getRelatedApplicationTypeMetadata(formBackingType, memberDetails, jspMetadataId);
    final JavaTypeMetadataDetails formbackingTypeMetadata = relatedTypeMd.get(formBackingType);
    Validate.notNull(formbackingTypeMetadata, "Form backing type metadata required");
    final JavaTypePersistenceMetadataDetails formBackingTypePersistenceMetadata = formbackingTypeMetadata.getPersistenceDetails();
    if (formBackingTypePersistenceMetadata == null) {
        return null;
    }
    final ClassOrInterfaceTypeDetails formBackingTypeDetails = getTypeLocationService().getTypeDetails(formBackingType);
    final LogicalPath formBackingTypePath = PhysicalTypeIdentifier.getPath(formBackingTypeDetails.getDeclaredByMetadataId());
    getMetadataDependencyRegistry().registerDependency(PhysicalTypeIdentifier.createIdentifier(formBackingType, formBackingTypePath), JspMetadata.createIdentifier(formBackingType, formBackingTypePath));
    final LogicalPath path = JspMetadata.getPath(jspMetadataId);
    // Install web artifacts only if Spring MVC config is missing
    // TODO: Remove this call when 'controller' commands are gone
    final PathResolver pathResolver = getProjectOperations().getPathResolver();
    final LogicalPath webappPath = LogicalPath.getInstance(Path.SRC_MAIN_WEBAPP, path.getModule());
    if (!getFileManager().exists(pathResolver.getIdentifier(webappPath, WEB_INF_VIEWS))) {
        getJspOperations().installCommonViewArtefacts(path.getModule());
    }
    installImage(webappPath, "images/show.png");
    if (webScaffoldMetadata.getAnnotationValues().isUpdate()) {
        installImage(webappPath, "images/update.png");
    }
    if (webScaffoldMetadata.getAnnotationValues().isDelete()) {
        installImage(webappPath, "images/delete.png");
    }
    final List<FieldMetadata> eligibleFields = getWebMetadataService().getScaffoldEligibleFieldMetadata(formBackingType, memberDetails, jspMetadataId);
    if (eligibleFields.isEmpty() && formBackingTypePersistenceMetadata.getRooIdentifierFields().isEmpty()) {
        return null;
    }
    final JspViewManager viewManager = new JspViewManager(eligibleFields, webScaffoldMetadata.getAnnotationValues(), relatedTypeMd);
    String controllerPath = webScaffoldMetadata.getAnnotationValues().getPath();
    if (controllerPath.startsWith("/")) {
        controllerPath = controllerPath.substring(1);
    }
    // Make the holding directory for this controller
    final String destinationDirectory = pathResolver.getIdentifier(webappPath, WEB_INF_VIEWS + controllerPath);
    if (!getFileManager().exists(destinationDirectory)) {
        getFileManager().createDirectory(destinationDirectory);
    } else {
        final File file = new File(destinationDirectory);
        Validate.isTrue(file.isDirectory(), "%s is a file, when a directory was expected", destinationDirectory);
    }
    // By now we have a directory to put the JSPs inside
    final String listPath1 = destinationDirectory + "/list.jspx";
    getXmlRoundTripFileManager().writeToDiskIfNecessary(listPath1, viewManager.getListDocument());
    getTilesOperations().addViewDefinition(controllerPath, webappPath, controllerPath + "/" + "list", TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS + controllerPath + "/list.jspx");
    final String showPath = destinationDirectory + "/show.jspx";
    getXmlRoundTripFileManager().writeToDiskIfNecessary(showPath, viewManager.getShowDocument());
    getTilesOperations().addViewDefinition(controllerPath, webappPath, controllerPath + "/" + "show", TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS + controllerPath + "/show.jspx");
    final Map<String, String> properties = new LinkedHashMap<String, String>();
    final JavaSymbolName categoryName = new JavaSymbolName(formBackingType.getSimpleTypeName());
    properties.put("menu_category_" + categoryName.getSymbolName().toLowerCase() + "_label", categoryName.getReadableSymbolName());
    final JavaSymbolName newMenuItemId = new JavaSymbolName("new");
    properties.put("menu_item_" + categoryName.getSymbolName().toLowerCase() + "_" + newMenuItemId.getSymbolName().toLowerCase() + "_label", new JavaSymbolName(formBackingType.getSimpleTypeName()).getReadableSymbolName());
    if (webScaffoldMetadata.getAnnotationValues().isCreate()) {
        final String listPath = destinationDirectory + "/create.jspx";
        getXmlRoundTripFileManager().writeToDiskIfNecessary(listPath, viewManager.getCreateDocument());
        // Add 'create new' menu item
        getMenuOperations().addMenuItem(categoryName, newMenuItemId, "global_menu_new", "/" + controllerPath + "?form", MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
        getTilesOperations().addViewDefinition(controllerPath, webappPath, controllerPath + "/" + "create", TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS + controllerPath + "/create.jspx");
    } else {
        getMenuOperations().cleanUpMenuItem(categoryName, new JavaSymbolName("new"), MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
        getTilesOperations().removeViewDefinition(controllerPath + "/" + "create", controllerPath, webappPath);
    }
    if (webScaffoldMetadata.getAnnotationValues().isUpdate()) {
        final String listPath = destinationDirectory + "/update.jspx";
        getXmlRoundTripFileManager().writeToDiskIfNecessary(listPath, viewManager.getUpdateDocument());
        getTilesOperations().addViewDefinition(controllerPath, webappPath, controllerPath + "/" + "update", TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS + controllerPath + "/update.jspx");
    } else {
        getTilesOperations().removeViewDefinition(controllerPath + "/" + "update", controllerPath, webappPath);
    }
    // Setup labels for i18n support
    final String resourceId = XmlUtils.convertId("label." + formBackingType.getFullyQualifiedTypeName().toLowerCase());
    properties.put(resourceId, new JavaSymbolName(formBackingType.getSimpleTypeName()).getReadableSymbolName());
    final String pluralResourceId = XmlUtils.convertId(resourceId + ".plural");
    final String plural = formBackingTypeMetadataDetails.getPlural();
    properties.put(pluralResourceId, new JavaSymbolName(plural).getReadableSymbolName());
    final JavaTypePersistenceMetadataDetails javaTypePersistenceMetadataDetails = formBackingTypeMetadataDetails.getPersistenceDetails();
    Validate.notNull(javaTypePersistenceMetadataDetails, "Unable to determine persistence metadata for type %s", formBackingType.getFullyQualifiedTypeName());
    if (!javaTypePersistenceMetadataDetails.getRooIdentifierFields().isEmpty()) {
        for (final FieldMetadata idField : javaTypePersistenceMetadataDetails.getRooIdentifierFields()) {
            properties.put(XmlUtils.convertId(resourceId + "." + javaTypePersistenceMetadataDetails.getIdentifierField().getFieldName().getSymbolName() + "." + idField.getFieldName().getSymbolName().toLowerCase()), idField.getFieldName().getReadableSymbolName());
        }
    }
    // If no auto generated value for id, put name in i18n
    if (javaTypePersistenceMetadataDetails.getIdentifierField().getAnnotation(JpaJavaType.GENERATED_VALUE) == null) {
        properties.put(XmlUtils.convertId(resourceId + "." + javaTypePersistenceMetadataDetails.getIdentifierField().getFieldName().getSymbolName().toLowerCase()), javaTypePersistenceMetadataDetails.getIdentifierField().getFieldName().getReadableSymbolName());
    }
    for (final MethodMetadata method : memberDetails.getMethods()) {
        if (!BeanInfoUtils.isAccessorMethod(method)) {
            continue;
        }
        final FieldMetadata field = BeanInfoUtils.getFieldForJavaBeanMethod(memberDetails, method);
        if (field == null) {
            continue;
        }
        final JavaSymbolName fieldName = field.getFieldName();
        final String fieldResourceId = XmlUtils.convertId(resourceId + "." + fieldName.getSymbolName().toLowerCase());
        if (getTypeLocationService().isInProject(method.getReturnType()) && getWebMetadataService().isRooIdentifier(method.getReturnType(), getWebMetadataService().getMemberDetails(method.getReturnType()))) {
            final JavaTypePersistenceMetadataDetails typePersistenceMetadataDetails = getWebMetadataService().getJavaTypePersistenceMetadataDetails(method.getReturnType(), getWebMetadataService().getMemberDetails(method.getReturnType()), jspMetadataId);
            if (typePersistenceMetadataDetails != null) {
                for (final FieldMetadata f : typePersistenceMetadataDetails.getRooIdentifierFields()) {
                    final String sb = f.getFieldName().getReadableSymbolName();
                    properties.put(XmlUtils.convertId(resourceId + "." + javaTypePersistenceMetadataDetails.getIdentifierField().getFieldName().getSymbolName() + "." + f.getFieldName().getSymbolName().toLowerCase()), StringUtils.isNotBlank(sb) ? sb : fieldName.getSymbolName());
                }
            }
        } else if (!method.getMethodName().equals(javaTypePersistenceMetadataDetails.getIdentifierAccessorMethod().getMethodName()) || javaTypePersistenceMetadataDetails.getVersionAccessorMethod() != null && !method.getMethodName().equals(javaTypePersistenceMetadataDetails.getVersionAccessorMethod().getMethodName())) {
            final String sb = fieldName.getReadableSymbolName();
            properties.put(fieldResourceId, StringUtils.isNotBlank(sb) ? sb : fieldName.getSymbolName());
        }
    }
    if (javaTypePersistenceMetadataDetails.getFindAllMethod() != null) {
        // Add 'list all' menu item
        final JavaSymbolName listMenuItemId = new JavaSymbolName("list");
        getMenuOperations().addMenuItem(categoryName, listMenuItemId, "global_menu_list", "/" + controllerPath + "?page=1&size=${empty param.size ? 10 : param.size}", MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
        properties.put("menu_item_" + categoryName.getSymbolName().toLowerCase() + "_" + listMenuItemId.getSymbolName().toLowerCase() + "_label", new JavaSymbolName(plural).getReadableSymbolName());
    } else {
        getMenuOperations().cleanUpMenuItem(categoryName, new JavaSymbolName("list"), MenuOperations.DEFAULT_MENU_ITEM_PREFIX, webappPath);
    }
    final String controllerPhysicalTypeId = PhysicalTypeIdentifier.createIdentifier(JspMetadata.getJavaType(jspMetadataId), JspMetadata.getPath(jspMetadataId));
    final PhysicalTypeMetadata controllerPhysicalTypeMd = (PhysicalTypeMetadata) getMetadataService().get(controllerPhysicalTypeId);
    if (controllerPhysicalTypeMd == null) {
        return null;
    }
    final MemberHoldingTypeDetails mhtd = controllerPhysicalTypeMd.getMemberHoldingTypeDetails();
    if (mhtd == null) {
        return null;
    }
    final List<String> allowedMenuItems = new ArrayList<String>();
    if (MemberFindingUtils.getAnnotationOfType(mhtd.getAnnotations(), RooJavaType.ROO_WEB_FINDER) != null) {
        // This controller is annotated with @RooWebFinder
        final Set<FinderMetadataDetails> finderMethodsDetails = getWebMetadataService().getDynamicFinderMethodsAndFields(formBackingType, memberDetails, jspMetadataId);
        if (finderMethodsDetails == null) {
            return null;
        }
        for (final FinderMetadataDetails finderDetails : finderMethodsDetails) {
            final String finderName = finderDetails.getFinderMethodMetadata().getMethodName().getSymbolName();
            final String listPath = destinationDirectory + "/" + finderName + ".jspx";
            // long (see ROO-1027)
            if (listPath.length() > 244) {
                continue;
            }
            getXmlRoundTripFileManager().writeToDiskIfNecessary(listPath, viewManager.getFinderDocument(finderDetails));
            final JavaSymbolName finderLabel = new JavaSymbolName(finderName.replace("find" + plural + "By", ""));
            // Add 'Find by' menu item
            getMenuOperations().addMenuItem(categoryName, finderLabel, "global_menu_find", "/" + controllerPath + "?find=" + finderName.replace("find" + plural, "") + "&form" + "&page=1&size=${empty param.size ? 10 : param.size}", MenuOperations.FINDER_MENU_ITEM_PREFIX, webappPath);
            properties.put("menu_item_" + categoryName.getSymbolName().toLowerCase() + "_" + finderLabel.getSymbolName().toLowerCase() + "_label", finderLabel.getReadableSymbolName());
            allowedMenuItems.add(MenuOperations.FINDER_MENU_ITEM_PREFIX + categoryName.getSymbolName().toLowerCase() + "_" + finderLabel.getSymbolName().toLowerCase());
            for (final JavaSymbolName paramName : finderDetails.getFinderMethodMetadata().getParameterNames()) {
                properties.put(XmlUtils.convertId(resourceId + "." + paramName.getSymbolName().toLowerCase()), paramName.getReadableSymbolName());
            }
            getTilesOperations().addViewDefinition(controllerPath, webappPath, controllerPath + "/" + finderName, TilesOperations.DEFAULT_TEMPLATE, WEB_INF_VIEWS + controllerPath + "/" + finderName + ".jspx");
        }
    }
    getMenuOperations().cleanUpFinderMenuItems(categoryName, allowedMenuItems, webappPath);
    return new JspMetadata(jspMetadataId, webScaffoldMetadata);
}
Also used : JavaTypePersistenceMetadataDetails(org.springframework.roo.addon.web.mvc.controller.addon.details.JavaTypePersistenceMetadataDetails) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) WebScaffoldMetadata(org.springframework.roo.addon.web.mvc.controller.addon.scaffold.WebScaffoldMetadata) JavaTypeMetadataDetails(org.springframework.roo.addon.web.mvc.controller.addon.details.JavaTypeMetadataDetails) LogicalPath(org.springframework.roo.project.LogicalPath) PathResolver(org.springframework.roo.project.PathResolver) FinderMetadataDetails(org.springframework.roo.addon.web.mvc.controller.addon.details.FinderMetadataDetails) RooJavaType(org.springframework.roo.model.RooJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) PhysicalTypeMetadata(org.springframework.roo.classpath.PhysicalTypeMetadata) MemberHoldingTypeDetails(org.springframework.roo.classpath.details.MemberHoldingTypeDetails) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) File(java.io.File)

Aggregations

MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)149 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)119 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)115 ArrayList (java.util.ArrayList)111 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)110 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)92 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)73 JavaType (org.springframework.roo.model.JavaType)72 SpringJavaType (org.springframework.roo.model.SpringJavaType)40 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)39 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)38 JdkJavaType (org.springframework.roo.model.JdkJavaType)28 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)27 RooJavaType (org.springframework.roo.model.RooJavaType)22 ServiceMetadata (org.springframework.roo.addon.layers.service.addon.ServiceMetadata)18 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)18 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)17 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)16 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)16 JpaJavaType (org.springframework.roo.model.JpaJavaType)15