/** * Transforms a {@link PlanboardMessage} to a {@link FlexOfferDto}. * * @param offer * @return */ public static FlexOfferDto transform(PlanboardMessage offer) { if (offer == null) { return null; } FlexOfferDto flexOfferDto = new FlexOfferDto(); flexOfferDto.setPeriod(offer.getPeriod()); flexOfferDto.setParticipantDomain(offer.getParticipantDomain()); flexOfferDto.setConnectionGroupEntityAddress(offer.getConnectionGroup().getUsefIdentifier()); flexOfferDto.setSequenceNumber(offer.getSequence()); flexOfferDto.setFlexRequestSequenceNumber(offer.getOriginSequence()); flexOfferDto.setExpirationDateTime(offer.getExpirationDate()); return flexOfferDto; }
/** * Transforms a complete list of {@link PtuFlexOffer} to a {@link FlexOfferDto}. * * @param ptuFlexOffers a {@link java.util.List} of {@link PtuFlexOffer}. * @return a {@link FlexOfferDto}. */ public static FlexOfferDto transformPtuFlexOffers(List<PtuFlexOffer> ptuFlexOffers) { if (ptuFlexOffers == null || ptuFlexOffers.isEmpty()) { return null; } PtuFlexOffer firstPtuFlexOffer = ptuFlexOffers.get(0); FlexOfferDto flexOfferDto = new FlexOfferDto(); flexOfferDto.setParticipantDomain(firstPtuFlexOffer.getParticipantDomain()); flexOfferDto.setConnectionGroupEntityAddress( firstPtuFlexOffer.getConnectionGroup().getUsefIdentifier()); flexOfferDto.setPeriod(firstPtuFlexOffer.getPtuContainer().getPtuDate()); flexOfferDto.setFlexRequestSequenceNumber(firstPtuFlexOffer.getFlexRequestSequence()); flexOfferDto.setSequenceNumber(firstPtuFlexOffer.getSequence()); ptuFlexOffers .stream() .forEach(ptuFlexOffer -> flexOfferDto.getPtus().add(transformPtuFlexOffer(ptuFlexOffer))); return flexOfferDto; }
private void populateFlexOfferDto( FlexOfferDto flexOfferDto, FlexRequestDto flexRequestDto, boolean populatePtus) { flexOfferDto.setPeriod(flexRequestDto.getPeriod()); flexOfferDto.setConnectionGroupEntityAddress(flexRequestDto.getConnectionGroupEntityAddress()); flexOfferDto.setParticipantDomain(flexRequestDto.getParticipantDomain()); if (populatePtus) { flexRequestDto .getPtus() .stream() .forEach( ptuFlexRequestDto -> { PtuFlexOfferDto ptuFlexOfferDto = new PtuFlexOfferDto(); ptuFlexOfferDto.setPtuIndex(ptuFlexRequestDto.getPtuIndex()); if (ptuFlexRequestDto.getDisposition() == DispositionTypeDto.AVAILABLE) { ptuFlexOfferDto.setPrice(BigDecimal.ZERO); ptuFlexOfferDto.setPower(BigInteger.ZERO); } else { max100PercentOfOriginalPower(ptuFlexRequestDto, ptuFlexOfferDto); } flexOfferDto.getPtus().add(ptuFlexOfferDto); }); } }