Search in sources :

Example 1 with WindowId

use of de.metas.ui.web.window.datatypes.WindowId 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 WindowId

use of de.metas.ui.web.window.datatypes.WindowId 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 WindowId

use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.

the class ViewRestController method getAvailableViewProfiles.

@GetMapping("/availableProfiles")
public JSONViewProfilesList getAvailableViewProfiles(@PathVariable(PARAM_WindowId) final String windowIdStr, @RequestParam(name = PARAM_ViewDataType, required = true) final JSONViewDataType viewDataType) {
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final List<ViewProfile> availableProfiles = viewsRepo.getAvailableProfiles(windowId, viewDataType);
    return JSONViewProfilesList.of(availableProfiles, userSession.getAD_Language());
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 4 with WindowId

use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.

the class ViewRestController method extractWindowId.

private static final WindowId extractWindowId(final String pathWindowIdStr, final WindowId requestWindowId) {
    final WindowId pathWindowId = WindowId.fromNullableJson(pathWindowIdStr);
    WindowId windowIdEffective = requestWindowId;
    if (windowIdEffective == null) {
        windowIdEffective = WindowId.fromJson(pathWindowIdStr);
    } else if (!Objects.equals(pathWindowId, windowIdEffective)) {
        throw new IllegalArgumentException("Request's windowId is not matching the one from path");
    }
    return windowIdEffective;
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId)

Example 5 with WindowId

use of de.metas.ui.web.window.datatypes.WindowId in project metasfresh-webui-api by metasfresh.

the class ViewRestController method getViewLayout.

@GetMapping("/layout")
public ResponseEntity<JSONViewLayout> getViewLayout(@PathVariable(PARAM_WindowId) final String windowIdStr, @RequestParam(name = PARAM_ViewDataType, required = true) final JSONViewDataType viewDataType, @RequestParam(name = "profileId", required = false) final String profileIdStr, final WebRequest request) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final ViewLayout viewLayout = viewsRepo.getViewLayout(windowId, viewDataType, ViewProfileId.fromJson(profileIdStr));
    return ETagResponseEntityBuilder.ofETagAware(request, viewLayout).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).jsonOptions(() -> newJSONOptions()).toJson(JSONViewLayout::of);
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) ViewLayout(de.metas.ui.web.view.descriptor.ViewLayout) JSONViewLayout(de.metas.ui.web.view.json.JSONViewLayout) JSONViewLayout(de.metas.ui.web.view.json.JSONViewLayout) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

WindowId (de.metas.ui.web.window.datatypes.WindowId)48 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)22 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)13 GetMapping (org.springframework.web.bind.annotation.GetMapping)13 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)9 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)9 List (java.util.List)9 Set (java.util.Set)9 ImmutableList (com.google.common.collect.ImmutableList)8 ImmutableSet (com.google.common.collect.ImmutableSet)8 AdempiereException (org.adempiere.exceptions.AdempiereException)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 NonNull (lombok.NonNull)7 Services (org.adempiere.util.Services)7 LogManager (de.metas.logging.LogManager)6 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)6 DetailId (de.metas.ui.web.window.descriptor.DetailId)6 Logger (org.slf4j.Logger)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 JSONViewDataType (de.metas.ui.web.view.json.JSONViewDataType)5