diff --git a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGLangDetectService.java b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGLangDetectService.java index 3d50473d..2e41671a 100644 --- a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGLangDetectService.java +++ b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGLangDetectService.java @@ -5,11 +5,19 @@ import org.apache.commons.lang3.StringUtils; import eu.europeana.api.translation.definitions.service.exception.LanguageDetectionException; +/** + * Dummy implementation preventing invocation of remote google service + * @author GordeaS + * + */ public class DummyGLangDetectService extends GoogleLangDetectService { - public DummyGLangDetectService(String googleProjectId, - GoogleTranslationServiceClientWrapper clientWrapperBean) { - super(googleProjectId, clientWrapperBean); + /** + * Constructor using dummy project id + * @param clientWrapperBean the client wrapper implemnetation + */ + public DummyGLangDetectService(GoogleTranslationServiceClientWrapper clientWrapperBean) { + super(GoogleTranslationServiceClientWrapper.MOCK_CLIENT_PROJ_ID, clientWrapperBean); } @Override diff --git a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGTranslateService.java b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGTranslateService.java index 21d162c3..7fb0e3bb 100644 --- a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGTranslateService.java +++ b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/DummyGTranslateService.java @@ -3,11 +3,19 @@ import java.util.List; import eu.europeana.api.translation.definitions.service.exception.TranslationException; +/** + * Dummy implementation preventing invocation of remote google service + * @author GordeaS + * + */ public class DummyGTranslateService extends GoogleTranslationService { - public DummyGTranslateService(String googleProjectId, - GoogleTranslationServiceClientWrapper clientWrapperBean) { - super(googleProjectId, clientWrapperBean); + /** + * Constructor using dummy project id + * @param clientWrapperBean the client wrapper implemnetation + */ + public DummyGTranslateService(GoogleTranslationServiceClientWrapper clientWrapperBean) { + super(GoogleTranslationServiceClientWrapper.MOCK_CLIENT_PROJ_ID, clientWrapperBean); } @Override diff --git a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleLangDetectService.java b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleLangDetectService.java index a3f6016f..a7cb1ef2 100644 --- a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleLangDetectService.java +++ b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleLangDetectService.java @@ -12,6 +12,11 @@ import eu.europeana.api.translation.definitions.service.LanguageDetectionService; import eu.europeana.api.translation.definitions.service.exception.LanguageDetectionException; +/** + * Translation service implementing remote invocation of google language detection service + * @author GordeaS + * + */ public class GoogleLangDetectService implements LanguageDetectionService { protected static final Logger LOG = LogManager.getLogger(GoogleLangDetectService.class); diff --git a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationService.java b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationService.java index 9b49c723..5a440ceb 100644 --- a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationService.java +++ b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationService.java @@ -12,8 +12,11 @@ import eu.europeana.api.translation.definitions.service.exception.TranslationException; /** - * Note that this requires the GOOGLE_APPLICATION_CREDENTIALS environment variable to be available + * Translation service implementing remote invocation of google language detection service + * Note that this requires the GOOGLE_APPLICATION_CREDENTIALS environment variable to be available * as well as a projectId (defined in the application properties). + * @author GordeaS + * */ public class GoogleTranslationService implements TranslationService { diff --git a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationServiceClientWrapper.java b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationServiceClientWrapper.java index 83a84457..fb57273a 100644 --- a/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationServiceClientWrapper.java +++ b/translation-service-google/src/main/java/eu/europeana/api/translation/service/google/GoogleTranslationServiceClientWrapper.java @@ -8,6 +8,11 @@ import com.google.cloud.translate.v3.TranslationServiceClient; import com.google.cloud.translate.v3.TranslationServiceSettings; +/** + * Wrapper for google client to handle the proper behavior for different configurations + * @author GordeaS + * + */ public class GoogleTranslationServiceClientWrapper { public static final String MOCK_CLIENT_PROJ_ID = "google-test"; diff --git a/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangLangDetectService.java b/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangLangDetectService.java index 27ca2a33..c339150d 100644 --- a/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangLangDetectService.java +++ b/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangLangDetectService.java @@ -5,8 +5,16 @@ import org.apache.commons.lang3.StringUtils; import eu.europeana.api.translation.definitions.service.exception.LanguageDetectionException; +/** + * Dummy implementation preventing invocation of remote pangeanic service + * @author GordeaS + * + */ public class DummyPangLangDetectService extends PangeanicLangDetectService { + /** + * Constructor using null as endpoint + */ public DummyPangLangDetectService() { super(null); } diff --git a/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangTranslationService.java b/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangTranslationService.java index 75b9d7bb..8dea3f8f 100644 --- a/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangTranslationService.java +++ b/translation-service-pangeanic/src/main/java/eu/europeana/api/translation/service/pangeanic/DummyPangTranslationService.java @@ -3,8 +3,16 @@ import java.util.List; import eu.europeana.api.translation.definitions.service.exception.TranslationException; +/** + * Dummy implementation preventing invocation of remote pangeanic service + * @author GordeaS + * + */ public class DummyPangTranslationService extends PangeanicTranslationService{ + /** + * Constructor using null as endpoint + */ public DummyPangTranslationService() { super(null, null); } diff --git a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java index 8c7befb3..c5346ae7 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationApiAutoconfig.java @@ -1,6 +1,5 @@ package eu.europeana.api.translation.config; -import static eu.europeana.api.translation.service.google.GoogleTranslationServiceClientWrapper.MOCK_CLIENT_PROJ_ID; import java.io.IOException; import java.util.Arrays; import java.util.Locale; @@ -111,8 +110,7 @@ public PangeanicTranslationService getPangeanicTranslationService( public GoogleLangDetectService getGoogleLangDetectService( @Qualifier(BeanNames.BEAN_GOOGLE_TRANSLATION_CLIENT_WRAPPER) GoogleTranslationServiceClientWrapper googleTranslationServiceClientWrapper) { if (useDummyServices) { - return new DummyGLangDetectService(MOCK_CLIENT_PROJ_ID, - googleTranslationServiceClientWrapper); + return new DummyGLangDetectService(googleTranslationServiceClientWrapper); } else { return new GoogleLangDetectService(translationConfig.getGoogleTranslateProjectId(), googleTranslationServiceClientWrapper); @@ -123,7 +121,7 @@ public GoogleLangDetectService getGoogleLangDetectService( public GoogleTranslationService getGoogleTranslationService( @Qualifier(BeanNames.BEAN_GOOGLE_TRANSLATION_CLIENT_WRAPPER) GoogleTranslationServiceClientWrapper googleTranslationServiceClientWrapper) { if (useDummyServices) { - return new DummyGTranslateService(MOCK_CLIENT_PROJ_ID, googleTranslationServiceClientWrapper); + return new DummyGTranslateService(googleTranslationServiceClientWrapper); } else { return new GoogleTranslationService(translationConfig.getGoogleTranslateProjectId(), googleTranslationServiceClientWrapper); @@ -135,10 +133,7 @@ public GoogleTranslationService getGoogleTranslationService( BeanNames.BEAN_PANGEANIC_TRANSLATION_SERVICE, BeanNames.BEAN_GOOGLE_TRANSLATION_SERVICE}) public TranslationServiceProvider getTranslationServiceProvider() { this.translationServiceConfigProvider = new TranslationServiceProvider(); - // failing as the service beans are not initialized yet, would need to think of another way to - // call this initialization - // translationServiceConfigProvider#initTranslationServicesConfiguration; - return translationServiceConfigProvider; + return this.translationServiceConfigProvider; } @Override @@ -169,6 +164,12 @@ private void loadServices(ApplicationStartedEvent event) { } } + /** + * Method for initialization of service provider using the service configurations + * @param ctx + * @throws TranslationServiceConfigurationException + * @throws LangDetectionServiceConfigurationException + */ public void initTranslationServices(ApplicationContext ctx) throws TranslationServiceConfigurationException, LangDetectionServiceConfigurationException { TranslationServiceProvider translationServiceProvider = @@ -176,9 +177,11 @@ public void initTranslationServices(ApplicationContext ctx) translationServiceProvider.initTranslationServicesConfiguration(); } + /** + * Method to verify required properties in translation config + * @param ctx the application context holding references to instantiated beans + */ public void verifyMandatoryProperties(ApplicationContext ctx) { - TranslationConfig translationConfig = - (TranslationConfig) ctx.getBean(BeanNames.BEAN_TRANSLATION_CONFIG); translationConfig.verifyRequiredProperties(); } diff --git a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationServiceProvider.java b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationServiceProvider.java index f945277e..925c0fa5 100644 --- a/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationServiceProvider.java +++ b/translation-web/src/main/java/eu/europeana/api/translation/config/TranslationServiceProvider.java @@ -86,7 +86,11 @@ public void initTranslationServicesConfiguration() validateAndInitServices(); } - public void readServiceConfigurations() throws TranslationServiceConfigurationException { + /** + * Method for reading and parsing service configurations + * @throws TranslationServiceConfigurationException + */ + void readServiceConfigurations() throws TranslationServiceConfigurationException { try (InputStream inputStream = getClass().getResourceAsStream(getServiceConfigFile())) { BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); String content = reader.lines().collect(Collectors.joining(System.lineSeparator())); @@ -300,7 +304,6 @@ private void validateDeclaredLangDetectionServices() } - public String getServiceConfigFile() { return serviceConfigFile; }