Search in sources :

Example 86 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class BasicEntityMetadataProvider method addTabAndGroupMetadataFromCmdProperties.

@Override
public MetadataProviderResponse addTabAndGroupMetadataFromCmdProperties(ClassMetadata cmd, Map<String, TabMetadata> metadata) {
    for (Property p : cmd.getProperties()) {
        FieldMetadata fmd = p.getMetadata();
        boolean isExcluded = fmd.getExcluded() != null && fmd.getExcluded() == true;
        boolean isHidden = fmd instanceof BasicFieldMetadata && ((BasicFieldMetadata) fmd).getVisibility() != null && (((BasicFieldMetadata) fmd).getVisibility().equals(VisibilityEnum.HIDDEN_ALL) || ((BasicFieldMetadata) fmd).getVisibility().equals(VisibilityEnum.FORM_HIDDEN));
        if (!(isExcluded || isHidden)) {
            GroupMetadata groupMetadata = getGroupFromMetadata(fmd.getGroup(), metadata);
            if (groupMetadata == null) {
                TabMetadata tabMetadata = getTabFromMetadata(fmd.getTab(), metadata);
                Map<String, GroupMetadata> groupMetadataMap = tabMetadata == null || tabMetadata.getGroupMetadata() == null ? new HashMap<String, GroupMetadata>() : tabMetadata.getGroupMetadata();
                if (tabMetadata == null && !(fmd.getTab() == null || fmd.getTab().isEmpty())) {
                    tabMetadata = new TabMetadata();
                    tabMetadata.setTabName(fmd.getTab());
                    tabMetadata.setTabOrder(fmd.getTabOrder());
                    tabMetadata.setOwningClass(cmd.getPolymorphicEntities().getFullyQualifiedClassname());
                    tabMetadata.setGroupMetadata(groupMetadataMap);
                    metadata.put(fmd.getTab(), tabMetadata);
                }
                // is a collection being added to only the specified tab, not a group as well.
                if (!(fmd.getGroup() == null || fmd.getGroup().isEmpty())) {
                    groupMetadata = new GroupMetadata();
                    groupMetadata.setOwningClass(cmd.getPolymorphicEntities().getFullyQualifiedClassname());
                    groupMetadata.setGroupName(fmd.getGroup());
                    groupMetadata.setGroupOrder(fmd.getGroupOrder());
                    groupMetadata.setColumn(0);
                    groupMetadata.setUntitled(false);
                    groupMetadata.setCollapsed(false);
                    groupMetadataMap.put(fmd.getGroup(), groupMetadata);
                }
            }
        }
    }
    return MetadataProviderResponse.HANDLED;
}
Also used : FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) GroupMetadata(org.broadleafcommerce.openadmin.dto.GroupMetadata) TabMetadata(org.broadleafcommerce.openadmin.dto.TabMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) FieldMetadataOverride(org.broadleafcommerce.openadmin.dto.override.FieldMetadataOverride) AdminTabPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminTabPresentationOverride) AdminGroupPresentationOverride(org.broadleafcommerce.common.presentation.override.AdminGroupPresentationOverride) GroupMetadataOverride(org.broadleafcommerce.openadmin.dto.override.GroupMetadataOverride) MetadataOverride(org.broadleafcommerce.openadmin.dto.override.MetadataOverride)

Example 87 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminUserCustomPersistenceHandler method update.

@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
    Entity entity = persistencePackage.getEntity();
    try {
        PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
        Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(AdminUser.class.getName(), persistencePerspective);
        Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
        AdminUser adminInstance = (AdminUser) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
        Entity errorEntity = validateLegalUsernameAndEmail(entity, adminInstance, false);
        if (errorEntity != null) {
            return errorEntity;
        }
        String passwordBefore = adminInstance.getPassword();
        adminInstance.setPassword(null);
        adminInstance = (AdminUser) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
        Property passwordProperty = entity.getPMap().get("password");
        if (passwordProperty != null) {
            if (StringUtils.isNotEmpty(passwordProperty.getValue())) {
                adminInstance.setUnencodedPassword(passwordProperty.getValue());
                adminInstance.setPassword(null);
            } else {
                adminInstance.setPassword(passwordBefore);
            }
        }
        validateUserUpdateSecurity(persistencePackage, adminInstance);
        adminInstance = adminSecurityService.saveAdminUser(adminInstance);
        Entity adminEntity = helper.getRecord(adminProperties, adminInstance, null, null);
        return adminEntity;
    } catch (Exception e) {
        throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) AdminUser(org.broadleafcommerce.openadmin.server.security.domain.AdminUser) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException)

Example 88 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminSecurityServiceRemote method securityCheck.

