Search in sources :

Example 51 with MemberDetails

use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.

the class LinkFactoryMetadataProviderImpl method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Get controller JavaType from @RooLinkFactory
    LinkFactoryAnnotationValues annotationValues = new LinkFactoryAnnotationValues(governorPhysicalTypeMetadata);
    JavaType controller = annotationValues.getController();
    // Check if it is a valid controller
    ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller);
    // Get ControllerMetadata to get info from it
    String controllerMetadataKey = ControllerMetadata.createIdentifier(controllerDetails);
    final ControllerMetadata controllerMetadata = getMetadataService().get(controllerMetadataKey);
    // Get the controller methods
    List<MethodMetadata> controllerMethods = new ArrayList<MethodMetadata>();
    MemberDetails controllerMemberDetails = getMemberDetails(controllerDetails);
    for (MethodMetadata method : controllerMemberDetails.getMethods()) {
        // Check if is a @RequestMapping method
        if (method.getAnnotation(SpringJavaType.GET_MAPPING) != null || method.getAnnotation(SpringJavaType.POST_MAPPING) != null || method.getAnnotation(SpringJavaType.PUT_MAPPING) != null || method.getAnnotation(SpringJavaType.DELETE_MAPPING) != null || method.getAnnotation(SpringJavaType.REQUEST_MAPPING) != null) {
            controllerMethods.add(method);
        }
    }
    return new LinkFactoryMetadata(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, controller, controllerMetadata, controllerMethods);
}
Also used : ControllerMetadata(org.springframework.roo.addon.web.mvc.controller.addon.ControllerMetadata) SpringJavaType(org.springframework.roo.model.SpringJavaType) JavaType(org.springframework.roo.model.JavaType) RooJavaType(org.springframework.roo.model.RooJavaType) ArrayList(java.util.ArrayList) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 52 with MemberDetails

use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.

the class AbstractViewGenerationService method createDetailEntityItem.

/**
 * Create a new instance of {@link DetailEntityItem}. Implementation can
 * override this method to include it own information or extend defaults.
 *
 * @param detailController
 * @param detailSuffix
 * @param ctx
 * @param string
 * @param entityMetadata
 * @param entity
 * @return
 */
