use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadata method getFindAllByIdsInGlobalSearchMethod.
/**
* Method that generates the findAllByIdsIn method on current interface.
*
* @return
*/
private MethodMetadata getFindAllByIdsInGlobalSearchMethod() {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
// Identifiers parameter
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(JavaType.wrapperOf(JavaType.LIST, identifierType)));
parameterNames.add(new JavaSymbolName("ids"));
// Global search parameter
parameterTypes.add(GLOBAL_SEARCH_PARAMETER);
parameterNames.add(GOBAL_SEARCH_PARAMETER_NAME);
// Pageable parameter
parameterTypes.add(PAGEABLE_PARAMETER);
parameterNames.add(PAGEABLE_PARAMETER_NAME);
// Method name
JavaSymbolName methodName = new JavaSymbolName("findAllByIdsIn");
// Return type
JavaType returnType = new JavaType("org.springframework.data.domain.Page", 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();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadata method getCustomCount.
/**
* Method that generates count methods for custom finders.
*
* @param formBean the object containing the properties to search to
* @param javaSymbolName the finder name
* @return
*/
private MethodMetadata getCustomCount(JavaType formBean, JavaSymbolName finderName) {
// Define method parameter types and parameter names
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
parameterTypes.add(AnnotatedJavaType.convertFromJavaType(formBean));
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
parameterNames.add(new JavaSymbolName("formBean"));
// Create count method name
String countName = finderName.getSymbolName();
if (StringUtils.startsWith(countName, "find")) {
countName = StringUtils.removeStart(countName, "find");
} else if (StringUtils.startsWith(countName, "query")) {
countName = StringUtils.removeStart(countName, "query");
} else if (StringUtils.startsWith(countName, "read")) {
countName = StringUtils.removeStart(countName, "read");
}
countName = "count".concat(countName);
JavaSymbolName countMethodName = new JavaSymbolName(countName);
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC + Modifier.ABSTRACT, countMethodName, JavaType.LONG_PRIMITIVE, parameterTypes, parameterNames, null);
// Build and return a MethodMetadata
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceImplMetadata method getMethod.
/**
* Method that generates implementation of provided method
*
* @return MethodMetadataBuilder
*/
private MethodMetadata getMethod(final MethodMetadata methodToBeImplemented, boolean isTransactional) {
// Check if is batch method
boolean isBatch = false;
for (AnnotatedJavaType parameters : methodToBeImplemented.getParameterTypes()) {
JavaType type = parameters.getJavaType();
isBatch = !type.getParameters().isEmpty();
if (isBatch) {
break;
}
}
// Check what is the particular method
boolean isDelete = methodToBeImplemented.getMethodName().getSymbolName().equals("delete");
boolean isSaveMethod = methodToBeImplemented.equals(this.serviceMetadata.getCurrentSaveMethod());
boolean isFindOneForUpdate = methodToBeImplemented.getMethodName().getSymbolName().equals("findOneForUpdate");
InvocableMemberBodyBuilder bodyBuilder;
if (isDelete) {
bodyBuilder = builDeleteMethodBody(methodToBeImplemented, isBatch);
} else if (isSaveMethod) {
bodyBuilder = builSaveMethodBody(methodToBeImplemented);
} else if (isFindOneForUpdate) {
bodyBuilder = buildFindOneForUpdateBody(methodToBeImplemented);
} else {
bodyBuilder = builMethodBody(methodToBeImplemented);
}
return getMethod(methodToBeImplemented, isTransactional, bodyBuilder);
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceImplMetadata method getEntityTypeGetterMethod.
/**
* Builds a method which returns the class of entity JavaType.
*
* @return MethodMetadataBuilder
*/
private MethodMetadata getEntityTypeGetterMethod() {
List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
MethodMetadata existingMethod = getGovernorMethod(GET_ENTITY_TYPE_METHOD_NAME, AnnotatedJavaType.convertFromAnnotatedJavaTypes(parameterTypes));
if (existingMethod != null) {
return existingMethod;
}
InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
// return ENTITY_TYPE.class;
bodyBuilder.appendFormalLine("return %s.class;", this.entity.getNameIncludingTypeParameters(false, importResolver));
// Use the MethodMetadataBuilder for easy creation of MethodMetadata
MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), Modifier.PUBLIC, GET_ENTITY_TYPE_METHOD_NAME, JavaType.wrapperOf(JavaType.CLASS, this.entity), parameterTypes, parameterNames, bodyBuilder);
// Build and return a MethodMetadata instance
return methodBuilder.build();
}
use of org.springframework.roo.classpath.details.annotations.AnnotatedJavaType in project spring-roo by spring-projects.
the class ServiceImplMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final ServiceImplAnnotationValues annotationValues = new ServiceImplAnnotationValues(governorPhysicalTypeMetadata);
// Getting service interface
JavaType serviceInterface = annotationValues.getService();
ClassOrInterfaceTypeDetails serviceInterfaceDetails = getTypeLocationService().getTypeDetails(serviceInterface);
final ServiceMetadata serviceMetadata = getServiceMetadata(metadataIdentificationString, serviceInterfaceDetails);
AnnotationMetadata serviceAnnotation = serviceInterfaceDetails.getAnnotation(RooJavaType.ROO_SERVICE);
Validate.notNull(serviceAnnotation, "ERROR: Provided service should be annotated with @RooService");
JavaType entity = (JavaType) serviceAnnotation.getAttribute("entity").getValue();
ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
final String entityMetadataId = JpaEntityMetadata.createIdentifier(entityDetails.getType(), PhysicalTypeIdentifier.getPath(entityDetails.getDeclaredByMetadataId()));
final JpaEntityMetadata entityMetadata = (JpaEntityMetadata) getMetadataService().get(entityMetadataId);
// Add dependencies between modules
if (serviceMetadata != null) {
for (MethodMetadata method : serviceMetadata.getAllMethods()) {
List<JavaType> types = new ArrayList<JavaType>();
types.add(method.getReturnType());
types.addAll(method.getReturnType().getParameters());
for (AnnotatedJavaType parameter : method.getParameterTypes()) {
types.add(AnnotatedJavaType.convertFromAnnotatedJavaType(parameter));
types.addAll(AnnotatedJavaType.convertFromAnnotatedJavaType(parameter).getParameters());
}
for (JavaType parameter : types) {
getTypeLocationService().addModuleDependency(governorPhysicalTypeMetadata.getType().getModule(), parameter);
}
}
}
// Getting associated repository
ClassOrInterfaceTypeDetails repositoryDetails = getRepositoryJpaLocator().getRepository(entity);
final String repositoryMetadataId = RepositoryJpaMetadata.createIdentifier(repositoryDetails.getType(), PhysicalTypeIdentifier.getPath(repositoryDetails.getDeclaredByMetadataId()));
final RepositoryJpaMetadata repositoryMetadata = (RepositoryJpaMetadata) getMetadataService().get(repositoryMetadataId);
// Locate related services API types required by relations
Map<JavaType, ServiceMetadata> requiredServicesByEntity = new HashMap<JavaType, ServiceMetadata>();
ClassOrInterfaceTypeDetails relatedService;
for (RelationInfo info : entityMetadata.getRelationInfos().values()) {
if (info.cardinality != Cardinality.ONE_TO_ONE && !requiredServicesByEntity.containsKey(info.childType)) {
relatedService = getServiceLocator().getFirstService(info.childType);
if (relatedService != null) {
requiredServicesByEntity.put(info.childType, getServiceMetadata(metadataIdentificationString, relatedService));
}
}
}
// Get child relations info
List<Pair<FieldMetadata, RelationInfo>> childRelationsInfo = getJpaOperations().getFieldChildPartOfRelation(entityDetails);
return new ServiceImplMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, serviceInterface, repositoryDetails.getType(), repositoryMetadata, entity, entityMetadata, serviceMetadata, requiredServicesByEntity, childRelationsInfo);
}
Aggregations