Search in sources :

Example 1 with JSONViewDataType

use of de.metas.ui.web.view.json.JSONViewDataType in project metasfresh-webui-api by metasfresh.

the class ViewsRepository method createFactoriesMap.

private static ImmutableMap<ArrayKey, IViewFactory> createFactoriesMap(final Collection<IViewFactory> viewFactories) {
    final Map<ArrayKey, IViewFactory> factories = new HashMap<>();
    for (final IViewFactory factory : viewFactories) {
        final ViewFactory annotation = factory.getClass().getAnnotation(ViewFactory.class);
        if (annotation == null) {
            // this might be a development bug
            logger.warn("Skip {} because it's not annotated with {}", factory, ViewFactory.class);
            continue;
        }
        final WindowId windowId = WindowId.fromJson(annotation.windowId());
        JSONViewDataType[] viewTypes = annotation.viewTypes();
        if (viewTypes.length == 0) {
            viewTypes = JSONViewDataType.values();
        }
        for (final JSONViewDataType viewType : viewTypes) {
            factories.put(mkFactoryKey(windowId, viewType), factory);
        }
    }
    return ImmutableMap.copyOf(factories);
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayKey(org.compiere.util.Util.ArrayKey) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType)

Example 2 with JSONViewDataType

use of de.metas.ui.web.view.json.JSONViewDataType in project metasfresh-webui-api by metasfresh.

the class ViewsRepository method createView.

@Override
public IView createView(final CreateViewRequest request) {
    logger.trace("Creating new view from {}", request);
    final WindowId windowId = request.getViewId().getWindowId();
    final JSONViewDataType viewType = request.getViewType();
    final IViewFactory factory = getFactory(windowId, viewType);
    final IView view = factory.createView(request);
    if (view == null) {
        throw new AdempiereException("Failed creating view").setParameter("request", request).setParameter("factory", factory.toString());
    }
    getViewsStorageFor(view.getViewId()).put(view);
    logger.trace("Created view {}", view);
    return view;
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType)

Example 3 with JSONViewDataType

use of de.metas.ui.web.view.json.JSONViewDataType in project metasfresh-webui-api by metasfresh.

the class ViewColumnHelper method createClassViewColumnDescriptor.

private static ClassViewColumnDescriptor createClassViewColumnDescriptor(final Field field) {
    final ViewColumn viewColumnAnn = field.getAnnotation(ViewColumn.class);
    final String fieldName = !Check.isEmpty(viewColumnAnn.fieldName(), true) ? viewColumnAnn.fieldName().trim() : field.getName();
    final String captionKey = !Check.isEmpty(viewColumnAnn.captionKey()) ? viewColumnAnn.captionKey() : fieldName;
    final ImmutableMap<JSONViewDataType, ClassViewColumnLayoutDescriptor> layoutsByViewType = Stream.of(viewColumnAnn.layouts()).map(layoutAnn -> ClassViewColumnLayoutDescriptor.builder().viewType(layoutAnn.when()).displayed(layoutAnn.displayed()).seqNo(layoutAnn.seqNo()).build()).collect(GuavaCollectors.toImmutableMapByKey(ClassViewColumnLayoutDescriptor::getViewType));
    return ClassViewColumnDescriptor.builder().fieldName(fieldName).caption(Services.get(IMsgBL.class).translatable(captionKey)).widgetType(viewColumnAnn.widgetType()).editorRenderMode(viewColumnAnn.editor()).allowSorting(viewColumnAnn.sorting()).fieldReference(FieldReference.of(field)).layoutsByViewType(layoutsByViewType).restrictToMediaTypes(ImmutableSet.copyOf(viewColumnAnn.restrictToMediaTypes())).build();
}
Also used : LoadingCache(com.google.common.cache.LoadingCache) Getter(lombok.Getter) Singular(lombok.Singular) GuavaCollectors(org.adempiere.util.GuavaCollectors) Values(de.metas.ui.web.window.datatypes.Values) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) DocumentLayoutElementDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementDescriptor) Value(lombok.Value) LinkedHashMap(java.util.LinkedHashMap) UtilityClass(lombok.experimental.UtilityClass) ImmutableList(com.google.common.collect.ImmutableList) ToString(lombok.ToString) FieldReference(org.adempiere.util.reflect.FieldReference) JSONNullValue(de.metas.ui.web.window.datatypes.json.JSONNullValue) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) ViewEditorRenderMode(de.metas.ui.web.window.descriptor.ViewEditorRenderMode) Set(java.util.Set) MediaType(de.metas.ui.web.window.datatypes.MediaType) Field(java.lang.reflect.Field) EqualsAndHashCode(lombok.EqualsAndHashCode) ExecutionException(java.util.concurrent.ExecutionException) CacheLoader(com.google.common.cache.CacheLoader) Services(org.adempiere.util.Services) DocumentLayoutElementFieldDescriptor(de.metas.ui.web.window.descriptor.DocumentLayoutElementFieldDescriptor) List(java.util.List) IViewRow(de.metas.ui.web.view.IViewRow) Stream(java.util.stream.Stream) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) ReflectionUtils(org.reflections.ReflectionUtils) CacheBuilder(com.google.common.cache.CacheBuilder) Comparator(java.util.Comparator) IMsgBL(de.metas.i18n.IMsgBL) ToString(lombok.ToString) ITranslatableString(de.metas.i18n.ITranslatableString) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType)

