use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class ViewProcessInstancesRepository method createNewProcessInstance.
@Override
public IProcessInstanceController createNewProcessInstance(final CreateProcessInstanceRequest request) {
//
// Get the view and and the viewActionDescriptor
final IPair<String, String> viewIdAndActionId = extractViewIdAndActionId(request.getProcessId());
final String viewId = viewIdAndActionId.getLeft();
final String actionId = viewIdAndActionId.getRight();
final IView view = viewsRepository.getView(viewId);
final ViewActionDescriptor viewActionDescriptor = getViewActionDescriptors(view).getAction(actionId);
//
// Create the view action instance
// and add it to our internal list of current view action instances
final ViewActionInstancesList viewActionInstancesList = viewActionInstancesByViewId.getOrLoad(viewId, () -> new ViewActionInstancesList(viewId));
final DocumentId pinstanceId = viewActionInstancesList.nextPInstanceId();
final ViewActionInstance viewActionInstance = ViewActionInstance.builder().pinstanceId(pinstanceId).view(view).viewActionDescriptor(viewActionDescriptor).selectedDocumentIds(request.getViewRowIdsSelection().getRowIds()).build();
request.assertProcessIdEquals(viewActionInstance.getProcessId());
viewActionInstancesList.add(viewActionInstance);
// Return the newly created instance
return viewActionInstance;
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class JSONCreateViewRequest method getReferencingDocumentPaths.
public Set<DocumentPath> getReferencingDocumentPaths() {
if (referencing == null) {
return ImmutableSet.of();
}
final Set<String> documentIds = referencing.getDocumentIds();
if (documentIds == null || documentIds.isEmpty()) {
return ImmutableSet.of();
}
final WindowId windowId = WindowId.fromJson(referencing.getDocumentType());
final String tabIdStr = referencing.getTabId();
if (tabIdStr == null) {
return documentIds.stream().map(id -> DocumentPath.rootDocumentPath(windowId, id)).collect(ImmutableSet.toImmutableSet());
} else {
final DocumentId documentId = DocumentId.of(ListUtils.singleElement(documentIds));
final DetailId tabId = DetailId.fromJson(tabIdStr);
final Set<String> rowIds = referencing.getRowIds();
return rowIds.stream().map(DocumentId::of).map(rowId -> DocumentPath.includedDocumentPath(windowId, documentId, tabId, rowId)).collect(ImmutableSet.toImmutableSet());
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method processRecord.
/**
* @task https://github.com/metasfresh/metasfresh/issues/1090
*/
@GetMapping("/{windowId}/{documentId}/processNewRecord")
public int processRecord(//
@PathVariable("windowId") final String windowIdStr, //
@PathVariable("documentId") final String documentIdStr) {
userSession.assertLoggedIn();
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
final IDocumentChangesCollector changesCollector = NullDocumentChangesCollector.instance;
return Execution.callInNewExecution("window.processTemplate", () -> documentCollection.forDocumentWritable(documentPath, changesCollector, document -> {
document.saveIfValidAndHasChanges();
if (document.hasChangesRecursivelly()) {
throw new AdempiereException("Not saved");
}
final int newRecordId = newRecordDescriptorsProvider.getNewRecordDescriptor(document.getEntityDescriptor()).getProcessor().processNewRecordDocument(document);
return newRecordId;
}));
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method invalidateDocumentByRecordId.
/**
* Invalidates all root documents identified by tableName/recordId and notifies frontend (via websocket).
*
* @param tableName
* @param recordId
*/
public void invalidateDocumentByRecordId(final String tableName, final int recordId) {
//
// Create possible documentKeys for given tableName/recordId
final DocumentId documentId = DocumentId.of(recordId);
final Set<DocumentKey> documentKeys = getCachedWindowIdsForTableName(tableName).stream().map(windowId -> DocumentKey.of(windowId, documentId)).collect(ImmutableSet.toImmutableSet());
// stop here if no document keys found
if (documentKeys.isEmpty()) {
return;
}
//
// Invalidate the root documents
rootDocuments.invalidateAll(documentKeys);
//
// Notify frontend
documentKeys.forEach(documentKey -> websocketPublisher.staleRootDocument(documentKey.getWindowId(), documentKey.getDocumentId()));
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method invalidateIncludedDocumentsByRecordId.
public void invalidateIncludedDocumentsByRecordId(final String tableName, final int recordId, final String childTableName, final int childRecordId) {
final DocumentId documentId = DocumentId.of(recordId);
final DocumentId rowId = childRecordId > 0 ? DocumentId.of(childRecordId) : null;
final Function<DocumentEntityDescriptor, DocumentPath> toDocumentPath;
if (rowId != null) {
toDocumentPath = includedEntity -> DocumentPath.includedDocumentPath(includedEntity.getWindowId(), documentId, includedEntity.getDetailId(), rowId);
} else {
// all rows for given tab/detail
toDocumentPath = includedEntity -> DocumentPath.includedDocumentPath(includedEntity.getWindowId(), documentId, includedEntity.getDetailId());
}
//
// Create possible documentKeys for given tableName/recordId
final ImmutableSet<DocumentPath> documentPaths = getCachedWindowIdsForTableName(tableName).stream().map(this::getDocumentEntityDescriptor).flatMap(rootEntity -> rootEntity.streamIncludedEntitiesByTableName(childTableName)).map(toDocumentPath).collect(ImmutableSet.toImmutableSet());
documentPaths.forEach(this::invalidateIncludedDocuments);
}
Aggregations