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);
}
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);
}
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;
}
}
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);
}
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;
}
Aggregations