Search in sources :

Example 91 with ClassOrInterfaceTypeDetails

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;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionVisibilityIndicator(org.springframework.roo.shell.CliOptionVisibilityIndicator)

Example 92 with ClassOrInterfaceTypeDetails

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;
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) CliOptionAutocompleteIndicator(org.springframework.roo.shell.CliOptionAutocompleteIndicator)

Example 93 with ClassOrInterfaceTypeDetails

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);
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 94 with ClassOrInterfaceTypeDetails

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);
}
Also used : RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) RelationInfo(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata) Pair(org.apache.commons.lang3.tuple.Pair)

Example 95 with ClassOrInterfaceTypeDetails

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));
}
Also used : JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Aggregations

ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)232 JavaType (org.springframework.roo.model.JavaType)114 ArrayList (java.util.ArrayList)87 RooJavaType (org.springframework.roo.model.RooJavaType)86 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)52 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)43 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)42 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)40 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)39 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)36 JpaJavaType (org.springframework.roo.model.JpaJavaType)34 SpringJavaType (org.springframework.roo.model.SpringJavaType)28 CliOptionAutocompleteIndicator (org.springframework.roo.shell.CliOptionAutocompleteIndicator)24 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)23 JdkJavaType (org.springframework.roo.model.JdkJavaType)22 Test (org.junit.Test)20 File (java.io.File)19 List (java.util.List)19 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)19 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)17