Search in sources :

Example 11 with DetailId

use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.

the class WindowQuickInputRestController method create.

@PostMapping
public JSONDocument create(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, // 
@PathVariable("tabId") final String tabIdStr) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentPath rootDocumentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
    final DetailId detailId = DetailId.fromJson(tabIdStr);
    return Execution.callInNewExecution("quickInput.create", () -> {
        final QuickInput quickInput = documentsCollection.forRootDocumentReadonly(rootDocumentPath, rootDocument -> {
            // Make sure we can edit our root document. Fail fast.
            DocumentPermissionsHelper.assertCanEdit(rootDocument, userSession.getUserRolePermissions());
            final DocumentEntityDescriptor includedDocumentDescriptor = rootDocument.getEntityDescriptor().getIncludedEntityByDetailId(detailId);
            final QuickInputDescriptor quickInputDescriptor = quickInputDescriptors.getQuickInputEntityDescriptor(includedDocumentDescriptor);
            try {
                return QuickInput.builder().setQuickInputDescriptor(quickInputDescriptor).setRootDocumentPath(rootDocument.getDocumentPath()).build().bindRootDocument(rootDocument).assertTargetWritable();
            } catch (Exception ex) {
                // see https://github.com/metasfresh/metasfresh-webui-frontend/issues/487
                throw EntityNotFoundException.wrapIfNeeded(ex);
            }
        });
        commit(quickInput);
        return JSONDocument.ofDocument(quickInput.getQuickInputDocument(), newJSONOptions());
    });
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) EntityNotFoundException(de.metas.ui.web.exceptions.EntityNotFoundException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Aggregations

DetailId (de.metas.ui.web.window.descriptor.DetailId)11 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)6 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)5 WindowId (de.metas.ui.web.window.datatypes.WindowId)5 JsonAutoDetect (com.fasterxml.jackson.annotation.JsonAutoDetect)2 Visibility (com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility)2 JsonCreator (com.fasterxml.jackson.annotation.JsonCreator)2 JsonInclude (com.fasterxml.jackson.annotation.JsonInclude)2 JsonProperty (com.fasterxml.jackson.annotation.JsonProperty)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)2 DocumentType (de.metas.ui.web.window.datatypes.DocumentType)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 List (java.util.List)2 Set (java.util.Set)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 MoreObjects (com.google.common.base.MoreObjects)1 Preconditions (com.google.common.base.Preconditions)1