Search in sources :

Example 71 with MethodMetadataBuilder

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

the class ServiceMetadata method getFindAllReferencedFieldMethod.

/**
 * Method that generates findAll method for provided referenced fields on current interface
 *
 * @param countMethod
 * @return
 */
private MethodMetadata getFindAllReferencedFieldMethod(MethodMetadata method) {
    // Define method parameter types and parameter names
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
    List<AnnotatedJavaType> methodParamTypes = method.getParameterTypes();
    List<JavaSymbolName> methodParamNames = method.getParameterNames();
    for (int i = 0; i < method.getParameterTypes().size(); i++) {
        parameterTypes.add(methodParamTypes.get(i));
        parameterNames.add(methodParamNames.get(i));
    }
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, method.getMethodName(), method.getReturnType(), 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)

Example 72 with MethodMetadataBuilder

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

the class ServiceMetadata method getFindAllByIdsInGlobalSearchMethod.

/**
 * Method that generates method "findAll" method. This method includes
 * GlobalSearch parameters to be able to filter results.
 *
 * @return MethodMetadata
 */
private MethodMetadata getFindAllByIdsInGlobalSearchMethod() {
    // Define method name
    JavaSymbolName methodName = this.findAllByIdsInGlobalSearchMethod.getMethodName();
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = this.findAllByIdsInGlobalSearchMethod.getParameterTypes();
    // Define method parameter names
    List<JavaSymbolName> parameterNames = this.findAllByIdsInGlobalSearchMethod.getParameterNames();
    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, this.findAllByIdsInGlobalSearchMethod.getReturnType(), 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) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata)

Example 73 with MethodMetadataBuilder

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

the class ServiceMetadata method getAddToRelationMethod.

/**
 * Generates "AddToRelation" Method for this service
 * @param relationInfo
 * @return
 */
private MethodMetadata getAddToRelationMethod(RelationInfo relationInfo) {
    final MethodMetadata entityAddMethod = relationInfo.addMethod;
    // Define method name
    JavaSymbolName methodName = entityAddMethod.getMethodName();
    // Define method parameter types
    List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
    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(entityAddMethod.getParameterNames().get(0));
    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 74 with MethodMetadataBuilder

use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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 75 with MethodMetadataBuilder

use of org.springframework.roo.classpath.details.MethodMetadataBuilder 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)

Aggregations

MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)155 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)143 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)120 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)117 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)115 ArrayList (java.util.ArrayList)110 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)87 JavaType (org.springframework.roo.model.JavaType)65 SpringJavaType (org.springframework.roo.model.SpringJavaType)48 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)43 JdkJavaType (org.springframework.roo.model.JdkJavaType)34 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)30 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)27 ServiceMetadata (org.springframework.roo.addon.layers.service.addon.ServiceMetadata)15 CommentStructure (org.springframework.roo.classpath.details.comments.CommentStructure)14 JavadocComment (org.springframework.roo.classpath.details.comments.JavadocComment)14 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)12 RelationInfoExtended (org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended)11 JpaJavaType (org.springframework.roo.model.JpaJavaType)9 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)7