Search in sources :

Example 61 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Example 62 with DocumentId

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);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Test(org.junit.Test)

Example 63 with DocumentId

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);
    }
}
Also used : DocumentPermissionsHelper(de.metas.ui.web.window.controller.DocumentPermissionsHelper) DocumentZoomIntoInfo(de.metas.ui.web.window.model.lookup.DocumentZoomIntoInfo) ITrx(org.adempiere.ad.trx.api.ITrx) Env(org.compiere.util.Env) Autowired(org.springframework.beans.factory.annotation.Autowired) OutputType(de.metas.adempiere.report.jasper.OutputType) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) Evaluatee(org.compiere.util.Evaluatee) TableModelLoader(org.adempiere.ad.persistence.TableModelLoader) InterfaceWrapperHelper(org.adempiere.model.InterfaceWrapperHelper) DocumentWebsocketPublisher(de.metas.ui.web.window.events.DocumentWebsocketPublisher) CopyRecordSupport(org.adempiere.model.CopyRecordSupport) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) NonNull(lombok.NonNull) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) DocumentDescriptor(de.metas.ui.web.window.descriptor.DocumentDescriptor) Set(java.util.Set) Objects(java.util.Objects) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) UserSession(de.metas.ui.web.session.UserSession) Services(org.adempiere.util.Services) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) List(java.util.List) Builder(lombok.Builder) CopyRecordFactory(org.adempiere.model.CopyRecordFactory) CacheBuilder(com.google.common.cache.CacheBuilder) DocumentType(de.metas.ui.web.window.datatypes.DocumentType) LogManager(de.metas.logging.LogManager) ProcessInfo(de.metas.process.ProcessInfo) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) ProcessExecutionResult(de.metas.process.ProcessExecutionResult) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) ILogicExpression(org.adempiere.ad.expression.api.ILogicExpression) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException) Function(java.util.function.Function) PlainContextAware(org.adempiere.model.PlainContextAware) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) Value(lombok.Value) CopyMode(de.metas.ui.web.window.model.Document.CopyMode) ImmutableList(com.google.common.collect.ImmutableList) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Nullable(javax.annotation.Nullable) OnVariableNotFound(org.adempiere.ad.expression.api.IExpressionEvaluator.OnVariableNotFound) MADBoilerPlate(de.metas.letters.model.MADBoilerPlate) Logger(org.slf4j.Logger) Evaluatees(org.compiere.util.Evaluatees) DocumentDescriptorFactory(de.metas.ui.web.window.descriptor.factory.DocumentDescriptorFactory) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) MoreObjects(com.google.common.base.MoreObjects) WindowId(de.metas.ui.web.window.datatypes.WindowId) IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) ExecutionException(java.util.concurrent.ExecutionException) BoilerPlateContext(de.metas.letters.model.MADBoilerPlate.BoilerPlateContext) Component(org.springframework.stereotype.Component) AdempiereException(org.adempiere.exceptions.AdempiereException) Check(org.adempiere.util.Check) Preconditions(com.google.common.base.Preconditions) PO(org.compiere.model.PO) Cache(com.google.common.cache.Cache) AllArgsConstructor(lombok.AllArgsConstructor) Collections(java.util.Collections) Immutable(javax.annotation.concurrent.Immutable) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException)

Example 64 with DocumentId

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();
    }
}
Also used : ArrayList(java.util.ArrayList) DocumentId(de.metas.ui.web.window.datatypes.DocumentId)

Example 65 with DocumentId

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);
}
Also used : ITrxManager(org.adempiere.ad.trx.api.ITrxManager) ILocationBL(de.metas.adempiere.service.ILocationBL) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) I_C_Location(de.metas.adempiere.model.I_C_Location) Document(de.metas.ui.web.window.model.Document)

Aggregations

DocumentId (de.metas.ui.web.window.datatypes.DocumentId)99 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)18 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)14 List (java.util.List)14 ImmutableList (com.google.common.collect.ImmutableList)12 GetMapping (org.springframework.web.bind.annotation.GetMapping)12 AdempiereException (org.adempiere.exceptions.AdempiereException)11 JSONLookupValuesList (de.metas.ui.web.window.datatypes.json.JSONLookupValuesList)9 ArrayList (java.util.ArrayList)9 Set (java.util.Set)9 NonNull (lombok.NonNull)9 Test (org.junit.Test)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9 UserSession (de.metas.ui.web.session.UserSession)8 ViewId (de.metas.ui.web.view.ViewId)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)8 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)8 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8