Search in sources :

Example 41 with WindowId

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

the class ADProcessPostProcessService method extractReferencingDocumentPaths.

private static final Set<DocumentPath> extractReferencingDocumentPaths(final ProcessInfo processInfo) {
    final String tableName = processInfo.getTableNameOrNull();
    if (tableName == null) {
        return ImmutableSet.of();
    }
    final TableRecordReference sourceRecordRef = processInfo.getRecordRefOrNull();
    final IQueryFilter<Object> selectionQueryFilter = processInfo.getQueryFilterOrElse(null);
    if (selectionQueryFilter != null) {
        final List<Integer> recordIds = Services.get(IQueryBL.class).createQueryBuilder(tableName, PlainContextAware.newWithThreadInheritedTrx()).filter(selectionQueryFilter).setLimit(MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + 1).create().listIds();
        if (recordIds.isEmpty()) {
            return ImmutableSet.of();
        } else if (recordIds.size() > MAX_REFERENCED_DOCUMENTPATHS_ALLOWED) {
            throw new AdempiereException("Selecting more than " + MAX_REFERENCED_DOCUMENTPATHS_ALLOWED + " records is not allowed");
        }
        final TableRecordReference firstRecordRef = TableRecordReference.of(tableName, recordIds.get(0));
        // assume all records are from same window
        final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(firstRecordRef));
        return recordIds.stream().map(recordId -> DocumentPath.rootDocumentPath(windowId, recordId)).collect(ImmutableSet.toImmutableSet());
    } else if (sourceRecordRef != null) {
        final WindowId windowId = WindowId.of(RecordZoomWindowFinder.findAD_Window_ID(sourceRecordRef));
        final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, sourceRecordRef.getRecord_ID());
        return ImmutableSet.of(documentPath);
    } else {
        return ImmutableSet.of();
    }
}
Also used : MimeType(org.compiere.util.MimeType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) OpenViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenViewAction) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) OpenReportAction(de.metas.ui.web.process.ProcessInstanceResult.OpenReportAction) Supplier(java.util.function.Supplier) IQueryFilter(org.adempiere.ad.dao.IQueryFilter) PlainContextAware(org.adempiere.model.PlainContextAware) OpenIncludedViewAction(de.metas.ui.web.process.ProcessInstanceResult.OpenIncludedViewAction) IView(de.metas.ui.web.view.IView) RecordsToOpen(de.metas.process.ProcessExecutionResult.RecordsToOpen) Map(java.util.Map) ResultAction(de.metas.ui.web.process.ProcessInstanceResult.ResultAction) Suppliers(com.google.common.base.Suppliers) ProcessInstanceResult(de.metas.ui.web.process.ProcessInstanceResult) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) Util(org.compiere.util.Util) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) Logger(org.slf4j.Logger) ImmutableSet(com.google.common.collect.ImmutableSet) OpenTarget(de.metas.process.ProcessExecutionResult.RecordsToOpen.OpenTarget) OpenSingleDocument(de.metas.ui.web.process.ProcessInstanceResult.OpenSingleDocument) NonNull(lombok.NonNull) ViewProfileId(de.metas.ui.web.view.ViewProfileId) Set(java.util.Set) IOException(java.io.IOException) JavaProcess(de.metas.process.JavaProcess) WindowId(de.metas.ui.web.window.datatypes.WindowId) IQueryBL(org.adempiere.ad.dao.IQueryBL) File(java.io.File) Services(org.adempiere.util.Services) List(java.util.List) Builder(lombok.Builder) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(de.metas.printing.esb.base.util.Check) CreateViewRequest(de.metas.ui.web.view.CreateViewRequest) IViewsRepository(de.metas.ui.web.view.IViewsRepository) ViewId(de.metas.ui.web.view.ViewId) IQueryBL(org.adempiere.ad.dao.IQueryBL) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) WindowId(de.metas.ui.web.window.datatypes.WindowId) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 42 with WindowId

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

Example 43 with WindowId

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

the class SqlViewRowIdsOrderedSelectionFactory method createOrderedSelectionFromSelection.

