use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse 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.server.service.persistence.PersistenceResponse 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.server.service.persistence.PersistenceResponse 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.server.service.persistence.PersistenceResponse 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;
}
use of org.broadleafcommerce.openadmin.server.service.persistence.PersistenceResponse in project BroadleafCommerce by BroadleafCommerce.
the class DynamicEntityRemoteService method add.
@Override
public PersistenceResponse add(final PersistencePackage persistencePackage) throws ServiceException {
final PersistenceResponse[] response = new PersistenceResponse[1];
try {
PlatformTransactionManager transactionManager = identifyTransactionManager(persistencePackage);
transUtil.runTransactionalOperation(new StreamCapableTransactionalOperationAdapter() {
@Override
public void execute() throws Throwable {
response[0] = nonTransactionalAdd(persistencePackage);
}
@Override
public boolean shouldRetryOnTransactionLockAcquisitionFailure() {
return super.shouldRetryOnTransactionLockAcquisitionFailure();
}
}, RuntimeException.class, transactionManager);
} catch (RuntimeException e) {
if (e.getCause() instanceof ServiceException) {
throw (ServiceException) e.getCause();
}
throw e;
}
return response[0];
}
Aggregations