Search in sources :

Example 11 with RepositoryJpaMetadata

use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata 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 12 with RepositoryJpaMetadata

use of org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata 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)

Aggregations

RepositoryJpaMetadata (org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata)12 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)12 JavaType (org.springframework.roo.model.JavaType)11 RooJavaType (org.springframework.roo.model.RooJavaType)11 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)7 DetailEntityItem (org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem)6 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)6 JdkJavaType (org.springframework.roo.model.JdkJavaType)6 JpaJavaType (org.springframework.roo.model.JpaJavaType)6 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)6 SpringJavaType (org.springframework.roo.model.SpringJavaType)6 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)6 EntityItem (org.springframework.roo.addon.web.mvc.views.components.EntityItem)5 FieldItem (org.springframework.roo.addon.web.mvc.views.components.FieldItem)5 JpaEntityMetadata (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 RelationInfo (org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo)2 PartTree (org.springframework.roo.addon.layers.repository.jpa.addon.finder.parser.PartTree)2