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