use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class HUEditorRowId method ofHU.
public static HUEditorRowId ofHU(final int huId, final int topLevelHUId) {
final int storageProductId = -1;
// to be computed when needed
final String json = null;
// to be computed when needed
final DocumentId documentId = null;
return new HUEditorRowId(huId, storageProductId, topLevelHUId, json, documentId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class HUEditorRowId method toTopLevelRowId.
public HUEditorRowId toTopLevelRowId() {
if (isTopLevel()) {
return this;
}
final int huId = getTopLevelHUId();
final int storageProductId = -1;
final int topLevelHUId = -1;
final String json = null;
final DocumentId documentId = null;
return new HUEditorRowId(huId, storageProductId, topLevelHUId, json, documentId);
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method retrieveRowIdsByPage.
@Override
public List<DocumentId> retrieveRowIdsByPage(final ViewEvaluationCtx viewEvalCtx, final ViewRowIdsOrderedSelection orderedSelection, final int firstRow, final int pageLength) {
logger.debug("Getting page: firstRow={}, pageLength={} - {}", firstRow, pageLength, this);
logger.debug("Using: {}", orderedSelection);
final ViewId viewId = orderedSelection.getViewId();
final SqlAndParams sqlAndParams = sqlViewSelect.selectRowIdsByPage().viewEvalCtx(viewEvalCtx).viewId(viewId).firstRowZeroBased(firstRow).pageLength(pageLength).build();
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sqlAndParams.getSql(), ITrx.TRXNAME_ThreadInherited);
pstmt.setMaxRows(pageLength);
DB.setParameters(pstmt, sqlAndParams.getSqlParams());
rs = pstmt.executeQuery();
final ImmutableList.Builder<DocumentId> rowIds = ImmutableList.builder();
// N/A, not important
final String adLanguage = null;
while (rs.next()) {
final DocumentId rowId = retrieveRowId(rs, adLanguage);
if (rowId == null) {
continue;
}
rowIds.add(rowId);
}
return rowIds.build();
} catch (final SQLException | DBException e) {
throw DBException.wrapIfNeeded(e).setSqlIfAbsent(sqlAndParams.getSql(), sqlAndParams.getSqlParams());
} finally {
DB.close(rs, pstmt);
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method retrieveRowId_SingleKey.
private DocumentId retrieveRowId_SingleKey(final ResultSet rs, final String adLanguage) throws SQLException {
final String keyColumnName = keyColumnNamesMap.getSingleKeyColumnName();
final SqlViewRowFieldLoader fieldLoader = rowFieldLoaders.get(keyColumnName);
final Object jsonRowIdObj = fieldLoader.retrieveValueAsJson(rs, adLanguage);
if (JSONNullValue.isNull(jsonRowIdObj)) {
return null;
} else if (jsonRowIdObj instanceof DocumentId) {
return (DocumentId) jsonRowIdObj;
} else if (jsonRowIdObj instanceof Integer) {
return DocumentId.of((Integer) jsonRowIdObj);
} else if (jsonRowIdObj instanceof String) {
return DocumentId.of(jsonRowIdObj.toString());
} else if (jsonRowIdObj instanceof JSONLookupValue) {
// case: usually this is happening when a view's column which is Lookup is also marked as KEY.
final JSONLookupValue jsonLookupValue = (JSONLookupValue) jsonRowIdObj;
return DocumentId.of(jsonLookupValue.getKey());
} else {
throw new IllegalArgumentException("Cannot convert id '" + jsonRowIdObj + "' (" + jsonRowIdObj.getClass() + ") to integer");
}
}
use of de.metas.ui.web.window.datatypes.DocumentId in project metasfresh-webui-api by metasfresh.
the class SqlViewDataRepository method loadViewRows.
private final ImmutableList<IViewRow> loadViewRows(final ResultSet rs, final ViewEvaluationCtx viewEvalCtx, final ViewId viewId, final int limit) throws SQLException {
final Map<DocumentId, ViewRow.Builder> rowBuilders = new LinkedHashMap<>();
final Set<DocumentId> rootRowIds = new HashSet<>();
while (rs.next()) {
final ViewRow.Builder rowBuilder = loadViewRow(rs, viewId.getWindowId(), viewEvalCtx.getAD_Language());
if (rowBuilder == null) {
continue;
}
final DocumentId rowId = rowBuilder.getRowId();
rowBuilders.put(rowId, rowBuilder);
if (rowBuilder.isRootRow()) {
rootRowIds.add(rowId);
}
// Enforce limit
if (limit > 0 && limit <= rowBuilders.size()) {
break;
}
}
// Load lines
if (hasIncludedRows && !rootRowIds.isEmpty()) {
retrieveRowLines(viewEvalCtx, viewId, DocumentIdsSelection.of(rootRowIds)).forEach(line -> {
final DocumentId parentId = ViewRow.cast(line).getParentId();
final ViewRow.Builder rowBuilder = rowBuilders.get(parentId);
if (rowBuilder == null) {
// shall not happen
return;
}
rowBuilder.addIncludedRow(line);
});
}
return rowBuilders.values().stream().map(rowBuilder -> rowBuilder.build()).collect(ImmutableList.toImmutableList());
}
Aggregations