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