use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class FinderCommands method isReturnTypeParameterVisible.
/**
* This indicator says if --returnType parameter should be visible or not.
*
* @param context ShellContext
* @return false if domain entity specified in --entity parameter has no associated Projections.
*/
@CliOptionVisibilityIndicator(params = "returnType", command = "finder add", help = "--returnType parameter is not visible if --entity parameter hasn't " + "been specified before or if there aren't exist any Projection class associated " + "to the current entity.")
public boolean isReturnTypeParameterVisible(ShellContext shellContext) {
// Get current value of 'entity'
JavaType entity = getTypeFromEntityParam(shellContext);
if (entity == null) {
return false;
}
Set<ClassOrInterfaceTypeDetails> projectionsInProject = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_ENTITY_PROJECTION);
for (ClassOrInterfaceTypeDetails projection : projectionsInProject) {
// Add only projections associated to the entity specified in the command
if (projection.getAnnotation(RooJavaType.ROO_ENTITY_PROJECTION).getAttribute("entity").getValue().equals(entity)) {
return true;
}
}
return false;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class FinderCommands method getReturnTypePossibleResults.
@CliOptionAutocompleteIndicator(command = "finder add", includeSpaceOnFinish = false, param = "returnType", help = "--returnType option could be a Projection class related with the specified entity or the same entity. " + "By default, uses the value of the 'defaultReturnType' parameter specified during the Jpa Repository creation.")
public List<String> getReturnTypePossibleResults(ShellContext shellContext) {
// Get current value of returnType
String currentText = shellContext.getParameters().get("returnType");
List<String> allPossibleValues = new ArrayList<String>();
// Get current value of 'entity'
JavaType entity = getTypeFromEntityParam(shellContext);
Set<ClassOrInterfaceTypeDetails> entityProjections = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation(RooJavaType.ROO_ENTITY_PROJECTION);
for (ClassOrInterfaceTypeDetails projection : entityProjections) {
if (entity != null && projection.getAnnotation(RooJavaType.ROO_ENTITY_PROJECTION).getAttribute("entity").getValue().equals(entity)) {
String name = replaceTopLevelPackageString(projection, currentText);
if (!allPossibleValues.contains(name)) {
allPossibleValues.add(name);
}
}
}
// Always include the entity name, because if the defaultReturnType of the repository
// is a projection, the developer should be able to specify an entity as return type.
String entityName = replaceTopLevelPackageString(getTypeLocationService().getTypeDetails(entity), currentText);
if (!allPossibleValues.contains(entityName)) {
allPossibleValues.add(entityName);
}
return allPossibleValues;
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class FinderCommands method getEntityDetails.
@Override
public MemberDetails getEntityDetails(JavaType entity) {
Validate.notNull(entity, "ERROR: Entity should be provided");
if (entitiesDetails.containsKey(entity)) {
return entitiesDetails.get(entity);
}
// We know the file exists, as there's already entity metadata for it
final ClassOrInterfaceTypeDetails cid = getTypeLocationService().getTypeDetails(entity);
if (cid == null) {
return null;
}
if (cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY) == null) {
LOGGER.warning("Unable to find the entity annotation on '" + entity + "'");
return null;
}
entitiesDetails.put(entity, getMemberDetailsScanner().getMemberDetails(getClass().getName(), cid));
return entitiesDetails.get(entity);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class RepositoryJpaCustomMetadataProviderImpl method getMetadata.
@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
final RepositoryJpaCustomAnnotationValues annotationValues = new RepositoryJpaCustomAnnotationValues(governorPhysicalTypeMetadata);
// Getting repository custom
JavaType entity = annotationValues.getEntity();
Validate.notNull(entity, "ERROR: Repository custom interface should be contain an entity on @RooJpaRepositoryCustom annotation");
final ClassOrInterfaceTypeDetails repositoryClass = getRepositoryJpaLocator().getRepository(entity);
final String repositoryMedatadataId = RepositoryJpaMetadata.createIdentifier(repositoryClass);
registerDependency(repositoryMedatadataId, metadataIdentificationString);
RepositoryJpaMetadata repositoryMetadata = getMetadataService().get(repositoryMedatadataId);
// This metadata is not available yet.
if (repositoryMetadata == null) {
return null;
}
// Add dependency between modules
ClassOrInterfaceTypeDetails cid = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
String module = cid.getName().getModule();
getTypeLocationService().addModuleDependency(module, entity);
getTypeLocationService().addModuleDependency(module, repositoryMetadata.getDefaultReturnType());
// Get field which entity is field part
List<Pair<FieldMetadata, RelationInfo>> relationsAsChild = getJpaOperations().getFieldChildPartOfRelation(entity);
for (Pair<FieldMetadata, RelationInfo> fieldInfo : relationsAsChild) {
// Add dependency between modules
getTypeLocationService().addModuleDependency(module, fieldInfo.getLeft().getFieldType());
}
// Register dependency between JavaBeanMetadata and this one
final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
final String javaBeanMetadataKey = JavaBeanMetadata.createIdentifier(entityDetails);
registerDependency(javaBeanMetadataKey, metadataIdentificationString);
String entityMetadataKey = JpaEntityMetadata.createIdentifier(entityDetails);
JpaEntityMetadata entityMetadata = getMetadataService().get(entityMetadataKey);
// Entity metadata is not available
if (entityMetadata == null) {
return null;
}
return new RepositoryJpaCustomMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, annotationValues, entityMetadata.getCurrentIndentifierField().getFieldType(), entity, repositoryMetadata, relationsAsChild);
}
use of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails in project spring-roo by spring-projects.
the class RepositoryJpaLayerProvider method getMemberTypeAdditions.
public MemberTypeAdditions getMemberTypeAdditions(final String callerMID, final String methodIdentifier, final JavaType targetEntity, final JavaType idType, boolean autowire, final MethodParameter... callerParameters) {
Validate.isTrue(StringUtils.isNotBlank(callerMID), "Caller's metadata ID required");
Validate.notBlank(methodIdentifier, "Method identifier required");
Validate.notNull(targetEntity, "Target enitity type required");
Validate.notNull(idType, "Enitity Id type required");
// Look for a repository layer method with this ID and parameter types
final List<JavaType> parameterTypes = new PairList<JavaType, JavaSymbolName>(callerParameters).getKeys();
final RepositoryJpaLayerMethod method = RepositoryJpaLayerMethod.valueOf(methodIdentifier, parameterTypes, targetEntity, idType);
if (method == null) {
return null;
}
// Look for repositories that support this domain type
final Collection<ClassOrInterfaceTypeDetails> repositories = repositoryLocator.getRepositories(targetEntity);
if (CollectionUtils.isEmpty(repositories)) {
return null;
}
// Use the first such repository (could refine this later)
final ClassOrInterfaceTypeDetails repository = repositories.iterator().next();
// Return the additions the caller needs to make
return getMethodAdditions(callerMID, method, repository.getName(), Arrays.asList(callerParameters));
}
Aggregations