protected DetailEntityItem createDetailEntityItem(T detailController, MemberDetails entityMembers, JpaEntityMetadata entityMetadata, String entityName, ViewContext<T> ctx, String detailSuffix, EntityItem rootEntity) {
    ControllerMetadata controllerMetadata = detailController.getControllerMetadata();
    RelationInfoExtended last = controllerMetadata.getLastDetailsInfo();
    ClassOrInterfaceTypeDetails childEntityDetails = getTypeLocationService().getTypeDetails(last.childType);
    JpaEntityMetadata childEntityMetadata = last.childEntityMetadata;
    String controllerPath = getControllerOperations().getBasePathForController(controllerMetadata.getDestination());
    DetailEntityItem detailItem = new DetailEntityItem(childEntityMetadata, controllerMetadata, controllerPath, detailSuffix, rootEntity);
    // Saving necessary configuration
    detailItem.addConfigurationElement("referencedFieldType", last.childType.getSimpleTypeName());
    // Getting identifier field
    detailItem.addConfigurationElement("identifierField", childEntityMetadata.getCurrentIndentifierField().getFieldName().getSymbolName());
    // Getting referencedfield label plural
    detailItem.addConfigurationElement("referencedFieldLabel", FieldItem.buildLabel(entityName, last.fieldName));
    // Getting all referenced fields
    List<FieldMetadata> referencedFields = null;
    // Get the repository related with the child entity to check the default return type
    RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(childEntityMetadata.getAnnotatedEntity());
    // All views should have a repository
    Validate.notNull(repository, "ERROR: The provided child entity should have an associated repository to be able " + "to generate the list view.");
    // Obtain the defaultReturnType
    JavaType defaultReturnType = repository.getDefaultReturnType();
    // The defaultReturnType must not be null. If it's not an entity projection,
    // it must be an entity
    Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
    // Obtain details of the provided defaultReturnType. If not exists as type, show an error
    ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
    Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
    MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
    Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
    List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
    if (defaultReturnTypeFields.isEmpty()) {
        referencedFields = getEditableFields(getMemberDetailsScanner().getMemberDetails(getClass().toString(), childEntityDetails).getFields());
    } else {
        referencedFields = getEditableFields(defaultReturnTypeFields);
    }
    detailItem.addConfigurationElement("referenceFieldFields", getFieldViewItems(childEntityMetadata, referencedFields, entityName + "." + last.fieldName, true, ctx, StringUtils.EMPTY));
    detailItem.addConfigurationElement("fields", getFieldViewItems(childEntityMetadata, referencedFields, detailItem.getEntityName(), true, ctx, StringUtils.EMPTY));
    return detailItem;
}
Also used : RepositoryJpaMetadata(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata) ControllerMetadata(org.springframework.roo.addon.web.mvc.controller.addon.ControllerMetadata) Jsr303JavaType(org.springframework.roo.model.Jsr303JavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) DetailEntityItem(org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) RelationInfoExtended(org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Example 53 with MemberDetails

use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addListDeleteModalView.

@Override
public void addListDeleteModalView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ViewContext<T> ctx) {
    // Get the repository related with the entity to check the default return type
    RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(entityMetadata.getAnnotatedEntity());
    // All views should have a repository
    Validate.notNull(repository, "ERROR: The provided entity should have an associated repository to be able " + "to generate the list view.");
    // Obtain the defaultReturnType
    JavaType defaultReturnType = repository.getDefaultReturnType();
    // The defaultReturnType must not be null. If it's not an entity projection,
    // it must be an entity
    Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
    // Obtain details of the provided defaultReturnType. If not exists as type, show an error
    ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
    Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
    MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
    Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
    List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
    // all the entity fields will be used
    if (defaultReturnTypeFields.isEmpty()) {
        defaultReturnTypeFields = entity.getFields();
    }
    // Getting entity fields that should be included on view
    List<FieldMetadata> entityFields = getPersistentFields(defaultReturnTypeFields);
    List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
    // Process elements to generate
    DOC newDoc = null;
    // Getting new viewName
    String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat("/listDeleteModal").concat(getViewsExtension());
    EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
    // Check if new view to generate exists or not
    if (existsFile(viewName)) {
        DOC existingDoc = loadExistingDoc(viewName);
        if (!isUserManagedDocument(existingDoc)) {
            newDoc = mergeListDeleteModalView("listDeleteModal", existingDoc, ctx, entityItem, fields);
        }
    } else {
        ctx.addExtraParameter("entity", entityItem);
        ctx.addExtraParameter("fields", fields);
        newDoc = process("listDeleteModal", ctx);
    }
    // Write newDoc on disk
    writeDoc(newDoc, viewName);
}
Also used : RepositoryJpaMetadata(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata) Jsr303JavaType(org.springframework.roo.model.Jsr303JavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) FieldItem(org.springframework.roo.addon.web.mvc.views.components.FieldItem) EntityItem(org.springframework.roo.addon.web.mvc.views.components.EntityItem) DetailEntityItem(org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem)

Example 54 with MemberDetails

use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addListDeleteModalDetailView.

