use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class AdminProductController method constructSelectizeOptionMap.
public Map<String, Object> constructSelectizeOptionMap(DynamicResultSet drs, ClassMetadata cmd) {
Map<String, Object> result = new HashMap<>();
List<Map<String, String>> options = new ArrayList<>();
for (Entity e : drs.getRecords()) {
Map<String, String> selectizeOption = new HashMap<>();
Property p = e.findProperty("MAIN_ENTITY_NAME");
if (p != null) {
selectizeOption.put("name", p.getValue());
selectizeOption.put("id", p.getValue());
}
if (e.findProperty(ALTERNATE_ID_PROPERTY) != null) {
selectizeOption.put("alternateId", e.findProperty(ALTERNATE_ID_PROPERTY).getValue());
}
options.add(selectizeOption);
}
result.put("options", options);
return result;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class OfferTargetItemCriteriaValidator method validate.
@Override
public PropertyValidationResult validate(Entity entity, Serializable instance, Map<String, FieldMetadata> entityFieldMetadata, Map<String, String> validationConfiguration, BasicFieldMetadata propertyMetadata, String propertyName, String value) {
Property offerTypeProperty = entity.findProperty("type");
if (OfferType.ORDER_ITEM.getType().equals(offerTypeProperty.getValue())) {
String targetItemCriteriaJson = entity.findProperty("targetItemCriteria").getUnHtmlEncodedValue();
if (targetItemCriteriaJson == null) {
targetItemCriteriaJson = entity.findProperty("targetItemCriteriaJson").getUnHtmlEncodedValue();
}
DataWrapper dw = ruleFieldExtractionUtility.convertJsonToDataWrapper(targetItemCriteriaJson);
if (CollectionUtils.isEmpty(dw.getData()) && dw.getRawMvel() == null) {
return new PropertyValidationResult(false, "requiredValidationFailure");
}
}
return new PropertyValidationResult(true);
}
use of org.broadleafcommerce.openadmin.dto.Property 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.Property 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;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method constructSelectizeOptionMap.
@Override
public Map<String, Object> constructSelectizeOptionMap(DynamicResultSet drs, ClassMetadata cmd) {
Map<String, Object> result = new HashMap<>();
List<Map<String, String>> options = new ArrayList<>();
List<Field> headerFields = new ArrayList<>();
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
Field hf = createHeaderField(p, md);
headerFields.add(hf);
}
}
}
for (Entity e : drs.getRecords()) {
Map<String, String> selectizeOption = new HashMap<>();
for (Field headerField : headerFields) {
Property p = e.findProperty(headerField.getName());
if (p != null) {
selectizeOption.put("name", p.getValue());
break;
}
}
if (e.findProperty("id") != null) {
selectizeOption.put("id", e.findProperty("id").getValue());
}
if (e.findProperty(ALTERNATE_ID_PROPERTY) != null) {
selectizeOption.put("alternateId", e.findProperty(ALTERNATE_ID_PROPERTY).getValue());
}
options.add(selectizeOption);
}
result.put("options", options);
return result;
}
Aggregations