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); } } }
/** * Clones this including cost assignments and order position (without id's). * * @return */ public AbstractRechnungsPositionDO newClone() { final AbstractRechnungsPositionDO rechnungsPosition = newInstance(); rechnungsPosition.copyValuesFrom(this, "id", "kostZuweisungen"); if (this.getKostZuweisungen() != null) { for (final KostZuweisungDO origKostZuweisung : this.getKostZuweisungen()) { final KostZuweisungDO kostZuweisung = origKostZuweisung.newClone(); rechnungsPosition.addKostZuweisung(kostZuweisung); } } return rechnungsPosition; }
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; }
pos.addKostZuweisung(zuweisung); save(zuweisung);
for (int i = 0; i < zuweisungen.size(); ++i) { KostZuweisungDO zuweisung = zuweisungen.get(i); pos.addKostZuweisung(zuweisung); zuweisung.setKost1((Kost1DO) persserivce.persist(ctx, zuweisung.getKost1())); zuweisung.setKost2((Kost2DO) persserivce.persist(ctx, zuweisung.getKost2()));