Search in sources :

Example 11 with DocumentId

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;
}
Also used : IView(de.metas.ui.web.view.IView) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ToString(lombok.ToString)

Example 12 with DocumentId

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());
    }
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) ImmutableSet(com.google.common.collect.ImmutableSet) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ViewProfileId(de.metas.ui.web.view.ViewProfileId) Set(java.util.Set) Visibility(com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility) WindowId(de.metas.ui.web.window.datatypes.WindowId) JsonAutoDetect(com.fasterxml.jackson.annotation.JsonAutoDetect) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ListUtils(org.adempiere.util.collections.ListUtils) JsonCreator(com.fasterxml.jackson.annotation.JsonCreator) DetailId(de.metas.ui.web.window.descriptor.DetailId) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) Preconditions(com.google.common.base.Preconditions) JSONDocumentFilter(de.metas.ui.web.document.filter.json.JSONDocumentFilter) DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 13 with DocumentId

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;
    }));
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebRequest(org.springframework.web.context.request.WebRequest) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) JSONZoomInto(de.metas.ui.web.window.datatypes.json.JSONZoomInto) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ReasonSupplier(de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier) ApiOperation(io.swagger.annotations.ApiOperation) DocumentWebsocketPublisher(de.metas.ui.web.window.events.DocumentWebsocketPublisher) IDocumentFieldView(de.metas.ui.web.window.model.IDocumentFieldView) JSONDocumentReferencesGroupList(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroupList) DocumentReference(de.metas.ui.web.window.model.DocumentReference) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImmutableSet(com.google.common.collect.ImmutableSet) Predicate(java.util.function.Predicate) HttpHeaders(org.springframework.http.HttpHeaders) MediaType(org.springframework.http.MediaType) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) Set(java.util.Set) ProcessRestController(de.metas.ui.web.process.ProcessRestController) RestController(org.springframework.web.bind.annotation.RestController) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) IMsgBL(de.metas.i18n.IMsgBL) MenuTreeRepository(de.metas.ui.web.menu.MenuTreeRepository) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) IADTableDAO(org.adempiere.ad.table.api.IADTableDAO) JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) DocumentReferencesService(de.metas.ui.web.window.model.DocumentReferencesService) WebConfig(de.metas.ui.web.config.WebConfig) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ButtonFieldActionDescriptor(de.metas.ui.web.window.descriptor.ButtonFieldActionDescriptor) MenuTree(de.metas.ui.web.menu.MenuTree) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) NullDocumentChangesCollector(de.metas.ui.web.window.model.NullDocumentChangesCollector) RequestBody(org.springframework.web.bind.annotation.RequestBody) ImmutableList(com.google.common.collect.ImmutableList) DetailId(de.metas.ui.web.window.descriptor.DetailId) GetMapping(org.springframework.web.bind.annotation.GetMapping) JSONDocumentReferencesGroup(de.metas.ui.web.window.datatypes.json.JSONDocumentReferencesGroup) NewRecordDescriptorsProvider(de.metas.ui.web.window.descriptor.factory.NewRecordDescriptorsProvider) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) Api(io.swagger.annotations.Api) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) WindowId(de.metas.ui.web.window.datatypes.WindowId) ETagResponseEntityBuilder(de.metas.ui.web.cache.ETagResponseEntityBuilder) WebuiRelatedProcessDescriptor(de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor) HttpStatus(org.springframework.http.HttpStatus) JSONDocumentActionsList(de.metas.ui.web.process.json.JSONDocumentActionsList) DocumentPreconditionsAsContext(de.metas.ui.web.process.DocumentPreconditionsAsContext) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONDocumentReference(de.metas.ui.web.window.datatypes.json.JSONDocumentReference) ResponseEntity(org.springframework.http.ResponseEntity) JSONDocumentLayout(de.metas.ui.web.window.datatypes.json.JSONDocumentLayout) Document(de.metas.ui.web.window.model.Document) WindowId(de.metas.ui.web.window.datatypes.WindowId) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 14 with DocumentId

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()));
}
Also used : DocumentPermissionsHelper(de.metas.ui.web.window.controller.DocumentPermissionsHelper) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) OutputType(de.metas.adempiere.report.jasper.OutputType) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) Evaluatee(org.compiere.util.Evaluatee) TableModelLoader(org.adempiere.ad.persistence.TableModelLoader) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) DocumentWebsocketPublisher(de.metas.ui.web.window.events.DocumentWebsocketPublisher) CopyRecordSupport(org.adempiere.model.CopyRecordSupport) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) NonNull(lombok.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) Set(java.util.Set) Objects(java.util.Objects) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Builder(lombok.Builder) CopyRecordFactory(org.adempiere.model.CopyRecordFactory) CacheBuilder(com.google.common.cache.CacheBuilder) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException) Function(java.util.function.Function) PlainContextAware(org.adempiere.model.PlainContextAware) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) Value(lombok.Value) CopyMode(de.metas.ui.web.window.model.Document.CopyMode) ImmutableList(com.google.common.collect.ImmutableList) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Logger(org.slf4j.Logger) Evaluatees(org.compiere.util.Evaluatees) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ExecutionException(java.util.concurrent.ExecutionException) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Component(org.springframework.stereotype.Component) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) Preconditions(com.google.common.base.Preconditions) PO(org.compiere.model.PO) Cache(com.google.common.cache.Cache) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Immutable(javax.annotation.concurrent.Immutable) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 15 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8