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