Search in sources :

Example 1 with DocumentSaveStatus

use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.

the class DefaultView method patchViewRow.

@Override
public void patchViewRow(final RowEditingContext ctx, final List<JSONDocumentChangedEvent> fieldChangeRequests) {
    final DocumentId rowId = ctx.getRowId();
    final DocumentCollection documentsCollection = ctx.getDocumentsCollection();
    final DocumentPath documentPath = getById(rowId).getDocumentPath();
    Services.get(ITrxManager.class).runInThreadInheritedTrx(() -> documentsCollection.forDocumentWritable(documentPath, NullDocumentChangesCollector.instance, document -> {
        // 
        // Process changes and the save the document
        document.processValueChanges(fieldChangeRequests, ReasonSupplier.NONE);
        document.saveIfValidAndHasChanges();
        // 
        // Important: before allowing the document to be stored back in documents collection,
        // we need to make sure it's valid and saved.
        final DocumentValidStatus validStatus = document.getValidStatus();
        if (!validStatus.isValid()) {
            throw new AdempiereException(validStatus.getReason());
        }
        final DocumentSaveStatus saveStatus = document.getSaveStatus();
        if (saveStatus.isNotSaved()) {
            throw new AdempiereException(saveStatus.getReason());
        }
        // nothing/not important
        return null;
    }));
    invalidateRowById(rowId);
    ViewChangesCollector.getCurrentOrAutoflush().collectRowChanged(this, rowId);
    documentsCollection.invalidateRootDocument(documentPath);
}
Also used : CCache(org.compiere.util.CCache) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ReasonSupplier(de.metas.ui.web.window.model.IDocumentChangesCollector.ReasonSupplier) BigDecimal(java.math.BigDecimal) Evaluatee(org.compiere.util.Evaluatee) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) JSONDocumentFilter(de.metas.ui.web.document.filter.json.JSONDocumentFilter) ImmutableSet(com.google.common.collect.ImmutableSet) ITranslatableString(de.metas.i18n.ITranslatableString) NonNull(lombok.NonNull) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) Objects(java.util.Objects) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Stream(java.util.stream.Stream) DocumentFieldWidgetType(de.metas.ui.web.window.descriptor.DocumentFieldWidgetType) ImmutableTranslatableString(de.metas.i18n.ImmutableTranslatableString) LogManager(de.metas.logging.LogManager) Iterables(com.google.common.collect.Iterables) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Getter(lombok.Getter) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) DocumentFilterDescriptorsProvider(de.metas.ui.web.document.filter.DocumentFilterDescriptorsProvider) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SqlOptions(de.metas.ui.web.window.model.sql.SqlOptions) JSONViewDataType(de.metas.ui.web.view.json.JSONViewDataType) ExtendedMemorizingSupplier(org.adempiere.util.lang.ExtendedMemorizingSupplier) ArrayList(java.util.ArrayList) NullDocumentChangesCollector(de.metas.ui.web.window.model.NullDocumentChangesCollector) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) Predicates(com.google.common.base.Predicates) DocumentFilter(de.metas.ui.web.document.filter.DocumentFilter) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) DocumentQueryOrderBy(de.metas.ui.web.window.model.DocumentQueryOrderBy) Nullable(javax.annotation.Nullable) DocumentIdsSelection(de.metas.ui.web.window.datatypes.DocumentIdsSelection) Logger(org.slf4j.Logger) MoreObjects(com.google.common.base.MoreObjects) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) NumberUtils(org.adempiere.util.NumberUtils) AdempiereException(org.adempiere.exceptions.AdempiereException) ViewChangesCollector(de.metas.ui.web.view.event.ViewChangesCollector) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) AdempiereException(org.adempiere.exceptions.AdempiereException) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection)

Example 2 with DocumentSaveStatus

use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.

the class JSONDocument method ofEventOrNull.

private static JSONDocument ofEventOrNull(final DocumentChanges documentChangedEvents, final JSONOptions jsonOpts) {
    if (documentChangedEvents.isEmpty()) {
        return null;
    }
    final DocumentPath documentPath = documentChangedEvents.getDocumentPath();
    final JSONDocument jsonDocument = new JSONDocument(documentPath);
    // If the document was deleted, we just need to export that flag. All the other changes are not relevant.
    if (documentChangedEvents.isDeleted()) {
        jsonDocument.setDeleted();
        return jsonDocument;
    }
    // 
    // Fields
    {
        final List<JSONDocumentField> jsonFields = new ArrayList<>();
        documentChangedEvents.getFieldChangesList().stream().filter(jsonOpts.documentFieldChangeFilter()).forEach((field) -> {
            // Add the pseudo-field "ID" first
            if (field.isKey()) {
                jsonFields.add(0, JSONDocumentField.idField(field.getValueAsJsonObject()));
            }
            // Append the other fields
            final JSONDocumentField jsonField = JSONDocumentField.ofDocumentFieldChangedEvent(field, jsonOpts);
            // apply permissions
            jsonOpts.getDocumentPermissions().apply(documentPath, jsonField);
            jsonFields.add(jsonField);
        });
        jsonDocument.setFields(jsonFields);
    }
    // 
    // Valid status
    final DocumentValidStatus documentValidStatus = documentChangedEvents.getDocumentValidStatus();
    if (documentValidStatus != null) {
        jsonDocument.setValidStatus(documentValidStatus);
    }
    // 
    // Save status
    final DocumentSaveStatus documentSaveStatus = documentChangedEvents.getDocumentSaveStatus();
    if (documentSaveStatus != null) {
        jsonDocument.setSaveStatus(documentSaveStatus);
    }
    // 
    // Included tabs info
    documentChangedEvents.getIncludedDetailInfos().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(documentPath, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
    return jsonDocument;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IIncludedDocumentsCollection(de.metas.ui.web.window.model.IIncludedDocumentsCollection) DocumentChanges(de.metas.ui.web.window.model.DocumentChanges) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) DocumentStandardAction(de.metas.ui.web.window.model.DocumentStandardAction) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) Collection(java.util.Collection) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) Collectors(java.util.stream.Collectors) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) Document(de.metas.ui.web.window.model.Document) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 3 with DocumentSaveStatus

