Skip to content

Commit

Permalink
EA-3619 - move model from web to definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
SrishtiSingh-eu committed Dec 4, 2023
1 parent 6edd012 commit 1db76ff
Show file tree
Hide file tree
Showing 18 changed files with 41 additions and 60 deletions.
28 changes: 5 additions & 23 deletions translation-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,6 @@
</properties>

<dependencies>

<dependency>
<groupId>eu.europeana.api</groupId>
<artifactId>translation-web</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
Expand All @@ -35,16 +28,11 @@
<artifactId>reactor-netty-http</artifactId>
<version>1.0.16</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>eu.europeana.api</groupId>-->
<!-- <artifactId>translation-definitions</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<!-- <dependency>-->
<!-- <groupId>eu.europeana.api</groupId>-->
<!-- <artifactId>translation-service-common</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- </dependency>-->
<dependency>
<groupId>eu.europeana.api</groupId>
<artifactId>translation-definitions</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
Expand All @@ -55,12 +43,6 @@
<artifactId>corelib-definitions</artifactId>
<version>${corelib.version}</version>
</dependency>
<!-- test-->
<dependency>
<groupId>eu.europeana.corelib</groupId>
<artifactId>corelib-storage</artifactId>
<version>${corelib.version}</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import eu.europeana.api.commons.error.EuropeanaApiException;
import eu.europeana.api.translation.client.utils.LanguageDetectionUtils;
import eu.europeana.api.translation.client.web.TranslationApiClient;
import eu.europeana.api.translation.model.TranslationRequest;
import eu.europeana.api.translation.model.TranslationResponse;
import eu.europeana.api.translation.definitions.model.TranslationRequest;
import eu.europeana.api.translation.definitions.model.TranslationResponse;
import eu.europeana.corelib.utils.ComparatorUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import javax.annotation.Nonnull;
import javax.validation.constraints.NotNull;
import java.util.*;

