Search in sources :

Example 1 with JSONDocumentChangedEvent

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

the class WEBUI_CreateRequest method createRequestFromBPartner.

private void createRequestFromBPartner(final I_C_BPartner bpartner) {
    final I_AD_User defaultContact = Services.get(IBPartnerDAO.class).retrieveDefaultContactOrNull(bpartner, I_AD_User.class);
    final List<JSONDocumentChangedEvent> events = new ArrayList<>();
    events.add(JSONDocumentChangedEvent.replace(I_R_Request.COLUMNNAME_SalesRep_ID, getAD_User_ID()));
    events.add(JSONDocumentChangedEvent.replace(I_R_Request.COLUMNNAME_C_BPartner_ID, bpartner.getC_BPartner_ID()));
    if (defaultContact != null) {
        events.add(JSONDocumentChangedEvent.replace(I_R_Request.COLUMNNAME_AD_User_ID, defaultContact.getAD_User_ID()));
    }
    final DocumentPath documentPath = DocumentPath.builder().setDocumentType(WindowConstants.WINDOWID_R_Request).setDocumentId(DocumentId.NEW_ID_STRING).allowNewDocumentId().build();
    final DocumentId documentId = documentCollection.forDocumentWritable(documentPath, NullDocumentChangesCollector.instance, document -> {
        document.processValueChanges(events, ReasonSupplier.NONE);
        return document.getDocumentId();
    });
    getResult().setRecordToOpen(TableRecordReference.of(I_R_Request.Table_Name, documentId.toInt()), documentPath.getWindowId().toInt(), OpenTarget.SingleDocumentModal);
}
Also used : IBPartnerDAO(org.adempiere.bpartner.service.IBPartnerDAO) I_AD_User(org.compiere.model.I_AD_User) ArrayList(java.util.ArrayList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent)

Example 2 with JSONDocumentChangedEvent

use of de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent 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 3 with JSONDocumentChangedEvent

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

the class MailRestController method changeEmail.

private void changeEmail(final WebuiEmail email, final WebuiEmailBuilder newEmailBuilder, final JSONDocumentChangedEvent event) {
    if (!event.isReplace()) {
        throw new AdempiereException("Unsupported event").setParameter("event", event);
    }
    final String fieldName = event.getPath();
    if (PATCH_FIELD_To.equals(fieldName)) {
        @SuppressWarnings("unchecked") final List<Object> jsonTo = (List<Object>) event.getValue();
        @SuppressWarnings("unchecked") final LookupValuesList to = jsonTo.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.integerLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
        newEmailBuilder.to(to);
    } else if (PATCH_FIELD_Subject.equals(fieldName)) {
        final String subject = (String) event.getValue();
        newEmailBuilder.subject(subject);
    } else if (PATCH_FIELD_Message.equals(fieldName)) {
        final String message = (String) event.getValue();
        newEmailBuilder.message(message);
    } else if (PATCH_FIELD_Attachments.equals(fieldName)) {
        @SuppressWarnings("unchecked") final List<Object> jsonAttachments = (List<Object>) event.getValue();
        @SuppressWarnings("unchecked") final LookupValuesList attachments = jsonAttachments.stream().map(mapObj -> (Map<String, Object>) mapObj).map(map -> JSONLookupValue.stringLookupValueFromJsonMap(map)).collect(LookupValuesList.collect());
        newEmailBuilder.attachments(attachments);
    } else if (PATCH_FIELD_TemplateId.equals(fieldName)) {
        @SuppressWarnings("unchecked") final LookupValue templateId = JSONLookupValue.integerLookupValueFromJsonMap((Map<String, Object>) event.getValue());
        applyTemplate(email, newEmailBuilder, templateId);
    } else {
        throw new AdempiereException("Unsupported event path").setParameter("event", event).setParameter("fieldName", fieldName).setParameter("availablePaths", PATCH_FIELD_ALL);
    }
}
Also used : FillMandatoryException(org.adempiere.exceptions.FillMandatoryException) PathVariable(org.springframework.web.bind.annotation.PathVariable) RequestParam(org.springframework.web.bind.annotation.RequestParam) WebuiEmailRemovedEvent(de.metas.ui.web.mail.WebuiMailRepository.WebuiEmailRemovedEvent) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) UnaryOperator(java.util.function.UnaryOperator) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection) ApiOperation(io.swagger.annotations.ApiOperation) Map(java.util.Map) JSONEmail(de.metas.ui.web.mail.json.JSONEmail) PostMapping(org.springframework.web.bind.annotation.PostMapping) ImmutableSet(com.google.common.collect.ImmutableSet) EMail(de.metas.email.EMail) NonNull(lombok.NonNull) Set(java.util.Set) EventListener(org.springframework.context.event.EventListener) 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) List(java.util.List) I_AD_Client(org.compiere.model.I_AD_Client) Stream(java.util.stream.Stream) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) IMailBL(de.metas.email.IMailBL) ApiModel(io.swagger.annotations.ApiModel) LogManager(de.metas.logging.LogManager) EMailSentStatus(de.metas.email.EMailSentStatus) WebConfig(de.metas.ui.web.config.WebConfig) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) Supplier(com.google.common.base.Supplier) IUserBL(org.adempiere.user.api.IUserBL) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) IUserDAO(org.adempiere.user.api.IUserDAO) PatchMapping(org.springframework.web.bind.annotation.PatchMapping) RequestBody(org.springframework.web.bind.annotation.RequestBody) ImmutableList(com.google.common.collect.ImmutableList) GetMapping(org.springframework.web.bind.annotation.GetMapping) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) I_AD_User(org.compiere.model.I_AD_User) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Properties(java.util.Properties) Logger(org.slf4j.Logger) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) IOException(java.io.IOException) WebuiEmailBuilder(de.metas.ui.web.mail.WebuiEmail.WebuiEmailBuilder) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) AdempiereException(org.adempiere.exceptions.AdempiereException) IClientDAO(org.adempiere.service.IClientDAO) Check(de.metas.printing.esb.base.util.Check) EMailAttachment(de.metas.email.EMailAttachment) JSONEmailRequest(de.metas.ui.web.mail.json.JSONEmailRequest) MultipartFile(org.springframework.web.multipart.MultipartFile) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LookupValuesList(de.metas.ui.web.window.datatypes.LookupValuesList) Map(java.util.Map) IntegerLookupValue(de.metas.ui.web.window.datatypes.LookupValue.IntegerLookupValue) JSONLookupValue(de.metas.ui.web.window.datatypes.json.JSONLookupValue) LookupValue(de.metas.ui.web.window.datatypes.LookupValue)

