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);
}
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;
}
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();
}
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();
}
Aggregations