Search in sources :

Example 1 with IdentityHashKey

use of org.jowidgets.util.collection.IdentityHashKey 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;
}
Also used : IBeanDataMapper(org.jowidgets.cap.service.api.creator.IBeanDataMapper) IdentityHashKey(org.jowidgets.util.collection.IdentityHashKey) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)1 IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)1 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)1 IBeanDataMapper (org.jowidgets.cap.service.api.creator.IBeanDataMapper)1 IdentityHashKey (org.jowidgets.util.collection.IdentityHashKey)1