use of org.adempiere.util.lang.ITableRecordReference in project metasfresh-webui-api by metasfresh.
the class UserNotificationRepository method save.
private UserNotification save(final Event event, final int recipientUserId) {
final I_AD_Note notificationPO = InterfaceWrapperHelper.newInstance(I_AD_Note.class);
//
// Important
final boolean important = DisplayType.toBoolean(event.getProperty(EVENT_PARAM_Important), false);
notificationPO.setAD_User_ID(recipientUserId);
notificationPO.setIsImportant(important);
//
// detailADMessage -> AD_Message
int adMessageId = -1;
final String detailADMessage = event.getDetailADMessage();
if (!Check.isEmpty(detailADMessage, true)) {
adMessageId = Services.get(IADMessageDAO.class).retrieveIdByValue(detailADMessage);
}
if (adMessageId <= 0) {
adMessageId = Services.get(IADMessageDAO.class).retrieveIdByValue(DEFAULT_AD_MESSAGE);
}
notificationPO.setAD_Message_ID(adMessageId);
//
// detailADMessageParams
final Map<String, Object> detailADMessageParams = event.getProperties();
try {
final String detailADMessageParamsJSON = jsonMapper.writeValueAsString(detailADMessageParams);
notificationPO.setAD_Message_ParamsJSON(detailADMessageParamsJSON);
} catch (final JsonProcessingException e) {
throw new AdempiereException(e);
}
//
// detailPlain
final String detailPlain = event.getDetailPlain();
notificationPO.setTextMsg(detailPlain);
//
// Target: window (from document record)
final ITableRecordReference targetRecord = event.getRecord();
final TargetType targetType;
final String targetTableName;
final int targetADTableId;
final int targetRecordId;
final int targetADWindowId;
if (targetRecord != null) {
targetType = TargetType.Window;
final Object suggestedWindowIdObj = event.getProperty(Event.PROPERTY_SuggestedWindowId);
final int suggestedWindowId = suggestedWindowIdObj instanceof Number ? ((Number) suggestedWindowIdObj).intValue() : -1;
if (suggestedWindowId > 0) {
targetADWindowId = suggestedWindowId;
targetADTableId = targetRecord.getAD_Table_ID();
targetTableName = targetRecord.getTableName();
targetRecordId = targetRecord.getRecord_ID();
} else {
final RecordZoomWindowFinder recordWindowFinder = RecordZoomWindowFinder.newInstance(targetRecord);
targetADWindowId = recordWindowFinder.findAD_Window_ID();
targetADTableId = recordWindowFinder.getAD_Table_ID();
targetTableName = recordWindowFinder.getTableName();
targetRecordId = recordWindowFinder.getRecord_ID();
}
} else {
targetType = TargetType.None;
targetADWindowId = -1;
targetTableName = null;
targetADTableId = -1;
targetRecordId = -1;
}
notificationPO.setAD_Table_ID(targetADTableId);
notificationPO.setRecord_ID(targetRecordId);
notificationPO.setAD_Window_ID(targetADWindowId);
//
//
InterfaceWrapperHelper.save(notificationPO);
return UserNotification.builder().id(String.valueOf(notificationPO.getAD_Note_ID())).timestamp(notificationPO.getCreated().getTime()).important(important).recipientUserId(recipientUserId).detailADMessage(detailADMessage).detailADMessageParams(detailADMessageParams).detailPlain(detailPlain).targetType(targetType).targetTableName(targetTableName).targetRecordId(targetRecordId).targetADWindowId(targetADWindowId).build();
}
Aggregations