use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityDaoImpl method getClassTree.
@Override
public ClassTree getClassTree(Class<?>[] polymorphicClasses) {
String ceilingClass = null;
for (Class<?> clazz : polymorphicClasses) {
AdminPresentationClass classPresentation = AnnotationUtils.findAnnotation(clazz, AdminPresentationClass.class);
if (classPresentation != null) {
String ceilingEntity = classPresentation.ceilingDisplayEntity();
if (!StringUtils.isEmpty(ceilingEntity)) {
ceilingClass = ceilingEntity;
break;
}
}
}
if (ceilingClass != null) {
int pos = -1;
int j = 0;
for (Class<?> clazz : polymorphicClasses) {
if (clazz.getName().equals(ceilingClass)) {
pos = j;
break;
}
j++;
}
if (pos >= 0) {
Class<?>[] temp = new Class<?>[pos + 1];
System.arraycopy(polymorphicClasses, 0, temp, 0, j + 1);
polymorphicClasses = temp;
}
}
ClassTree classTree = null;
if (!ArrayUtils.isEmpty(polymorphicClasses)) {
Class<?> topClass = polymorphicClasses[polymorphicClasses.length - 1];
classTree = new ClassTree(topClass.getName(), isExcludeClassFromPolymorphism(topClass));
createClassTreeFromAnnotation(topClass, classTree);
for (int j = polymorphicClasses.length - 1; j >= 0; j--) {
addClassToTree(polymorphicClasses[j], classTree);
}
classTree.finalizeStructure(1);
}
return classTree;
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class StructuredContentTypeCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
String structuredContentTypeId = persistencePackage.getCustomCriteria()[3];
StructuredContentType structuredContentType = structuredContentService.findStructuredContentTypeById(Long.valueOf(structuredContentTypeId));
ClassMetadata metadata = new ClassMetadata();
metadata.setCeilingType(StructuredContentType.class.getName());
ClassTree entities = new ClassTree(StructuredContentTypeImpl.class.getName());
metadata.setPolymorphicEntities(entities);
Property[] properties = dynamicFieldUtil.buildDynamicPropertyList(structuredContentType.getStructuredContentFieldTemplate().getFieldGroups(), StructuredContentTypeImpl.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 AdminBasicEntityController method showAddCollectionItem.
/**
* Shows the modal dialog that is used to add an item to a given collection. There are several possible outcomes
* of this call depending on the type of the specified collection field.
*
* <ul>
* <li>
* <b>Basic Collection (Persist)</b> - Renders a blank form for the specified target entity so that the user may
* enter information and associate the record with this collection. Used by fields such as ProductAttribute.
* </li>
* <li>
* <b>Basic Collection (Lookup)</b> - Renders a list grid that allows the user to click on an entity and select it.
* Used by fields such as "allParentCategories".
* </li>
* <li>
* <b>Adorned Collection (without form)</b> - Renders a list grid that allows the user to click on an entity and
* select it. The view rendered by this is identical to basic collection (lookup), but will perform the operation
* on an adorned field, which may carry extra meta-information about the created relationship, such as order.
* </li>
* <li>
* <b>Adorned Collection (with form)</b> - Renders a list grid that allows the user to click on an entity and
* select it. Once the user selects the entity, he will be presented with an empty form based on the specified
* "maintainedAdornedTargetFields" for this field. Used by fields such as "crossSellProducts", which in addition
* to linking an entity, provide extra fields, such as a promotional message.
* </li>
* <li>
* <b>Map Collection</b> - Renders a form for the target entity that has an additional key field. This field is
* populated either from the configured map keys, or as a result of a lookup in the case of a key based on another
* entity. Used by fields such as the mediaMap on a Sku.
* </li>
*
* @param request
* @param response
* @param model
* @param pathVars
* @param id
* @param collectionField
* @param requestParams
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}/{collectionField:.*}/add", method = RequestMethod.GET)
public String showAddCollectionItem(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "id") String id, @PathVariable(value = "collectionField") String collectionField, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String mainClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, 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).withFilterAndSortCriteria(getCriteria(requestParams)).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withLastId(getLastId(requestParams)).withFirstId(getFirstId(requestParams)).withUpperCount(getUpperCount(requestParams)).withLowerCount(getLowerCount(requestParams)).withPageSize(getPageSize(requestParams)).withPresentationFetch(true);
if (md instanceof BasicCollectionMetadata) {
BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
if (fmd.getAddMethodType().equals(AddMethodType.PERSIST)) {
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 (requestParams.containsKey("entityType")) {
entityType = requestParams.get("entityType").get(0);
}
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, sectionKey);
return "modules/modalContainer";
} else {
ppr = ppr.withCeilingEntityClassname(entityType);
}
}
} else if (md instanceof MapMetadata) {
ExtensionResultStatusType result = extensionManager.getProxy().modifyModelForAddCollectionType(request, response, model, sectionKey, id, requestParams, (MapMetadata) md);
if (result.equals(ExtensionResultStatusType.HANDLED)) {
model.addAttribute("entityId", id);
model.addAttribute("sectionKey", sectionKey);
model.addAttribute("collectionField", collectionField);
return "modules/modalContainer";
}
}
// service.getContextSpecificRelationshipId(mainMetadata, entity, prefix);
model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
return buildAddCollectionItemModel(request, response, model, id, collectionField, sectionKey, collectionProperty, md, ppr, null, null);
}
use of org.broadleafcommerce.openadmin.dto.ClassTree in project BroadleafCommerce by BroadleafCommerce.
the class PolymorphicEntityMapUtil method buildPolymorphicEntityMap.
protected void buildPolymorphicEntityMap(ClassTree entity, LinkedHashMap<String, String> map) {
String friendlyName = entity.getFriendlyName();
if (friendlyName != null && !friendlyName.equals("")) {
// TODO: fix this for i18N
// check if the friendly name is an i18N key
// String val = BLCMain.getMessageManager().getString(friendlyName);
// if (val != null) {
// friendlyName = val;
// }
}
map.put(entity.getFullyQualifiedClassname(), friendlyName != null ? friendlyName : entity.getName());
for (ClassTree child : entity.getChildren()) {
buildPolymorphicEntityMap(child, map);
}
}
Aggregations