use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class CustomerPaymentCustomPersistenceHandler method inspect.
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<MergedPropertyType, Map<String, FieldMetadata>>();
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> properties = helper.getSimpleMergedProperties(CustomerPayment.class.getName(), persistencePerspective);
// Hide "Payment Gateway Type" column & create "Saved Payment Info" ListGrid column
FieldMetadata paymentGatewayType = properties.get("paymentGatewayType");
if (paymentGatewayType != null) {
((BasicFieldMetadata) paymentGatewayType).setProminent(false);
}
BasicFieldMetadata savedPaymentInfo = new BasicFieldMetadata();
savedPaymentInfo.setName(SAVED_PAYMENT_INFO);
savedPaymentInfo.setFriendlyName("CustomerPaymentImpl_Saved_Payment_Info");
savedPaymentInfo.setFieldType(SupportedFieldType.STRING);
savedPaymentInfo.setInheritedFromType(CustomerPaymentImpl.class.getName());
savedPaymentInfo.setAvailableToTypes(new String[] { CustomerPaymentImpl.class.getName() });
savedPaymentInfo.setProminent(true);
savedPaymentInfo.setGridOrder(2000);
savedPaymentInfo.setReadOnly(true);
savedPaymentInfo.setVisibility(VisibilityEnum.FORM_HIDDEN);
properties.put(SAVED_PAYMENT_INFO, savedPaymentInfo);
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(CustomerPayment.class);
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
return new DynamicResultSet(mergedMetadata, null, null);
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildIsActiveFieldMetaData.
protected FieldMetadata buildIsActiveFieldMetaData() {
BasicFieldMetadata isActive = new BasicFieldMetadata();
isActive.setFieldType(SupportedFieldType.BOOLEAN);
isActive.setName(IS_ACTIVE);
isActive.setFriendlyName("OfferImpl_Is_Active");
isActive.setProminent(true);
isActive.setGridOrder(999999);
isActive.setVisibility(VisibilityEnum.FORM_HIDDEN);
return isActive;
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class OfferCustomPersistenceHandler method buildQualifiersCanBeQualifiersFieldMetaData.
protected FieldMetadata buildQualifiersCanBeQualifiersFieldMetaData() {
BasicFieldMetadata qualifiersCanBeQualifiers = new BasicFieldMetadata();
qualifiersCanBeQualifiers.setFieldType(SupportedFieldType.BOOLEAN);
qualifiersCanBeQualifiers.setName(QUALIFIERS_CAN_BE_QUALIFIERS);
qualifiersCanBeQualifiers.setFriendlyName("OfferImpl_Qualifiers_Can_Be_Qualifiers");
qualifiersCanBeQualifiers.setGroup(OfferAdminPresentation.GroupName.QualifierRuleRestriction);
qualifiersCanBeQualifiers.setOrder(OfferAdminPresentation.FieldOrder.QualifiersCanBeQualifiers);
qualifiersCanBeQualifiers.setDefaultValue("false");
return qualifiersCanBeQualifiers;
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method setReadOnlyState.
/**
* The given <b>entityForm</b> is marked as readonly for the following cases:
* <ol>
* <li>All of the properties from <b>cmd</b> are readonly</b></li>
* <li>The user does not have the security to {@link EntityOperationType#UPDATE} the given class name represented by
* the <b>entityForm</b> (determined by {@link #getSecurityClassname(EntityForm, ClassMetadata)})</li>
* <li>The user does not have the security necessary to modify the given <b>entity</b> according to the
* {@link RowLevelSecurityService#canUpdate(AdminUser, Entity)}</li>
* </ol>
*
* @param entityForm the form being generated
* @param cmd the metatadata used to build the <b>entityForm</b> for the <b>entity</b>
* @param entity the entity being edited
* @see {@link SecurityVerifier#securityCheck(String, EntityOperationType)}
* @see {@link #getSecurityClassname(EntityForm, ClassMetadata)}
* @see {@link RowLevelSecurityService#canUpdate(AdminUser, Entity)}
*/
protected void setReadOnlyState(EntityForm entityForm, ClassMetadata cmd, Entity entity) {
boolean readOnly = true;
// If all of the fields are read only, we'll mark the form as such
for (Property property : cmd.getProperties()) {
FieldMetadata fieldMetadata = property.getMetadata();
if (fieldMetadata instanceof BasicFieldMetadata) {
readOnly = ((BasicFieldMetadata) fieldMetadata).getReadOnly() != null && ((BasicFieldMetadata) fieldMetadata).getReadOnly();
if (!readOnly) {
break;
}
} else {
readOnly = ((CollectionMetadata) fieldMetadata).isMutable();
if (!readOnly) {
break;
}
}
}
if (!readOnly) {
// If the user does not have edit permissions, we will go ahead and make the form read only to prevent confusion
try {
String securityEntityClassname = getSecurityClassname(entityForm, cmd);
adminRemoteSecurityService.securityCheck(securityEntityClassname, EntityOperationType.UPDATE);
} catch (ServiceException e) {
if (e instanceof SecurityServiceException) {
readOnly = true;
}
}
}
// are not readonly, then check the row-level security
if (!readOnly) {
readOnly = !rowLevelSecurityService.canUpdate(adminRemoteSecurityService.getPersistentAdminUser(), entity);
}
if (readOnly) {
entityForm.setReadOnly();
// If someone has replaced RowLevelSecurityService, check here to make sure the replacement implements the expected interface
if (rowLevelSecurityService instanceof ExceptionAwareRowLevelSecurityProvider) {
EntityFormModifierConfiguration entityFormModifierConfiguration = ((ExceptionAwareRowLevelSecurityProvider) rowLevelSecurityService).getUpdateDenialExceptions();
for (EntityFormModifierData<EntityFormModifierDataPoint> data : entityFormModifierConfiguration.getData()) {
for (EntityFormModifier modifier : entityFormModifierConfiguration.getModifier()) {
if (modifier.isQualified(data.getModifierType())) {
modifier.modifyEntityForm(new EntityFormModifierRequest().withEntityForm(entityForm).withConfiguration(data).withCurrentUser(adminRemoteSecurityService.getPersistentAdminUser()).withEntity(entity).withRowLevelSecurityService(rowLevelSecurityService));
}
}
}
}
}
}
use of org.broadleafcommerce.openadmin.dto.BasicFieldMetadata in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildAdornedListForm.
@Override
public EntityForm buildAdornedListForm(AdornedTargetCollectionMetadata adornedMd, AdornedTargetList adornedList, String parentId, boolean isViewCollectionItem, EntityForm ef, List<SectionCrumb> sectionCrumbs, boolean isAdd) throws ServiceException {
ef.setEntityType(adornedList.getAdornedTargetEntityClassname());
// Get the metadata for this adorned field
PersistencePackageRequest request = PersistencePackageRequest.adorned().withCeilingEntityClassname(adornedMd.getCollectionCeilingEntity()).withAdornedList(adornedList).withSectionCrumbs(sectionCrumbs);
request.setAddOperationInspect(isAdd);
ClassMetadata collectionMetadata = adminEntityService.getClassMetadata(request).getDynamicResultSet().getClassMetaData();
List<Property> entityFormProperties = new ArrayList<>();
if (isViewCollectionItem) {
Collections.addAll(entityFormProperties, collectionMetadata.getProperties());
} else {
// We want our entity form to only render the maintained adorned target fields
for (String targetFieldName : adornedMd.getMaintainedAdornedTargetFields()) {
Property p = collectionMetadata.getPMap().get(targetFieldName);
if (p.getMetadata() instanceof BasicFieldMetadata && BooleanUtils.isNotTrue(p.getMetadata().getExcluded())) {
((BasicFieldMetadata) p.getMetadata()).setVisibility(VisibilityEnum.VISIBLE_ALL);
entityFormProperties.add(p);
}
}
}
// Set the maintained fields on the form
setEntityFormFields(collectionMetadata, ef, entityFormProperties);
// Add these two additional hidden fields that are required for persistence
Field f = new Field().withName(adornedList.getLinkedObjectPath() + "." + adornedList.getLinkedIdProperty()).withFieldType(SupportedFieldType.HIDDEN.toString()).withValue(parentId);
ef.addHiddenField(collectionMetadata, f);
f = new Field().withName(adornedList.getTargetObjectPath() + "." + adornedList.getTargetIdProperty()).withFieldType(SupportedFieldType.HIDDEN.toString()).withIdOverride("adornedTargetIdProperty");
ef.addHiddenField(collectionMetadata, f);
if (StringUtils.isNotBlank(adornedList.getSortField())) {
f = new Field().withName(adornedList.getSortField()).withFieldType(SupportedFieldType.HIDDEN.toString());
ef.addHiddenField(collectionMetadata, f);
}
ef.setParentId(parentId);
extensionManager.getProxy().addAdditionalAdornedFormActions(ef);
return ef;
}
Aggregations