@Override
public ViewRowIdsOrderedSelection createOrderedSelectionFromSelection(final ViewEvaluationCtx viewEvalCtx, final ViewRowIdsOrderedSelection fromSelection, final List<DocumentQueryOrderBy> orderBys) {
    final WindowId windowId = fromSelection.getWindowId();
    final String fromSelectionId = fromSelection.getSelectionId();
    final ViewId newViewId = ViewId.random(windowId);
    final int rowsCount;
    final SqlViewSelectionQueryBuilder viewQueryBuilder = newSqlViewSelectionQueryBuilder();
    if (viewQueryBuilder.hasGroupingFields()) {
        final SqlAndParams sqlCreateSelectionLines = viewQueryBuilder.buildSqlCreateSelectionLinesFromSelectionLines(viewEvalCtx, newViewId, fromSelectionId);
        final int linesCount = DB.executeUpdateEx(sqlCreateSelectionLines.getSql(), sqlCreateSelectionLines.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
        if (linesCount > 0) {
            final SqlAndParams sqlCreateSelection = viewQueryBuilder.buildSqlCreateSelectionFromSelectionLines(viewEvalCtx, newViewId, orderBys);
            rowsCount = DB.executeUpdateEx(sqlCreateSelection.getSql(), sqlCreateSelection.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
        } else {
            rowsCount = 0;
        }
    } else {
        final SqlAndParams sqlCreateSelection = viewQueryBuilder.buildSqlCreateSelectionFromSelection(viewEvalCtx, newViewId, fromSelectionId, orderBys);
        rowsCount = DB.executeUpdateEx(sqlCreateSelection.getSql(), sqlCreateSelection.getSqlParamsArray(), ITrx.TRXNAME_ThreadInherited);
    }
    return ViewRowIdsOrderedSelection.builder().setViewId(newViewId).setSize(rowsCount).setOrderBys(orderBys).setQueryLimit(fromSelection.getQueryLimit()).build();
}
Also used : SqlViewSelectionQueryBuilder(de.metas.ui.web.view.descriptor.SqlViewSelectionQueryBuilder) WindowId(de.metas.ui.web.window.datatypes.WindowId) SqlAndParams(de.metas.ui.web.view.descriptor.SqlAndParams) WindowMaxQueryRecordsConstraint(org.adempiere.ad.security.permissions.WindowMaxQueryRecordsConstraint)

Example 44 with WindowId

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

the class WindowQuickInputRestController method checkSupported.

@RequestMapping(method = RequestMethod.HEAD)
public ResponseEntity<Object> checkSupported(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr_NOTUSED, // 
@PathVariable("tabId") final String tabIdStr) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentEntityDescriptor includedDocumentDescriptor = documentsCollection.getDocumentEntityDescriptor(windowId).getIncludedEntityByDetailId(DetailId.fromJson(tabIdStr));
    if (quickInputDescriptors.hasQuickInputEntityDescriptor(includedDocumentDescriptor)) {
        return new ResponseEntity<>(HttpStatus.OK);
    } else {
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 45 with WindowId

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

the class WindowQuickInputRestController method create.

@PostMapping
public JSONDocument create(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, // 
@PathVariable("tabId") final String tabIdStr) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentPath rootDocumentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
    final DetailId detailId = DetailId.fromJson(tabIdStr);
    return Execution.callInNewExecution("quickInput.create", () -> {
        final QuickInput quickInput = documentsCollection.forRootDocumentReadonly(rootDocumentPath, rootDocument -> {
            // Make sure we can edit our root document. Fail fast.
            DocumentPermissionsHelper.assertCanEdit(rootDocument, userSession.getUserRolePermissions());
            final DocumentEntityDescriptor includedDocumentDescriptor = rootDocument.getEntityDescriptor().getIncludedEntityByDetailId(detailId);
            final QuickInputDescriptor quickInputDescriptor = quickInputDescriptors.getQuickInputEntityDescriptor(includedDocumentDescriptor);
            try {
                return QuickInput.builder().setQuickInputDescriptor(quickInputDescriptor).setRootDocumentPath(rootDocument.getDocumentPath()).build().bindRootDocument(rootDocument).assertTargetWritable();
            } catch (Exception ex) {
                // see https://github.com/metasfresh/metasfresh-webui-frontend/issues/487
                throw EntityNotFoundException.wrapIfNeeded(ex);
            }
        });
        commit(quickInput);
        return JSONDocument.ofDocument(quickInput.getQuickInputDocument(), newJSONOptions());
    });
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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