use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getCollectionListGrid.
// **********************************
// HELPER METHODS FOR BUILDING DTOS *
// **********************************
/**
* Convenience method for obtaining a ListGrid DTO object for a collection. Note that if no <b>criteria</b> is
* available, then this should be null (or empty)
*
* @param mainMetadata class metadata for the root entity that this <b>collectionProperty</b> relates to
* @param entity
* @param collectionProperty property that this collection should be based on from the root entity
* @param requestParams
* @param sectionKey the current main section key
* @param persistenceResponse
* @param sectionCrumbs
* @return the list grid
* @throws ServiceException
*/
protected ListGrid getCollectionListGrid(ClassMetadata mainMetadata, Entity entity, Property collectionProperty, MultiValueMap<String, String> requestParams, String sectionKey, PersistenceResponse persistenceResponse, List<SectionCrumb> sectionCrumbs) throws ServiceException {
String idProperty = service.getIdProperty(mainMetadata);
if (persistenceResponse != null && persistenceResponse.getAdditionalData().containsKey(PersistenceResponse.AdditionalData.CLONEID)) {
entity.findProperty(idProperty).setValue((String) persistenceResponse.getAdditionalData().get(PersistenceResponse.AdditionalData.CLONEID));
}
FetchPageRequest pageRequest = new FetchPageRequest().withLastId(getLastId(requestParams)).withFirstId(getFirstId(requestParams)).withStartIndex(getStartIndex(requestParams)).withMaxIndex(getMaxIndex(requestParams)).withUpperCount(getUpperCount(requestParams)).withLowerCount(getLowerCount(requestParams)).withPageSize(getPageSize(requestParams));
DynamicResultSet drs = service.getPagedRecordsForCollection(mainMetadata, entity, collectionProperty, getCriteria(requestParams), pageRequest, null, sectionCrumbs).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(entity.findProperty(idProperty).getValue(), drs, collectionProperty, sectionKey, sectionCrumbs);
return listGrid;
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class AdminAbstractController method getEntityForm.
// *********************************************************
// UNBOUND CONTROLLER METHODS (USED BY DIFFERENT SECTIONS) *
// *********************************************************
/**
* Convenience method for obtaining a fully built EntityForm for the given sectionKey, sectionClassName, and id.
*
* @param sectionKey
* @param sectionClassName
* @param id
* @return a fully composed EntityForm
* @throws ServiceException
*/
protected EntityForm getEntityForm(String sectionKey, String sectionClassName, String id) throws ServiceException {
SectionCrumb sc = new SectionCrumb();
sc.setSectionId(id);
sc.setSectionIdentifier("structured-content/all");
List<SectionCrumb> crumbs = new ArrayList<>(1);
crumbs.add(sc);
PersistencePackageRequest ppr = getSectionPersistencePackageRequest(sectionClassName, crumbs, null);
ClassMetadata cmd = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
Entity entity = service.getRecord(ppr, id, cmd, false).getDynamicResultSet().getRecords()[0];
Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForAllSubCollections(ppr, entity, crumbs);
EntityForm entityForm = formService.createEntityForm(cmd, entity, subRecordsMap, crumbs);
return entityForm;
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class IndexFieldCustomPersistenceHandler method fetch.
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
FilterAndSortCriteria fieldFsc = cto.getCriteriaMap().get("field");
if (fieldFsc != null) {
List<String> filterValues = fieldFsc.getFilterValues();
cto.getCriteriaMap().remove("field");
cto.getAdditionalFilterMappings().add(new FilterMapping().withFieldPath(new FieldPath().withTargetProperty("field.friendlyName")).withFilterValues(filterValues).withSortDirection(fieldFsc.getSortDirection()).withRestriction(new Restriction().withPredicateProvider(new PredicateProvider() {
@Override
public Predicate buildPredicate(CriteriaBuilder builder, FieldPathBuilder fieldPathBuilder, From root, String ceilingEntity, String fullPropertyName, Path explicitPath, List directValues) {
return builder.like(explicitPath.as(String.class), "%" + directValues.get(0) + "%");
}
})));
}
DynamicResultSet resultSet = helper.getCompatibleModule(OperationType.BASIC).fetch(persistencePackage, cto);
return resultSet;
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildMapForm.
@Override
public EntityForm buildMapForm(MapMetadata mapMd, final MapStructure mapStructure, ClassMetadata cmd, String parentId, EntityForm ef) throws ServiceException {
ForeignKey foreignKey = (ForeignKey) mapMd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.FOREIGNKEY);
ef.setEntityType(foreignKey.getForeignKeyClass());
Field keyField;
if (!mapMd.getForceFreeFormKeys()) {
// We will use a combo field to render the key choices
ComboField temp = new ComboField();
temp.withName("key").withFieldType("combo_field").withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
if (mapMd.getKeys() != null) {
// The keys can be explicitly set in the annotation...
temp.setOptions(mapMd.getKeys());
} else {
// Or they could be based on a different entity
PersistencePackageRequest ppr = PersistencePackageRequest.standard().withCeilingEntityClassname(mapMd.getMapKeyOptionEntityClass());
DynamicResultSet drs = adminEntityService.getRecords(ppr).getDynamicResultSet();
for (Entity entity : drs.getRecords()) {
String keyValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityValueField()).getValue();
String keyDisplayValue = entity.getPMap().get(mapMd.getMapKeyOptionEntityDisplayField()).getValue();
temp.putOption(keyValue, keyDisplayValue);
}
}
keyField = temp;
} else {
keyField = new Field().withName("key").withFieldType(SupportedFieldType.STRING.toString()).withFriendlyName(mapStructure.getKeyPropertyFriendlyName());
}
keyField.setRequired(true);
ef.addMapKeyField(cmd, keyField);
// Set the fields for this form
List<Property> mapFormProperties;
if (mapMd.isSimpleValue()) {
ef.setIdProperty("key");
mapFormProperties = new ArrayList<>();
Property valueProp = cmd.getPMap().get("value");
mapFormProperties.add(valueProp);
} else {
String valueClassName = mapStructure.getValueClassName();
List<String> classNames = getValueClassNames(valueClassName);
mapFormProperties = new ArrayList<>(Arrays.asList(cmd.getProperties()));
filterMapFormProperties(mapFormProperties, classNames);
}
setEntityFormFields(cmd, ef, mapFormProperties);
Field f = new Field().withName("priorKey").withFieldType(SupportedFieldType.HIDDEN.toString());
ef.addHiddenField(cmd, f);
ef.setParentId(parentId);
return ef;
}
use of org.broadleafcommerce.openadmin.dto.DynamicResultSet 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);
}
Aggregations