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