use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldData in project BroadleafCommerce by BroadleafCommerce.
the class AbstractRuleBuilderFieldService method setFields.
@Override
@SuppressWarnings("unchecked")
public void setFields(final List<FieldData> fields) {
List<FieldData> proxyFields = (List<FieldData>) Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { List.class }, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (method.getName().equals("add")) {
FieldData fieldData = (FieldData) args[0];
testFieldName(fieldData);
}
if (method.getName().equals("addAll")) {
Collection<FieldData> addCollection = (Collection<FieldData>) args[0];
Iterator<FieldData> itr = addCollection.iterator();
while (itr.hasNext()) {
FieldData fieldData = itr.next();
testFieldName(fieldData);
}
}
return method.invoke(fields, args);
}
private void testFieldName(FieldData fieldData) throws ClassNotFoundException {
if (!fieldData.getSkipValidation()) {
if (!StringUtils.isEmpty(fieldData.getFieldName()) && dynamicEntityDao != null) {
String dtoClassName = getDtoClassName();
if (fieldData.getOverrideDtoClassName() != null) {
dtoClassName = fieldData.getOverrideDtoClassName();
}
Class<?>[] dtos = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(Class.forName(dtoClassName));
if (ArrayUtils.isEmpty(dtos)) {
dtos = new Class<?>[] { Class.forName(dtoClassName) };
}
Field field = null;
for (Class<?> dto : dtos) {
field = dynamicEntityDao.getFieldManager().getField(dto, fieldData.getFieldName());
if (field != null) {
break;
}
}
if (field == null) {
throw new IllegalArgumentException("Unable to find the field declared in FieldData (" + fieldData.getFieldName() + ") on the target class (" + dtoClassName + "), or any registered entity class that derives from it.");
}
}
}
}
});
this.fields = proxyFields;
}
use of org.broadleafcommerce.openadmin.web.rulebuilder.dto.FieldData in project BroadleafCommerce by BroadleafCommerce.
the class AbstractRuleBuilderFieldService method onApplicationEvent.
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
// This bean only is valid when the following bean is active. (admin)
if (applicationContext.containsBean(PersistenceManagerFactory.getPersistenceManagerRef()) && applicationContext.containsBean("blPersistenceManagerFactory")) {
// initialize the factory bean
applicationContext.getBean("blPersistenceManagerFactory");
PersistenceManager persistenceManager = PersistenceManagerFactory.getDefaultPersistenceManager();
dynamicEntityDao = persistenceManager.getDynamicEntityDao();
setFields(new ArrayList<FieldData>());
// This cannot be null during startup as we do not want to remove the null safety checks in a multi-tenant env.
boolean contextWasNull = false;
if (BroadleafRequestContext.getBroadleafRequestContext() == null) {
BroadleafRequestContext brc = new BroadleafRequestContext();
brc.setIgnoreSite(true);
BroadleafRequestContext.setBroadleafRequestContext(brc);
contextWasNull = true;
}
try {
init();
// Initialize additional static fields method for the component.
if (extensionManager != null) {
extensionManager.getProxy().addFields(fields, getName(), getDtoClassName());
}
validateRuleBuilderState(this);
} finally {
if (contextWasNull) {
BroadleafRequestContext.setBroadleafRequestContext(null);
}
}
}
}
Aggregations