use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class SystemPropertyCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
// Get an instance of SystemProperty with the updated values from the form
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(SystemProperty.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
SystemProperty adminInstance = (SystemProperty) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
adminInstance = (SystemProperty) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
// Verify that the value entered matches up with the type of this property
Entity errorEntity = validateTypeAndValueCombo(adminInstance);
if (errorEntity != null) {
entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
return entity;
}
adminInstance = (SystemProperty) dynamicEntityDao.merge(adminInstance);
// Fill out the DTO and add in the product option value properties to it
return helper.getRecord(adminProperties, adminInstance, null, null);
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + SystemProperty.class.getName(), e);
}
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class SystemPropertyCustomPersistenceHandler method validateTypeAndValueCombo.
protected Entity validateTypeAndValueCombo(SystemProperty prop) {
if (!spService.isValueValidForType(prop.getValue(), prop.getPropertyType())) {
Entity errorEntity = new Entity();
errorEntity.addValidationError("value", "valueIllegalForPropertyType");
return errorEntity;
}
return null;
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method getCollectionValueDetails.
@RequestMapping(value = "/{collectionField:.*}/details", method = RequestMethod.GET)
@ResponseBody
public Map<String, String> getCollectionValueDetails(HttpServletRequest request, HttpServletResponse response, Model model, @PathVariable Map<String, String> pathVars, @PathVariable(value = "collectionField") String collectionField, @RequestParam String ids, @RequestParam MultiValueMap<String, String> requestParams) throws Exception {
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, null, null);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, requestParams, sectionCrumbs, pathVars);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
FieldMetadata md = collectionProperty.getMetadata();
ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
ppr.setStartIndex(getStartIndex(requestParams));
ppr.setMaxIndex(getMaxIndex(requestParams));
if (md instanceof BasicFieldMetadata) {
String idProp = ((BasicFieldMetadata) md).getForeignKeyProperty();
String displayProp = ((BasicFieldMetadata) md).getForeignKeyDisplayValueProperty();
List<String> filterValues = BLCArrayUtils.asList(ids.split(FILTER_VALUE_SEPARATOR_REGEX));
ppr.addFilterAndSortCriteria(new FilterAndSortCriteria(idProp, filterValues));
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
Map<String, String> returnMap = new HashMap<>();
for (Entity e : drs.getRecords()) {
String id = e.getPMap().get(idProp).getValue();
String disp = e.getPMap().get(displayProp).getDisplayValue();
if (StringUtils.isBlank(disp)) {
disp = e.getPMap().get(displayProp).getValue();
}
returnMap.put(id, disp);
}
return returnMap;
}
return null;
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method getCollectionFieldRecords.
/**
* Returns the records for a given collectionField filtered by a particular criteria
*
* @param request
* @param response
* @param model
* @param pathVars
* @param collectionField
* @param requestParams
* @return the return view path
* @throws Exception
*/
@RequestMapping(value = "/{id}/{collectionField:.*}", method = RequestMethod.GET)
public String getCollectionFieldRecords(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);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(mainClassName, requestParams, sectionCrumbs, pathVars);
ClassMetadata mainMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Property collectionProperty = mainMetadata.getPMap().get(collectionField);
ppr = getSectionPersistencePackageRequest(mainClassName, sectionCrumbs, pathVars);
Entity entity = service.getRecord(ppr, id, mainMetadata, false).getDynamicResultSet().getRecords()[0];
// Next, we must get the new list grid that represents this collection
ListGrid listGrid = getCollectionListGrid(mainMetadata, entity, collectionProperty, requestParams, sectionKey, sectionCrumbs);
model.addAttribute("listGrid", listGrid);
model.addAttribute("currentParams", new ObjectMapper().writeValueAsString(requestParams));
// We return the new list grid so that it can replace the currently visible one
setModelAttributes(model, sectionKey);
return "views/standaloneListGrid";
}
use of org.broadleafcommerce.openadmin.dto.Entity in project BroadleafCommerce by BroadleafCommerce.
the class AdminBasicEntityController method buildDirtyList.
public List<String> buildDirtyList(Map<String, String> pathVars, HttpServletRequest request, String id) throws ServiceException {
List<String> dirtyList = new ArrayList<>();
String sectionKey = getSectionKey(pathVars);
String sectionClassName = getClassNameForSection(sectionKey);
List<SectionCrumb> sectionCrumbs = getSectionCrumbs(request, sectionKey, id);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, sectionCrumbs, pathVars);
ClassMetadata cmd = null;
Entity entity = null;
cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
for (Property p : entity.getProperties()) {
if (p.getIsDirty()) {
dirtyList.add(p.getName());
}
}
return dirtyList;
}
Aggregations