use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlDocumentsRepository method save.
@Override
public void save(final Document document) {
Services.get(ITrxManager.class).assertThreadInheritedTrxExists();
assertThisRepository(document.getEntityDescriptor());
DocumentPermissionsHelper.assertCanEdit(document);
// Runnables to be executed after the PO is saved
final List<Runnable> afterSaveRunnables = new ArrayList<>();
//
// Load the PO / Create new PO instance
final PO po = retrieveOrCreatePO(document);
//
// Set values to PO
final boolean isNew = document.isNew();
boolean changes = false;
for (final IDocumentFieldView documentField : document.getFieldViews()) {
if (!isNew && !documentField.hasChangesToSave()) {
logger.trace("Skip setting PO value because document field has no changes: {}", documentField);
continue;
}
if (DocumentFieldWidgetType.Labels == documentField.getWidgetType()) {
// save labels after PO is saved because we want to make sure it's not new (so we can link to it)
afterSaveRunnables.add(() -> saveLabels(document, documentField));
}
if (setPOValue(po, documentField)) {
changes = true;
}
}
//
// Save the PO
boolean needsRefresh = false;
if (changes) {
//
// Actual save
// TODO: advice the PO to not reload after save.
InterfaceWrapperHelper.save(po);
document.markAsNotNew();
needsRefresh = true;
} else {
logger.trace("Skip saving {} because there was no actual change", po);
}
// Execute after save runnables
if (!afterSaveRunnables.isEmpty()) {
afterSaveRunnables.forEach(r -> r.run());
needsRefresh = true;
}
// Reload the document
if (needsRefresh) {
final SqlDocumentEntityDataBindingDescriptor dataBinding = document.getEntityDescriptor().getDataBinding(SqlDocumentEntityDataBindingDescriptor.class);
final DocumentId idNew = extractDocumentId(po, dataBinding);
refresh(document, idNew);
}
// Notify the parent document that one of it's children were saved
if (!document.isRootDocument()) {
document.getParentDocument().onChildSaved(document);
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PurchaseRowFactoryTest method test.
@Test
public void test() {
final PurchaseCandidate purchaseCandidate = createPurchaseCandidate(30);
final PurchaseRowFactory purchaseRowFactory = new PurchaseRowFactory();
final PurchaseRow candidateRow = purchaseRowFactory.rowFromPurchaseCandidateBuilder().purchaseCandidate(purchaseCandidate).vendorProductInfo(purchaseCandidate.getVendorProductInfo()).datePromised(SystemTime.asTimestamp()).build();
final DocumentId id = candidateRow.getId();
final PurchaseRowId purchaseRowId = PurchaseRowId.fromDocumentId(id);
assertThat(purchaseRowId.getVendorBPartnerId()).isEqualTo(purchaseCandidate.getVendorBPartnerId());
assertThat(purchaseRowId.getSalesOrderLineId()).isEqualTo(purchaseCandidate.getSalesOrderLineId());
assertThat(purchaseRowId.getProcessedPurchaseCandidateId()).isEqualTo(30);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PurchaseRowIdTest method groupId.
@Test
public void groupId() {
final PurchaseRowId rowId = PurchaseRowId.groupId(20);
final DocumentId documentId = rowId.toDocumentId();
assertThat(documentId.toString()).isEqualTo("20");
assertThat(rowId.isGroupRowId()).isTrue();
assertThat(rowId.isLineRowId()).isFalse();
assertThat(rowId.isAvailabilityRowId()).isFalse();
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PurchaseRowIdTest method fromDocumentId_Available.
@Test
public void fromDocumentId_Available() {
final DocumentId documentId = DocumentId.ofString("1000007-2156423-0-AVAILABLE-11");
final PurchaseRowId purchaseRowId = PurchaseRowId.fromDocumentId(documentId);
assertThat(purchaseRowId.getSalesOrderLineId()).isEqualTo(1000007);
assertThat(purchaseRowId.getVendorBPartnerId()).isEqualTo(2156423);
assertThat(purchaseRowId.getProcessedPurchaseCandidateId()).isEqualTo(0);
assertThat(purchaseRowId.getAvailabilityType()).isEqualTo(Type.AVAILABLE);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PurchaseRowIdTest method lineId_performWithParams.
private void lineId_performWithParams(final String salesOrderLineId, final String vendorBPartnerId, final String processedPurchaseCandidateId) {
final PurchaseRowId rowId = PurchaseRowId.lineId(Integer.parseInt(salesOrderLineId), Integer.parseInt(vendorBPartnerId), Integer.parseInt(processedPurchaseCandidateId));
final DocumentId documentId = rowId.toDocumentId();
assertThat(documentId.toString()).isEqualTo(salesOrderLineId + PurchaseRowId.PARTS_SEPARATOR + vendorBPartnerId + PurchaseRowId.PARTS_SEPARATOR + processedPurchaseCandidateId);
assertThat(rowId.isGroupRowId()).isFalse();
assertThat(rowId.isLineRowId()).isTrue();
assertThat(rowId.isAvailabilityRowId()).isFalse();
}
Aggregations