use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method buildCollectionListGrid.
@Override
public ListGrid buildCollectionListGrid(String containingEntityId, DynamicResultSet drs, Property field, String sectionKey, List<SectionCrumb> sectionCrumbs) throws ServiceException {
FieldMetadata fmd = field.getMetadata();
// Get the class metadata for this particular field
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(fmd, sectionCrumbs);
if (field != null) {
ppr.setSectionEntityField(field.getName());
}
ClassMetadata cmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
List<Field> headerFields = new ArrayList<>();
ListGrid.Type type = null;
boolean editable = false;
boolean sortable = false;
boolean readOnly = false;
boolean hideIdColumn = false;
boolean canFilterAndSort = true;
boolean modalSingleSelectable = false;
boolean modalMultiSelectable = false;
boolean selectize = false;
boolean isMedia = false;
boolean isLookup = false;
String sortProperty = null;
FieldWrapper wrapper = new FieldWrapper();
ArrayList<FieldDTO> defaultWrapperFields = new ArrayList<>();
String idProperty = "id";
for (Property property : cmd.getProperties()) {
if (property.getMetadata() instanceof BasicFieldMetadata && SupportedFieldType.ID == ((BasicFieldMetadata) property.getMetadata()).getFieldType() && // make sure it's a property for this entity - not an association
!property.getName().contains(".")) {
idProperty = property.getName();
break;
}
}
// kind of field this is.
if (fmd instanceof BasicFieldMetadata) {
readOnly = ((BasicFieldMetadata) fmd).getReadOnly();
modalSingleSelectable = true;
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
if (SupportedFieldType.ID.equals(md.getFieldType())) {
idProperty = md.getName();
}
if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
Field hf = createHeaderField(p, md);
headerFields.add(hf);
defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
}
if (md.getIsFilter() != null && md.getIsFilter()) {
Field f = createHeaderField(p, md);
wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
}
}
}
type = ListGrid.Type.TO_ONE;
} else if (fmd instanceof BasicCollectionMetadata) {
BasicCollectionMetadata bcm = (BasicCollectionMetadata) fmd;
readOnly = !bcm.isMutable();
if (AddMethodType.LOOKUP.equals(bcm.getAddMethodType())) {
isLookup = true;
}
if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
Property p = cmd.getPMap().get(bcm.getSelectizeVisibleField());
if (p != null) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
Field hf = createHeaderField(p, md);
headerFields.add(hf);
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
}
} else {
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);
defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
}
if (md.getIsFilter() != null && md.getIsFilter()) {
Field f = createHeaderField(p, md);
wrapper.getFields().add(constructFieldDTOFromFieldData(f, md));
}
}
}
}
type = ListGrid.Type.BASIC;
if (AddMethodType.PERSIST.equals(bcm.getAddMethodType()) || AddMethodType.PERSIST_EMPTY.equals(bcm.getAddMethodType())) {
editable = true;
} else if (AddMethodType.SELECTIZE_LOOKUP.equals(bcm.getAddMethodType())) {
selectize = true;
modalSingleSelectable = true;
} else {
modalSingleSelectable = true;
}
sortable = StringUtils.isNotBlank(bcm.getSortProperty());
if (sortable) {
sortProperty = bcm.getSortProperty();
}
} else if (fmd instanceof AdornedTargetCollectionMetadata) {
modalSingleSelectable = true;
readOnly = !((AdornedTargetCollectionMetadata) fmd).isMutable();
AdornedTargetCollectionMetadata atcmd = (AdornedTargetCollectionMetadata) fmd;
if (AdornedTargetAddMethodType.LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
isLookup = true;
}
if (AdornedTargetAddMethodType.SELECTIZE_LOOKUP.equals(atcmd.getAdornedTargetAddMethodType())) {
selectize = true;
Property p = cmd.getPMap().get(atcmd.getSelectizeVisibleField());
if (p != null) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
Field hf = createHeaderField(p, md);
headerFields.add(hf);
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
}
} else {
for (String fieldName : atcmd.getGridVisibleFields()) {
Property p = cmd.getPMap().get(fieldName);
if (p != null) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
Field hf = createHeaderField(p, md);
headerFields.add(hf);
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
}
}
}
type = ListGrid.Type.ADORNED;
if (atcmd.getMaintainedAdornedTargetFields().length > 0) {
editable = true;
}
AdornedTargetList adornedList = (AdornedTargetList) atcmd.getPersistencePerspective().getPersistencePerspectiveItems().get(PersistencePerspectiveItemType.ADORNEDTARGETLIST);
sortable = StringUtils.isNotBlank(adornedList.getSortField());
if (sortable) {
sortProperty = adornedList.getSortField();
}
} else if (fmd instanceof MapMetadata) {
readOnly = !((MapMetadata) fmd).isMutable();
MapMetadata mmd = (MapMetadata) fmd;
Property p2 = cmd.getPMap().get("key");
BasicFieldMetadata keyMd = (BasicFieldMetadata) p2.getMetadata();
keyMd.setFriendlyName(getMapKeyFriendlyName(p2));
Field hf = createHeaderField(p2, keyMd);
headerFields.add(hf);
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, keyMd));
if (mmd.isSimpleValue()) {
Property valueProperty = cmd.getPMap().get("value");
BasicFieldMetadata valueMd = (BasicFieldMetadata) valueProperty.getMetadata();
valueMd.setFriendlyName("Value");
hf = createHeaderField(valueProperty, valueMd);
headerFields.add(hf);
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, valueMd));
idProperty = "key";
hideIdColumn = true;
} else {
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata md = (BasicFieldMetadata) p.getMetadata();
String valueClassName = mmd.getValueClassName();
if (!StringUtils.isEmpty(mmd.getToOneTargetProperty())) {
Class<?> clazz;
try {
clazz = Class.forName(mmd.getValueClassName());
} catch (ClassNotFoundException e) {
throw ExceptionHelper.refineException(e);
}
java.lang.reflect.Field nestedField = FieldManager.getSingleField(clazz, mmd.getToOneTargetProperty());
ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class);
if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) {
valueClassName = manyToOne.targetEntity().getName();
} else {
OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) {
valueClassName = oneToOne.targetEntity().getName();
}
}
}
if (md.getTargetClass().equals(valueClassName)) {
if (md.isProminent() != null && md.isProminent() && !ArrayUtils.contains(getGridHiddenVisibilities(), md.getVisibility())) {
hf = createHeaderField(p, md);
headerFields.add(hf);
defaultWrapperFields.add(constructFieldDTOFromFieldData(hf, md));
// Is this a media listgrid
if (hf.getFieldType().equals("ASSET_LOOKUP")) {
isMedia = true;
}
}
if (md.getIsFilter() != null && md.getIsFilter()) {
wrapper.getFields().add(constructFieldDTOFromFieldData(hf, md));
}
}
}
}
}
type = ListGrid.Type.MAP;
editable = true;
canFilterAndSort = false;
}
String ceilingType = "";
if (fmd instanceof BasicFieldMetadata) {
ceilingType = cmd.getCeilingType();
} else if (fmd instanceof CollectionMetadata) {
ceilingType = ((CollectionMetadata) fmd).getCollectionCeilingEntity();
}
if (CollectionUtils.isEmpty(headerFields)) {
String message = "There are no listgrid header fields configured for the class " + ceilingType + " and property '" + StringUtil.sanitize(field.getName()) + "'.";
if (selectize && (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM)) {
message += " Please configure 'selectizeVisibleField' in your @AdminPresentationAdornedTargetCollection configuration";
} else if (type == ListGrid.Type.ADORNED || type == ListGrid.Type.ADORNED_WITH_FORM) {
message += " Please configure 'gridVisibleFields' in your @AdminPresentationAdornedTargetCollection configuration";
} else if (selectize && type == ListGrid.Type.BASIC) {
message += " Please configure 'selectizeVisibleField' in your @AdminPresentationCollection configuration";
} else {
message += " Please mark some @AdminPresentation fields with 'prominent = true'";
}
LOG.error(message);
}
ListGrid listGrid = createListGrid(ceilingType, headerFields, type, drs, sectionKey, fmd.getOrder(), idProperty, sectionCrumbs, sortProperty);
listGrid.setSubCollectionFieldName(field.getName());
listGrid.setFriendlyName(field.getMetadata().getFriendlyName());
if (StringUtils.isEmpty(listGrid.getFriendlyName())) {
listGrid.setFriendlyName(field.getName());
}
listGrid.setContainingEntityId(containingEntityId);
listGrid.setIsReadOnly(readOnly);
listGrid.setHideIdColumn(hideIdColumn);
listGrid.setCanFilterAndSort(canFilterAndSort);
// Set up the filter builder params
Date c = new Date();
String friendlyName = field.getMetadata().getFriendlyName();
String jsonFriendlyName = friendlyName.replaceAll(" ", "_");
listGrid.setJsonFieldName(jsonFriendlyName + c.getTime() + "Json");
listGrid.setFriendlyName(friendlyName);
listGrid.setFieldBuilder("RULE_SIMPLE");
if (CollectionUtils.isEmpty(wrapper.getFields())) {
wrapper.setFields(defaultWrapperFields);
}
listGrid.setFieldWrapper(wrapper);
String blankJsonString = "{\"data\":[]}";
listGrid.setJson(blankJsonString);
DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
if (dw != null) {
listGrid.setDataWrapper(dw);
}
if (editable) {
listGrid.getRowActions().add(DefaultListGridActions.UPDATE);
}
if (readOnly) {
listGrid.getRowActions().add(DefaultListGridActions.VIEW);
}
if (sortable) {
listGrid.setCanFilterAndSort(false);
listGrid.setIsSortable(true);
}
if (modalSingleSelectable) {
if (readOnly) {
listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT.clone().withForListGridReadOnly(true));
} else {
listGrid.addModalRowAction(DefaultListGridActions.SINGLE_SELECT);
}
}
listGrid.setSelectType(ListGrid.SelectType.SINGLE_SELECT);
if (selectize) {
listGrid.setSelectizeUrl(buildSelectizeUrl(listGrid));
listGrid.setSelectType(ListGrid.SelectType.SELECTIZE);
}
if (modalMultiSelectable) {
listGrid.addModalRowAction(DefaultListGridActions.MULTI_SELECT);
listGrid.setSelectType(ListGrid.SelectType.MULTI_SELECT);
}
listGrid.getRowActions().add(DefaultListGridActions.REMOVE);
if (fmd.getManualFetch()) {
listGrid.setManualFetch(true);
listGrid.getToolbarActions().add(DefaultListGridActions.MANUAL_FETCH);
}
if (isMedia) {
listGrid.setListGridType(ListGrid.Type.ASSET_GRID);
}
extensionManager.getProxy().modifyListGrid(listGrid.getClassName(), listGrid);
// 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.modifyListGrid(new EntityFormModifierRequest().withListGrid(listGrid).withConfiguration(data).withCurrentUser(adminRemoteSecurityService.getPersistentAdminUser()).withRowLevelSecurityService(rowLevelSecurityService));
}
}
}
}
return listGrid;
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper 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.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method setEntityFormFields.
protected void setEntityFormFields(ClassMetadata cmd, EntityForm ef, List<Property> properties) {
List<Field> homelessFields = new ArrayList<>();
List<Field> fieldsWithAssociations = new ArrayList<>();
for (Property property : properties) {
if (property.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata fmd = (BasicFieldMetadata) property.getMetadata();
if (!ArrayUtils.contains(getFormHiddenVisibilities(), fmd.getVisibility())) {
// Depending on visibility, field for the particular property is not created on the form
String fieldType = fmd.getFieldType() == null ? null : fmd.getFieldType().toString();
// Create the field and set some basic attributes
Field f;
if (fieldType.equals(SupportedFieldType.BROADLEAF_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.EXPLICIT_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.DATA_DRIVEN_ENUMERATION.toString()) || fieldType.equals(SupportedFieldType.EMPTY_ENUMERATION.toString())) {
// We're dealing with fields that should render as drop-downs, so set their possible values
f = new ComboField();
((ComboField) f).setOptions(fmd.getEnumerationValues());
if (fmd.getHideEnumerationIfEmpty() != null && fmd.getHideEnumerationIfEmpty().booleanValue() && ((ComboField) f).getOptions().size() == 0) {
f.setIsVisible(false);
}
} else if (fieldType.equals(SupportedFieldType.CODE.toString())) {
f = new CodeField();
} else if (fieldType.equals(SupportedFieldType.RULE_SIMPLE.toString()) || fieldType.equals(SupportedFieldType.RULE_SIMPLE_TIME.toString()) || fieldType.equals(SupportedFieldType.RULE_WITH_QUANTITY.toString())) {
// We're dealing with rule builders, so we'll create those specialized fields
f = new RuleBuilderField();
((RuleBuilderField) f).setJsonFieldName(property.getName() + "Json");
((RuleBuilderField) f).setDataWrapper(new DataWrapper());
((RuleBuilderField) f).setFieldBuilder(fmd.getRuleIdentifier());
((RuleBuilderField) f).setDisplayType(fmd.getDisplayType().toString());
String blankJsonString = "{\"data\":[]}";
((RuleBuilderField) f).setJson(blankJsonString);
DataWrapper dw = convertJsonToDataWrapper(blankJsonString);
if (dw != null) {
((RuleBuilderField) f).setDataWrapper(dw);
}
if (fieldType.equals(SupportedFieldType.RULE_SIMPLE.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-simple");
} else if (fieldType.equals(SupportedFieldType.RULE_WITH_QUANTITY.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-with-quantity");
} else if (fieldType.equals(SupportedFieldType.RULE_SIMPLE_TIME.toString())) {
((RuleBuilderField) f).setRuleType("rule-builder-simple-time");
}
} else if (LookupType.DROPDOWN.equals(fmd.getLookupType())) {
// We're dealing with a to-one field that wants to be rendered as a dropdown instead of in a
// modal, so we'll provision the combo field here. Available options will be set as part of a
// subsequent operation
f = new ComboField();
} else if (fieldType.equals(SupportedFieldType.MEDIA.toString())) {
f = new MediaField();
} else {
// Create a default field since there was no specialized handler
f = new Field();
}
Boolean required = fmd.getRequiredOverride();
if (required == null) {
required = fmd.getRequired();
}
Boolean allowNoValueEnum = fmd.getAllowNoValueEnumOption();
if (allowNoValueEnum != null) {
f.setAllowNoValueEnumOption(allowNoValueEnum);
}
f.withName(property.getName()).withFieldType(fieldType).withFieldComponentRenderer(getFieldComponentRenderer(fmd)).withGridFieldComponentRenderer(getGridFieldComponentRenderer(fmd)).withOrder(fmd.getOrder()).withFriendlyName(fmd.getFriendlyName()).withForeignKeyDisplayValueProperty(fmd.getForeignKeyDisplayValueProperty()).withForeignKeyClass(fmd.getForeignKeyClass()).withForeignKeySectionPath(getAdminSectionPath(fmd.getForeignKeyClass())).withOwningEntityClass(fmd.getOwningClass() != null ? fmd.getOwningClass() : fmd.getInheritedFromType()).withRequired(required).withReadOnly(fmd.getReadOnly()).withTranslatable(fmd.getTranslatable()).withAlternateOrdering((Boolean) fmd.getAdditionalMetadata().get(Field.ALTERNATE_ORDERING)).withLargeEntry(fmd.isLargeEntry()).withHint(fmd.getHint()).withTooltip(fmd.getTooltip()).withHelp(fmd.getHelpText()).withTypeaheadEnabled(fmd.getEnableTypeaheadLookup()).withCanLinkToExternalEntity(fmd.getCanLinkToExternalEntity()).withAssociatedFieldName(fmd.getAssociatedFieldName());
String defaultValue = fmd.getDefaultValue();
if (defaultValue != null) {
defaultValue = extractDefaultValueFromFieldData(fieldType, fmd);
f.withValue(defaultValue);
}
if (StringUtils.isBlank(f.getFriendlyName())) {
f.setFriendlyName(f.getName());
}
// If is form hidden, set visible to false
if (VisibilityEnum.FORM_EXPLICITLY_HIDDEN.equals(fmd.getVisibility())) {
f.setIsVisible(false);
}
if (VisibilityEnum.VISIBLE_ALL.equals(fmd.getVisibility())) {
f.setIsVisible(true);
}
// Add the field to the appropriate FieldGroup
if (fmd.getGroup() == null) {
homelessFields.add(f);
} else {
ef.addField(cmd, f, fmd.getGroup(), fmd.getGroupOrder(), fmd.getTab(), fmd.getTabOrder());
}
if (StringUtils.isNotEmpty(fmd.getAssociatedFieldName())) {
fieldsWithAssociations.add(f);
}
}
}
}
for (Field f : homelessFields) {
ef.addField(cmd, f, null, null, null, null);
}
for (Field f : fieldsWithAssociations) {
Field associatedField = findAssociatedField(ef, f);
if (associatedField != null) {
associatedField.setShouldRender(false);
f.setAssociatedFieldName(associatedField.getName());
} else {
f.setAssociatedFieldName(null);
}
}
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityFormFieldValues.
@Override
public void populateEntityFormFieldValues(ClassMetadata cmd, Entity entity, EntityForm ef) {
// Set the appropriate property values
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
BasicFieldMetadata basicFM = (BasicFieldMetadata) p.getMetadata();
Property entityProp = entity.findProperty(p.getName());
boolean explicitlyShown = VisibilityEnum.FORM_EXPLICITLY_SHOWN.equals(basicFM.getVisibility());
// always show special map fields
if (p.getName().equals("key") || p.getName().equals("priorKey")) {
explicitlyShown = true;
}
if (entityProp == null && explicitlyShown) {
Field field = ef.findField(p.getName());
if (field != null) {
field.setValue(null);
}
} else if (entityProp == null && !SupportedFieldType.PASSWORD_CONFIRM.equals(basicFM.getExplicitFieldType())) {
ef.removeField(p.getName());
} else {
Field field = ef.findField(p.getName());
if (field != null) {
if (entityProp != null) {
// protect against null - can happen with password confirmation fields (i.e. admin user)
field.setDirty(entityProp.getIsDirty());
}
if (basicFM.getFieldType() == SupportedFieldType.RULE_SIMPLE || basicFM.getFieldType() == SupportedFieldType.RULE_SIMPLE_TIME || basicFM.getFieldType() == SupportedFieldType.RULE_WITH_QUANTITY) {
RuleBuilderField rbf = (RuleBuilderField) field;
if (entity.getPMap().containsKey(rbf.getJsonFieldName())) {
String json = entity.getPMap().get(rbf.getJsonFieldName()).getValue();
rbf.setJson(json);
DataWrapper dw = convertJsonToDataWrapper(json);
if (dw != null) {
rbf.setDataWrapper(dw);
}
}
}
if (basicFM.getFieldType() == SupportedFieldType.MEDIA) {
field.setValue(entityProp.getValue());
field.setDisplayValue(entityProp.getDisplayValue());
MediaField mf = (MediaField) field;
Class<MediaDto> type = entityConfiguration.lookupEntityClass(MediaDto.class.getName(), MediaDto.class);
mf.setMedia(mediaBuilderService.convertJsonToMedia(entityProp.getUnHtmlEncodedValue(), type));
} else if (!SupportedFieldType.PASSWORD_CONFIRM.equals(basicFM.getExplicitFieldType())) {
field.setValue(entityProp.getValue());
field.setDisplayValue(entityProp.getDisplayValue());
}
}
}
}
}
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper in project BroadleafCommerce by BroadleafCommerce.
the class MVELToDataWrapperTranslator method createRuleData.
public DataWrapper createRuleData(Entity[] entities, String mvelProperty, String quantityProperty, String idProperty, String containedProperty, RuleBuilderFieldService fieldService) {
if (entities == null || entities.length == 0 || mvelProperty == null) {
return null;
}
DataWrapper dataWrapper = new DataWrapper();
String mvel = null;
try {
for (Entity e : entities) {
Integer qty = null;
Long id = null;
Long containedId = null;
for (Property p : e.getProperties()) {
if (mvelProperty.equals(p.getName())) {
mvel = p.getValue();
}
if (quantityProperty != null && quantityProperty.equals(p.getName())) {
qty = Integer.parseInt(p.getValue());
}
if (idProperty != null && idProperty.equals(p.getName())) {
id = Long.parseLong(p.getValue());
}
if (containedProperty != null && containedProperty.equals(p.getName())) {
containedId = Long.parseLong(p.getValue());
}
}
if (mvel != null) {
Group group = groupingTranslator.createGroups(mvel);
DataDTO dataDTO = createRuleDataDTO(null, group, fieldService);
if (dataDTO != null) {
dataDTO.setPk(id);
dataDTO.setContainedPk(containedId);
dataDTO.setQuantity(qty);
dataWrapper.getData().add(dataDTO);
if (group.getSubGroups().size() > 0) {
Boolean invalidSubGroupFound = checkForInvalidSubGroup(dataDTO);
if (invalidSubGroupFound) {
throw new MVELTranslationException(MVELTranslationException.SUB_GROUP_DETECTED, SUB_GROUP_MESSAGE);
}
}
}
}
}
} catch (MVELTranslationException e) {
LOG.error("Unable to translate rule MVEL", e);
dataWrapper.getData().clear();
dataWrapper.setError(e.getLocalizedMessage());
dataWrapper.setRawMvel(mvel);
}
return dataWrapper;
}
Aggregations