Project

General

Profile

« Previous | Next » 

Revision 6057b354

Added by Andreas Müller over 3 years ago

ref #4770, ref #4908, ref #5163 some finetuning on convertPerson2Team

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/AgentServiceImpl.java
227 227
        ConvertMergeStrategy strategy = ConvertMergeStrategy.NewInstance(TeamOrPersonBase.class);
228 228
        strategy.setDefaultMergeMode(MergeMode.SECOND);
229 229
        strategy.setDefaultCollectionMergeMode(MergeMode.SECOND);
230
        team.setProtectedTitleCache(true);
230
        if (person.isProtectedTitleCache() || !person.getTitleCache().startsWith("Person#")){  //the later is for checking if the person is empty, this can be done better
231
            team.setTitleCache(person.getTitleCache(), true);  //as there are no members we set the titleCache to protected (as long as titleCache does not take the protected nomenclatural title but results in '-empty team-' in this situation); for some reason it is necessary to also set the title cache as well here, otherwise it is recomputed during the merge
232
        }
231 233
        strategy.setMergeMode("protectedTitleCache", MergeMode.FIRST); //as we do not add team members, the titleCache of the new team should be always protected
232 234
        strategy.setDeleteSecondObject(true);
235
        team.setNomenclaturalTitle(person.getNomenclaturalTitle(), true);  //sets the protected flag always to true, this is necessary as long as person does not have a nomenclatural title cache; maybe setting the protected title itself is not necessary but does no harm
233 236

  
234 237
        if (! genericDao.isMergeable(team, person, strategy)){
235 238
			throw new MergeException("Person can not be transformed into team.");
236 239
		}
237 240
		try {
238
			team.setProtectedNomenclaturalTitleCache(false);
239
			if (person.isProtectedTitleCache() || !person.getTitleCache().startsWith("Person#")){
240
			    team.setTitleCache(person.getTitleCache(), true);
241
			}
242
	        team.setNomenclaturalTitle(person.getNomenclaturalTitle(), true);
243 241
			team = this.save(team);
244 242
			genericDao.merge(team, person, strategy);
245 243
			team.setProtectedNomenclaturalTitleCache(true); //for some reason it is not protected when titleCache is also not protected
246
			//team.addTeamMember(person); it is not wanted to keep the person as member
244

  
245
			//Note: we decided  never add the old person as (first) member of the team as there are not many usecases for this.
246
			//But we may try to parse the old person into members which may handle the case that teams have been stored as unparsed persons
247 247

  
248 248
		} catch (Exception e) {
249 249
			throw new MergeException("Unhandled merge exception", e);

Also available in: Unified diff