Example 4 with JSONDocumentChangedEvent

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

the class PurchaseRowsCollection method applyFieldChangeRequests.

private void applyFieldChangeRequests(@NonNull final PurchaseRow editableGroupRow, final PurchaseRowId includedRowId, @NonNull final List<JSONDocumentChangedEvent> fieldChangeRequests) {
    Check.errorIf(includedRowId == null, "Only group rows with an includedRowId may be edited, but includedRowId=null; fieldChangeRequests={}; editableGroupRow={}", fieldChangeRequests, editableGroupRow);
    for (final JSONDocumentChangedEvent fieldChangeRequest : fieldChangeRequests) {
        final String fieldName = fieldChangeRequest.getPath();
        if (PurchaseRow.FIELDNAME_QtyToPurchase.equals(fieldName)) {
            final BigDecimal qtyToPurchase = fieldChangeRequest.getValueAsBigDecimal();
            editableGroupRow.changeQtyToPurchase(includedRowId, qtyToPurchase);
        } else if (PurchaseRow.FIELDNAME_DatePromised.equals(fieldName)) {
            final Date datePromised = fieldChangeRequest.getValueAsDateTime();
            editableGroupRow.changeDatePromised(includedRowId, datePromised);
        } else {
            throw new AdempiereException("Field " + fieldName + " is not editable").setParameter("row", editableGroupRow);
        }
    }
}
Also used : AdempiereException(org.adempiere.exceptions.AdempiereException) JSONDocumentChangedEvent(de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent) BigDecimal(java.math.BigDecimal) Date(java.util.Date)

Aggregations

JSONDocumentChangedEvent (de.metas.ui.web.window.datatypes.json.JSONDocumentChangedEvent)4 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)3 AdempiereException (org.adempiere.exceptions.AdempiereException)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 LogManager (de.metas.logging.LogManager)2 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)2 LookupValuesList (de.metas.ui.web.window.datatypes.LookupValuesList)2 DocumentCollection (de.metas.ui.web.window.model.DocumentCollection)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Set (java.util.Set)2 Stream (java.util.stream.Stream)2 NonNull (lombok.NonNull)2 Services (org.adempiere.util.Services)2 I_AD_User (org.compiere.model.I_AD_User)2 Logger (org.slf4j.Logger)2 MoreObjects (com.google.common.base.MoreObjects)1 Predicates (com.google.common.base.Predicates)1 Supplier (com.google.common.base.Supplier)1