use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method addClassToTree.
protected void addClassToTree(Class<?> clazz, ClassTree tree) {
Class<?> testClass;
try {
testClass = Class.forName(tree.getFullyQualifiedClassname());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
if (clazz.equals(testClass)) {
return;
}
if (clazz.getSuperclass().equals(testClass)) {
ClassTree myTree = new ClassTree(clazz.getName(), isExcludeClassFromPolymorphism(clazz));
createClassTreeFromAnnotation(clazz, myTree);
tree.setChildren(ArrayUtils.add(tree.getChildren(), myTree));
} else {
for (ClassTree child : tree.getChildren()) {
addClassToTree(clazz, child);
}
}
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class PageTemplateCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
List<FieldGroup> fieldGroups = getFieldGroups(persistencePackage, dynamicEntityDao);
ClassMetadata metadata = new ClassMetadata();
metadata.setCeilingType(PageTemplate.class.getName());
ClassTree entities = new ClassTree(PageTemplateImpl.class.getName());
metadata.setPolymorphicEntities(entities);
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(fieldGroups, PageTemplate.class);
metadata.setProperties(properties);
DynamicResultSet results = new DynamicResultSet(metadata);
return results;
} catch (Exception e) {
throw new ServiceException("Unable to perform inspect for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityForm.
@Override
public void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String, DynamicResultSet> collectionRecords, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
// Get the form with values for this entity
populateEntityForm(cmd, entity, ef, sectionCrumbs);
// Attach the sub-collection list grids and specialty UI support
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
continue;
}
if (!ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), entity.getType()[0])) {
continue;
}
if (collectionRecords != null) {
DynamicResultSet subCollectionEntities = collectionRecords.get(p.getName());
String containingEntityId = entity.getPMap().get(ef.getIdProperty()).getValue();
ListGrid listGrid = buildCollectionListGrid(containingEntityId, subCollectionEntities, p, ef.getSectionKey(), sectionCrumbs);
CollectionMetadata md = ((CollectionMetadata) p.getMetadata());
if (md instanceof BasicCollectionMetadata) {
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
ClassMetadata collectionCmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (collectionCmd.getPolymorphicEntities().getChildren().length != 0) {
List<ClassTree> entityTypes = collectionCmd.getPolymorphicEntities().getCollapsedClassTrees();
ListGridActionGroup actionGroup = new ListGridActionGroup().withName("Add");
for (ClassTree entityType : entityTypes) {
ListGridAction ADD = new ListGridAction(ListGridAction.ADD).withButtonClass(AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? "sub-list-grid-add-empty" : "sub-list-grid-add").withActionTargetEntity(entityType.getFullyQualifiedClassname()).withUrlPostfix("/add").withIconClass("fa fa-plus").withDisplayText(BLCMessageUtils.getMessage(entityType.getFriendlyName()));
actionGroup.getListGridActions().add(0, ADD);
}
listGrid.addToolbarActionGroup(actionGroup);
} else {
listGrid.getToolbarActions().add(0, AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? DefaultListGridActions.ADD_EMPTY : DefaultListGridActions.ADD);
}
} else {
listGrid.getToolbarActions().add(0, DefaultListGridActions.ADD);
}
if (subCollectionEntities.getUnselectedTabMetadata().get(md.getTab()) != null) {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), true);
} else {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), false);
}
}
}
if (CollectionUtils.isEmpty(ef.getActions())) {
ef.addAction(DefaultEntityFormActions.SAVE);
}
addDeleteActionIfAllowed(ef, cmd, entity);
setReadOnlyState(ef, cmd, entity);
// check for fields that should be hidden based on annotations
setVisibilityBasedOnShowIfFieldEquals(cmd, entity, ef);
extensionManager.getProxy().modifyDetailEntityForm(ef);
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class CriteriaTranslatorImpl method determineRoot.
/**
* Determines the appropriate entity in this current class tree to use as the ceiling entity for the query. Because
* we filter with AND instead of OR, we throw an exception if an attempt to utilize properties from mutually exclusive
* class trees is made as it would be impossible for such a query to return results.
*
* @param dynamicEntityDao
* @param ceilingMarker
* @param filterMappings
* @return the root class
* @throws NoPossibleResultsException
*/
@SuppressWarnings("unchecked")
protected Class<Serializable> determineRoot(DynamicEntityDao dynamicEntityDao, Class<Serializable> ceilingMarker, List<FilterMapping> filterMappings) throws NoPossibleResultsException {
Class<?>[] polyEntities = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(ceilingMarker);
ClassTree root = dynamicEntityDao.getClassTree(polyEntities);
List<ClassTree> parents = new ArrayList<ClassTree>();
for (FilterMapping mapping : filterMappings) {
if (mapping.getInheritedFromClass() != null) {
root = determineRootInternal(root, parents, mapping.getInheritedFromClass());
if (root == null) {
throw new NoPossibleResultsException("AND filter on different class hierarchies produces no results");
}
}
}
for (Class<?> clazz : polyEntities) {
if (clazz.getName().equals(root.getFullyQualifiedClassname())) {
return (Class<Serializable>) clazz;
}
}
throw new IllegalStateException("Class didn't match - this should not occur");
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method showAddAdditionalSku.
protected String showAddAdditionalSku(HttpServletRequest request, HttpServletResponse response, Model model, String id, Map<String, String> pathVars) throws Exception {
String collectionField = "additionalSkus";
String mainClassName = getClassNameForSection(SECTION_KEY);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, SECTION_KEY, id);
ClassMetadata mainMetadata = service.getClassMetadata(getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars)).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
FieldMetadata md = collectionProperty.getMetadata();
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
// If the entity type isn't specified, we need to determine if there are various polymorphic types
// for this entity.
String entityType = null;
if (request.getParameter("entityType") != null) {
entityType = request.getParameter("entityType");
}
if (StringUtils.isBlank(entityType)) {
if (cmd.getPolymorphicEntities().getChildren().length == 0) {
entityType = cmd.getPolymorphicEntities().getFullyQualifiedClassname();
} else {
entityType = getDefaultEntityType();
}
} else {
entityType = URLDecoder.decode(entityType, "UTF-8");
}
if (StringUtils.isBlank(entityType)) {
List<ClassTree> entityTypes = getAddEntityTypes(cmd.getPolymorphicEntities());
model.addAttribute("entityTypes", entityTypes);
model.addAttribute("viewType", "modal/entityTypeSelection");
model.addAttribute("entityFriendlyName", cmd.getPolymorphicEntities().getFriendlyName());
String requestUri = request.getRequestURI();
if (!request.getContextPath().equals("/") && requestUri.startsWith(request.getContextPath())) {
requestUri = requestUri.substring(request.getContextPath().length() + 1, requestUri.length());
}
model.addAttribute("currentUri", requestUri);
model.addAttribute("modalHeaderType", ModalHeaderType.ADD_ENTITY.getType());
setModelAttributes(model, SECTION_KEY);
return "modules/modalContainer";
} else {
ppr = ppr.withCeilingEntityClassname(entityType);
}
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
EntityForm entityForm = formService.createEntityForm(collectionMetadata, sectionCrumbs);
entityForm.setCeilingEntityClassname(ppr.getCeilingEntityClassname());
entityForm.setEntityType(ppr.getCeilingEntityClassname());
formService.removeNonApplicableFields(collectionMetadata, entityForm, ppr.getCeilingEntityClassname());
entityForm.removeAction(DefaultEntityFormActions.DELETE);
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/simpleAddEntity");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.ADD_COLLECTION_ITEM.getType());
model.addAttribute("collectionProperty", collectionProperty);
setModelAttributes(model, SECTION_KEY);
return "modules/modalContainer";
}
Aggregations