use of org.jowidgets.cap.service.api.creator.IBeanDataMapper in project jo-client-platform by jo-source.
the class AbstractSyncCreatorServiceImpl method create.
@SuppressWarnings("unchecked")
@Override
public final List<IBeanDto> create(final List<? extends IBeanKey> parentBeanKeys, final Collection<? extends IBeanData> beansData, final IExecutionCallback executionCallback) {
final List<IBeanDto> result = new LinkedList<IBeanDto>();
final List<BEAN_TYPE> beans = new ArrayList<BEAN_TYPE>(beansData.size());
final Map<IdentityHashKey, IBeanData> beanDataMap = new HashMap<IdentityHashKey, IBeanData>();
for (final IBeanData beanData : beansData) {
CapServiceToolkit.checkCanceled(executionCallback);
final BEAN_TYPE bean = createBean((Collection<IBeanKey>) parentBeanKeys, executionCallback);
beanDataMap.put(new IdentityHashKey(bean), beanData);
beans.add(bean);
}
final IBeanDataMapper<BEAN_TYPE> beanDataMapper = new BeanDataMapper(beanDataMap);
beforeInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
beanInitializer.initialize(bean, beanDataMapper.getBeanData(bean));
}
afterInitialize((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
checkExecutableStates(beans, executionCallback);
validate(beans, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
persistBean((Collection<IBeanKey>) parentBeanKeys, bean, executionCallback);
}
afterCreate((List<IBeanKey>) parentBeanKeys, beans, beanDataMapper, executionCallback);
for (final BEAN_TYPE bean : beans) {
CapServiceToolkit.checkCanceled(executionCallback);
result.add(dtoFactory.createDto(bean));
}
CapServiceToolkit.checkCanceled(executionCallback);
return result;
}
Aggregations