@Override public KostZuweisungDO newInstance() { return new KostZuweisungDO(); } }
@Override public KostZuweisungDO newInstance() { return new KostZuweisungDO(); } }
/** * Clones this cost assignment (without id's). * * @return */ public KostZuweisungDO newClone() { final KostZuweisungDO kostZuweisung = new KostZuweisungDO(); kostZuweisung.copyValuesFrom(this, "id"); return kostZuweisung; } }
public static void copy(final List<KostZuweisungDO> srcList, final AbstractRechnungsPositionDO destPosition) { final List<KostZuweisungDO> destList = destPosition.ensureAndGetKostzuweisungen(); // first remove every deletable entry destList.removeIf(destPosition::isKostZuweisungDeletable); // then copy values from src to dest entry or create new dest entry if it does not exist if (srcList != null) { for (final KostZuweisungDO srcEntry : srcList) { final KostZuweisungDO destEntry; // checks if the destList already contains an entry which equals the source entry regarding their IDs and not necessarily their values // see KostZuweisungDO.equals() final int index = destList.indexOf(srcEntry); if (index >= 0) { // dest entry already exists, get it destEntry = destList.get(index); } else { // create new dest entry destEntry = new KostZuweisungDO(); destPosition.addKostZuweisung(destEntry); } destEntry.copyValuesFrom(srcEntry, IGNORE_FIELDS); } } }
final KostZuweisungDO zuweisung = new KostZuweisungDO(); if (position instanceof RechnungsPositionDO) { zuweisung.setRechnungsPosition((RechnungsPositionDO) position);
private KostZuweisungDO addZuweisung(final AbstractRechnungsPositionDO position) { final KostZuweisungDO kostZuweisung = new KostZuweisungDO(); position.addKostZuweisung(kostZuweisung); if (kostZuweisung.getIndex() > 0) { final KostZuweisungDO predecessor = position.getKostZuweisung(kostZuweisung.getIndex() - 1); if (predecessor != null) { kostZuweisung.setKost1(predecessor.getKost1()); // Preset kost1 from the predecessor position. kostZuweisung.setKost2(predecessor.getKost2()); // Preset kost2 from the predecessor position. } } if (RechnungsPositionDO.class.isAssignableFrom(position.getClass()) == true && kostZuweisung.getKost2() == null) { // Preset kost2 with first kost2 found for the projekt. final RechnungsPositionDO rechnungsPosition = (RechnungsPositionDO) position; final RechnungDO rechnung = rechnungsPosition.getRechnung(); if (rechnung != null) { final ProjektDO project = rechnung.getProjekt(); if (project != null) { final List<Kost2DO> kost2List = kost2Dao.getActiveKost2(project); if (CollectionUtils.isNotEmpty(kost2List) == true) { kostZuweisung.setKost2(kost2List.get(0)); } } } } kostZuweisung.setNetto(position.getKostZuweisungNetFehlbetrag().negate()); return kostZuweisung; }
assertEquals(0, destPos.getKostZuweisungen().size()); final KostZuweisungDO kostZuweisung = new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("1"); kostZuweisung.setId(4711); // simulate non deletable srcPos.addKostZuweisung(kostZuweisung); assertEquals(srcPos.getKostZuweisungen().get(0), destPos.getKostZuweisungen().get(0)); destPos.addKostZuweisung(new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("1")); assertEquals(2, destPos.getKostZuweisungen().size()); assertEquals("10", destPos.getKostZuweisung(0).getComment()); srcPos.addKostZuweisung(new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("2")); srcPos.addKostZuweisung(new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("3")); srcPos.addKostZuweisung(new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("4")); srcPos.addKostZuweisung(new KostZuweisungDO().setNetto(BigDecimal.ONE).setComment("5")); KostZuweisungenCopyHelper.copy(srcPos.getKostZuweisungen(), destPos); assertEquals(5, destPos.getKostZuweisungen().size());