src/main/java/gov/usgs/cida/pubs/busservice/mp/MpPublicationCostCenterBusService.java
@Override
	public void merge(Integer parentId, Collection<? super PublicationCostCenter<MpPublicationCostCenter>> collection) {
		if (null != parentId) {
			//First grab the current collection from the database.
			Map<String, Object> filters = new HashMap<>();
			filters.put("publicationId", parentId);
			List<MpPublicationCostCenter> mpccs = MpPublicationCostCenter.getDao().getByMap(filters);

			//Now put into a map keyed by costCenterId.
			Map<Integer, MpPublicationCostCenter> map = new HashMap<>();
			for (MpPublicationCostCenter pubCostCenter : mpccs) {
				map.put(pubCostCenter.getCostCenter().getId(), pubCostCenter);
			}

			//And do the merge.
			if (null != collection && !collection.isEmpty()) {
				for (Object pubObject : collection) {
					PublicationCostCenter<?> pubCostCenter = (PublicationCostCenter<?>) pubObject;
					if (map.containsKey(pubCostCenter.getCostCenter().getId())) {
						//Just remove from the map - there isn't really anything to update.
						map.remove(pubCostCenter.getCostCenter().getId());
					} else {
						//Add in the new cost center.
						//pubCostCenter.setPublicationId(parentId);
						MpPublicationCostCenter pcc = new MpPublicationCostCenter();
						pcc.setPublicationId(parentId);
						pcc.setCostCenter(pubCostCenter.getCostCenter());
						//MpPublicationCostCenter.getDao().add(pubCostCenter);
						MpPublicationCostCenter.getDao().add(pcc);
					}
				}
			}

			//Delete any left overs (would only apply to applications which are not sending the delete like they should.
			if (!map.isEmpty()) {
				for (MpPublicationCostCenter pubCostCenter : map.values()) {
					deleteObject(pubCostCenter);
				}
			}
		}
	}
/** 
	 * Cost center merge needs to deal with the association id not being preserved.
	 */
Cost center merge needs to deal with the association id not being preserved.
Cost center merge needs to deal with the association id not being preserved .
@Override
	public void merge(Integer parentId, Collection<? super PublicationCostCenter<MpPublicationCostCenter>> collection) {
		if (null != parentId) {
			Map<String, Object> filters = new HashMap<>();
			filters.put("publicationId", parentId);
			List<MpPublicationCostCenter> mpccs = MpPublicationCostCenter.getDao().getByMap(filters);
			Map<Integer, MpPublicationCostCenter> map = new HashMap<>();
			for (MpPublicationCostCenter pubCostCenter : mpccs) {
				map.put(pubCostCenter.getCostCenter().getId(), pubCostCenter);
			}
			if (null != collection && !collection.isEmpty()) {
				for (Object pubObject : collection) {
					PublicationCostCenter<?> pubCostCenter = (PublicationCostCenter<?>) pubObject;
					if (map.containsKey(pubCostCenter.getCostCenter().getId())) {
						map.remove(pubCostCenter.getCostCenter().getId());
					} else {
						MpPublicationCostCenter pcc = new MpPublicationCostCenter();
						pcc.setPublicationId(parentId);
						pcc.setCostCenter(pubCostCenter.getCostCenter());
						MpPublicationCostCenter.getDao().add(pcc);
					}
				}
			}
			if (!map.isEmpty()) {
				for (MpPublicationCostCenter pubCostCenter : map.values()) {
					deleteObject(pubCostCenter);
				}
			}
		}
	}
@ Override public void merge ( Integer parentId , Collection < ? super PublicationCostCenter < MpPublicationCostCenter > > collection ) { if ( null != parentId ) { Map < String , Object > filters = new HashMap < > ( ) ; filters . put ( "publicationId" , parentId ) ; List < MpPublicationCostCenter > mpccs = MpPublicationCostCenter . getDao ( ) . getByMap ( filters ) ; Map < Integer , MpPublicationCostCenter > map = new HashMap < > ( ) ; for ( MpPublicationCostCenter pubCostCenter : mpccs ) { map . put ( pubCostCenter . getCostCenter ( ) . getId ( ) , pubCostCenter ) ; } if ( null != collection && ! collection . isEmpty ( ) ) { for ( Object pubObject : collection ) { PublicationCostCenter < ? > pubCostCenter = ( PublicationCostCenter < ? > ) pubObject ; if ( map . containsKey ( pubCostCenter . getCostCenter ( ) . getId ( ) ) ) { map . remove ( pubCostCenter . getCostCenter ( ) . getId ( ) ) ; } else { MpPublicationCostCenter pcc = new MpPublicationCostCenter ( ) ; pcc . setPublicationId ( parentId ) ; pcc . setCostCenter ( pubCostCenter . getCostCenter ( ) ) ; MpPublicationCostCenter . getDao ( ) . add ( pcc ) ; } } } if ( ! map . isEmpty ( ) ) { for ( MpPublicationCostCenter pubCostCenter : map . values ( ) ) { deleteObject ( pubCostCenter ) ; } } } }
Cost center merge needs to deal with the association id not being preserved.
Cost center merge needs to deal with the association id not being preserved .
//First grab the current collection from the database. //Now put into a map keyed by costCenterId. //And do the merge. //Just remove from the map - there isn't really anything to update. //Add in the new cost center. //pubCostCenter.setPublicationId(parentId); //MpPublicationCostCenter.getDao().add(pubCostCenter); //Delete any left overs (would only apply to applications which are not sending the delete like they should.