use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PickingSlotRowIdTests method testFromDocumentId_HU.
/**
* Tests the conversion between {@link DocumentId} and {@link PickingSlotRowId} in case of a picked HU.
*/
@Test
public void testFromDocumentId_HU() {
final DocumentId documentId = PickingSlotRowId.ofPickedHU(123, 456, -111).toDocumentId();
assertThat(documentId.toJson()).isEqualTo("123-456");
final PickingSlotRowId rowId = PickingSlotRowId.fromDocumentId(documentId);
assertThat(rowId.toDocumentId()).isEqualTo(documentId);
assertThat(rowId.getPickingSlotId()).isEqualTo(123);
assertThat(rowId.getHuId()).isEqualTo(456);
assertThat(rowId.getHuStorageProductId()).isLessThanOrEqualTo(0);
assertIsPickedHURow(rowId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class PickingSlotRowIdTests method testFromDocumentId_SourceHU.
/**
* Tests the conversion between {@link DocumentId} and {@link PickingSlotRowId} in case of a source-HU row (which has no picking slot ID).
*/
@Test
public void testFromDocumentId_SourceHU() {
final DocumentId documentId = PickingSlotRowId.ofSourceHU(18052595).toDocumentId();
assertThat(documentId.toJson()).isEqualTo("0-18052595");
final PickingSlotRowId rowId = PickingSlotRowId.fromDocumentId(documentId);
assertThat(rowId.toDocumentId()).isEqualTo(documentId);
assertThat(rowId.getPickingSlotId()).isLessThanOrEqualTo(0);
assertThat(rowId.getHuId()).isEqualTo(18052595);
assertThat(rowId.getHuStorageProductId()).isLessThanOrEqualTo(0);
assertIsPickingSourceHURow(rowId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method getDocumentPath.
/**
* Retrieves document path for given ZoomInto info.
*
* @param zoomIntoInfo
*/
public DocumentPath getDocumentPath(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
if (!zoomIntoInfo.isRecordIdPresent()) {
throw new IllegalArgumentException("recordId must be set in " + zoomIntoInfo);
}
//
// Find the root window ID
final WindowId zoomIntoWindowIdEffective = getWindowId(zoomIntoInfo);
final DocumentEntityDescriptor rootEntityDescriptor = getDocumentEntityDescriptor(zoomIntoWindowIdEffective);
final String zoomIntoTableName = zoomIntoInfo.getTableName();
// (i.e. root descriptor's table is matching record's table)
if (Objects.equals(rootEntityDescriptor.getTableName(), zoomIntoTableName)) {
final DocumentId rootDocumentId = DocumentId.of(zoomIntoInfo.getRecordId());
return DocumentPath.rootDocumentPath(zoomIntoWindowIdEffective, rootDocumentId);
} else //
// We are dealing with an included document
{
// Search the root descriptor for any child entity descriptor which would match record's TableName
final List<DocumentEntityDescriptor> childEntityDescriptors = rootEntityDescriptor.getIncludedEntities().stream().filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableName(), zoomIntoTableName)).collect(ImmutableList.toImmutableList());
if (childEntityDescriptors.isEmpty()) {
throw new EntityNotFoundException("Cannot find the detail tab to zoom into").setParameter("zoomIntoInfo", zoomIntoInfo).setParameter("zoomIntoWindowId", zoomIntoWindowIdEffective).setParameter("rootEntityDescriptor", rootEntityDescriptor);
} else if (childEntityDescriptors.size() > 1) {
logger.warn("More then one child descriptors matched our root descriptor. Picking the fist one. \nRoot descriptor: {} \nChild descriptors: {}", rootEntityDescriptor, childEntityDescriptors);
}
//
final DocumentEntityDescriptor childEntityDescriptor = childEntityDescriptors.get(0);
// Find the root DocumentId
final DocumentId rowId = DocumentId.of(zoomIntoInfo.getRecordId());
final DocumentId rootDocumentId = DocumentQuery.ofRecordId(childEntityDescriptor, rowId).retrieveParentDocumentId(rootEntityDescriptor);
//
return DocumentPath.includedDocumentPath(zoomIntoWindowIdEffective, rootDocumentId, childEntityDescriptor.getDetailId(), rowId);
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class HighVolumeReadWriteIncludedDocumentsCollection method deleteDocuments.
@Override
public void deleteDocuments(final DocumentIdsSelection documentIds) {
if (documentIds.isEmpty()) {
throw new IllegalArgumentException("At least one rowId shall be specified when deleting included documents");
}
assertWritable();
final List<Document> deletedDocuments = new ArrayList<>();
for (final DocumentId documentId : documentIds.toSet()) {
final Document document = getDocumentById(documentId);
// Delete it from underlying repository (if it's present there)
if (!document.isNew()) {
document.deleteFromRepository();
}
document.markAsDeleted();
forgetChangedDocument(documentId);
deletedDocuments.add(document);
}
// We need to invalidate them...
if (!deletedDocuments.isEmpty()) {
markStaleAll();
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class AddressRepository method complete.
public LookupValue complete(final int addressDocIdInt) {
final DocumentId addressDocId = DocumentId.of(addressDocIdInt);
final Document addressDoc = getAddressDocumentForWriting(addressDocId, NullDocumentChangesCollector.instance);
final I_C_Location locationRecord = createC_Location(addressDoc);
Services.get(ITrxManager.class).getCurrentTrxListenerManagerOrAutoCommit().newEventListener(TrxEventTiming.AFTER_COMMIT).registerHandlingMethod(trx -> removeAddressDocumentById(addressDocId));
final String locationStr = Services.get(ILocationBL.class).mkAddress(locationRecord);
return IntegerLookupValue.of(locationRecord.getC_Location_ID(), locationStr);
}
Aggregations