Example 4 with JSONViewDataType

use of de.metas.ui.web.view.json.JSONViewDataType in project metasfresh-webui-api by metasfresh.

the class SqlViewFactory method createView.

@Override
public IView createView(final CreateViewRequest request) {
    final WindowId windowId = request.getViewId().getWindowId();
    final JSONViewDataType viewType = request.getViewType();
    final ViewProfileId profileId = !ViewProfileId.isNull(request.getProfileId()) ? request.getProfileId() : getDefaultProfileIdByWindowId(windowId);
    final SqlViewBindingKey sqlViewBindingKey = new SqlViewBindingKey(windowId, viewType.getRequiredFieldCharacteristic(), profileId);
    final SqlViewBinding sqlViewBinding = getViewBinding(sqlViewBindingKey);
    final IViewDataRepository viewDataRepository = new SqlViewDataRepository(sqlViewBinding);
    final DefaultView.Builder viewBuilder = DefaultView.builder(viewDataRepository).setViewId(request.getViewId()).setViewType(viewType).setProfileId(profileId).setReferencingDocumentPaths(request.getReferencingDocumentPaths()).setParentViewId(request.getParentViewId()).setParentRowId(request.getParentRowId()).addStickyFilters(request.getStickyFilters()).addStickyFilter(extractReferencedDocumentFilter(windowId, request.getSingleReferencingDocumentPathOrNull())).viewInvalidationAdvisor(sqlViewBinding.getViewInvalidationAdvisor());
    final DocumentFiltersList filters = request.getFilters();
    if (filters.isJson()) {
        viewBuilder.setFiltersFromJSON(filters.getJsonFilters());
    } else {
        viewBuilder.setFilters(filters.getFilters());
    }
    if (request.isUseAutoFilters()) {
        final List<DocumentFilter> autoFilters = createAutoFilters(sqlViewBindingKey);
        viewBuilder.addFiltersIfAbsent(autoFilters);
    }
    if (!request.getFilterOnlyIds().isEmpty()) {
        final String keyColumnName = sqlViewBinding.getSqlViewKeyColumnNamesMap().getSingleKeyColumnName();
        viewBuilder.addStickyFilter(DocumentFilter.inArrayFilter(keyColumnName, keyColumnName, request.getFilterOnlyIds()));
    }
    return viewBuilder.build();
}
Also used : DocumentFiltersList(de.metas.ui.web.document.filter.DocumentFiltersList) SqlViewBinding(de.metas.ui.web.view.descriptor.SqlViewBinding) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) WindowId(de.metas.ui.web.window.datatypes.WindowId) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType)

Aggregations

JSONViewDataType (de.metas.ui.web.view.json.JSONViewDataType)4 WindowId (de.metas.ui.web.window.datatypes.WindowId)3 AdempiereException (org.adempiere.exceptions.AdempiereException)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 CacheLoader (com.google.common.cache.CacheLoader)1 LoadingCache (com.google.common.cache.LoadingCache)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 IMsgBL (de.metas.i18n.IMsgBL)1 ITranslatableString (de.metas.i18n.ITranslatableString)1 Check (de.metas.printing.esb.base.util.Check)1 DocumentFilter (de.metas.ui.web.document.filter.DocumentFilter)1 DocumentFiltersList (de.metas.ui.web.document.filter.DocumentFiltersList)1 IViewRow (de.metas.ui.web.view.IViewRow)1 SqlViewBinding (de.metas.ui.web.view.descriptor.SqlViewBinding)1 MediaType (de.metas.ui.web.window.datatypes.MediaType)1 Values (de.metas.ui.web.window.datatypes.Values)1 JSONNullValue (de.metas.ui.web.window.datatypes.json.JSONNullValue)1 DocumentFieldWidgetType (de.metas.ui.web.window.descriptor.DocumentFieldWidgetType)1