use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class TimeDTOCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
Map<String, FieldMetadata> mergedProperties = dynamicEntityDao.getSimpleMergedProperties(ceilingEntityFullyQualifiedClassname, persistencePackage.getPersistencePerspective());
allMergedProperties.put(MergedPropertyType.PRIMARY, mergedProperties);
ClassMetadata mergedMetadata = helper.buildClassMetadata(new Class<?>[] { Class.forName(ceilingEntityFullyQualifiedClassname) }, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata);
return results;
} catch (Exception e) {
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
throw ex;
}
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method showUpdateAdditionalSku.
protected String showUpdateAdditionalSku(HttpServletRequest request, Model model, String id, String collectionItemId, Map<String, String> pathVars, EntityForm entityForm) throws Exception {
String collectionField = "additionalSkus";
// Find out metadata for the additionalSkus property
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();
// Find the metadata and the entity for the selected sku
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withCustomCriteria(new String[] { id });
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (collectionMetadata.getCeilingType().equals(SkuImpl.class.getName())) {
collectionMetadata.setCeilingType(Sku.class.getName());
}
Entity entity = service.getRecord(ppr, collectionItemId, collectionMetadata, true).getDynamicResultSet().getRecords()[0];
String currentTabName = getCurrentTabName(pathVars, collectionMetadata);
Map<String, DynamicResultSet> subRecordsMap = service.getRecordsForSelectedTab(collectionMetadata, entity, sectionCrumbs, currentTabName);
if (entityForm == null) {
entityForm = formService.createEntityForm(collectionMetadata, entity, subRecordsMap, sectionCrumbs);
} else {
entityForm.clearFieldsMap();
formService.populateEntityForm(collectionMetadata, entity, subRecordsMap, entityForm, sectionCrumbs);
// remove all the actions since we're not trying to redisplay them on the form
entityForm.removeAllActions();
}
entityForm.removeAction(DefaultEntityFormActions.DELETE);
// Ensure that operations on the Sku subcollections go to the proper URL
for (ListGrid lg : entityForm.getAllListGrids()) {
lg.setSectionKey("org.broadleafcommerce.core.catalog.domain.Sku");
lg.setSectionCrumbs(sectionCrumbs);
}
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/simpleEditEntity");
model.addAttribute("currentUrl", request.getRequestURL().toString());
model.addAttribute("modalHeaderType", ModalHeaderType.UPDATE_COLLECTION_ITEM.getType());
model.addAttribute("collectionProperty", collectionProperty);
setModelAttributes(model, SECTION_KEY);
return "modules/modalContainer";
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method updateSubCollectionEntity.
@Override
public PersistenceResponse updateSubCollectionEntity(EntityForm entityForm, ClassMetadata mainMetadata, Property field, Entity parentEntity, String collectionItemId, String alternateId, List<SectionCrumb> sectionCrumbs) throws ServiceException, ClassNotFoundException {
List<Property> properties = getPropertiesFromEntityForm(entityForm);
FieldMetadata md = field.getMetadata();
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs).withEntity(new Entity());
if (md instanceof BasicCollectionMetadata) {
BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
ppr.setCeilingEntityClassname(fmd.getCollectionCeilingEntity());
ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
Property fp = new Property();
fp.setName(ppr.getForeignKey().getManyToField());
fp.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
if (!properties.contains(fp)) {
properties.add(fp);
}
} else if (md instanceof AdornedTargetCollectionMetadata) {
String adornedTargetEntityClassname = ppr.getAdornedList().getAdornedTargetEntityClassname();
ppr.setCeilingEntityClassname(adornedTargetEntityClassname);
ppr.getEntity().setType(new String[] { adornedTargetEntityClassname });
for (Property property : properties) {
if (property.getName().equals(ppr.getAdornedList().getLinkedObjectPath() + "." + ppr.getAdornedList().getLinkedIdProperty())) {
break;
}
}
if (!StringUtils.isEmpty(alternateId)) {
Property p = new Property();
p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
p.setValue(alternateId);
if (!properties.contains(p)) {
properties.add(p);
}
}
} else if (md instanceof MapMetadata) {
ppr.getEntity().setType(new String[] { entityForm.getEntityType() });
Property p = new Property();
p.setName("symbolicId");
p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
properties.add(p);
} else {
throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was" + " not a collection field.", field.getName(), mainMetadata.getCeilingType()));
}
String sectionField = field.getName();
if (sectionField.contains(".")) {
sectionField = sectionField.substring(0, sectionField.lastIndexOf("."));
}
ppr.setSectionEntityField(sectionField);
Property parentNameProp = parentEntity.getPMap().get(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
if (parentNameProp != null) {
ppr.setRequestingEntityName(parentNameProp.getValue());
}
Property p = new Property();
p.setName(entityForm.getIdProperty());
p.setValue(collectionItemId);
if (!properties.contains(p)) {
properties.add(p);
}
Property[] propArr = new Property[properties.size()];
properties.toArray(propArr);
ppr.getEntity().setProperties(propArr);
return update(ppr);
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getAdvancedCollectionRecord.
@Override
public PersistenceResponse getAdvancedCollectionRecord(ClassMetadata containingClassMetadata, Entity containingEntity, Property collectionProperty, String collectionItemId, List<SectionCrumb> sectionCrumbs, String alternateId, String[] customCriteria) throws ServiceException {
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(collectionProperty.getMetadata(), sectionCrumbs);
ppr.addCustomCriteria(customCriteria);
FieldMetadata md = collectionProperty.getMetadata();
String containingEntityId = getContextSpecificRelationshipId(containingClassMetadata, containingEntity, collectionProperty.getName());
ppr.setSectionEntityField(collectionProperty.getName());
PersistenceResponse response;
if (md instanceof AdornedTargetCollectionMetadata) {
FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName());
fasc.setFilterValue(containingEntityId);
ppr.addFilterAndSortCriteria(fasc);
fasc = new FilterAndSortCriteria(ppr.getAdornedList().getCollectionFieldName() + "Target");
fasc.setFilterValue(collectionItemId);
ppr.addFilterAndSortCriteria(fasc);
if (!StringUtils.isEmpty(alternateId)) {
fasc = new FilterAndSortCriteria(ppr.getAdornedList().getIdProperty());
fasc.setFilterValue(alternateId);
ppr.addFilterAndSortCriteria(fasc);
}
response = fetch(ppr);
Entity[] entities = response.getDynamicResultSet().getRecords();
if (ArrayUtils.isEmpty(entities)) {
throw new EntityNotFoundException();
}
} else if (md instanceof MapMetadata) {
MapMetadata mmd = (MapMetadata) md;
FilterAndSortCriteria fasc = new FilterAndSortCriteria(ppr.getForeignKey().getManyToField());
fasc.setFilterValue(containingEntityId);
ppr.addFilterAndSortCriteria(fasc);
response = fetch(ppr);
Entity[] entities = response.getDynamicResultSet().getRecords();
for (Entity e : entities) {
String idProperty = getIdProperty(containingClassMetadata);
if (mmd.isSimpleValue()) {
idProperty = "key";
}
Property p = e.getPMap().get(idProperty);
if (p.getValue().equals(collectionItemId)) {
response.setEntity(e);
break;
}
}
} else {
throw new IllegalArgumentException(String.format("The specified field [%s] for class [%s] was not an " + "advanced collection field.", collectionProperty.getName(), containingClassMetadata.getCeilingType()));
}
return response;
}
use of org.broadleafcommerce.openadmin.dto.FieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getAllRecordsForAllSubCollections.
@Override
public Map<String, DynamicResultSet> getAllRecordsForAllSubCollections(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb) throws ServiceException {
Map<String, DynamicResultSet> map = new HashMap<>();
for (Property p : cmd.getProperties()) {
FieldMetadata fieldMetadata = p.getMetadata();
boolean fieldAvailable = ArrayUtils.contains(fieldMetadata.getAvailableToTypes(), containingEntity.getType()[0]);
if (fieldAvailable && fieldMetadata instanceof CollectionMetadata) {
FetchPageRequest pageRequest = new FetchPageRequest().withPageSize(Integer.MAX_VALUE);
PersistenceResponse resp = getPagedRecordsForCollection(cmd, containingEntity, p, null, pageRequest, null, sectionCrumb);
map.put(p.getName(), resp.getDynamicResultSet());
}
}
return map;
}
Aggregations