public class TranslationMap extends LinkedHashMap<String, List<String>> {
Expand All @@ -18,14 +18,14 @@ public class TranslationMap extends LinkedHashMap<String, List<String>> {

private static final Logger LOG = LogManager.getLogger(TranslationMap.class);

@Nonnull
@NotNull
private final String sourceLanguage;

public TranslationMap(@Nonnull String sourceLanguage) {
public TranslationMap(@NotNull String sourceLanguage) {
this.sourceLanguage = sourceLanguage;
}

public TranslationMap(@Nonnull String sourceLanguage, String fieldName, List<String> values) {
public TranslationMap(@NotNull String sourceLanguage, String fieldName, List<String> values) {
this.sourceLanguage = sourceLanguage;
add(fieldName, values);
}
Expand Down Expand Up @@ -124,7 +124,7 @@ private List<String> getTranslationsToAdd(List<String> translationsForField) {
return translationsForField;
}

@Nonnull
@NotNull
public String getSourceLanguage() {
return sourceLanguage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import eu.europeana.api.commons.error.EuropeanaApiException;
import eu.europeana.api.translation.client.exception.InvalidParamValueException;
import eu.europeana.api.translation.client.web.TranslationApiClient;
import eu.europeana.api.translation.service.exception.TranslationException;
import eu.europeana.corelib.definitions.edm.beans.FullBean;
import eu.europeana.corelib.definitions.edm.entity.ContextualClass;
import eu.europeana.corelib.definitions.edm.entity.Proxy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import eu.europeana.api.translation.definitions.language.Language;
import eu.europeana.api.translation.definitions.language.LanguageValueFieldMap;
import eu.europeana.api.translation.client.utils.LanguageDetectionUtils;
import eu.europeana.api.translation.model.LangDetectRequest;
import eu.europeana.api.translation.service.exception.LanguageDetectionException;
import eu.europeana.api.translation.definitions.model.LangDetectRequest;
import eu.europeana.corelib.definitions.edm.beans.FullBean;
import eu.europeana.corelib.definitions.edm.entity.Proxy;
import org.apache.commons.lang3.SerializationUtils;
Expand Down Expand Up @@ -63,7 +62,6 @@ private String getHintForLanguageDetect(FullBean bean) {
*
* @param bean
* @throws EuropeanaApiException
* @throws LanguageDetectionException
*/
public FullBean detectLanguageForProxy(FullBean bean) throws EuropeanaApiException {
long start = System.currentTimeMillis();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.europeana.api.translation.client.service;

import eu.europeana.api.translation.client.exception.InvalidParamValueException;
import eu.europeana.api.translation.client.exception.TechnicalRuntimeException;
import eu.europeana.api.translation.client.utils.TranslationClientUtils;
import eu.europeana.api.translation.model.LangDetectResponse;
import eu.europeana.api.translation.model.TranslationResponse;
import eu.europeana.api.translation.web.exception.ParamValidationException;
import eu.europeana.api.translation.definitions.model.LangDetectResponse;
import eu.europeana.api.translation.definitions.model.TranslationResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -77,7 +77,7 @@ public <T> T getTranslationApiResponse(WebClient webClient, Function<UriBuilder,
if (t instanceof TechnicalRuntimeException) {
throw new TechnicalRuntimeException("User is not authorised to perform this action");
}
if (t instanceof ParamValidationException) {
if (t instanceof InvalidParamValueException) {
LOGGER.debug("Invalid request body - {} ", e.getMessage());
return null ;
}
Expand All @@ -94,12 +94,14 @@ private WebClient.ResponseSpec executePost(WebClient webClient, Function<UriBuil
.uri(uriBuilderURIFunction)
.contentType(MediaType.APPLICATION_JSON)
// TODO need to figure out how we will pass token across API's
.header("Authorization", " ")
.header("Authorization", "Bearer eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICI1SW55MldXRkhZQ1YxcFNNc0NKXzl2LVhaUUgwUk84c05KNUxLd2JHcmk0In0.eyJleHAiOjE3MDE0NDU3NTgsImlhdCI6MTcwMTQ0MjE1OCwianRpIjoiYjA4MDA2ZTUtNGFmN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RpdG9yQGV1cm9wZWFuYS5ldSJ9.Wk60gb_4rl7fiHhgRBIKxrvMZpvbC0H9g_Iq6w6sHXudl8I_rsLhQMRkfvTpXxubkJcTt6rFVQAOtfpnVc_4LhVIuCD7KwkihTSvhzbdvP29K7jH3-VoG63wZPnk666OsHd4h98P7UlIetBKixVHb13CuctIVZ5LdjPuNfe4eFWO491GjiE58cLh8JNe7Z2AdR2NWDWLugIU5yrvMkwl-Ono4PjnWycX8r7SfB7XaXbnvjTBtn8SiiM5EUi9MWxrkyynCFvlXsikKypsQgNVYNgITTGPvRQrdOY6ls6mBAajpjWSd0nq2XOYX19SXIM2zJ5va58OIWAI4K9XaFS8tw")
.body(BodyInserters.fromValue(jsonBody))
.retrieve()
.onStatus(
HttpStatus.UNAUTHORIZED::equals,
response -> response.bodyToMono(String.class).map(TechnicalRuntimeException::new));
response -> response.bodyToMono(String.class).map(TechnicalRuntimeException::new))
.onStatus(HttpStatus.BAD_REQUEST:: equals,
response -> response.bodyToMono(String.class).map(InvalidParamValueException::new));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import eu.europeana.api.commons.error.EuropeanaApiException;
import eu.europeana.api.translation.client.BaseTranslationApiClient;
import eu.europeana.api.translation.client.config.TranslationClientConfiguration;
import eu.europeana.api.translation.model.LangDetectRequest;
import eu.europeana.api.translation.model.LangDetectResponse;
import eu.europeana.api.translation.model.TranslationRequest;
import eu.europeana.api.translation.model.TranslationResponse;
import eu.europeana.api.translation.definitions.model.LangDetectRequest;
import eu.europeana.api.translation.definitions.model.LangDetectResponse;
import eu.europeana.api.translation.definitions.model.TranslationRequest;
import eu.europeana.api.translation.definitions.model.TranslationResponse;

public class TranslationApiClient extends BaseTranslationApiClient {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.europeana.api.translation.model;
package eu.europeana.api.translation.definitions.model;

/**
* object model for the cached translations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.europeana.api.translation.model;
package eu.europeana.api.translation.definitions.model;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.europeana.api.translation.model;
package eu.europeana.api.translation.definitions.model;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.europeana.api.translation.model;
package eu.europeana.api.translation.definitions.model;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package eu.europeana.api.translation.model;
package eu.europeana.api.translation.definitions.model;

import java.util.List;
import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import eu.europeana.api.commons.config.i18n.I18nService;
import eu.europeana.api.commons.config.i18n.I18nServiceImpl;
import eu.europeana.api.commons.oauth2.service.impl.EuropeanaClientDetailsService;
import eu.europeana.api.translation.model.CachedTranslation;
import eu.europeana.api.translation.definitions.model.CachedTranslation;
import eu.europeana.api.translation.serialization.JsonRedisSerializer;
import eu.europeana.api.translation.service.exception.LangDetectionServiceConfigurationException;
import eu.europeana.api.translation.service.exception.TranslationServiceConfigurationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.data.redis.serializer.SerializationException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import eu.europeana.api.translation.model.CachedTranslation;
import eu.europeana.api.translation.definitions.model.CachedTranslation;

/**
* Json Serializer for objects managed with redis cache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import org.springframework.web.bind.annotation.RestController;
import eu.europeana.api.commons.web.http.HttpHeaders;
import eu.europeana.api.commons.web.model.vocabulary.Operations;
import eu.europeana.api.translation.model.LangDetectRequest;
import eu.europeana.api.translation.model.LangDetectResponse;
import eu.europeana.api.translation.definitions.model.LangDetectRequest;
import eu.europeana.api.translation.definitions.model.LangDetectResponse;
import eu.europeana.api.translation.web.exception.ParamValidationException;
import eu.europeana.api.translation.web.service.LangDetectionWebService;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import eu.europeana.api.commons.web.model.vocabulary.Operations;
import eu.europeana.api.translation.definitions.language.LanguagePair;
import eu.europeana.api.translation.definitions.vocabulary.TranslationAppConstants;
import eu.europeana.api.translation.model.TranslationRequest;
import eu.europeana.api.translation.model.TranslationResponse;
import eu.europeana.api.translation.definitions.model.TranslationRequest;
import eu.europeana.api.translation.definitions.model.TranslationResponse;
import eu.europeana.api.translation.web.exception.ParamValidationException;
import eu.europeana.api.translation.web.service.TranslationWebService;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import eu.europeana.api.commons.error.EuropeanaI18nApiException;
import eu.europeana.api.translation.config.TranslationServiceProvider;
import eu.europeana.api.translation.definitions.vocabulary.TranslationAppConstants;
import eu.europeana.api.translation.model.LangDetectRequest;
import eu.europeana.api.translation.model.LangDetectResponse;
import eu.europeana.api.translation.definitions.model.LangDetectRequest;
import eu.europeana.api.translation.definitions.model.LangDetectResponse;
import eu.europeana.api.translation.service.LanguageDetectionService;
import eu.europeana.api.translation.service.exception.LanguageDetectionException;
import eu.europeana.api.translation.web.exception.ParamValidationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import eu.europeana.api.translation.definitions.model.TranslationObj;
import eu.europeana.api.translation.model.CachedTranslation;
import eu.europeana.api.translation.definitions.model.CachedTranslation;
import io.micrometer.core.instrument.util.StringUtils;

public class RedisCacheService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import eu.europeana.api.translation.definitions.language.LanguagePair;
import eu.europeana.api.translation.definitions.model.TranslationObj;
import eu.europeana.api.translation.definitions.vocabulary.TranslationAppConstants;
import eu.europeana.api.translation.model.TranslationRequest;
import eu.europeana.api.translation.model.TranslationResponse;
import eu.europeana.api.translation.definitions.model.TranslationRequest;
import eu.europeana.api.translation.definitions.model.TranslationResponse;
import eu.europeana.api.translation.service.TranslationService;
import eu.europeana.api.translation.service.exception.TranslationException;
import eu.europeana.api.translation.web.exception.ParamValidationException;
Expand Down

0 comments on commit 1db76ff

Please sign in to comment.