use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getRecordsForSelectedTab.
@Override
public Map<String, DynamicResultSet> getRecordsForSelectedTab(ClassMetadata cmd, Entity containingEntity, List<SectionCrumb> sectionCrumb, String currentTabName) throws ServiceException {
Map<String, DynamicResultSet> map = new HashMap<String, DynamicResultSet>();
for (Property p : cmd.getProperties()) {
if (ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), containingEntity.getType()[0]) && p.getMetadata() instanceof CollectionMetadata) {
CollectionMetadata collectionMetadata = (CollectionMetadata) p.getMetadata();
// Give preference to the Group since EntityForm.addListGrid() gives preference to the Group
TabMetadata tabMetadata = cmd.getTabMetadataUsingGroupKey(collectionMetadata.getGroup());
if (tabMetadata == null) {
tabMetadata = cmd.getTabMetadataUsingTabKey(collectionMetadata.getTab());
}
String tabName = tabMetadata == null ? collectionMetadata.getTab() : tabMetadata.getTabName();
int tabOrder = tabMetadata == null ? collectionMetadata.getTabOrder() : tabMetadata.getTabOrder();
updateTabInfo(collectionMetadata, cmd, tabName, tabOrder);
if (collectionMetadata.getLazyFetch() != null && collectionMetadata.getLazyFetch() && tabName.toUpperCase().startsWith(currentTabName.toUpperCase()) && !collectionMetadata.getManualFetch()) {
PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, null, null, sectionCrumb);
map.put(p.getName(), response2.getDynamicResultSet());
} else if (collectionMetadata.getLazyFetch() != null && !collectionMetadata.getLazyFetch() && !collectionMetadata.getManualFetch()) {
PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, null, null, sectionCrumb);
map.put(p.getName(), response2.getDynamicResultSet());
} else {
DynamicResultSet drs = new DynamicResultSet();
Map<String, Tab> tabMap = new HashMap<String, Tab>();
Tab tab = new Tab();
tab.setKey(tabName);
tab.setTitle(BLCMessageUtils.getMessage(tabName));
tab.setOrder(tabOrder);
tabMap.put(tab.getTitle(), tab);
drs.setUnselectedTabMetadata(tabMap);
drs.setTotalRecords(0);
drs.setStartIndex(0);
drs.setBatchId(1);
drs.setClassMetaData(null);
drs.setPageSize(1);
drs.setRecords(new Entity[0]);
map.put(p.getName(), drs);
}
}
}
return map;
}
use of org.broadleafcommerce.openadmin.dto.Property 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.Property in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method removeSubCollectionEntity.
@Override
public PersistenceResponse removeSubCollectionEntity(ClassMetadata mainMetadata, Property field, Entity parentEntity, String itemId, String alternateId, String priorKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
List<Property> properties = new ArrayList<Property>();
Property p;
String parentId = getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName());
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(field.getMetadata(), sectionCrumbs).withEntity(new Entity());
if (field.getMetadata() instanceof BasicCollectionMetadata) {
BasicCollectionMetadata fmd = (BasicCollectionMetadata) field.getMetadata();
p = new Property();
p.setName("id");
p.setValue(itemId);
properties.add(p);
p = new Property();
p.setName(ppr.getForeignKey().getManyToField());
p.setValue(parentId);
properties.add(p);
ppr.getEntity().setType(new String[] { fmd.getCollectionCeilingEntity() });
} else if (field.getMetadata() instanceof AdornedTargetCollectionMetadata) {
AdornedTargetList adornedList = ppr.getAdornedList();
p = new Property();
p.setName(adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty());
p.setValue(parentId);
properties.add(p);
p = new Property();
p.setName(adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty());
p.setValue(itemId);
properties.add(p);
if (!StringUtils.isEmpty(alternateId)) {
p = new Property();
p.setName(BasicPersistenceModule.ALTERNATE_ID_PROPERTY);
p.setValue(alternateId);
properties.add(p);
}
ppr.getEntity().setType(new String[] { adornedList.getAdornedTargetEntityClassname() });
} else if (field.getMetadata() instanceof MapMetadata) {
MapMetadata fmd = (MapMetadata) field.getMetadata();
p = new Property();
p.setName("id");
p.setValue(itemId);
properties.add(p);
p = new Property();
p.setName("symbolicId");
p.setValue(getContextSpecificRelationshipId(mainMetadata, parentEntity, field.getName()));
properties.add(p);
p = new Property();
p.setName("priorKey");
p.setValue(priorKey);
properties.add(p);
MapStructure mapStructure = ppr.getMapStructure();
p = new Property();
p.setName(mapStructure.getKeyPropertyName());
p.setValue(itemId);
properties.add(p);
ppr.getEntity().setType(new String[] { fmd.getTargetClass() });
}
ppr.setCeilingEntityClassname(ppr.getEntity().getType()[0]);
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[] propArr = new Property[properties.size()];
properties.toArray(propArr);
ppr.getEntity().setProperties(propArr);
return remove(ppr);
}
use of org.broadleafcommerce.openadmin.dto.Property 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;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method getRecordsForAllSubCollections.
@Override
public Map<String, DynamicResultSet> getRecordsForAllSubCollections(PersistencePackageRequest ppr, Entity containingEntity, Integer startIndex, Integer maxIndex, List<SectionCrumb> sectionCrumb) throws ServiceException {
Map<String, DynamicResultSet> map = new HashMap<String, DynamicResultSet>();
PersistenceResponse response = getClassMetadata(ppr);
ClassMetadata cmd = response.getDynamicResultSet().getClassMetaData();
for (Property p : cmd.getProperties()) {
if (ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), containingEntity.getType()[0]) && p.getMetadata() instanceof CollectionMetadata) {
PersistenceResponse response2 = getRecordsForCollection(cmd, containingEntity, p, null, startIndex, maxIndex, sectionCrumb);
map.put(p.getName(), response2.getDynamicResultSet());
}
}
return map;
}
Aggregations