Search in sources :

Example 6 with Document

use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.

the class ASIRepository method createNewFrom.

public ASIDocument createNewFrom(final JSONCreateASIRequest request) {
    final ASIEditingInfo info = createASIEditingInfo(request);
    // 
    // Get the ASI descriptor
    final ASIDescriptor asiDescriptor = descriptorsFactory.getASIDescriptor(info);
    // 
    // Create the new ASI document
    final Document asiDocData = Document.builder(asiDescriptor.getEntityDescriptor()).initializeAsNewDocument(nextASIDocId, VERSION_DEFAULT).build();
    // 
    // If we have a template ASI, populate the ASI document from it
    final MAttributeSetInstance templateASI = info.getM_AttributeSetInstance();
    if (templateASI != null) {
        for (final I_M_AttributeInstance fromAI : Services.get(IAttributeDAO.class).retrieveAttributeInstances(templateASI)) {
            loadASIDocumentField(asiDocData, fromAI);
        }
    }
    // 
    // Validate, log and add the new ASI document to our index
    asiDocData.checkAndGetValidStatus();
    logger.trace("Created from ASI={}: {}", templateASI, asiDocData);
    final ASIDocument asiDoc = new ASIDocument(asiDescriptor, asiDocData);
    commit(asiDoc);
    return asiDoc;
}
Also used : ASIEditingInfo(org.adempiere.mm.attributes.util.ASIEditingInfo) Document(de.metas.ui.web.window.model.Document) MAttributeSetInstance(org.compiere.model.MAttributeSetInstance) I_M_AttributeInstance(org.compiere.model.I_M_AttributeInstance) IAttributeDAO(org.adempiere.mm.attributes.api.IAttributeDAO)

Example 7 with Document

use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.

the class HUReportProcessInstancesRepository method createNewProcessInstance.

@Override
public HUReportProcessInstance createNewProcessInstance(final CreateProcessInstanceRequest request) {
    final WebuiHUProcessDescriptor descriptor = getWebuiHUProcessDescriptor(request.getProcessId());
    final DocumentId instanceId = nextPInstanceId();
    final Document parameters = Document.builder(descriptor.getParametersDescriptor()).initializeAsNewDocument(instanceId, /* version */
    "0");
    final HUReportProcessInstance instance = HUReportProcessInstance.builder().instanceId(instanceId).viewRowIdsSelection(request.getViewRowIdsSelection()).reportAdProcessId(descriptor.getReportAdProcessId()).parameters(parameters).build();
    instance.setCopies(1);
    putInstance(instance);
    return instance;
}
Also used : DocumentId(de.metas.ui.web.window.datatypes.DocumentId) Document(de.metas.ui.web.window.model.Document)

Example 8 with Document

use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.

the class DataEntrySubTabBindingRepository method extractDataEntryRecordQuery.

private static DataEntryRecordQuery extractDataEntryRecordQuery(@NonNull final Document document) {
    final DetailId detailId = document.getEntityDescriptor().getDetailId();
    final DataEntrySubTabId subGroupId = extractDataEntrySubGroupId(detailId);
    final Document parentDocument = document.getParentDocument();
    final TableRecordReference parentRecordReference = extractParentRecordReference(parentDocument);
    return DataEntryRecordQuery.builder().dataEntrySubTabId(subGroupId).recordId(parentRecordReference.getRecord_ID()).build();
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) ITableRecordReference(org.adempiere.util.lang.ITableRecordReference) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DataEntrySubTabId(de.metas.dataentry.DataEntrySubTabId) Document(de.metas.ui.web.window.model.Document)

Example 9 with Document

use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.

the class DataEntrySubTabBindingRepository method retrieveDocumentIfExists.

