Search in sources :

Example 1 with DocumentNotFoundException

use of de.metas.ui.web.window.exceptions.DocumentNotFoundException in project metasfresh-webui-api by metasfresh.

the class HighVolumeReadWriteIncludedDocumentsCollection method getDocumentById.

@Override
public Document getDocumentById(final DocumentId documentId) {
    // Try documents which have changes in progress, but not yet saved
    final Document documentWithChanges = getChangedDocumentOrNull(documentId);
    if (documentWithChanges != null) {
        return documentWithChanges;
    }
    // Retrieve from repository
    final Document documentRetrieved = DocumentQuery.builder(entityDescriptor).setParentDocument(parentDocument).setRecordId(documentId).setChangesCollector(NullDocumentChangesCollector.instance).retriveDocumentOrNull();
    if (documentRetrieved == null) {
        final DocumentPath documentPath = parentDocumentPath.createChildPath(detailId, documentId);
        throw new DocumentNotFoundException(documentPath);
    }
    return documentRetrieved.copy(parentDocument, parentDocument.isWritable() ? CopyMode.CheckOutWritable : CopyMode.CheckInReadonly);
}
Also used : DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath)

Example 2 with DocumentNotFoundException

use of de.metas.ui.web.window.exceptions.DocumentNotFoundException in project metasfresh-webui-api by metasfresh.

the class SqlDocumentsRepository method refresh.

private void refresh(@NonNull final Document document, @NonNull final DocumentId documentId) {
    logger.debug("Refreshing: {}, using ID={}", document, documentId);
    if (documentId.isNew()) {
        throw new AdempiereException("Invalid documentId to refresh: " + documentId);
    }
    final DocumentEntityDescriptor entityDescriptor = document.getEntityDescriptor();
    final DocumentQuery query = DocumentQuery.ofRecordId(entityDescriptor, documentId).setChangesCollector(document.getChangesCollector()).build();
    final SqlDocumentQueryBuilder sqlBuilder = SqlDocumentQueryBuilder.of(query);
    final List<Object> sqlParams = new ArrayList<>();
    final String sql = sqlBuilder.getSql(sqlParams);
    final String adLanguage = sqlBuilder.getAD_Language();
    logger.debug("Retrieving records: SQL={} -- {}", sql, sqlParams);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, ITrx.TRXNAME_ThreadInherited);
        DB.setParameters(pstmt, sqlParams);
        rs = pstmt.executeQuery();
        if (rs.next()) {
            final ResultSetDocumentValuesSupplier fieldValueSupplier = new ResultSetDocumentValuesSupplier(entityDescriptor, adLanguage, rs);
            document.refreshFromSupplier(fieldValueSupplier);
        } else {
            // Document is no longer in our repository
            final DocumentPath documentPathEffective = document.getDocumentPath().withDocumentId(documentId);
            throw new DocumentNotFoundException(documentPathEffective);
        }
        if (rs.next()) {
            throw new AdempiereException("More than one record found while trying to reload document: " + document);
        }
    } catch (final SQLException e) {
        throw new DBException(e, sql, sqlParams);
    } finally {
        DB.close(rs, pstmt);
    }
}
Also used : DBException(org.adempiere.exceptions.DBException) DocumentNotFoundException(de.metas.ui.web.window.exceptions.DocumentNotFoundException) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) DocumentQuery(de.metas.ui.web.window.model.DocumentQuery) AdempiereException(org.adempiere.exceptions.AdempiereException) ResultSet(java.sql.ResultSet) DocumentPath(de.metas.ui.web.window.datatypes.DocumentPath) DocumentEntityDescriptor(de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)

Example 3 with DocumentNotFoundException

use of de.metas.ui.web.window.exceptions.DocumentNotFoundException 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)

Aggregations

DocumentNotFoundException (de.metas.ui.web.window.exceptions.DocumentNotFoundException)3 DocumentPath (de.metas.ui.web.window.datatypes.DocumentPath)2 DocumentEntityDescriptor (de.metas.ui.web.window.descriptor.DocumentEntityDescriptor)2 SourceDocument (de.metas.letters.model.MADBoilerPlate.SourceDocument)1 InvalidDocumentPathException (de.metas.ui.web.window.exceptions.InvalidDocumentPathException)1 DocumentQuery (de.metas.ui.web.window.model.DocumentQuery)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 DBException (org.adempiere.exceptions.DBException)1