@Override
public void securityCheck(PersistencePackage persistencePackage, EntityOperationType operationType) throws ServiceException {
    Set<String> ceilingNames = new HashSet<String>();
    ceilingNames.add(persistencePackage.getSecurityCeilingEntityFullyQualifiedClassname());
    if (!ArrayUtils.isEmpty(persistencePackage.getSectionCrumbs())) {
        ceilingNames.addAll(CollectionUtils.transform(Arrays.asList(persistencePackage.getSectionCrumbs()), new Transformer() {

            @Override
            public Object transform(Object o) {
                return ((SectionCrumb) o).getSectionIdentifier();
            }
        }));
    }
    Entity entity = persistencePackage.getEntity();
    if (persistencePackage.getPersistencePerspectiveItems().containsKey(PersistencePerspectiveItemType.ADORNEDTARGETLIST)) {
        if (persistencePackage.getEntity() != null) {
            for (Property property : persistencePackage.getProperties()) {
                if (property.getName() != null && property.getName().endsWith(".id") && property.getValue() == null) {
                    entity.addGlobalValidationError("adornedTargetRequired");
                    throw new ValidationException(entity);
                }
            }
        }
    }
    GlobalValidationResult globalValidationResult = null;
    if (operationType.equals(EntityOperationType.UPDATE)) {
        globalValidationResult = rowLevelSecurityService.validateUpdateRequest(getPersistentAdminUser(), entity, persistencePackage);
    } else if (operationType.equals(EntityOperationType.REMOVE)) {
        globalValidationResult = rowLevelSecurityService.validateRemoveRequest(getPersistentAdminUser(), entity, persistencePackage);
    } else if (operationType.equals(EntityOperationType.ADD)) {
        globalValidationResult = rowLevelSecurityService.validateAddRequest(getPersistentAdminUser(), entity, persistencePackage);
    }
    if (globalValidationResult != null) {
        if (!globalValidationResult.isValid()) {
            if (StringUtils.isEmpty(globalValidationResult.getErrorMessage())) {
                entity.addGlobalValidationError("rowLevelSecurityFailed");
            } else {
                entity.addGlobalValidationErrors(globalValidationResult.getErrorMessages());
            }
            throw new ValidationException(entity, "Row level security check failed for " + operationType);
        }
    }
    securityCheck(ceilingNames.toArray(new String[ceilingNames.size()]), operationType);
}
Also used : SectionCrumb(org.broadleafcommerce.openadmin.dto.SectionCrumb) Entity(org.broadleafcommerce.openadmin.dto.Entity) Transformer(org.springframework.cglib.core.Transformer) ValidationException(org.broadleafcommerce.openadmin.server.service.ValidationException) GlobalValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.GlobalValidationResult) Property(org.broadleafcommerce.openadmin.dto.Property) HashSet(java.util.HashSet)

Example 89 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getPropertiesFromEntityForm.

protected List<Property> getPropertiesFromEntityForm(EntityForm entityForm) {
    List<Property> properties = new ArrayList<Property>(entityForm.getFields().size());
    for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
        Property p = new Property();
        p.setName(entry.getKey());
        p.setValue(entry.getValue().getValue());
        p.setDisplayValue(entry.getValue().getDisplayValue());
        p.setIsDirty(entry.getValue().getIsDirty());
        properties.add(p);
    }
    return properties;
}
Also used : Field(org.broadleafcommerce.openadmin.web.form.entity.Field) ArrayList(java.util.ArrayList) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) Property(org.broadleafcommerce.openadmin.dto.Property)

Example 90 with Property

use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.

the class AdminEntityServiceImpl method getContextSpecificRelationshipId.

@Override
public String getContextSpecificRelationshipId(ClassMetadata cmd, Entity entity, String propertyName) {
    String prefix;
    if (propertyName.contains(".")) {
        prefix = propertyName.substring(0, propertyName.lastIndexOf("."));
    } else {
        prefix = "";
    }
    if (prefix.equals("")) {
        return entity.findProperty("id").getValue();
    } else {
        // we need to check all the parts of the prefix. For example, the prefix could include an @Embedded class like
        // defaultSku.dimension. In this case, we want the id from the defaultSku property, since the @Embedded does
        // not have an id property - nor should it.
        String[] prefixParts = prefix.split("\\.");
        for (int j = 0; j < prefixParts.length; j++) {
            StringBuilder sb = new StringBuilder();
            for (int x = 0; x < prefixParts.length - j; x++) {
                sb.append(prefixParts[x]);
                if (x < prefixParts.length - j - 1) {
                    sb.append(".");
                }
            }
            String tempPrefix = sb.toString();
            for (Property property : entity.getProperties()) {
                if (property.getName().startsWith(tempPrefix)) {
                    // in the case of the prefix defaultSku, we want defaultSku.id not defaultSku.skuAttributes.id
                    if (StringUtils.countMatches(property.getName().replace(tempPrefix, ""), ".") == 1) {
                        if (cmd.getPMap().containsKey(property.getName())) {
                            BasicFieldMetadata md = (BasicFieldMetadata) cmd.getPMap().get(property.getName()).getMetadata();
                            if (md.getFieldType().equals(SupportedFieldType.ID)) {
                                return property.getValue();
                            }
                        }
                    }
                }
            }
        }
    }
    if (!prefix.contains(".")) {
        // this may be an embedded class directly on the root entity (e.g. embeddablePriceList.restrictedPriceLists on OfferImpl)
        return entity.findProperty("id").getValue();
    }
    throw new RuntimeException("Unable to establish a relationship id");
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BLCSystemProperty(org.broadleafcommerce.common.util.BLCSystemProperty) 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