Search in sources :

Example 56 with DocumentPath

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

the class DocumentChangesCollector method collectFrom.

private void collectFrom(final DocumentChanges fromDocumentChanges) {
    final DocumentPath documentPath = fromDocumentChanges.getDocumentPath();
    documentChanges(documentPath).collectFrom(fromDocumentChanges);
}
Also used : DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 57 with DocumentPath

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

the class DocumentChangesCollector method isStaleDocumentChanges.

private boolean isStaleDocumentChanges(final DocumentChanges documentChanges) {
    final DocumentPath documentPath = documentChanges.getDocumentPath();
    if (!documentPath.isSingleIncludedDocument()) {
        return false;
    }
    final DocumentPath rootDocumentPath = documentPath.getRootDocumentPath();
    final DetailId detailId = documentPath.getDetailId();
    return documentChangesIfExists(rootDocumentPath).flatMap(rootDocumentChanges -> rootDocumentChanges.includedDetailInfoIfExists(detailId)).map(IncludedDetailInfo::isStale).orElse(false);
}
Also used : DetailId(de.metas.ui.web.window.descriptor.DetailId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 58 with DocumentPath

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

the class DocumentCollection method forRootDocumentWritable.

public <R> R forRootDocumentWritable(@NonNull final DocumentPath documentPathOrNew, final IDocumentChangesCollector changesCollector, @NonNull final Function<Document, R> rootDocumentProcessor) {
    final DocumentPath rootDocumentPathOrNew = documentPathOrNew.getRootDocumentPath();
    final Document lockHolder;
    final boolean isNewRootDocument;
    final DocumentKey rootDocumentKey;
    if (rootDocumentPathOrNew.isNewDocument()) {
        final Document newRootDocument = createRootDocument(rootDocumentPathOrNew, changesCollector);
        lockHolder = newRootDocument;
        rootDocumentKey = DocumentKey.ofRootDocumentPath(newRootDocument.getDocumentPath());
        isNewRootDocument = true;
    } else {
        rootDocumentKey = DocumentKey.ofRootDocumentPath(rootDocumentPathOrNew);
        lockHolder = getOrLoadDocument(rootDocumentKey);
        isNewRootDocument = false;
    }
    try (@SuppressWarnings("unused") final IAutoCloseable writeLock = lockHolder.lockForWriting()) {
        final Document rootDocument;
        if (isNewRootDocument) {
            rootDocument = lockHolder;
        } else {
            rootDocument = getOrLoadDocument(rootDocumentKey).copy(CopyMode.CheckOutWritable, changesCollector).refreshFromRepositoryIfStaled();
            DocumentPermissionsHelper.assertCanEdit(rootDocument);
        }
        // 
        // Execute the actual processor
        final R result = rootDocumentProcessor.apply(rootDocument);
        // Commit or remove it from cache if deleted
        if (rootDocument.isDeleted()) {
            rootDocuments.invalidate(rootDocumentKey);
            changesCollector.collectDeleted(rootDocument.getDocumentPath());
        } else {
            commitRootDocument(rootDocument);
        }
        // Return the result
        return result;
    }
}
Also used : IAutoCloseable(org.adempiere.util.lang.IAutoCloseable) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument)

Example 59 with DocumentPath

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

the class CommentsRestController method addComment.

@PostMapping
public void addComment(@PathVariable("windowId") final String windowIdStr, @PathVariable("documentId") final String documentId, @RequestBody final JSONCommentCreateRequest jsonCommentCreateRequest) {
    userSession.assertLoggedIn();
    final DocumentPath documentPath = DocumentPath.rootDocumentPath(WindowId.fromJson(windowIdStr), documentId);
    final TableRecordReference tableRecordReference = documentDescriptorFactory.getTableRecordReference(documentPath);
    commentsService.addComment(tableRecordReference, jsonCommentCreateRequest);
}
Also used : TableRecordReference(org.adempiere.util.lang.impl.TableRecordReference) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 60 with DocumentPath

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

the class WindowRestController method getDocumentPrint.

@GetMapping("/{windowId}/{documentId}/print/{filename:.*}")
public ResponseEntity<byte[]> getDocumentPrint(// 
@PathVariable("windowId") final String windowIdStr, // 
@PathVariable("documentId") final String documentIdStr, @PathVariable("filename") final String filename) {
    userSession.assertLoggedIn();
    final WindowId windowId = WindowId.fromJson(windowIdStr);
    final DocumentPath documentPath = DocumentPath.rootDocumentPath(windowId, documentIdStr);
    final DocumentPrint documentPrint = documentCollection.createDocumentPrint(documentPath);
    final byte[] reportData = documentPrint.getReportData();
    final String reportContentType = documentPrint.getReportContentType();
    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.parseMediaType(reportContentType));
    headers.set(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + filename + "\"");
    headers.setCacheControl("must-revalidate, post-check=0, pre-check=0");
    final ResponseEntity<byte[]> response = new ResponseEntity<>(reportData, headers, HttpStatus.OK);
    return response;
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) JSONDocumentPath(de.metas.ui.web.window.datatypes.json.JSONDocumentPath) DocumentPrint(de.metas.ui.web.window.model.DocumentCollection.DocumentPrint) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)65 WindowId (de.metas.ui.web.window.datatypes.WindowId)29 JSONDocumentPath (de.metas.ui.web.window.datatypes.json.JSONDocumentPath)22 DocumentId (de.metas.ui.web.window.datatypes.DocumentId)20 GetMapping (org.springframework.web.bind.annotation.GetMapping)14 List (java.util.List)13 ImmutableList (com.google.common.collect.ImmutableList)12 ImmutableSet (com.google.common.collect.ImmutableSet)12 DetailId (de.metas.ui.web.window.descriptor.DetailId)12 Set (java.util.Set)11 NonNull (lombok.NonNull)10 TableRecordReference (org.adempiere.util.lang.impl.TableRecordReference)10 AdempiereException (org.adempiere.exceptions.AdempiereException)9 PostMapping (org.springframework.web.bind.annotation.PostMapping)9 DocumentIdsSelection (de.metas.ui.web.window.datatypes.DocumentIdsSelection)8 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)8 Document (de.metas.ui.web.window.model.Document)7 ViewId (de.metas.ui.web.view.ViewId)6 Services (de.metas.util.Services)6 EntityNotFoundException (de.metas.ui.web.exceptions.EntityNotFoundException)5