use of org.adempiere.ad.element.api.AdWindowId in project metasfresh-webui-api by metasfresh.
the class BoardDescriptorRepository method createBoardDescriptor.
private BoardDescriptor createBoardDescriptor(final int boardId) {
//
// Retrieve the board PO
final IQueryBL queryBL = Services.get(IQueryBL.class);
final I_WEBUI_Board boardPO = queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board.class).addEqualsFilter(I_WEBUI_Board.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().create().firstOnly(I_WEBUI_Board.class);
if (boardPO == null) {
throw new EntityNotFoundException("No board found for ID=" + boardId);
}
//
// Board document mappings
final String tableName = Services.get(IADTableDAO.class).retrieveTableName(boardPO.getAD_Table_ID());
final String keyColumnName = InterfaceWrapperHelper.getKeyColumnName(tableName);
// TODO: hardcoded
final String userIdColumnName = "UpdatedBy";
//
// Board document info
// TODO boardPO.getAD_Window_ID();
AdWindowId adWindowId = null;
if (adWindowId == null) {
adWindowId = RecordZoomWindowFinder.findAdWindowId(tableName).get();
}
final WindowId documentWindowId = WindowId.of(adWindowId);
final DocumentEntityDescriptor documentEntityDescriptor = documentDescriptors.getDocumentEntityDescriptor(documentWindowId);
final SqlDocumentEntityDataBindingDescriptor documentBinding = documentEntityDescriptor.getDataBinding(SqlDocumentEntityDataBindingDescriptor.class);
final String tableAlias = documentBinding.getTableAlias();
//
// Board document lookup provider
final int adValRuleId = boardPO.getAD_Val_Rule_ID();
final LookupDescriptorProvider documentLookupDescriptorProvider = SqlLookupDescriptor.builder().setCtxTableName(null).setCtxColumnName(keyColumnName).setDisplayType(DisplayType.Search).setWidgetType(DocumentFieldWidgetType.Lookup).setAD_Val_Rule_ID(adValRuleId).buildProvider();
//
// Board descriptor
final IModelTranslationMap boardTrlMap = InterfaceWrapperHelper.getModelTranslationMap(boardPO);
final BoardDescriptorBuilder boardDescriptor = BoardDescriptor.builder().boardId(boardPO.getWEBUI_Board_ID()).caption(boardTrlMap.getColumnTrl(I_WEBUI_Board.COLUMNNAME_Name, boardPO.getName())).documentWindowId(documentWindowId).documentLookupDescriptorProvider(documentLookupDescriptorProvider).tableName(tableName).tableAlias(tableAlias).keyColumnName(keyColumnName).userIdColumnName(userIdColumnName).websocketEndpoint(WebSocketConfig.buildBoardTopicName(boardId));
// Source document filters: AD_Val_Rule_ID
if (adValRuleId > 0) {
final IValidationRule validationRule = Services.get(IValidationRuleFactory.class).create(// ctx table name
tableName, // ctx table name
adValRuleId, // ctx table name
null, // ctx column name
null);
final String sqlWhereClause = validationRule.getPrefilterWhereClause().evaluate(Evaluatees.ofCtx(Env.getCtx()), OnVariableNotFound.Fail);
final DocumentFilter adValRuleFilter = DocumentFilter.builder().setFilterId("AD_Val_Rule_" + adValRuleId).addParameter(DocumentFilterParam.ofSqlWhereClause(true, sqlWhereClause)).build();
boardDescriptor.documentFilters(DocumentFilterList.of(adValRuleFilter));
}
//
// Lanes
{
queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_Lane.class).addEqualsFilter(I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_Lane.COLUMN_SeqNo).addColumn(// just have a predictable order
I_WEBUI_Board_Lane.COLUMN_WEBUI_Board_Lane_ID).endOrderBy().create().stream(I_WEBUI_Board_Lane.class).map(this::createBoardLaneDescriptor).forEach(lane -> boardDescriptor.lane(lane.getLaneId(), lane));
}
//
// Board card fields
{
queryBL.createQueryBuilderOutOfTrx(I_WEBUI_Board_CardField.class).addEqualsFilter(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_ID, boardId).addOnlyActiveRecordsFilter().orderBy().addColumn(I_WEBUI_Board_CardField.COLUMN_SeqNo).addColumn(I_WEBUI_Board_CardField.COLUMN_WEBUI_Board_CardField_ID).endOrderBy().create().stream(I_WEBUI_Board_CardField.class).map(cardFieldPO -> createBoardCardFieldDescriptor(cardFieldPO, documentEntityDescriptor)).forEach(cardField -> boardDescriptor.cardFieldByFieldName(cardField.getFieldName(), cardField));
}
//
return boardDescriptor.build();
}
use of org.adempiere.ad.element.api.AdWindowId in project metasfresh-webui-api by metasfresh.
the class WEBUI_Fact_Acct_Repost_SingleDocument method checkPreconditionsApplicable.
@Override
public ProcessPreconditionsResolution checkPreconditionsApplicable(IProcessPreconditionsContext context) {
final String recordTableName = context.getTableName();
if (I_Fact_Acct.Table_Name.equals(recordTableName) || WEBUI_Fact_Acct_Repost_ViewRows.TABLENAME_RV_UnPosted.contentEquals(recordTableName)) {
return ProcessPreconditionsResolution.accept();
} else {
final AdWindowId adWindowId = context.getAdWindowId();
final int recordId = context.getSingleSelectedRecordId();
final DocumentPath documentPath = DocumentPath.rootDocumentPath(adWindowId, recordId);
final Document document = documentsCollection.getDocumentReadonly(documentPath);
final BooleanWithReason allowPosting = checkAllowReposting(document);
return allowPosting.isTrue() ? ProcessPreconditionsResolution.accept() : ProcessPreconditionsResolution.reject(allowPosting.getReason()).toInternal();
}
}
use of org.adempiere.ad.element.api.AdWindowId in project metasfresh-webui-api by metasfresh.
the class PurchaseCandidateReminderSchedulerRestController method assertAuth.
private void assertAuth() {
userSession.assertLoggedIn();
final AdWindowId purchaseCandidatesWindowId = RecordZoomWindowFinder.findAdWindowId(I_C_PurchaseCandidate.Table_Name).get();
if (!userSession.getUserRolePermissions().checkWindowPermission(purchaseCandidatesWindowId).hasWriteAccess()) {
throw new AdempiereException("No read/write access to purchase candidates window");
}
}
use of org.adempiere.ad.element.api.AdWindowId in project metasfresh-webui-api by metasfresh.
the class DocumentPermissionsHelper method checkWindowAccess.
public static ElementPermission checkWindowAccess(@NonNull final DocumentEntityDescriptor entityDescriptor, final IUserRolePermissions permissions) {
final AdWindowId adWindowId = entityDescriptor.getWindowId().toAdWindowId();
final ElementPermission windowPermission = permissions.checkWindowPermission(adWindowId);
final boolean readAccess = windowPermission.hasReadAccess();
final boolean writeAccess = windowPermission.hasWriteAccess();
// no access
if (!readAccess && !writeAccess) {
final AdempiereException ex = DocumentPermissionException.of(DocumentPermission.WindowAccess, "@NoAccess@").setParameter("Role", permissions.getName()).setParameter("WindowName", entityDescriptor.getCaption()).setParameter("AD_Window_ID", adWindowId);
logAccessIfWindowExistsAndThrowEx(permissions, adWindowId, ex);
}
return windowPermission;
}
use of org.adempiere.ad.element.api.AdWindowId in project metasfresh-webui-api by metasfresh.
the class DocumentPermissionsHelper method assertViewAccess.
/**
* Asserts view access
*
* @param windowId
* @param viewId optional viewId, used only for error reporting
* @param permissions
*/
public static void assertViewAccess(final WindowId windowId, @Nullable final String viewId, final IUserRolePermissions permissions) {
final AdWindowId adWindowId = windowId.toAdWindowIdOrNull();
if (adWindowId == null) {
// accept it
return;
}
//
// Check AD_Window_ID access
final ElementPermission windowPermission = permissions.checkWindowPermission(adWindowId);
if (!windowPermission.hasReadAccess()) {
final AdempiereException ex = DocumentPermissionException.of(DocumentPermission.WindowAccess, "@NoAccess@").setParameter("roleName", permissions.getName()).setParameter("view", viewId).setParameter("windowId", adWindowId);
logAccessIfWindowExistsAndThrowEx(permissions, adWindowId, ex);
}
}
Aggregations