Source:
private void convertDescriptions(TransactionContext context, final String conceptId) { TransactionContext newContext = context.inject().bind(Synonyms.class, new Synonyms(context)).build(); final Set<String> requiredDescriptionTypes = newHashSet(Concepts.FULLY_SPECIFIED_NAME, Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED); final Multiset<String> preferredLanguageRefSetIds = HashMultiset.create(); final Set<String> synonymAndDescendantIds = newContext.service(Synonyms.class).get(); for (final SnomedDescriptionCreateRequest descriptionRequest : descriptions) { descriptionRequest.setConceptId(conceptId); if (null == descriptionRequest.getModuleId()) { descriptionRequest.setModuleId(getModuleId()); } descriptionRequest.execute(context); final String typeId = descriptionRequest.getTypeId(); if (synonymAndDescendantIds.contains(typeId)) { for (final Entry<String, Acceptability> acceptability : descriptionRequest.getAcceptability().entrySet()) { if (Acceptability.PREFERRED.equals(acceptability.getValue())) { preferredLanguageRefSetIds.add(acceptability.getKey()); requiredDescriptionTypes.remove(Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED); } } } requiredDescriptionTypes.remove(typeId); } if (!requiredDescriptionTypes.isEmpty()) { throw new BadRequestException("At least one fully specified name and one preferred term must be supplied with the concept."); } for (final com.google.common.collect.Multiset.Entry<String> languageRefSetIdOccurence : preferredLanguageRefSetIds.entrySet()) { if (languageRefSetIdOccurence.getCount() > 1) { throw new BadRequestException("More than one preferred term has been added for language reference set %s.", languageRefSetIdOccurence.getElement()); } } }

Target:
private void convertDescriptions(TransactionContext context, final String conceptId) { final Set<String> requiredDescriptionTypes = newHashSet(Concepts.FULLY_SPECIFIED_NAME, Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED); final Multiset<String> preferredLanguageRefSetIds = HashMultiset.create(); final Set<String> synonymAndDescendantIds = context.service(Synonyms.class).get(); for (final SnomedDescriptionCreateRequest descriptionRequest : descriptions) { descriptionRequest.setConceptId(conceptId); if (null == descriptionRequest.getModuleId()) { descriptionRequest.setModuleId(getModuleId()); } descriptionRequest.execute(context); final String typeId = descriptionRequest.getTypeId(); if (synonymAndDescendantIds.contains(typeId)) { for (final Entry<String, Acceptability> acceptability : descriptionRequest.getAcceptability().entrySet()) { if (Acceptability.PREFERRED.equals(acceptability.getValue())) { preferredLanguageRefSetIds.add(acceptability.getKey()); requiredDescriptionTypes.remove(Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED); } } } requiredDescriptionTypes.remove(typeId); } if (!requiredDescriptionTypes.isEmpty()) { throw new BadRequestException("At least one fully specified name and one preferred term must be supplied with the concept."); } for (final com.google.common.collect.Multiset.Entry<String> languageRefSetIdOccurence : preferredLanguageRefSetIds.entrySet()) { if (languageRefSetIdOccurence.getCount() > 1) { throw new BadRequestException("More than one preferred term has been added for language reference set %s.", languageRefSetIdOccurence.getElement()); } } }