use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class PersistencePackageFactoryImpl method create.
@Override
public PersistencePackage create(PersistencePackageRequest request) {
PersistencePerspective persistencePerspective = new PersistencePerspective();
persistencePerspective.setAdditionalForeignKeys(request.getAdditionalForeignKeys());
persistencePerspective.setAdditionalNonPersistentProperties(new String[] {});
if (request.getForeignKey() != null) {
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.FOREIGNKEY, request.getForeignKey());
}
switch(request.getType()) {
case STANDARD:
persistencePerspective.setOperationTypes(getDefaultOperationTypes());
break;
case ADORNED:
if (request.getAdornedList() == null) {
throw new IllegalArgumentException("ADORNED type requires the adornedList to be set");
}
persistencePerspective.setOperationTypes(getOperationTypes(OperationType.ADORNEDTARGETLIST));
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.ADORNEDTARGETLIST, request.getAdornedList());
break;
case MAP:
if (request.getMapStructure() == null) {
throw new IllegalArgumentException("MAP type requires the mapStructure to be set");
}
persistencePerspective.setOperationTypes(getOperationTypes(OperationType.MAP));
persistencePerspective.addPersistencePerspectiveItem(PersistencePerspectiveItemType.MAPSTRUCTURE, request.getMapStructure());
break;
}
if (request.getOperationTypesOverride() != null) {
persistencePerspective.setOperationTypes(request.getOperationTypesOverride());
}
PersistencePackage pp = new PersistencePackage();
pp.setCeilingEntityFullyQualifiedClassname(request.getCeilingEntityClassname());
if (!StringUtils.isEmpty(request.getSecurityCeilingEntityClassname())) {
pp.setSecurityCeilingEntityFullyQualifiedClassname(request.getSecurityCeilingEntityClassname());
}
if (!ArrayUtils.isEmpty(request.getSectionCrumbs())) {
SectionCrumb[] converted = new SectionCrumb[request.getSectionCrumbs().length];
int index = 0;
for (SectionCrumb crumb : request.getSectionCrumbs()) {
SectionCrumb temp = new SectionCrumb();
String originalSectionIdentifier = crumb.getSectionIdentifier();
String sectionAsClassName;
try {
sectionAsClassName = getClassNameForSection(crumb.getSectionIdentifier());
} catch (Exception e) {
sectionAsClassName = request.getCeilingEntityClassname();
}
if (sectionAsClassName != null && !sectionAsClassName.equals(originalSectionIdentifier)) {
temp.setOriginalSectionIdentifier(originalSectionIdentifier);
}
temp.setSectionIdentifier(sectionAsClassName);
temp.setSectionId(crumb.getSectionId());
converted[index] = temp;
index++;
}
pp.setSectionCrumbs(converted);
} else {
pp.setSectionCrumbs(new SectionCrumb[0]);
}
pp.setSectionEntityField(request.getSectionEntityField());
pp.setFetchTypeFullyQualifiedClassname(null);
pp.setPersistencePerspective(persistencePerspective);
pp.setCustomCriteria(request.getCustomCriteria());
pp.setCsrfToken(null);
pp.setRequestingEntityName(request.getRequestingEntityName());
pp.setValidateUnsubmittedProperties(request.isValidateUnsubmittedProperties());
pp.setIsTreeCollection(request.isTreeCollection());
pp.setAddOperationInspect(request.isAddOperationInspect());
if (request.getEntity() != null) {
pp.setEntity(request.getEntity());
}
for (Map.Entry<String, PersistencePackageRequest> subRequest : request.getSubRequests().entrySet()) {
pp.getSubPackages().put(subRequest.getKey(), create(subRequest.getValue()));
}
return pp;
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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.server.domain.PersistencePackageRequest 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.server.domain.PersistencePackageRequest in project BroadleafCommerce by BroadleafCommerce.
the class AdminEntityServiceImpl method addEntity.
@Override
public PersistenceResponse addEntity(EntityForm entityForm, String[] customCriteria, List<SectionCrumb> sectionCrumb) throws ServiceException {
PersistencePackageRequest ppr = getRequestForEntityForm(entityForm, customCriteria, sectionCrumb);
// based on the criteria specific in the PersistencePackage.
for (Entry<String, EntityForm> entry : entityForm.getDynamicForms().entrySet()) {
DynamicEntityFormInfo info = entityForm.getDynamicFormInfo(entry.getKey());
if (info.getCustomCriteriaOverride() != null) {
customCriteria = info.getCustomCriteriaOverride();
} else {
String propertyName = info.getPropertyName();
String propertyValue;
if (entityForm.getFields().containsKey(propertyName)) {
propertyValue = entityForm.findField(propertyName).getValue();
} else {
propertyValue = info.getPropertyValue();
}
customCriteria = new String[] { info.getCriteriaName(), entityForm.getId(), propertyName, propertyValue };
}
PersistencePackageRequest subRequest = getRequestForEntityForm(entry.getValue(), customCriteria, sectionCrumb);
ppr.addSubRequest(info.getPropertyName(), subRequest);
}
return add(ppr);
}
use of org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest 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;
}
Aggregations