use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.
the class GridTabVOBasedDocumentEntityDescriptorFactory method createDocumentEntityBuilder.
private DocumentEntityDescriptor.Builder createDocumentEntityBuilder(final GridTabVO gridTabVO, final GridTabVO parentTabVO, final boolean isSOTrx, final List<I_AD_UI_Element> labelsUIElements) {
final String tableName = gridTabVO.getTableName();
final DetailId detailId = parentTabVO == null ? null : DetailId.fromAD_Tab_ID(gridTabVO.getAD_Tab_ID());
// Entity Data binding
if (!Check.isEmpty(gridTabVO.getOrderByClause(), true)) {
logger.warn("Ignoring SQL order by for {}. See https://github.com/metasfresh/metasfresh/issues/412.", gridTabVO);
}
final SqlDocumentEntityDataBindingDescriptor.Builder dataBinding = SqlDocumentEntityDataBindingDescriptor.builder().setDocumentsRepository(documentsRepository).setTableName(tableName).setTableAliasFromDetailId(detailId).setChildToParentLinkColumnNames(extractChildParentLinkColumnNames(gridTabVO, parentTabVO)).setSqlWhereClause(gridTabVO.getWhereClause());
final ILogicExpression allowInsert = ConstantLogicExpression.of(gridTabVO.isInsertRecord());
final ILogicExpression allowDelete = ConstantLogicExpression.of(gridTabVO.isDeleteable());
final ILogicExpression readonlyLogic = extractTabReadonlyLogic(gridTabVO);
final ILogicExpression allowCreateNewLogic = allowInsert.andNot(readonlyLogic);
final ILogicExpression allowDeleteLogic = allowDelete.andNot(readonlyLogic);
//
final ILogicExpression displayLogic = gridTabVO.getDisplayLogic().evaluatePartial(Evaluatees.mapBuilder().put(WebRestApiContextProvider.CTXNAME_IsWebUI, DisplayType.toBooleanString(true)).build());
//
// Entity descriptor
final DocumentEntityDescriptor.Builder entityDescriptorBuilder = DocumentEntityDescriptor.builder().setDocumentType(DocumentType.Window, gridTabVO.getAD_Window_ID()).setDetailId(detailId).setCaption(gridTabVO.getNameTrls(), gridTabVO.getName()).setDescription(gridTabVO.getDescriptionTrls(), gridTabVO.getDescription()).setReadonlyLogic(readonlyLogic).setAllowCreateNewLogic(allowCreateNewLogic).setAllowDeleteLogic(allowDeleteLogic).setDisplayLogic(displayLogic).setDataBinding(dataBinding).setHighVolume(gridTabVO.IsHighVolume).setAD_Tab_ID(// legacy
gridTabVO.getAD_Tab_ID()).setTableName(// legacy
tableName).setIsSOTrx(// legacy
isSOTrx).setPrintAD_Process_ID(gridTabVO.getPrint_Process_ID());
final Predicate<GridFieldVO> isKeyColumn;
if (gridTabVO.getFields().stream().anyMatch(GridFieldVO::isKey)) {
isKeyColumn = GridFieldVO::isKey;
} else {
isKeyColumn = GridFieldVO::isParentLink;
}
//
// Fields descriptor
gridTabVO.getFields().stream().forEach(gridFieldVO -> createAndAddDocumentField(entityDescriptorBuilder, gridFieldVO, isKeyColumn.test(gridFieldVO)));
//
// Labels field descriptors
labelsUIElements.forEach(labelUIElement -> createAndAddLabelsDocumentField(entityDescriptorBuilder, labelUIElement));
return entityDescriptorBuilder;
}
use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.
the class DocumentEvaluatee method get_ValueIfExists.
@Override
public Optional<Object> get_ValueIfExists(final String variableName, final Class<?> targetType) {
if (variableName == null) {
return Optional.empty();
}
if (isExcludedField(variableName)) {
return Optional.empty();
}
if (WindowConstants.CONTEXTVAR_NextLineNo.equals(variableName)) {
final Document parentDocument = _document.getParentDocument();
if (parentDocument != null) {
final DetailId detailId = _document.getEntityDescriptor().getDetailId();
final int nextLineNo = parentDocument.getIncludedDocumentsCollection(detailId).getNextLineNo();
return Optional.of(nextLineNo);
}
}
if (IValidationContext.PARAMETER_ContextTableName.equals(variableName)) {
return Optional.of(_document.getEntityDescriptor().getTableName());
}
//
// Check global context variable if this is an explicit global variable
boolean globalContextChecked = false;
if (CtxName.isExplicitGlobal(variableName)) {
final Object value = getGlobalContext(variableName, targetType);
globalContextChecked = true;
if (value != null) {
return Optional.of(value);
}
}
//
// Document field
final IDocumentFieldView documentField = getDocumentFieldOrNull(variableName);
boolean inScopeField = false;
if (documentField != null) {
inScopeField = isFieldInScope(documentField.getFieldName());
if (inScopeField) {
logger.trace("Skip evaluation of {} because it's actually the field for whom we do the whole evaluation", documentField);
} else {
final Object documentFieldValue = documentField.getValue();
if (documentFieldValue != null) {
return Optional.of(documentFieldValue);
}
}
}
// Document's dynamic attribute
if (_document.hasDynAttribute(variableName)) {
final Object value = _document.getDynAttribute(variableName);
if (value != null) {
return Optional.of(value);
}
}
//
// Check parent
final IDocumentEvaluatee parentEvaluatee = getParentEvaluateeOrNull();
final boolean hasParentEvaluatee = parentEvaluatee != null;
if (hasParentEvaluatee) {
final Optional<Object> value = parentEvaluatee.get_ValueIfExists(variableName, targetType);
if (value.isPresent()) {
return value;
}
}
// If it's about the field in scope, try checking the global context
if (inScopeField) {
if (!globalContextChecked) {
final Object value = getGlobalContext(variableName, targetType);
globalContextChecked = true;
if (value != null) {
return Optional.of(value);
}
}
}
// Fallback: Check again the documentField and assume some defaults
if (!hasParentEvaluatee) {
if (documentField != null) {
final Class<?> valueClass = documentField.getValueClass();
if (StringLookupValue.class.equals(valueClass)) {
// corner case: e.g. Field: C_Order.IncotermLocation's DisplayLogic=@Incoterm@!''
return Optional.of("");
}
}
final Optional<Object> defaultValue = getDefaultValue(variableName);
if (defaultValue.isPresent()) {
return defaultValue;
}
}
// Value not found
if (logger.isTraceEnabled()) {
logger.trace("Variable '{}' not found.", variableName);
logger.trace("Existing properties are: {}", _document.getFieldNames());
logger.trace("Existing dyn attributes are: {}", _document.getAvailableDynAttributes());
logger.trace("Was field in scope: {} (fieldInScope={})", inScopeField, _fieldNameInScope);
}
return Optional.empty();
}
use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.
the class WindowRestController method getLayout.
@GetMapping("/{windowId}/{tabId}/layout")
public ResponseEntity<JSONDocumentLayout> getLayout(@PathVariable("windowId") final String windowIdStr, @PathVariable("tabId") final String tabIdStr, @RequestParam(name = PARAM_Advanced, required = false, defaultValue = PARAM_Advanced_DefaultValue) final boolean advanced, final WebRequest request) {
userSession.assertLoggedIn();
final WindowId windowId = WindowId.fromJson(windowIdStr);
final DetailId detailId = DetailId.fromJson(tabIdStr);
final DocumentDescriptor descriptor = documentCollection.getDocumentDescriptorFactory().getDocumentDescriptor(windowId);
DocumentPermissionsHelper.checkWindowAccess(descriptor.getEntityDescriptor(), userSession.getUserRolePermissions());
return ETagResponseEntityBuilder.ofETagAware(request, descriptor).includeLanguageInETag().cacheMaxAge(userSession.getHttpCacheMaxAge()).map(desc -> desc.getLayout().getDetail(detailId)).jsonOptions(() -> newJSONOptions().setShowAdvancedFields(advanced).build()).toJson(JSONDocumentLayout::ofDetailTab);
}
use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.
the class DocumentChangesCollector method isStaleDocumentChanges.
private boolean isStaleDocumentChanges(final DocumentChanges documentChanges) {
final DocumentPath documentPath = documentChanges.getDocumentPath();
if (!documentPath.isSingleIncludedDocument()) {
return false;
}
final DocumentPath rootDocumentPath = documentPath.getRootDocumentPath();
final DetailId detailId = documentPath.getDetailId();
return documentChangesIfExists(rootDocumentPath).flatMap(rootDocumentChanges -> rootDocumentChanges.includedDetailInfoIfExists(detailId)).map(IncludedDetailInfo::isStale).orElse(false);
}
use of de.metas.ui.web.window.descriptor.DetailId in project metasfresh-webui-api by metasfresh.
the class QuickInputDescriptorFactoryService method getQuickInputEntityDescriptor.
public QuickInputDescriptor getQuickInputEntityDescriptor(final DocumentEntityDescriptor includedDocumentDescriptor) {
final DocumentType documentType = includedDocumentDescriptor.getDocumentType();
final DocumentId documentTypeId = includedDocumentDescriptor.getDocumentTypeId();
final String tableName = includedDocumentDescriptor.getTableNameOrNull();
final DetailId detailId = includedDocumentDescriptor.getDetailId();
final Optional<Boolean> soTrx = includedDocumentDescriptor.getIsSOTrx();
return getQuickInputEntityDescriptor(documentType, documentTypeId, tableName, detailId, soTrx);
}
Aggregations