Search in sources :

Example 1 with I_AD_Note

use of org.compiere.model.I_AD_Note in project metasfresh-webui-api by metasfresh.

the class UserNotificationRepository method delete.

public void delete(final String notificationId) {
    final I_AD_Note notificationPO = retrieveAD_Note(notificationId);
    if (notificationPO == null) {
        return;
    }
    notificationPO.setProcessed(false);
    InterfaceWrapperHelper.delete(notificationPO);
}
Also used : I_AD_Note(org.compiere.model.I_AD_Note)

Example 2 with I_AD_Note

use of org.compiere.model.I_AD_Note 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();
}
Also used : ITableRecordReference(org.adempiere.util.lang.ITableRecordReference) AdempiereException(org.adempiere.exceptions.AdempiereException) TargetType(de.metas.ui.web.notification.UserNotification.TargetType) RecordZoomWindowFinder(org.adempiere.model.RecordZoomWindowFinder) I_AD_Note(org.compiere.model.I_AD_Note) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with I_AD_Note

use of org.compiere.model.I_AD_Note in project metasfresh-webui-api by metasfresh.

the class UserNotificationRepository method markAsRead.

public boolean markAsRead(final UserNotification notification) {
    final boolean alreadyRead = notification.setRead(true);
    if (alreadyRead) {
        logger.trace("Skip marking notification as read because it's already read: {}", notification);
        return false;
    }
    final I_AD_Note notificationPO = retrieveAD_Note(notification);
    notificationPO.setProcessed(true);
    InterfaceWrapperHelper.save(notificationPO);
    // NOTE: log after updating unreadCount
    logger.trace("Marked notification as read on {}: {}", notification);
    return true;
}
Also used : I_AD_Note(org.compiere.model.I_AD_Note)

Aggregations

I_AD_Note (org.compiere.model.I_AD_Note)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 TargetType (de.metas.ui.web.notification.UserNotification.TargetType)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 RecordZoomWindowFinder (org.adempiere.model.RecordZoomWindowFinder)1 ITableRecordReference (org.adempiere.util.lang.ITableRecordReference)1