Search in sources :

Example 76 with Property

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;
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) MultiValueMap(org.springframework.util.MultiValueMap) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 77 with Property

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);
}
Also used : DataWrapper(org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper) PropertyValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.PropertyValidationResult) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 78 with Property

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));
                    }
                }
            }
        }
    }
}
Also used : SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) EntityFormModifierDataPoint(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierDataPoint) EntityFormModifier(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifier) EntityFormModifierConfiguration(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierConfiguration) ServiceException(org.broadleafcommerce.common.exception.ServiceException) SecurityServiceException(org.broadleafcommerce.common.exception.SecurityServiceException) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) EntityFormModifierRequest(org.broadleafcommerce.openadmin.server.security.service.EntityFormModifierRequest) ExceptionAwareRowLevelSecurityProvider(org.broadleafcommerce.openadmin.server.security.service.ExceptionAwareRowLevelSecurityProvider) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 79 with Property

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;
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) ArrayList(java.util.ArrayList) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 80 with Property

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;
}
Also used : AdminMainEntity(org.broadleafcommerce.common.admin.domain.AdminMainEntity) Entity(org.broadleafcommerce.openadmin.dto.Entity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CodeField(org.broadleafcommerce.openadmin.web.form.entity.CodeField) RuleBuilderField(org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField) Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ComboField(org.broadleafcommerce.openadmin.web.form.entity.ComboField) MediaField(org.broadleafcommerce.openadmin.web.form.component.MediaField) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) JSONObject(org.codehaus.jettison.json.JSONObject) Map(java.util.Map) HashMap(java.util.HashMap) Property(org.broadleafcommerce.openadmin.dto.Property)

Aggregations

Property (org.broadleafcommerce.openadmin.dto.Property)120 Entity (org.broadleafcommerce.openadmin.dto.Entity)62 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)45 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)38 ArrayList (java.util.ArrayList)28 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)26 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)25 DataWrapper (org.broadleafcommerce.openadmin.web.rulebuilder.dto.DataWrapper)21 SectionCrumb (org.broadleafcommerce.openadmin.dto.SectionCrumb)19 HashMap (java.util.HashMap)18 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)18 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)16 Map (java.util.Map)15 ServiceException (org.broadleafcommerce.common.exception.ServiceException)15 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)15 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)13 RuleBuilderField (org.broadleafcommerce.openadmin.web.form.component.RuleBuilderField)12 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)12