use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor 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.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method getDocumentPath.
/**
* Retrieves document path for given ZoomInto info.
*
* @param zoomIntoInfo
*/
public DocumentPath getDocumentPath(@NonNull final DocumentZoomIntoInfo zoomIntoInfo) {
if (!zoomIntoInfo.isRecordIdPresent()) {
throw new IllegalArgumentException("recordId must be set in " + zoomIntoInfo);
}
//
// Find the root window ID
final WindowId zoomIntoWindowIdEffective = getWindowId(zoomIntoInfo);
final DocumentEntityDescriptor rootEntityDescriptor = getDocumentEntityDescriptor(zoomIntoWindowIdEffective);
final String zoomIntoTableName = zoomIntoInfo.getTableName();
// (i.e. root descriptor's table is matching record's table)
if (Objects.equals(rootEntityDescriptor.getTableName(), zoomIntoTableName)) {
final DocumentId rootDocumentId = DocumentId.of(zoomIntoInfo.getRecordId());
return DocumentPath.rootDocumentPath(zoomIntoWindowIdEffective, rootDocumentId);
} else //
// We are dealing with an included document
{
// Search the root descriptor for any child entity descriptor which would match record's TableName
final List<DocumentEntityDescriptor> childEntityDescriptors = rootEntityDescriptor.getIncludedEntities().stream().filter(includedEntityDescriptor -> Objects.equals(includedEntityDescriptor.getTableName(), zoomIntoTableName)).collect(ImmutableList.toImmutableList());
if (childEntityDescriptors.isEmpty()) {
throw new EntityNotFoundException("Cannot find the detail tab to zoom into").setParameter("zoomIntoInfo", zoomIntoInfo).setParameter("zoomIntoWindowId", zoomIntoWindowIdEffective).setParameter("rootEntityDescriptor", rootEntityDescriptor);
} else if (childEntityDescriptors.size() > 1) {
logger.warn("More then one child descriptors matched our root descriptor. Picking the fist one. \nRoot descriptor: {} \nChild descriptors: {}", rootEntityDescriptor, childEntityDescriptors);
}
//
final DocumentEntityDescriptor childEntityDescriptor = childEntityDescriptors.get(0);
// Find the root DocumentId
final DocumentId rowId = DocumentId.of(zoomIntoInfo.getRecordId());
final DocumentId rootDocumentId = DocumentQuery.ofRecordId(childEntityDescriptor, rowId).retrieveParentDocumentId(rootEntityDescriptor);
//
return DocumentPath.includedDocumentPath(zoomIntoWindowIdEffective, rootDocumentId, childEntityDescriptor.getDetailId(), rowId);
}
}
use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor 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.descriptor.DocumentEntityDescriptor in project metasfresh-webui-api by metasfresh.
the class DocumentCollection method createDocumentPrint.
public DocumentPrint createDocumentPrint(final DocumentPath documentPath) {
final Document document = getDocumentReadonly(documentPath);
final int windowNo = document.getWindowNo();
final DocumentEntityDescriptor entityDescriptor = document.getEntityDescriptor();
final int printProcessId = entityDescriptor.getPrintProcessId();
final TableRecordReference recordRef = getTableRecordReference(documentPath);
final ProcessExecutionResult processExecutionResult = ProcessInfo.builder().setCtx(Env.getCtx()).setAD_Process_ID(printProcessId).setWindowNo(// important: required for ProcessInfo.findReportingLanguage
windowNo).setRecord(recordRef).setPrintPreview(true).setJRDesiredOutputType(OutputType.PDF).buildAndPrepareExecution().onErrorThrowException().switchContextWhenRunning().executeSync().getResult();
return DocumentPrint.builder().filename(processExecutionResult.getReportFilename()).reportContentType(processExecutionResult.getReportContentType()).reportData(processExecutionResult.getReportData()).build();
}
use of de.metas.ui.web.window.descriptor.DocumentEntityDescriptor 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