Skip to content

Commit

Permalink
InOutProcessedEventBus.notifyShipmentError
Browse files Browse the repository at this point in the history
  • Loading branch information
teosarca committed Dec 20, 2017
1 parent 5c79467 commit dfa8cd2
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,15 @@
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-2.0.html>.
* #L%
*/


import java.util.Collection;
import java.util.Collections;

Expand Down Expand Up @@ -60,14 +59,15 @@ public static final InOutProcessedEventBus newInstance()
.setName("de.metas.inout.InOut.ProcessedEvents")
.setType(Type.REMOTE)
.build();

// services
private final transient IDocumentBL docActionBL = Services.get(IDocumentBL.class);

private static final String MSG_Event_ShipmentGenerated = "Event_ShipmentGenerated";
private static final String MSG_Event_ReceiptGenerated = "Event_ReceiptGenerated";
//
private static final String MSG_Event_ShipmentReversed = "Event_ShipmentReversed";
private static final String MSG_Event_ShipmentError = "Event_ShipmentError";
//
private static final String MSG_Event_ReceiptGenerated = "Event_ReceiptGenerated";
private static final String MSG_Event_ReceiptReversed = "Event_ReceiptReversed";

private InOutProcessedEventBus(final IEventBus delegate)
Expand All @@ -88,7 +88,7 @@ public InOutProcessedEventBus queueEventsUntilTrxCommit(final String trxName)
super.queueEventsUntilTrxCommit(trxName);
return this;
}

@Override
public InOutProcessedEventBus queueEventsUntilCurrentTrxCommit()
{
Expand Down Expand Up @@ -153,10 +153,10 @@ private final Event createInOutGeneratedEvent(final I_M_InOut inout)
.build();
return event;
}

private final String getNotificationAD_Message(final I_M_InOut inout)
{
if(docActionBL.isDocumentReversedOrVoided(inout))
if (docActionBL.isDocumentReversedOrVoided(inout))
{
return inout.isSOTrx() ? MSG_Event_ShipmentReversed : MSG_Event_ReceiptReversed;
}
Expand All @@ -165,19 +165,19 @@ private final String getNotificationAD_Message(final I_M_InOut inout)
return inout.isSOTrx() ? MSG_Event_ShipmentGenerated : MSG_Event_ReceiptGenerated;
}
}

private final int getNotificationRecipientUserId(final I_M_InOut inout)
{
//
// In case of reversal i think we shall notify the current user too
if(docActionBL.isDocumentReversedOrVoided(inout))
if (docActionBL.isDocumentReversedOrVoided(inout))
{
final int currentUserId = Env.getAD_User_ID(Env.getCtx()); // current/triggering user
if(currentUserId > 0)
if (currentUserId > 0)
{
return currentUserId;
}

return inout.getUpdatedBy(); // last updated
}
//
Expand All @@ -187,4 +187,18 @@ private final int getNotificationRecipientUserId(final I_M_InOut inout)
return inout.getCreatedBy();
}
}

public InOutProcessedEventBus notifyShipmentError(final String sourceInfo, final String errorMessage)
{
final int recipientUserId = Env.getAD_User_ID(Env.getCtx());

final Event event = Event.builder()
.setDetailADMessage(MSG_Event_ShipmentError, sourceInfo, errorMessage)
.addRecipient_User_ID(recipientUserId)
.build();
postEvent(event);

return this;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-- 2017-12-20T15:22:55.105
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Message (MsgType,AD_Client_ID,IsActive,CreatedBy,Value,AD_Message_ID,MsgText,AD_Org_ID,EntityType,UpdatedBy,Created,Updated) VALUES ('I',0,'Y',100,'Event_ShipmentError',544614,'Cannot generate shipment for ''{0}'' because: {1}.',0,'de.metas.inout',100,TO_TIMESTAMP('2017-12-20 15:22:54','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2017-12-20 15:22:54','YYYY-MM-DD HH24:MI:SS'))
;

-- 2017-12-20T15:22:55.135
-- I forgot to set the DICTIONARY_ID_COMMENTS System Configurator
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=544614 AND NOT EXISTS (SELECT 1 FROM AD_Message_Trl tt WHERE tt.AD_Language=l.AD_Language AND tt.AD_Message_ID=t.AD_Message_ID)
;

0 comments on commit dfa8cd2

Please sign in to comment.