Search in sources :

Example 1 with JSONBoardChangedEventsListBuilder

use of de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method changeCard.

public BoardCard changeCard(final int boardId, final int cardId, final BoardCardChangeRequest request) {
    final BoardDescriptor board = getBoardDescriptor(boardId);
    final JSONBoardChangedEventsListBuilder eventsCollector = JSONBoardChangedEventsList.builder();
    Services.get(ITrxManager.class).run(ITrx.TRXNAME_ThreadInherited, () -> {
        final int oldLaneId = getLaneIdForCardId(boardId, cardId);
        int laneIdEffective = oldLaneId;
        boolean positionChanged = false;
        if (request.getNewLaneId() > 0 && request.getNewLaneId() != oldLaneId) {
            final int newLaneId = request.getNewLaneId();
            // move card to new lane
            changeLane(boardId, cardId, newLaneId);
            // update cards order in old lane
            final LaneCardsSequence oldLane_cardIds = changeCardsOrder(boardId, oldLaneId, cardIds -> cardIds.removeCardId(cardId));
            eventsCollector.event(JSONBoardLaneChangedEvent.of(boardId, oldLane_cardIds.getLaneId(), oldLane_cardIds.getCardIds()));
            // update cards order in new lane
            final LaneCardsSequence newLane_cardIds = changeCardsOrder(boardId, newLaneId, cardIds -> cardIds.addCardIdAtPosition(cardId, request.getNewPosition()));
            eventsCollector.event(JSONBoardLaneChangedEvent.of(boardId, newLane_cardIds.getLaneId(), newLane_cardIds.getCardIds()));
            laneIdEffective = newLaneId;
            positionChanged = true;
        }
        if (!positionChanged && request.getNewPosition() >= 0) {
            final int newPosition = request.getNewPosition();
            // update card's order
            final LaneCardsSequence laneCardIds = changeCardsOrder(boardId, laneIdEffective, cardIds -> cardIds.addCardIdAtPosition(cardId, newPosition));
            eventsCollector.event(JSONBoardLaneChangedEvent.of(boardId, laneCardIds.getLaneId(), laneCardIds.getCardIds()));
            positionChanged = true;
        }
    });
    final BoardCard card = getCard(boardId, cardId);
    sendEvents(board, eventsCollector.build());
    return card;
}
Also used : ITrxManager(org.adempiere.ad.trx.api.ITrxManager) JSONBoardChangedEventsListBuilder(de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder)

Example 2 with JSONBoardChangedEventsListBuilder

use of de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder 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)

Example 3 with JSONBoardChangedEventsListBuilder

use of de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder in project metasfresh-webui-api by metasfresh.

the class BoardDescriptorRepository method removeCard.

public void removeCard(final int boardId, final int cardId) {
    final BoardDescriptor board = getBoardDescriptor(boardId);
    final JSONBoardChangedEventsListBuilder eventsCollector = JSONBoardChangedEventsList.builder();
    Services.get(ITrxManager.class).run(ITrx.TRXNAME_ThreadInherited, () -> {
        final int laneId = getLaneIdForCardId(boardId, cardId);
        final int deletedCount = Services.get(IQueryBL.class).createQueryBuilder(I_WEBUI_Board_RecordAssignment.class).addEqualsFilter(I_WEBUI_Board_RecordAssignment.COLUMN_WEBUI_Board_ID, boardId).addEqualsFilter(I_WEBUI_Board_RecordAssignment.COLUMN_Record_ID, cardId).create().deleteDirectly();
        if (deletedCount > 0) {
            final LaneCardsSequence orderedCardIds = changeCardsOrder(boardId, laneId, cardIds -> cardIds.removeCardId(cardId));
            eventsCollector.event(JSONBoardLaneChangedEvent.of(boardId, laneId, orderedCardIds.getCardIds()));
        }
    });
    sendEvents(board, eventsCollector.build());
}
Also used : IQueryBL(org.adempiere.ad.dao.IQueryBL) ITrxManager(org.adempiere.ad.trx.api.ITrxManager) JSONBoardChangedEventsListBuilder(de.metas.ui.web.board.json.events.JSONBoardChangedEventsList.JSONBoardChangedEventsListBuilder)

Aggregations

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