Search in sources :

Example 6 with FieldItem

use of org.springframework.roo.addon.web.mvc.views.components.FieldItem in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addListDeleteModalBatchView.

@Override
public void addListDeleteModalBatchView(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("/listDeleteModalBatch").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 = mergeListDeleteModalBatchView("listDeleteModalBatch", loadExistingDoc(viewName), ctx, entityItem, fields);
        }
    } else {
        ctx.addExtraParameter("entity", entityItem);
        ctx.addExtraParameter("fields", fields);
        newDoc = process("listDeleteModalBatch", 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 7 with FieldItem

use of org.springframework.roo.addon.web.mvc.views.components.FieldItem in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addListDeleteModalDetailBatchView.

@Override
public void addListDeleteModalDetailBatchView(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("/listDeleteModalBatch").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 = mergeListDeleteModalBatchDetailView("listDeleteModalBatchDetail", loadExistingDoc(viewName), ctx, entityItem, fields);
        }
    } else {
        ctx.addExtraParameter("entity", entityItem);
        ctx.addExtraParameter("fields", fields);
        newDoc = process("listDeleteModalBatchDetail", 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 8 with FieldItem

use of org.springframework.roo.addon.web.mvc.views.components.FieldItem in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addListView.

@Override
public void addListView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, List<T> detailsControllers, 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("/list").concat(getViewsExtension());
    EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
    List<List<DetailEntityItem>> detailsLevels = new ArrayList<List<DetailEntityItem>>();
    if (detailsControllers != null && !detailsControllers.isEmpty()) {
        List<DetailEntityItem> details = new ArrayList<DetailEntityItem>();
        for (T detailController : detailsControllers) {
            DetailEntityItem detailItem = createDetailEntityItem(detailController, entity, entityMetadata, ctx.getEntityName(), ctx, DETAIL_SUFFIX, entityItem);
            details.add(detailItem);
        }
        // Sort details by path
        Collections.sort(details, new Comparator<DetailEntityItem>() {

            @Override
            public int compare(DetailEntityItem o1, DetailEntityItem o2) {
                return o1.getPathString().compareTo(o2.getPathString());
            }
        });
        // levels
        for (DetailEntityItem detail : details) {
            // Create group until item level
            while (detailsLevels.size() < detail.getLevel()) {
                detailsLevels.add(new ArrayList<DetailEntityItem>());
            }
            // Include detail in its group
            detailsLevels.get(detail.getLevel() - 1).add(detail);
            if (detail.getLevel() < 1) {
                // Nothing more to do with detail
                continue;
            }
            // look for parent
            for (DetailEntityItem parent : details) {
                if (detail.isTheParentEntity(parent)) {
                    // set parent
                    detail.setParentEntity(parent);
                    break;
                }
            }
        }
    }
    // Check if new view to generate exists or not
    if (existsFile(viewName)) {
        DOC existingDoc = loadExistingDoc(viewName);
        if (!isUserManagedDocument(existingDoc)) {
            newDoc = mergeListView("list", existingDoc, ctx, entityItem, fields, detailsLevels);
        }
    } else {
        ctx.addExtraParameter("entity", entityItem);
        ctx.addExtraParameter("fields", fields);
        ctx.addExtraParameter("detailsLevels", detailsLevels);
        newDoc = process("list", ctx);
    }
    // Write newDoc on disk
    writeDoc(newDoc, viewName);
}
Also used : RepositoryJpaMetadata(org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata) FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) 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) List(java.util.List) ArrayList(java.util.ArrayList) 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 9 with FieldItem

use of org.springframework.roo.addon.web.mvc.views.components.FieldItem in project spring-roo by spring-projects.

the class ThymeleafViewGeneratorServiceImpl method addFinderListView.