private Optional<Document> retrieveDocumentIfExists(@NonNull final DocumentQuery query, @NonNull final IDocumentChangesCollector changesCollector) {
    final DocumentEntityDescriptor entityDescriptor = query.getEntityDescriptor();
    final Document parentDocument = query.getParentDocument();
    final Function<DocumentId, Document> existingDocumentsSupplier = query.getExistingDocumentsSupplier();
    final DetailId detailId = query.getEntityDescriptor().getDetailId();
    final DataEntrySubTabId dataEntrySubTabId = extractDataEntrySubGroupId(detailId);
    final TableRecordReference parentRecordReference = extractParentRecordReference(parentDocument);
    final DataEntryRecordQuery dataEntryRecordQuery = DataEntryRecordQuery.builder().dataEntrySubTabId(dataEntrySubTabId).recordId(parentRecordReference.getRecord_ID()).build();
    final Optional<DataEntryRecord> dataEntryRecord = dataEntryRecordRepository.getBy(dataEntryRecordQuery);
    if (!dataEntryRecord.isPresent()) {
        return Optional.empty();
    }
    final DocumentValuesSupplier documentValuesSupplier = new DataEntryDocumentValuesSupplier(dataEntryRecord.get(), dataEntryWebuiTools);
    Document document = null;
    if (existingDocumentsSupplier != null) {
        final DocumentId documentId = documentValuesSupplier.getDocumentId();
        document = existingDocumentsSupplier.apply(documentId);
    }
    if (document == null) {
        document = Document.builder(entityDescriptor).setParentDocument(parentDocument).setChangesCollector(changesCollector).initializeAsExistingRecord(documentValuesSupplier);
    }
    return Optional.ofNullable(document);
}
Also used : DataEntryRecord(de.metas.dataentry.data.DataEntryRecord) DetailId(de.metas.ui.web.window.descriptor.DetailId) ITableRecordReference(org.adempiere.util.lang.ITableRecordReference) TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) DataEntrySubTabId(de.metas.dataentry.DataEntrySubTabId) DataEntryRecordQuery(de.metas.dataentry.data.DataEntryRecordQuery) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Document(de.metas.ui.web.window.model.Document) DocumentValuesSupplier(de.metas.ui.web.window.model.Document.DocumentValuesSupplier)

Example 10 with Document

use of de.metas.ui.web.window.model.Document in project metasfresh-webui-api by metasfresh.

the class WEBUI_Fact_Acct_Repost_SingleDocument method checkPreconditionsApplicable.

@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(IProcessPreconditionsContext context) {
    final String recordTableName = context.getTableName();
    if (I_Fact_Acct.Table_Name.equals(recordTableName) || WEBUI_Fact_Acct_Repost_ViewRows.TABLENAME_RV_UnPosted.contentEquals(recordTableName)) {
        return ProcessPreconditionsResolution.accept();
    } else {
        final AdWindowId adWindowId = context.getAdWindowId();
        final int recordId = context.getSingleSelectedRecordId();
        final DocumentPath documentPath = DocumentPath.rootDocumentPath(adWindowId, recordId);
        final Document document = documentsCollection.getDocumentReadonly(documentPath);
        final BooleanWithReason allowPosting = checkAllowReposting(document);
        return allowPosting.isTrue() ? ProcessPreconditionsResolution.accept() : ProcessPreconditionsResolution.reject(allowPosting.getReason()).toInternal();
    }
}
Also used : BooleanWithReason(de.metas.i18n.BooleanWithReason) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) Document(de.metas.ui.web.window.model.Document) AdWindowId(org.adempiere.ad.element.api.AdWindowId)

Aggregations

Document (de.metas.ui.web.window.model.Document)36 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)16 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)12 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)10 List (java.util.List)9 Set (java.util.Set)9 AdempiereException (org.adempiere.exceptions.AdempiereException)9 ImmutableList (com.google.common.collect.ImmutableList)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 ImmutableSet (com.google.common.collect.ImmutableSet)7 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)6 WindowConstants (de.metas.ui.web.window.WindowConstants)6 Services (de.metas.util.Services)6 ArrayList (java.util.ArrayList)6 Map (java.util.Map)6 JSONDocument (de.metas.ui.web.window.datatypes.json.JSONDocument)5 DocumentSaveStatus (de.metas.ui.web.window.model.DocumentSaveStatus)5 Collectors (java.util.stream.Collectors)5 NonNull (lombok.NonNull)5 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)4