Search in sources :

Example 1 with Document

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

the class WindowQuickInputRestController method complete.

@PostMapping("{quickInputId}/complete")
public JSONDocument complete(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, // 
@PathVariable("tabId") final String tabIdStr, // 
@PathVariable("quickInputId") final String quickInputIdStr) {
    userSession.assertLoggedIn();
    final QuickInputPath quickInputPath = QuickInputPath.of(windowIdStr, documentIdStr, tabIdStr, quickInputIdStr);
    final IDocumentChangesCollector changesCollector = NullDocumentChangesCollector.instance;
    return Execution.callInNewExecution("quickInput-writable-" + quickInputPath, () -> {
        return forQuickInputWritable(quickInputPath, changesCollector, quickInput -> {
            final Document document = quickInput.complete();
            return JSONDocument.ofDocument(document, newJSONOptions());
        });
    });
}
Also used : IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with Document

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

the class AddressRepository method createNewFrom.

public Document createNewFrom(final int fromC_Location_ID) {
    final DocumentEntityDescriptor entityDescriptor = descriptorsFactory.getAddressDescriptor().getEntityDescriptor();
    final Document addressDoc = Document.builder(entityDescriptor).initializeAsNewDocument(nextAddressDocId::getAndIncrement, VERSION_DEFAULT).build();
    final I_C_Location fromLocation = fromC_Location_ID <= 0 ? null : InterfaceWrapperHelper.create(Env.getCtx(), fromC_Location_ID, I_C_Location.class, ITrx.TRXNAME_ThreadInherited);
    if (fromLocation != null) {
        addressDoc.getFieldViews().stream().forEach(field -> {
            final Object value = field.getDescriptor().getDataBindingNotNull(AddressFieldBinding.class).readValue(fromLocation);
            addressDoc.processValueChange(field.getFieldName(), value, () -> "update from " + fromLocation);
        });
    }
    addressDoc.checkAndGetValidStatus();
    logger.trace("Created from C_Location_ID={}: {}", fromC_Location_ID, addressDoc);
    putAddressDocument(addressDoc);
    return addressDoc;
}
Also used : I_C_Location(de.metas.adempiere.model.I_C_Location) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) Document(de.metas.ui.web.window.model.Document) AddressFieldBinding(de.metas.ui.web.address.AddressDescriptorFactory.AddressFieldBinding)

Example 3 with Document

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

the class AddressRepository method putAddressDocument.

private final void putAddressDocument(final Document addressDoc) {
    final Document addressDocReadonly = addressDoc.copy(CopyMode.CheckInReadonly, NullDocumentChangesCollector.instance);
    id2addressDoc.put(addressDoc.getDocumentId(), addressDocReadonly);
    logger.trace("Added to repository: {}", addressDocReadonly);
}
Also used : Document(de.metas.ui.web.window.model.Document)

Example 4 with Document

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

the class AddressRestController method getAddressDocument.

@RequestMapping(value = "/{docId}", method = RequestMethod.GET)
public JSONDocument getAddressDocument(@PathVariable("docId") final int docId) {
    userSession.assertLoggedIn();
    final Document addressDoc = addressRepo.getAddressDocumentForReading(docId);
    return JSONDocument.ofDocument(addressDoc, newJsonOpts());
}
Also used : JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with Document

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

the class JSONDocument method ofEventOrNull.

private static JSONDocument ofEventOrNull(final DocumentChanges documentChangedEvents, final JSONOptions jsonOpts) {
    if (documentChangedEvents.isEmpty()) {
        return null;
    }
    final DocumentPath documentPath = documentChangedEvents.getDocumentPath();
    final JSONDocument jsonDocument = new JSONDocument(documentPath);
    // If the document was deleted, we just need to export that flag. All the other changes are not relevant.
    if (documentChangedEvents.isDeleted()) {
        jsonDocument.setDeleted();
        return jsonDocument;
    }
    // 
    // Fields
    {
        final List<JSONDocumentField> jsonFields = new ArrayList<>();
        documentChangedEvents.getFieldChangesList().stream().filter(jsonOpts.documentFieldChangeFilter()).forEach((field) -> {
            // Add the pseudo-field "ID" first
            if (field.isKey()) {
                jsonFields.add(0, JSONDocumentField.idField(field.getValueAsJsonObject()));
            }
            // Append the other fields
            final JSONDocumentField jsonField = JSONDocumentField.ofDocumentFieldChangedEvent(field, jsonOpts);
            // apply permissions
            jsonOpts.getDocumentPermissions().apply(documentPath, jsonField);
            jsonFields.add(jsonField);
        });
        jsonDocument.setFields(jsonFields);
    }
    // 
    // Valid status
    final DocumentValidStatus documentValidStatus = documentChangedEvents.getDocumentValidStatus();
    if (documentValidStatus != null) {
        jsonDocument.setValidStatus(documentValidStatus);
    }
    // 
    // Save status
    final DocumentSaveStatus documentSaveStatus = documentChangedEvents.getDocumentSaveStatus();
    if (documentSaveStatus != null) {
        jsonDocument.setSaveStatus(documentSaveStatus);
    }
    // 
    // Included tabs info
    documentChangedEvents.getIncludedDetailInfos().stream().map(JSONDocument::createIncludedTabInfo).peek(jsonIncludedTabInfo -> jsonOpts.getDocumentPermissions().apply(documentPath, jsonIncludedTabInfo)).forEach(jsonDocument::addIncludedTabInfo);
    return jsonDocument;
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) DocumentId(de.metas.ui.web.window.datatypes.DocumentId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IIncludedDocumentsCollection(de.metas.ui.web.window.model.IIncludedDocumentsCollection) DocumentChanges(de.metas.ui.web.window.model.DocumentChanges) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) DocumentStandardAction(de.metas.ui.web.window.model.DocumentStandardAction) ImmutableSet(com.google.common.collect.ImmutableSet) WindowConstants(de.metas.ui.web.window.WindowConstants) Collection(java.util.Collection) LogicExpressionResult(org.adempiere.ad.expression.api.LogicExpressionResult) Set(java.util.Set) WindowId(de.metas.ui.web.window.datatypes.WindowId) Collectors(java.util.stream.Collectors) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) List(java.util.List) AdempiereException(org.adempiere.exceptions.AdempiereException) IDocumentChangesCollector(de.metas.ui.web.window.model.IDocumentChangesCollector) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) WebSocketConfig(de.metas.ui.web.websocket.WebSocketConfig) Document(de.metas.ui.web.window.model.Document) DocumentSaveStatus(de.metas.ui.web.window.model.DocumentSaveStatus) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentValidStatus(de.metas.ui.web.window.model.DocumentValidStatus) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

Document (de.metas.ui.web.window.model.Document)23 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)11 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)6 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)6 IDocumentChangesCollector (de.metas.ui.web.window.model.IDocumentChangesCollector)6 AdempiereException (org.adempiere.exceptions.AdempiereException)6 ImmutableList (com.google.common.collect.ImmutableList)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Set (java.util.Set)5 ImmutableSet (com.google.common.collect.ImmutableSet)4 WindowConstants (de.metas.ui.web.window.WindowConstants)4 JSONDocument (de.metas.ui.web.window.datatypes.json.JSONDocument)4 Map (java.util.Map)4 ITrxManager (org.adempiere.ad.trx.api.ITrxManager)4 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)3 WebuiRelatedProcessDescriptor (de.metas.ui.web.process.descriptor.WebuiRelatedProcessDescriptor)3 UserSession (de.metas.ui.web.session.UserSession)3 PostMapping (org.springframework.web.bind.annotation.PostMapping)3 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)2