Search in sources :

Example 21 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method createInverseDirectLinkBeans.

private List<IBeanDto> createInverseDirectLinkBeans(final IBeanDto linkedBean, final Collection<IBeanData> beanDatas, final ICreatorService creatorService, final IExecutionCallback executionCallback) {
    final List<IBeanDto> result = new LinkedList<IBeanDto>();
    for (final IBeanData beanData : beanDatas) {
        final DecoratedLinkBeanData decoratedBeanData = new DecoratedLinkBeanData(beanData, linkedBean, null);
        result.add(createBean(decoratedBeanData, creatorService, executionCallback));
    }
    return result;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData) LinkedList(java.util.LinkedList)

Example 22 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method createLink.

private IBeanDto createLink(final IBeanDto sourceBean, final IBeanDto linkedBean, final IBeanData additionalProperties, final IExecutionCallback executionCallback) {
    final IBeanData decoratedBeanData = new DecoratedLinkBeanData(additionalProperties, linkedBean, sourceBean);
    final IBeanDto linkBean = createBean(decoratedBeanData, linkCreatorService, executionCallback);
    if (linkBean == null) {
        throw new ServiceException("Can not create link for source: " + sourceBean + ", linked: " + linkedBean + ", additional properties: " + additionalProperties + ".");
    }
    if (linkBeanType.equals(linkedBeanAccess.getBeanType()) && linkedBean == null) {
        return linkBean;
    } else {
        return linkedBean;
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) ServiceException(org.jowidgets.cap.common.api.exception.ServiceException) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData)

Example 23 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method createDirectLinkedBeans.

private List<IBeanDto> createDirectLinkedBeans(final List<IBeanDto> sourceBeans, final ILinkCreation link, final IExecutionCallback executionCallback) {
    if (sourceBeans.size() == 1) {
        final List<IBeanDto> result;
        final IBeanDto sourceBean = sourceBeans.iterator().next();
        result = getBeans(sourceBean, sourceProperties, link.getLinkableBeans(), linkedBeanAccess, linkedDtoFactory, executionCallback);
        result.addAll(createDirectLinkBeans(sourceBean, link.getTransientLinkableBeans(), linkableCreatorService, executionCallback));
        return result;
    } else {
        throw new IllegalArgumentException("A direct link must have exactly one source bean!");
    }
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto)

Example 24 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto in project jo-client-platform by jo-source.

the class LinkCreatorServiceImpl method createDirectLinkBeans.

private List<IBeanDto> createDirectLinkBeans(final IBeanDto sourceBean, final Collection<IBeanData> beanDatas, final ICreatorService creatorService, final IExecutionCallback executionCallback) {
    final List<IBeanDto> result = new LinkedList<IBeanDto>();
    for (final IBeanData beanData : beanDatas) {
        final DecoratedLinkBeanData decoratedBeanData = new DecoratedLinkBeanData(beanData, null, sourceBean);
        result.add(createBean(decoratedBeanData, creatorService, executionCallback));
    }
    return result;
}
Also used : IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanData(org.jowidgets.cap.common.api.bean.IBeanData) LinkedList(java.util.LinkedList)

Example 25 with IBeanDto

use of org.jowidgets.cap.common.api.bean.IBeanDto 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;
}
Also used : DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) IBeanDto(org.jowidgets.cap.common.api.bean.IBeanDto) IBeanKey(org.jowidgets.cap.common.api.bean.IBeanKey) BeanException(org.jowidgets.cap.common.api.exception.BeanException) DeletedBeanException(org.jowidgets.cap.common.api.exception.DeletedBeanException) LinkedList(java.util.LinkedList)

Aggregations

IBeanDto (org.jowidgets.cap.common.api.bean.IBeanDto)40 LinkedList (java.util.LinkedList)20 ArrayList (java.util.ArrayList)16 List (java.util.List)12 Test (org.junit.Test)12 IBeanKey (org.jowidgets.cap.common.api.bean.IBeanKey)8 IBeanProxy (org.jowidgets.cap.ui.api.bean.IBeanProxy)7 IBeanDtosUpdate (org.jowidgets.cap.common.api.bean.IBeanDtosUpdate)5 IExecutorService (org.jowidgets.cap.common.api.service.IExecutorService)5 BeanDtosInsertionUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosInsertionUpdate)5 SyncResultCallback (org.jowidgets.cap.common.tools.execution.SyncResultCallback)5 IBeanData (org.jowidgets.cap.common.api.bean.IBeanData)4 BeanKey (org.jowidgets.cap.common.tools.bean.BeanKey)4 HashMap (java.util.HashMap)3 ISort (org.jowidgets.cap.common.api.sort.ISort)3 AbstractUiResultCallback (org.jowidgets.cap.ui.tools.execution.AbstractUiResultCallback)3 TableCellBluePrint (org.jowidgets.tools.model.table.TableCellBluePrint)3 ServiceCanceledException (org.jowidgets.cap.common.api.exception.ServiceCanceledException)2 BeanDtosChangeUpdate (org.jowidgets.cap.common.tools.bean.BeanDtosChangeUpdate)2 IBeanSelectionClipboard (org.jowidgets.cap.ui.api.clipboard.IBeanSelectionClipboard)2