use of de.metas.ui.web.window.exceptions.InvalidDocumentPathException in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method createRootDocument.
/**
* Creates a new root document.
*
* @param documentPath
* @return new root document (writable)
*/
private Document createRootDocument(final DocumentPath documentPath, final IDocumentChangesCollector changesCollector) {
if (!documentPath.isNewDocument()) {
throw new InvalidDocumentPathException(documentPath, "new document ID was expected");
}
final WindowId windowId = documentPath.getWindowId();
final DocumentEntityDescriptor entityDescriptor = getDocumentEntityDescriptor(windowId);
assertNewDocumentAllowed(entityDescriptor);
final DocumentsRepository documentsRepository = entityDescriptor.getDataBinding().getDocumentsRepository();
final Document document = documentsRepository.createNewDocument(entityDescriptor, Document.NULL, changesCollector);
// NOTE: we are not adding it to index. That shall be done on "commit".
return document;
}
use of de.metas.ui.web.window.exceptions.InvalidDocumentPathException in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getData.
private List<JSONDocument> getData(final DocumentPath documentPath, final String fieldsListStr, final boolean advanced, final List<DocumentQueryOrderBy> orderBys) {
userSession.assertLoggedIn();
final JSONOptions jsonOpts = newJSONOptions().setShowAdvancedFields(advanced).setDataFieldsList(fieldsListStr).build();
return documentCollection.forRootDocumentReadonly(documentPath, rootDocument -> {
List<Document> documents;
if (documentPath.isRootDocument()) {
documents = ImmutableList.of(rootDocument);
} else if (documentPath.isAnyIncludedDocument()) {
documents = rootDocument.getIncludedDocuments(documentPath.getDetailId(), orderBys).toList();
} else if (documentPath.isSingleIncludedDocument()) {
documents = ImmutableList.of(rootDocument.getIncludedDocument(documentPath.getDetailId(), documentPath.getSingleRowId()));
} else {
throw new InvalidDocumentPathException(documentPath);
}
return JSONDocument.ofDocumentsList(documents, jsonOpts);
});
}
use of de.metas.ui.web.window.exceptions.InvalidDocumentPathException in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method retrieveRootDocumentFromRepository.
/**
* Retrieves document from repository
*/
private Document retrieveRootDocumentFromRepository(final DocumentKey documentKey) {
final DocumentEntityDescriptor entityDescriptor = getDocumentEntityDescriptor(documentKey.getWindowId());
if (documentKey.getDocumentId().isNew()) {
throw new InvalidDocumentPathException("documentId cannot be NEW");
}
final Document document = DocumentQuery.ofRecordId(entityDescriptor, documentKey.getDocumentId()).setChangesCollector(NullDocumentChangesCollector.instance).retriveDocumentOrNull();
if (document == null) {
throw new DocumentNotFoundException(documentKey.getDocumentPath());
}
return document;
}
use of de.metas.ui.web.window.exceptions.InvalidDocumentPathException in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method delete.
public void delete(final DocumentPath documentPath, final IDocumentChangesCollector changesCollector) {
if (documentPath.isRootDocument()) {
final DocumentEntityDescriptor entityDescriptor = documentDescriptorFactory.getDocumentEntityDescriptor(documentPath);
assertDeleteDocumentAllowed(entityDescriptor);
}
final DocumentPath rootDocumentPath = documentPath.getRootDocumentPath();
if (rootDocumentPath.isNewDocument()) {
throw new InvalidDocumentPathException(rootDocumentPath);
}
forRootDocumentWritable(rootDocumentPath, changesCollector, rootDocument -> {
if (documentPath.isRootDocument()) {
if (!rootDocument.isNew()) {
rootDocument.deleteFromRepository();
}
rootDocument.markAsDeleted();
} else if (documentPath.hasIncludedDocuments()) {
rootDocument.deleteIncludedDocuments(documentPath.getDetailId(), documentPath.getRowIds());
} else {
throw new InvalidDocumentPathException(documentPath);
}
// nothing to return
return null;
});
}
Aggregations