use of org.jowidgets.cap.common.api.exception.BeanException in project jo-client-platform by jo-source.
the class LinkCreatorServiceImpl method getBeans.
private <BEAN_TYPE extends IBean> List<IBeanDto> getBeans(final IBeanDto linkedBean, final IEntityLinkProperties linkProperties, final Collection<IBeanKey> beanKeys, final IBeanAccess<BEAN_TYPE> beanAccess, final IBeanDtoFactory<BEAN_TYPE> dtoFactory, final IExecutionCallback executionCallback) {
final List<IBeanDto> result = new LinkedList<IBeanDto>();
for (final IBeanKey beanKey : beanKeys) {
CapServiceToolkit.checkCanceled(executionCallback);
final List<IBeanKey> singletonList = Collections.singletonList(beanKey);
final List<BEAN_TYPE> beans = beanAccess.getBeans(singletonList, executionCallback);
if (!EmptyCheck.isEmpty(beans) && beans.size() == 1) {
final BEAN_TYPE bean = beans.iterator().next();
if (linkedBean != null && linkProperties != null) {
final Object sourceKey = linkedBean.getValue(linkProperties.getKeyPropertyName());
BeanUtils.setProperty(bean, linkProperties.getForeignKeyPropertyName(), sourceKey);
}
result.add(dtoFactory.createDto(bean));
} else if (!EmptyCheck.isEmpty(beans) && beans.size() > 1) {
throw new BeanException(beanKey.getId(), "More than one bean found for the key '" + beanKey + "'");
} else {
throw new DeletedBeanException(beanKey.getId());
}
}
return result;
}
use of org.jowidgets.cap.common.api.exception.BeanException in project jo-client-platform by jo-source.
the class BeanModifierImpl method modify.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void modify(final BEAN_TYPE bean, final IBeanModification modification) {
final Method writeMethod = writeMethods.get(modification.getPropertyName());
if (writeMethod != null || bean instanceof IPropertyMap) {
// plugin before invocation
final List<IBeanModifierPlugin<?>> plugins;
plugins = PluginProvider.getPlugins(IBeanModifierPlugin.ID, pluginProperties);
for (final IBeanModifierPlugin plugin : plugins) {
plugin.beforeModification(bean, modification);
}
// do modification
if (writeMethod != null) {
try {
writeMethod.invoke(bean, modification.getNewValue());
} catch (final Exception e) {
throw new RuntimeException(e);
}
} else if (bean instanceof IPropertyMap) {
((IPropertyMap) bean).setValue(modification.getPropertyName(), modification.getNewValue());
}
// plugin after invocation
for (final IBeanModifierPlugin plugin : plugins) {
plugin.afterModification(bean, modification);
}
} else {
throw new BeanException(modification.getId(), "Tryed to set the property '" + modification.getPropertyName() + "', but the property is not defined / allowed for this bean.");
}
}
use of org.jowidgets.cap.common.api.exception.BeanException in project jo-client-platform by jo-source.
the class LinkDeleterServiceImpl method resetDirectLink.
private <BEAN_TYPE extends IBean> void resetDirectLink(final IEntityLinkProperties linkProperties, final IBeanKey beanKey, final IBeanAccess<BEAN_TYPE> beanAccess, final IExecutionCallback executionCallback) {
CapServiceToolkit.checkCanceled(executionCallback);
final List<IBeanKey> singletonList = Collections.singletonList(beanKey);
final List<BEAN_TYPE> beans = beanAccess.getBeans(singletonList, executionCallback);
if (!EmptyCheck.isEmpty(beans) && beans.size() == 1) {
final BEAN_TYPE bean = beans.iterator().next();
BeanUtils.setProperty(bean, linkProperties.getForeignKeyPropertyName(), null);
} else if (!EmptyCheck.isEmpty(beans) && beans.size() > 1) {
throw new BeanException(beanKey.getId(), "More than one bean found for the key '" + beanKey + "'");
} else {
throw new DeletedBeanException(beanKey.getId());
}
}
Aggregations