@Override
public void addFinderListView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ThymeleafMetadata viewMetadata, JavaType formBean, JavaType returnType, String finderName, List<ThymeleafMetadata> detailsControllers, ViewContext<ThymeleafMetadata> ctx) {
    // Getting returnType details
    MemberDetails returnTypeDetails = getMemberDetailsScanner().getMemberDetails(getClass().getName(), getTypeLocationService().getTypeDetails(returnType));
    // Getting entity fields that should be included on view
    List<FieldMetadata> returnFields = getPersistentFields(returnTypeDetails.getFields());
    List<FieldItem> fields = getFieldViewItems(entityMetadata, returnFields, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
    // Getting formBean details
    MemberDetails formBeanDetails = getMemberDetailsScanner().getMemberDetails(getClass().getName(), getTypeLocationService().getTypeDetails(formBean));
    // Getting entity fields that should be included on view
    List<FieldMetadata> formBeanFieldsMetadata = getPersistentFields(formBeanDetails.getFields());
    List<FieldItem> formBeanFields = getFieldViewItems(entityMetadata, formBeanFieldsMetadata, ctx.getEntityName(), true, ctx, TABLE_SUFFIX);
    // Process elements to generate
    Document newDoc = null;
    // Getting new viewName
    String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat(finderName).concat(getViewsExtension());
    EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
    List<List<DetailEntityItem>> detailsLevels = new ArrayList<List<DetailEntityItem>>();
    if (detailsControllers != null && !detailsControllers.isEmpty()) {
        List<DetailEntityItem> details = new ArrayList<DetailEntityItem>();
        for (ThymeleafMetadata detailController : detailsControllers) {
            DetailEntityItem detailItem = createDetailEntityItem(detailController, entity, entityMetadata, ctx.getEntityName(), ctx, DETAIL_SUFFIX, entityItem);
            details.add(detailItem);
        }
        // Sort details by path
        Collections.sort(details, new Comparator<DetailEntityItem>() {

            @Override
            public int compare(DetailEntityItem o1, DetailEntityItem o2) {
                return o1.getPathString().compareTo(o2.getPathString());
            }
        });
        // levels
        for (DetailEntityItem detail : details) {
            // Create group until item level
            while (detailsLevels.size() < detail.getLevel()) {
                detailsLevels.add(new ArrayList<DetailEntityItem>());
            }
            // Include detail in its group
            detailsLevels.get(detail.getLevel() - 1).add(detail);
            if (detail.getLevel() < 1) {
                // Nothing more to do with detail
                continue;
            }
            // look for parent
            for (DetailEntityItem parent : details) {
                if (detail.isTheParentEntity(parent)) {
                    // set parent
                    detail.setParentEntity(parent);
                    break;
                }
            }
        }
    }
    ctx.addExtraParameter("detailsLevels", detailsLevels);
    final JavaType searchController = viewMetadata.getDestination();
    Map<String, MethodMetadata> finderDatatablesMethods = viewMetadata.getFinderDatatableMethods();
    MethodMetadata finderDtMethod = finderDatatablesMethods.get(finderName);
    Map<String, MethodMetadata> finderListMethods = viewMetadata.getFinderListMethods();
    MethodMetadata finderListMethod = finderListMethods.get(finderName);
    Map<String, MethodMetadata> finderFormMethods = viewMetadata.getFinderFormMethods();
    MethodMetadata finderFormMethod = finderFormMethods.get(finderName);
    ctx.addExtraParameter("entity", entityItem);
    ctx.addExtraParameter("fields", fields);
    // Adding formBean fields
    ctx.addExtraParameter("formbeanfields", formBeanFields);
    // Check if new view to generate exists or not
    if (existsFile(viewName)) {
        Document existingDoc = loadExistingDoc(viewName);
        if (!isUserManagedDocument(existingDoc)) {
            newDoc = mergeListView("finderList", existingDoc, ctx, entityItem, fields, detailsLevels);
        }
    } else {
        newDoc = process("finderList", ctx);
    }
    // Write newDoc on disk
    writeDoc(newDoc, viewName);
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) Document(org.jsoup.nodes.Document) RooJavaType(org.springframework.roo.model.RooJavaType) JavaType(org.springframework.roo.model.JavaType) DetailEntityItem(org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem) ArrayList(java.util.ArrayList) List(java.util.List) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) 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 10 with FieldItem

use of org.springframework.roo.addon.web.mvc.views.components.FieldItem in project spring-roo by spring-projects.

the class AbstractViewGenerationService method addUpdateView.

@Override
public void addUpdateView(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entityDetails, ViewContext<T> ctx) {
    // Getting entity fields that should be included on view
    List<FieldMetadata> entityFields = new ArrayList<FieldMetadata>();
    // Process elements to generate
    DOC newDoc = null;
    // Getting new viewName
    String viewName = getViewsFolder(moduleName).concat(ctx.getControllerPath()).concat("/").concat("/edit").concat(getViewsExtension());
    // Check and manage detail composition fields
    Map<String, List<FieldItem>> compositeRelationFields = manageChildcompositionFields(entityMetadata, entityDetails, ctx);
    // Remove one-to-one fields from composite relations and create EntityItems
    // for each referenced entity field
    Set<String> compositeRelationFieldNames = compositeRelationFields.keySet();
    for (FieldMetadata field : getEditableFields(entityDetails.getFields())) {
        if (!compositeRelationFieldNames.contains(field.getFieldName().getSymbolName())) {
            entityFields.add(field);
        }
    }
    List<FieldItem> fields = getFieldViewItems(entityMetadata, entityFields, ctx.getEntityName(), false, ctx, FIELD_SUFFIX);
    EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
    ctx.addExtraParameter("fields", fields);
    ctx.addExtraParameter("entity", entityItem);
    ctx.addExtraParameter("compositeRelationFields", compositeRelationFields);
    // Check if new view to generate exists or not
    if (existsFile(viewName)) {
        DOC existingDoc = loadExistingDoc(viewName);
        if (!isUserManagedDocument(existingDoc)) {
            newDoc = merge("edit", existingDoc, ctx, fields);
        }
    } else {
        newDoc = process("edit", ctx);
    }
    // Write newDoc on disk
    writeDoc(newDoc, viewName);
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) 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

FieldItem (org.springframework.roo.addon.web.mvc.views.components.FieldItem)16 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)13 DetailEntityItem (org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem)11 EntityItem (org.springframework.roo.addon.web.mvc.views.components.EntityItem)11 ArrayList (java.util.ArrayList)8 List (java.util.List)7 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)7 JavaType (org.springframework.roo.model.JavaType)7 RooJavaType (org.springframework.roo.model.RooJavaType)7 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)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 RepositoryJpaMetadata (org.springframework.roo.addon.layers.repository.jpa.addon.RepositoryJpaMetadata)5 Document (org.jsoup.nodes.Document)3 Element (org.jsoup.nodes.Element)2 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1