Search in sources :

Example 41 with BasicFieldMetadata

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);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) HashMap(java.util.HashMap) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment) MergedPropertyType(org.broadleafcommerce.openadmin.dto.MergedPropertyType) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) CustomerPaymentImpl(org.broadleafcommerce.profile.core.domain.CustomerPaymentImpl) HashMap(java.util.HashMap) Map(java.util.Map) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Example 42 with BasicFieldMetadata

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;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 43 with BasicFieldMetadata

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;
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)

Example 44 with BasicFieldMetadata

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));
                    }
                }
            }
        }
    }
}
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 45 with BasicFieldMetadata

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;
}
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)

Aggregations

BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)66 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)33 Property (org.broadleafcommerce.openadmin.dto.Property)28 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 Map (java.util.Map)14 Entity (org.broadleafcommerce.openadmin.dto.Entity)11 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)10 AdminMainEntity (org.broadleafcommerce.common.admin.domain.AdminMainEntity)9 FieldMetadataOverride (org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride)9 Field (java.lang.reflect.Field)8 PersistenceException (org.broadleafcommerce.openadmin.server.service.persistence.PersistenceException)8 ServiceException (org.broadleafcommerce.common.exception.ServiceException)7 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)7 ComboField (org.broadleafcommerce.openadmin.web.form.entity.ComboField)7 Field (org.broadleafcommerce.openadmin.web.form.entity.Field)7 Serializable (java.io.Serializable)6 SecurityServiceException (org.broadleafcommerce.common.exception.SecurityServiceException)6 MetadataOverride (org.broadleafcommerce.openadmin.dto.override.MetadataOverride)6 FieldInfo (org.broadleafcommerce.openadmin.server.dao.FieldInfo)6