use of org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem in project spring-roo by spring-projects.
the class ThymeleafViewGeneratorServiceImpl method mergeListView.
@Override
public Document mergeListView(String templateName, Document loadExistingDoc, ViewContext<ThymeleafMetadata> ctx, EntityItem entity, List<FieldItem> fields, List<List<DetailEntityItem>> detailsLevels) {
// Get field code if data-z attribute value is equals to user-managed
Element elementField = loadExistingDoc.getElementById(entity.getEntityItemId().concat("-table"));
if (elementField != null && elementField.hasAttr("data-z") && elementField.attr("data-z").equals("user-managed")) {
entity.setUserManaged(true);
entity.setCodeManaged(elementField.outerHtml());
}
for (List<DetailEntityItem> detailsLevel : detailsLevels) {
for (DetailEntityItem detail : detailsLevel) {
// Get detail code if data-z attribute value is equals to
// user-managed
Element elementDetail = loadExistingDoc.getElementById(detail.getEntityItemId().concat("-table"));
if (elementDetail != null && elementDetail.hasAttr("data-z") && elementDetail.attr("data-z").equals("user-managed")) {
detail.setUserManaged(true);
detail.setCodeManaged(elementDetail.outerHtml());
}
// Check tab code if data-z attribute value is equals to
// user-managed
Element elementTabCodeDetailField = loadExistingDoc.getElementById(detail.getEntityItemId().concat("-table-tab"));
if (elementTabCodeDetailField != null && elementTabCodeDetailField.hasAttr("data-z") && elementTabCodeDetailField.attr("data-z").equals("user-managed")) {
detail.setTabLinkCode(elementTabCodeDetailField.outerHtml());
}
}
}
ctx.addExtraParameter("userManagedComponents", mergeStructure(loadExistingDoc));
ctx.addExtraParameter("entity", entity);
ctx.addExtraParameter("fields", fields);
ctx.addExtraParameter("detailsLevels", detailsLevels);
Document newDoc = process(templateName, ctx);
return newDoc;
}
use of org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem in project spring-roo by spring-projects.
the class ThymeleafViewGeneratorServiceImpl method addDetailsViews.
@Override
public void addDetailsViews(String moduleName, JpaEntityMetadata entityMetadata, MemberDetails entity, ControllerMetadata controllerMetadata, ThymeleafMetadata viewMetadata, ViewContext<ThymeleafMetadata> ctx) {
super.addDetailsViews(moduleName, entityMetadata, entity, controllerMetadata, viewMetadata, ctx);
// Get root entity metadata
EntityItem entityItem = createEntityItem(entityMetadata, ctx, TABLE_SUFFIX);
DetailEntityItem detail = createDetailEntityItem(viewMetadata, entity, entityMetadata, ctx.getEntityName(), ctx, DETAIL_SUFFIX, entityItem);
detail.addConfigurationElement("entityLabel", StringUtils.uncapitalize(FieldItem.buildLabel(detail.getEntityName(), "")));
if (controllerMetadata.getLastDetailsInfo().type == JpaRelationType.AGGREGATION) {
addCreateDetailsView(moduleName, entityMetadata, entity, controllerMetadata, viewMetadata, ctx);
} else {
addCreateDetailsCompositionView(moduleName, entityMetadata, entity, controllerMetadata, viewMetadata, ctx);
}
ctx.addExtraParameter("detail", detail);
addListDeleteModalDetailView(moduleName, entityMetadata, entity, controllerMetadata, ctx);
addListDeleteModalDetailBatchView(moduleName, entityMetadata, entity, controllerMetadata, ctx);
}
use of org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem 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);
}
use of org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem 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);
}
use of org.springframework.roo.addon.web.mvc.views.components.DetailEntityItem 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;
}
Aggregations