Search in sources :

Example 61 with AnnotatedJavaType

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

the class ServiceMetadata method getFindAllIterableMethod.

/**
 * Method that generates method "findAll" with iterable parameter.
 *
 * @return MethodMetadataBuilder with public List <Entity> findAll(Iterable
 *         <Long> ids) structure
 */
private MethodMetadata getFindAllIterableMethod() {
    // Define method name
    JavaSymbolName methodName = new JavaSymbolName("findAll");
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(identifierType)));
    // Define method parameter names
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName("ids"));
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    JavaType listEntityJavaType = JavaType.listOf(entity);
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, listEntityJavaType, parameterTypes, parameterNames, null);
    // Build and return a MethodMetadata
    return methodBuilder.build();
// instance
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JavaType(org.springframework.roo.model.JavaType) 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)

Example 62 with AnnotatedJavaType

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

the class ServiceMetadata method getSetRelationMethod.

/**
 * Generates "setRelation" Method for this service
 * @param relationInfo
 * @return
 */
private MethodMetadata getSetRelationMethod(RelationInfo relationInfo) {
    // Define method name
    final JavaSymbolName methodName = new JavaSymbolName("set" + relationInfo.fieldMetadata.getFieldName().getSymbolNameCapitalisedFirstLetter());
    // Define method parameter types
    final List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    // add parent entity parameter
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(entity));
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(entity.getSimpleTypeName())));
    // add child entity parameter
    parameterNames.add(relationInfo.fieldMetadata.getFieldName());
    if (relationInfo.cardinality == Cardinality.ONE_TO_ONE) {
        parameterTypes.add(AnnotatedJavaType.convertFromJavaType(relationInfo.childType));
    } else if (relationInfo.type == JpaRelationType.COMPOSITION) {
        // Use objects
        parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(relationInfo.childType)));
    } else {
        // AGGREGATION: Use Child Pk: Get related entity metadata
        JpaEntityMetadata childEntityMetadata = relatedEntitiesMetadata.get(relationInfo.childType);
        Validate.notNull(childEntityMetadata, "Can't get entity metadata for %s entity generating %s", relationInfo.childType, aspectName);
        parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.iterableOf(childEntityMetadata.getCurrentIndentifierField().getFieldType())));
    }
    MethodMetadata existingMethod = getGovernorMethod(methodName, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
    if (existingMethod != null) {
        return existingMethod;
    }
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, entity, parameterTypes, parameterNames, null);
    // Build and return a MethodMetadata
    return methodBuilder.build();
// instance
}
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) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)

Example 63 with AnnotatedJavaType

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

the class ServiceMetadataProviderImpl method registerDependencyModulesOfFinder.

private void registerDependencyModulesOfFinder(final PhysicalTypeMetadata governorPhysicalTypeMetadata, MethodMetadata finder) {
    // Add dependencies between modules
    List<JavaType> types = new ArrayList<JavaType>();
    types.add(finder.getReturnType());
    types.addAll(finder.getReturnType().getParameters());
    for (AnnotatedJavaType parameter : finder.getParameterTypes()) {
        types.add(parameter.getJavaType());
        types.addAll(parameter.getJavaType().getParameters());
    }
    for (JavaType parameter : types) {
        getTypeLocationService().addModuleDependency(governorPhysicalTypeMetadata.getType().getModule(), parameter);
    }
}
Also used : AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList)

Example 64 with AnnotatedJavaType

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

the class RepositoryJpaCustomMetadata method getFindAllMethodByReferencedField.

/**
 * Method that generates the findAll method for provided referenced field on current interface.
 *
 * @param referencedField
 * @param identifierType
 *
 * @return
 */
private MethodMetadata getFindAllMethodByReferencedField(FieldMetadata referencedField, RelationInfo relationInfo) {
    // Define method name
    String findPattern = "findBy%s";
    if (relationInfo.cardinality == Cardinality.MANY_TO_MANY) {
        findPattern = "findBy%sContains";
    }
    // Method name
    JavaSymbolName methodName = new JavaSymbolName(String.format(findPattern, referencedField.getFieldName().getSymbolNameCapitalisedFirstLetter()));
    // Define method parameter types and parameter names
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    final JavaType paramType = referencedField.getFieldType().getBaseType();
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(paramType));
    parameterTypes.add(GLOBAL_SEARCH_PARAMETER);
    parameterTypes.add(PAGEABLE_PARAMETER);
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName(StringUtils.uncapitalize(referencedField.getFieldName().getSymbolName())));
    parameterNames.add(GOBAL_SEARCH_PARAMETER_NAME);
    parameterNames.add(PAGEABLE_PARAMETER_NAME);
    // Return type
    JavaType returnType = new JavaType(SpringJavaType.PAGE.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(defaultReturnType));
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, methodName, returnType, parameterTypes, parameterNames, null);
    // Build and return a MethodMetadata
    return methodBuilder.build();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) 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) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList)

Example 65 with AnnotatedJavaType

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

the class RepositoryJpaCustomMetadata method getCustomFinder.

/**
 * Method that generates finder methods whose return types are projections.
 *
 * @param finderReturnType
 * @param finderName
 * @param parameterType
 *
 * @return
 */
private MethodMetadata getCustomFinder(JavaType finderReturnType, JavaSymbolName finderName, JavaType parameterType) {
    // Define method parameter types and parameter names
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    parameterTypes.add(AnnotatedJavaType.convertFromJavaType(parameterType));
    parameterTypes.add(GLOBAL_SEARCH_PARAMETER);
    parameterTypes.add(PAGEABLE_PARAMETER);
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    parameterNames.add(new JavaSymbolName("formBean"));
    parameterNames.add(GOBAL_SEARCH_PARAMETER_NAME);
    parameterNames.add(PAGEABLE_PARAMETER_NAME);
    // Return type
    JavaType returnType = new JavaType(SpringJavaType.PAGE.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(finderReturnType));
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, finderName, returnType, parameterTypes, parameterNames, null);
    // Build and return a MethodMetadata
    return methodBuilder.build();
}
Also used : JavaSymbolName(org.springframework.roo.model.JavaSymbolName) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) 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) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) ArrayList(java.util.ArrayList)

Aggregations

AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)130 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)117 ArrayList (java.util.ArrayList)116 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)108 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)99 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)81 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)71 JavaType (org.springframework.roo.model.JavaType)63 SpringJavaType (org.springframework.roo.model.SpringJavaType)46 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)41 JdkJavaType (org.springframework.roo.model.JdkJavaType)28 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)25 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)23 ServiceMetadata (org.springframework.roo.addon.layers.service.addon.ServiceMetadata)18 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)16 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)15 RelationInfoExtended (org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended)12 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)10 Pair (org.apache.commons.lang3.tuple.Pair)7 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)7