Search in sources :

Example 1 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId 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 DocumentId

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

the class DefaultView method getFieldDropdown.

@Override
public LookupValuesList getFieldDropdown(final RowEditingContext ctx, final String fieldName) {
    final DocumentId rowId = ctx.getRowId();
    final DocumentCollection documentsCollection = ctx.getDocumentsCollection();
    final DocumentPath documentPath = getById(rowId).getDocumentPath();
    return documentsCollection.forDocumentReadonly(documentPath, document -> document.getFieldLookupValues(fieldName));
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentCollection(de.metas.ui.web.window.model.DocumentCollection)

Example 3 with DocumentId

use of de.metas.ui.web.window.datatypes.DocumentId 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 4 with DocumentId

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

the class ViewRowEditRestController method patchRow.

@PatchMapping
public JSONViewRow patchRow(@PathVariable(PARAM_WindowId) final String windowIdStr, @PathVariable(PARAM_ViewId) final String viewIdStr, @PathVariable(PARAM_RowId) final String rowIdStr, @RequestBody final List<JSONDocumentChangedEvent> fieldChangeRequests) {
    userSession.assertLoggedIn();
    final ViewId viewId = ViewId.of(windowIdStr, viewIdStr);
    final DocumentId rowId = DocumentId.of(rowIdStr);
    final IEditableView view = getEditableView(viewId);
    final RowEditingContext editingCtx = createRowEditingContext(rowId);
    view.patchViewRow(editingCtx, fieldChangeRequests);
    final IViewRow row = view.getById(rowId);
    final IViewRowOverrides rowOverrides = ViewRowOverridesHelper.getViewRowOverrides(view);
    return JSONViewRow.ofRow(row, rowOverrides, userSession.getAD_Language());
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) RowEditingContext(de.metas.ui.web.view.IEditableView.RowEditingContext) PatchMapping(org.springframework.web.bind.annotation.PatchMapping)

Example 5 with DocumentId

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

the class ViewRowAttributesRestController method getAttributeDropdown.

@GetMapping("/attribute/{attributeName}/dropdown")
public JSONLookupValuesList getAttributeDropdown(// 
@PathVariable(PARAM_WindowId) final String windowIdStr, // 
@PathVariable(PARAM_ViewId) final String viewIdStr, // 
@PathVariable(PARAM_RowId) final String rowIdStr, // 
@PathVariable("attributeName") final String attributeName) {
    userSession.assertLoggedIn();
    final ViewId viewId = ViewId.of(windowIdStr, viewIdStr);
    final DocumentId rowId = DocumentId.of(rowIdStr);
    return viewsRepo.getView(viewId).getById(rowId).getAttributes().getAttributeDropdown(attributeName).transform(JSONLookupValuesList::ofLookupValuesList);
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) JSONLookupValuesList(de.metas.ui.web.window.datatypes.json.JSONLookupValuesList) GetMapping(org.springframework.web.bind.annotation.GetMapping)

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