use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class SearchFieldResolverImpl method resolveField.
@Override
public String resolveField(String className) throws ServiceException {
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(className);
ClassMetadata md = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (md.getPMap().containsKey("name")) {
return "name";
}
if (md.getPMap().containsKey("friendlyName")) {
return "friendlyName";
}
if (md.getPMap().containsKey("templateName")) {
return "templateName";
}
return "id";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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";
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method viewEntityListSelectize.
@Override
@RequestMapping(value = "/selectize", method = RequestMethod.GET)
@ResponseBody
public Map<String, Object> viewEntityListSelectize(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> crumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, crumbs, pathVars).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withCustomCriteria(getCustomCriteria(requestParams));
FilterAndSortCriteria[] fascs = getCriteria(requestParams);
for (FilterAndSortCriteria fasc : fascs) {
if (SELECTIZE_NAME_PROPERTY.equals(fasc.getPropertyId())) {
fasc.setPropertyId(DEFAULT_SKU_NAME);
break;
}
}
ppr.withFilterAndSortCriteria(fascs);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
return constructSelectizeOptionMap(drs, cmd);
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildAdornedListForm.
@Override
public EntityForm buildAdornedListForm(AdornedTargetCollectionMetadata adornedMd, AdornedTargetList adornedList, String parentId, boolean isViewCollectionItem, EntityForm ef, List<SectionCrumb> sectionCrumbs, boolean isAdd) throws ServiceException {
ef.setEntityType(adornedList.getAdornedTargetEntityClassname());
// Get the metadata for this adorned field
PersistencePackageRequest request = PersistencePackageRequest.adorned().withCeilingEntityClassname(adornedMd.getCollectionCeilingEntity()).withAdornedList(adornedList).withSectionCrumbs(sectionCrumbs);
request.setAddOperationInspect(isAdd);
ClassMetadata collectionMetadata = adminEntityService.getClassMetadata(request).getDynamicResultSet().getClassMetaData();
List<Property> entityFormProperties = new ArrayList<>();
if (isViewCollectionItem) {
Collections.addAll(entityFormProperties, collectionMetadata.getProperties());
} else {
// We want our entity form to only render the maintained adorned target fields
for (String targetFieldName : adornedMd.getMaintainedAdornedTargetFields()) {
Property p = collectionMetadata.getPMap().get(targetFieldName);
if (p.getMetadata() instanceof BasicFieldMetadata && BooleanUtils.isNotTrue(p.getMetadata().getExcluded())) {
((BasicFieldMetadata) p.getMetadata()).setVisibility(VisibilityEnum.VISIBLE_ALL);
entityFormProperties.add(p);
}
}
}
// Set the maintained fields on the form
setEntityFormFields(collectionMetadata, ef, entityFormProperties);
// Add these two additional hidden fields that are required for persistence
Field f = new Field().withName(adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty()).withFieldType(SupportedFieldType.HIDDEN.toString()).withValue(parentId);
ef.addHiddenField(collectionMetadata, f);
f = new Field().withName(adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty()).withFieldType(SupportedFieldType.HIDDEN.toString()).withIdOverride("adornedTargetIdProperty");
ef.addHiddenField(collectionMetadata, f);
if (StringUtils.isNotBlank(adornedList.getSortField())) {
f = new Field().withName(adornedList.getSortField()).withFieldType(SupportedFieldType.HIDDEN.toString());
ef.addHiddenField(collectionMetadata, f);
}
ef.setParentId(parentId);
extensionManager.getProxy().addAdditionalAdornedFormActions(ef);
return ef;
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getRequestForEntityForm.
public PersistencePackageRequest getRequestForEntityForm(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumbs) {
// Ensure the ID property is on the form
Field idField = entityForm.findField(entityForm.getIdProperty());
if (idField == null) {
idField = new Field();
idField.setName(entityForm.getIdProperty());
idField.setValue(entityForm.getId());
entityForm.getFields().put(entityForm.getIdProperty(), idField);
} else {
idField.setValue(entityForm.getId());
}
List<Property> propList = getPropertiesFromEntityForm(entityForm);
Property[] properties = new Property[propList.size()];
properties = propList.toArray(properties);
Entity entity = new Entity();
entity.setProperties(properties);
String entityType = entityForm.getEntityType();
if (StringUtils.isEmpty(entityType)) {
entityType = entityForm.getCeilingEntityClassname();
}
entity.setType(new String[] { entityType });
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withEntity(entity).withCustomCriteria(customCriteria).withCeilingEntityClassname(entityForm.getCeilingEntityClassname()).withSectionCrumbs(sectionCrumbs).withRequestingEntityName(entityForm.getMainEntityName());
return ppr;
}
Aggregations