@Override
public void addListDeleteModalDetailView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ControllerMetadata controllerMetadata, ViewContext<T> ctx) {
    // Get the repository related with the entity to check the default return type
    RepositoryJpaMetadata repository = getRepositoryJpaLocator().getFirstRepositoryMetadata(entityMetadata.getAnnotatedEntity());
    // All views should have a repository
    Validate.notNull(repository, "ERROR: The provided entity should have an associated repository to be able " + "to generate the list view.");
    // Obtain the defaultReturnType
    JavaType defaultReturnType = repository.getDefaultReturnType();
    // The defaultReturnType must not be null. If it's not an entity projection,
    // it must be an entity
    Validate.notNull(defaultReturnType, "ERROR: The repository associated to the provided entity should define a defaultReturnType");
    // Obtain details of the provided defaultReturnType. If not exists as type, show an error
    ClassOrInterfaceTypeDetails defaultReturnTypeCid = getTypeLocationService().getTypeDetails(defaultReturnType);
    Validate.notNull(defaultReturnTypeCid, "ERROR: The provided defaultReturnType is not a valid type");
    MemberDetails defaultReturnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().toString(), defaultReturnTypeCid);
    Validate.notNull(defaultReturnTypeDetails, "ERROR: Is not possible to obtain any detail from the " + "provided defaultReturnType.");
    List<FieldMetadata> defaultReturnTypeFields = defaultReturnTypeDetails.getFields();
    // all the entity fields will be used
    if (defaultReturnTypeFields.isEmpty()) {
        defaultReturnTypeFields = entity.getFields();
    }
    // Getting entity fields that should be included on view
    List<FieldMetadata> entityFields = getPersistentFields(defaultReturnTypeFields);
    List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
    // Process elements to generate
    DOC newDoc = null;
    // Getting new viewName
    String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat(controllerMetadata.getDetailsPathAsString("/")).concat("/listDeleteModal").concat(getViewsExtension());
    EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
    // Check if new view to generate exists or not
    if (existsFile(viewName)) {
        DOC existingDoc = loadExistingDoc(viewName);
        if (!isUserManagedDocument(existingDoc)) {
            newDoc = mergeListDeleteModalDetailView("listDeleteModalDetail", existingDoc, ctx, entityItem, fields);
        }
    } else {
        ctx.addExtraParameter("entity", entityItem);
        ctx.addExtraParameter("fields", fields);
        newDoc = process("listDeleteModalDetail", ctx);
    }
    // Write newDoc on disk
    writeDoc(newDoc, viewName);
}
Also used : RepositoryJpaMetadata(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata) Jsr303JavaType(org.springframework.roo.model.Jsr303JavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) RooJavaType(org.springframework.roo.model.RooJavaType) SpringJavaType(org.springframework.roo.model.SpringJavaType) SpringletsJavaType(org.springframework.roo.model.SpringletsJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) FieldItem(org.springframework.roo.addon.web.mvc.views.components.FieldItem) EntityItem(org.springframework.roo.addon.web.mvc.views.components.EntityItem) DetailEntityItem(org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem)

Example 55 with MemberDetails

use of org.springframework.roo.classpath.scanner.MemberDetails in project spring-roo by spring-projects.

the class PersistenceMemberLocatorImpl method updateCache.

private void updateCache(final JavaType domainType) {
    if (!haveAssociatedTypesChanged(domainType)) {
        return;
    }
    final ClassOrInterfaceTypeDetails domainTypeDetails = typeLocationService.getTypeDetails(domainType);
    if (domainTypeDetails == null || !domainTypeDetails.getCustomData().keySet().contains(CustomDataKeys.PERSISTENT_TYPE)) {
        return;
    }
    final MemberDetails memberDetails = getMemberDetails(domainTypeDetails);
    // Update normal persistence ID fields cache
    populateIdTypes(memberDetails, domainType);
    // Update normal persistence ID cache
    populateIdFields(memberDetails, domainType);
    // Update embedded ID fields cache
    populateEmbeddedIdFields(memberDetails, domainType);
    // Update ID accessor cache
    populateIdAccessors(memberDetails, domainType);
    // Update version field cache
    populateVersionField(memberDetails, domainType);
    // Update version accessor cache
    populateVersionAccessor(memberDetails, domainType);
}
Also used : ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails)

Aggregations

MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)56 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)36 JavaType (org.springframework.roo.model.JavaType)35 RooJavaType (org.springframework.roo.model.RooJavaType)31 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)29 ArrayList (java.util.ArrayList)25 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)20 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)16 JpaJavaType (org.springframework.roo.model.JpaJavaType)15 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)14 SpringJavaType (org.springframework.roo.model.SpringJavaType)12 List (java.util.List)10 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)9 DetailEntityItem (org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem)8 EntityItem (org.springframework.roo.addon.web.mvc.views.components.EntityItem)7 FieldItem (org.springframework.roo.addon.web.mvc.views.components.FieldItem)7 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)7 JdkJavaType (org.springframework.roo.model.JdkJavaType)7 RepositoryJpaMetadata (org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata)6 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)6