Search in sources :

Example 1 with DBUniqueConstraintException

use of org.adempiere.exceptions.DBUniqueConstraintException in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method addCardForDocumentId.

public BoardCard addCardForDocumentId(final int boardId, final int laneId, @NonNull final DocumentId documentId, final int position) {
    final BoardDescriptor board = getBoardDescriptor(boardId);
    board.assertLaneIdExists(laneId);
    final int cardId = documentId.toInt();
    final JSONBoardChangedEventsListBuilder eventsCollector = JSONBoardChangedEventsList.builder();
    Services.get(ITrxManager.class).run(ITrx.TRXNAME_ThreadInherited, () -> {
        try {
            final I_WEBUI_Board_RecordAssignment assignment = InterfaceWrapperHelper.newInstance(I_WEBUI_Board_RecordAssignment.class);
            assignment.setAD_Org_ID(Env.CTXVALUE_AD_Org_ID_Any);
            assignment.setWEBUI_Board_ID(boardId);
            assignment.setWEBUI_Board_Lane_ID(laneId);
            assignment.setRecord_ID(cardId);
            // will be updated later
            assignment.setSeqNo(Integer.MAX_VALUE);
            InterfaceWrapperHelper.save(assignment);
        } catch (final DBUniqueConstraintException ex) {
            throw new AdempiereException("Card was already added to this board", ex).setParameter("boardI", boardId).setParameter("laneId", laneId).setParameter("cardId", cardId);
        }
        final LaneCardsSequence orderedCardIds = changeCardsOrder(boardId, laneId, cardIds -> cardIds.addCardIdAtPosition(cardId, position));
        eventsCollector.event(JSONBoardLaneChangedEvent.of(boardId, laneId, orderedCardIds.getCardIds()));
    });
    final BoardCard card = getCard(boardId, cardId);
    sendEvents(board, eventsCollector.build());
    return card;
}
Also used : DBUniqueConstraintException(org.adempiere.exceptions.DBUniqueConstraintException) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) I_WEBUI_Board_RecordAssignment(de.metas.ui.web.base.model.I_WEBUI_Board_RecordAssignment) AdempiereException(org.adempiere.exceptions.AdempiereException) JSONBoardChangedEventsListBuilder(de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder)

Aggregations

I_WEBUI_Board_RecordAssignment (de.metas.ui.web.base.model.I_WEBUI_Board_RecordAssignment)1 JSONBoardChangedEventsListBuilder (de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder)1 ITrxManager (org.adempiere.ad.trx.api.ITrxManager)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 DBUniqueConstraintException (org.adempiere.exceptions.DBUniqueConstraintException)1