use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class AdminPermissionCustomPersistenceHandler method checkPermissionName.
protected Entity checkPermissionName(PersistencePackage persistencePackage) throws ServiceException {
Entity entity = persistencePackage.getEntity();
Property prop = entity.findProperty("name");
String name = prop.getValue();
name = name.toUpperCase();
if (!name.startsWith("PERMISSION_")) {
throw new ServiceException("All Permission names must start with PERMISSION_");
}
String[] parts = name.split("_");
if (parts.length < 3) {
throw new ServiceException("All Permission names must adhere to the naming standard: PERMISSION_[Permission Type]_[User Defined Section]. E.g. PERMISSION_READ_CATEGORY");
}
if (PermissionType.getInstance(parts[1]) == null) {
throw new ServiceException("All Permission names must specify a valid permission type as part of the name. The permission name you specified (" + name + ") denotes the permission type of (" + parts[1] + "), which is not valid. See org.broadleafcommerce.openadmin.server.security.service.type.PermissionType for valid permission types.");
}
prop.setValue(name);
return entity;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class BasicPersistenceModule method getPrimaryKey.
@Override
public Object getPrimaryKey(Entity entity, Map<String, FieldMetadata> mergedUnfilteredProperties) {
Map<String, FieldMetadata> mergedProperties = filterOutCollectionMetadata(mergedUnfilteredProperties);
Object primaryKey = null;
String idPropertyName = null;
BasicFieldMetadata metaData = null;
for (String property : mergedProperties.keySet()) {
BasicFieldMetadata temp = (BasicFieldMetadata) mergedProperties.get(property);
if (temp.getFieldType() == SupportedFieldType.ID && !property.contains(".")) {
idPropertyName = property;
metaData = temp;
break;
}
}
if (idPropertyName == null) {
throw new RuntimeException("Could not find a primary key property in the passed entity with type: " + entity.getType()[0]);
}
for (Property property : entity.getProperties()) {
if (property.getName().equals(idPropertyName)) {
switch(metaData.getSecondaryType()) {
case INTEGER:
primaryKey = (property.getValue() == null) ? null : Long.valueOf(property.getValue());
break;
case STRING:
primaryKey = property.getValue();
break;
}
break;
}
}
if (primaryKey == null) {
throw new RuntimeException("Could not find the primary key property (" + idPropertyName + ") in the passed entity with type: " + entity.getType()[0]);
}
return primaryKey;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class BasicPersistenceModule method extractPropertiesFromPersistentEntity.
protected void extractPropertiesFromPersistentEntity(Map<String, FieldMetadata> mergedProperties, Serializable entity, List<Property> props, String[] customCriteria) {
FieldManager fieldManager = getFieldManager();
try {
if (entity instanceof AdminMainEntity) {
// its display name.
try {
Property propertyItem = new Property();
propertyItem.setName(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
propertyItem.setValue(((AdminMainEntity) entity).getMainEntityName());
props.add(propertyItem);
} catch (Exception e) {
// do nothing here except for not add the property. Exceptions could occur when there is a validation
// issue and some properties/relationships that are used for gleaning the main entity name end up
// not being set
}
}
for (Entry<String, FieldMetadata> entry : mergedProperties.entrySet()) {
String property = entry.getKey();
BasicFieldMetadata metadata = (BasicFieldMetadata) entry.getValue();
if (Class.forName(metadata.getInheritedFromType()).isAssignableFrom(entity.getClass()) || entity.getClass().isAssignableFrom(Class.forName(metadata.getInheritedFromType()))) {
boolean proceed = true;
if (property.contains(".")) {
StringTokenizer tokens = new StringTokenizer(property, ".");
Object testObject = entity;
while (tokens.hasMoreTokens()) {
String token = tokens.nextToken();
if (tokens.hasMoreTokens()) {
try {
testObject = fieldManager.getFieldValue(testObject, token);
} catch (FieldNotAvailableException e) {
proceed = false;
break;
}
if (testObject == null) {
Property propertyItem = new Property();
propertyItem.setName(property);
if (props.contains(propertyItem)) {
proceed = false;
break;
}
propertyItem.setValue(null);
props.add(propertyItem);
proceed = false;
break;
}
}
}
}
if (!proceed) {
continue;
}
boolean isFieldAccessible = true;
Object value = null;
try {
value = fieldManager.getFieldValue(entity, property);
} catch (FieldNotAvailableException e) {
isFieldAccessible = false;
}
checkField: {
if (isFieldAccessible) {
Property propertyItem = new Property();
propertyItem.setName(property);
if (props.contains(propertyItem)) {
continue;
}
props.add(propertyItem);
String displayVal = propertyItem.getDisplayValue();
boolean handled = false;
for (FieldPersistenceProvider fieldPersistenceProvider : fieldPersistenceProviders) {
MetadataProviderResponse response = fieldPersistenceProvider.extractValue(new ExtractValueRequest(props, fieldManager, metadata, value, displayVal, persistenceManager, this, entity, customCriteria), propertyItem);
if (MetadataProviderResponse.NOT_HANDLED != response) {
handled = true;
}
if (MetadataProviderResponse.HANDLED_BREAK == response) {
break;
}
}
if (!handled) {
defaultFieldPersistenceProvider.extractValue(new ExtractValueRequest(props, fieldManager, metadata, value, displayVal, persistenceManager, this, entity, customCriteria), propertyItem);
}
break checkField;
}
// try a direct property acquisition via reflection
try {
String strVal = null;
Method method;
try {
// try a 'get' prefixed mutator first
String temp = "get" + property.substring(0, 1).toUpperCase() + property.substring(1, property.length());
method = entity.getClass().getMethod(temp, new Class[] {});
} catch (NoSuchMethodException e) {
method = entity.getClass().getMethod(property, new Class[] {});
}
value = method.invoke(entity, new String[] {});
Property propertyItem = new Property();
propertyItem.setName(property);
if (props.contains(propertyItem)) {
continue;
}
props.add(propertyItem);
if (value == null) {
strVal = null;
} else {
if (Date.class.isAssignableFrom(value.getClass())) {
strVal = getSimpleDateFormatter().format((Date) value);
} else if (Timestamp.class.isAssignableFrom(value.getClass())) {
strVal = getSimpleDateFormatter().format(new Date(((Timestamp) value).getTime()));
} else if (Calendar.class.isAssignableFrom(value.getClass())) {
strVal = getSimpleDateFormatter().format(((Calendar) value).getTime());
} else if (Double.class.isAssignableFrom(value.getClass())) {
strVal = getDecimalFormatter().format(value);
} else if (BigDecimal.class.isAssignableFrom(value.getClass())) {
strVal = getDecimalFormatter().format(value);
} else {
strVal = value.toString();
}
}
propertyItem.setValue(strVal);
} catch (NoSuchMethodException e) {
LOG.debug("Unable to find a specified property in the entity: " + StringUtil.sanitize(property));
// do nothing - this property is simply not in the bean
}
}
}
}
} catch (ClassNotFoundException e) {
throw new PersistenceException(e);
} catch (IllegalAccessException e) {
throw new PersistenceException(e);
} catch (InvocationTargetException e) {
throw new PersistenceException(e);
}
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class MediaFieldPersistenceProvider method filterProperties.
@Override
public MetadataProviderResponse filterProperties(AddFilterPropertiesRequest addFilterPropertiesRequest, Map<String, FieldMetadata> properties) {
// BP: Basically copied this from RuleFieldPersistenceProvider
List<Property> propertyList = new ArrayList<Property>();
propertyList.addAll(Arrays.asList(addFilterPropertiesRequest.getEntity().getProperties()));
Iterator<Property> itr = propertyList.iterator();
List<Property> additionalProperties = new ArrayList<Property>();
while (itr.hasNext()) {
Property prop = itr.next();
if (prop.getName().endsWith("Json")) {
for (Map.Entry<String, FieldMetadata> entry : properties.entrySet()) {
if (prop.getName().startsWith(entry.getKey())) {
BasicFieldMetadata originalFM = (BasicFieldMetadata) entry.getValue();
if (originalFM.getFieldType() == SupportedFieldType.MEDIA) {
Property originalProp = addFilterPropertiesRequest.getEntity().findProperty(originalFM.getName());
if (originalProp == null) {
originalProp = new Property();
originalProp.setName(originalFM.getName());
additionalProperties.add(originalProp);
}
originalProp.setValue(prop.getValue());
originalProp.setRawValue(prop.getRawValue());
originalProp.setUnHtmlEncodedValue(prop.getUnHtmlEncodedValue());
itr.remove();
break;
}
}
}
}
}
propertyList.addAll(additionalProperties);
addFilterPropertiesRequest.getEntity().setProperties(propertyList.toArray(new Property[propertyList.size()]));
return MetadataProviderResponse.HANDLED;
}
use of org.broadleafcommerce.openadmin.dto.Property in project BroadleafCommerce by BroadleafCommerce.
the class RuleFieldPersistenceProvider method extractSimpleRule.
protected void extractSimpleRule(ExtractValueRequest extractValueRequest, Property property, ObjectMapper mapper, MVELToDataWrapperTranslator translator) {
Property jsonProperty;
if (extractValueRequest.getRequestedValue() != null) {
if (extractValueRequest.getRequestedValue() instanceof String) {
String val = (String) extractValueRequest.getRequestedValue();
property.setValue(val);
property.setDisplayValue(extractValueRequest.getDisplayVal());
jsonProperty = ruleFieldExtractionUtility.convertSimpleRuleToJson(translator, mapper, val, property.getName() + "Json", extractValueRequest.getMetadata().getRuleIdentifier());
} else {
Object simpleRule = extractValueRequest.getRequestedValue();
if (simpleRule != null) {
if (simpleRule instanceof SimpleRule) {
String val = ((SimpleRule) simpleRule).getMatchRule();
property.setValue(val);
property.setDisplayValue(extractValueRequest.getDisplayVal());
jsonProperty = convertSimpleRuleToJson(translator, mapper, (SimpleRule) simpleRule, property.getName() + "Json", extractValueRequest.getMetadata().getRuleIdentifier());
} else {
throw new UnsupportedOperationException("RULE_SIMPLE type is currently only supported on " + "fields of type SimpleRule");
}
} else {
jsonProperty = ruleFieldExtractionUtility.convertSimpleRuleToJson(translator, mapper, null, property.getName() + "Json", extractValueRequest.getMetadata().getRuleIdentifier());
}
}
} else {
jsonProperty = ruleFieldExtractionUtility.convertSimpleRuleToJson(translator, mapper, null, property.getName() + "Json", extractValueRequest.getMetadata().getRuleIdentifier());
}
extractValueRequest.getProps().add(jsonProperty);
}
Aggregations