Source:
<code>public Response addPhraseToPackage(@HeaderParam("Authorization") String authorization, @PathParam("package") String packageCode, @PathParam("pageName") String pageName, TranslationElement translationElement) { logger.info(String.format("Adding phrase w/ authorization %s", authorization)); AuthorizationRecord.checkAdminAccess(authorizationService.getAuthorizationRecord(null, authorization), clock.currentDateTime()); logger.info(String.format("Adding phrase, admin validated. Adding phrase for %s-%s", packageCode, pageName)); Optional<GodToolsTranslation> translationOptional = draftTranslation.retrieve(BASE_LANGUAGE_CODE, packageCode, false); if(!translationOptional.isPresent()) { translationOptional = publishedTranslation.retrieve(BASE_LANGUAGE_CODE, packageCode, false); if(!translationOptional.isPresent()) { logger.warn("Something weird... no published English translation for: " + packageCode); return Response.status(Response.Status.BAD_REQUEST).build(); } } <START> Optional<PageStructure> pageOptional = translationOptional.get().getPage(pageName); <END> if(!pageOptional.isPresent()) { logger.warn(String.format("Listing phrases, Page %s not found English translation for %s", pageName, packageCode)); return Response.status(Response.Status.NOT_FOUND).build(); } Package gtPackage = packageService.selectByCode(packageCode); translationElement.setFieldsForNewPhrase(pageOptional.get()); for(Language language : languageService.selectAllLanguages()) { Translation translation = translationService.selectByLanguageIdPackageIdVersionNumber(language.getId(), gtPackage.getId(), GodToolsVersion.LATEST_VERSION); if(translation == null) continue; TranslationElement translationElementForOtherLanguage = TranslationElement.copyOf(translationElement); translationElementForOtherLanguage.setTranslationId(translation.getId()); translationElementService.insert(translationElementForOtherLanguage); } translationUpload.doUpload(gtPackage.getTranslationProjectId(), BASE_LANGUAGE_CODE, pageName); return Response .status(Response.Status.CREATED) .build(); }</code><technical_language>of this method is similar some of listPhrasesForPage(), refactor por favor</technical_language>

Target:
public Response addPhraseToPackage(@HeaderParam("Authorization") String authorization, @PathParam("package") String packageCode, @PathParam("pageName") String pageName, TranslationElement translationElement) { logger.info(String.format("Adding phrase w/ authorization %s", authorization)); AuthorizationRecord.checkAdminAccess(authorizationService.getAuthorizationRecord(null, authorization), clock.currentDateTime()); logger.info(String.format("Adding phrase, admin validated. Adding phrase for %s-%s", packageCode, pageName)); Optional<GodToolsTranslation> translationOptional = getGodToolsTranslationOptional(packageCode); Optional<PageStructure> pageOptional = translationOptional.get().getPage(pageName); if(!pageOptional.isPresent()) { logger.warn(String.format("Adding phrases, Page %s not found English translation for %s", pageName, packageCode)); return Response.status(Response.Status.NOT_FOUND).build(); } Package gtPackage = packageService.selectByCode(packageCode); translationElement.setFieldsForNewPhrase(pageOptional.get()); for(Language language : languageService.selectAllLanguages()) { Translation translation = translationService.selectByLanguageIdPackageIdVersionNumber(language.getId(), gtPackage.getId(), GodToolsVersion.LATEST_VERSION); if(translation == null) continue; TranslationElement translationElementForOtherLanguage = TranslationElement.copyOf(translationElement); translationElementForOtherLanguage.setTranslationId(translation.getId()); translationElementService.insert(translationElementForOtherLanguage); } translationUpload.doUpload(gtPackage.getTranslationProjectId(), BASE_LANGUAGE_CODE, pageName); return Response .status(Response.Status.CREATED) .build(); }