Search in sources :

Example 1 with InvalidDocumentPathException

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;
}
Also used : WindowId(de.metas.ui.web.window.datatypes.WindowId) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException)

Example 2 with InvalidDocumentPathException

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);
    });
}
Also used : JSONOptions(de.metas.ui.web.window.datatypes.json.JSONOptions) JSONDocument(de.metas.ui.web.window.datatypes.json.JSONDocument) Document(de.metas.ui.web.window.model.Document) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException)

Example 3 with InvalidDocumentPathException

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;
}
Also used : DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) SourceDocument(de.metas.letters.model.MADBoilerPlate.SourceDocument) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException)

Example 4 with InvalidDocumentPathException

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;
    });
}
Also used : DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor) InvalidDocumentPathException(de.metas.ui.web.window.exceptions.InvalidDocumentPathException)

Aggregations

InvalidDocumentPathException (de.metas.ui.web.window.exceptions.InvalidDocumentPathException)4 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)3 SourceDocument (de.metas.letters.model.MADBoilerPlate.SourceDocument)2 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)1 WindowId (de.metas.ui.web.window.datatypes.WindowId)1 JSONDocument (de.metas.ui.web.window.datatypes.json.JSONDocument)1 JSONOptions (de.metas.ui.web.window.datatypes.json.JSONOptions)1 DocumentNotFoundException (de.metas.ui.web.window.exceptions.DocumentNotFoundException)1 Document (de.metas.ui.web.window.model.Document)1