use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.

the class ADProcessInstanceController method saveIfValidAndHasChanges.

/* package */
boolean saveIfValidAndHasChanges(final boolean throwEx) {
    final Document parametersDocument = getParametersDocument();
    final DocumentSaveStatus parametersSaveStatus = parametersDocument.saveIfValidAndHasChanges();
    final boolean saved = parametersSaveStatus.isSaved();
    if (!saved && throwEx) {
        throw new ProcessExecutionException(parametersSaveStatus.getReason());
    }
    return saved;
}
Also used : DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) ProcessExecutionException(de.metas.ui.web.process.exceptions.ProcessExecutionException) Document(de.metas.ui.web.window.model.Document)

Example 4 with DocumentSaveStatus

use of de.metas.ui.web.window.model.DocumentSaveStatus in project metasfresh-webui-api by metasfresh.

the class JSONDocument method ofDocument.

public static final JSONDocument ofDocument(final Document document, final JSONOptions jsonOpts) {
    final JSONDocument jsonDocument = new JSONDocument(document.getDocumentPath());
    // 
    // Fields
    {
        final List<JSONDocumentField> jsonFields = new ArrayList<>();
        // Add pseudo "ID" field first
        jsonFields.add(0, JSONDocumentField.idField(document.getDocumentIdAsJson()));
        // Append the other fields
        document.getFieldViews().stream().filter(jsonOpts.documentFieldFilter()).map(field -> JSONDocumentField.ofDocumentField(field, jsonOpts.getAD_Language())).peek(// apply permissions
        jsonField -> jsonOpts.getDocumentPermissions().apply(document, jsonField)).forEach(jsonFields::add);
        jsonDocument.setFields(jsonFields);
    }
    // 
    // Valid Status
    final DocumentValidStatus documentValidStatus = document.getValidStatus();
    if (documentValidStatus != null) {
        jsonDocument.setValidStatus(documentValidStatus);
    }
    // 
    // Save Status
    final DocumentSaveStatus documentSaveStatus = document.getSaveStatus();
    if (documentSaveStatus != null) {
        jsonDocument.setSaveStatus(documentSaveStatus);
    }
    // 
    // Included tabs info
    document.getIncludedDocumentsCollections().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(document, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
    // 
    // Available standard actions
    jsonDocument.setStandardActions(document.getStandardActions());
    // Set debugging info
    if (WindowConstants.isProtocolDebugging()) {
        jsonDocument.putDebugProperty("tablename", document.getEntityDescriptor().getTableNameOrNull());
        jsonDocument.putDebugProperty(JSONOptions.DEBUG_ATTRNAME, jsonOpts.toString());
        jsonDocument.putDebugProperty("fields-count", jsonDocument.getFieldsCount());
    }
    return jsonDocument;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IIncludedDocumentsCollection(de.metas.ui.web.window.model.IIncludedDocumentsCollection) DocumentChanges(de.metas.ui.web.window.model.DocumentChanges) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) DocumentStandardAction(de.metas.ui.web.window.model.DocumentStandardAction) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) Collection(java.util.Collection) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) Collectors(java.util.stream.Collectors) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) Document(de.metas.ui.web.window.model.Document) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

DocumentSaveStatus (de.metas.ui.web.window.model.DocumentSaveStatus)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableSet (com.google.common.collect.ImmutableSet)3 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)3 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)3 Document (de.metas.ui.web.window.model.Document)3 DocumentValidStatus (de.metas.ui.web.window.model.DocumentValidStatus)3 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 List (java.util.List)3 Set (java.util.Set)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 WebSocketConfig (de.metas.ui.web.websocket.WebSocketConfig)2 WindowConstants (de.metas.ui.web.window.WindowConstants)2 WindowId (de.metas.ui.web.window.datatypes.WindowId)2 DocumentChanges (de.metas.ui.web.window.model.DocumentChanges)2 DocumentStandardAction (de.metas.ui.web.window.model.DocumentStandardAction)2