Search in sources :

Example 1 with GetAllMessagesRequest

use of org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesRequest in project haikudepotserver by haiku.

the class MiscellaneousApiImpl method getAllMessages.

@Override
public GetAllMessagesResult getAllMessages(GetAllMessagesRequest getAllMessagesRequest) {
    Preconditions.checkNotNull(getAllMessagesRequest);
    Preconditions.checkNotNull(getAllMessagesRequest.naturalLanguageCode);
    ObjectContext context = serverRuntime.newContext();
    NaturalLanguage naturalLanguage = Optional.ofNullable(getAllMessagesRequest.naturalLanguageCode).filter(StringUtils::isNotBlank).flatMap(c -> NaturalLanguage.tryGetByCode(context, c)).orElseThrow(() -> new ObjectNotFoundException(NaturalLanguage.class.getSimpleName(), getAllMessagesRequest.naturalLanguageCode));
    Properties allLocalizationMessages = naturalLanguageService.getAllLocalizationMessages(naturalLanguage.getCode());
    GetAllMessagesResult getAllMessagesResult = new GetAllMessagesResult();
    getAllMessagesResult.messages = new HashMap<>();
    for (Object key : allLocalizationMessages.keySet()) {
        getAllMessagesResult.messages.put(key.toString(), allLocalizationMessages.get(key).toString());
    }
    return getAllMessagesResult;
}
Also used : ContributorsService(org.haiku.haikudepotserver.support.ContributorsService) ObjectContext(org.apache.cayenne.ObjectContext) java.util(java.util) Logger(org.slf4j.Logger) AutoJsonRpcServiceImpl(com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) RuntimeInformationService(org.haiku.haikudepotserver.support.RuntimeInformationService) org.haiku.haikudepotserver.api1.model.miscellaneous(org.haiku.haikudepotserver.api1.model.miscellaneous) StringUtils(org.apache.commons.lang3.StringUtils) FeedSpecification(org.haiku.haikudepotserver.feed.model.FeedSpecification) Collectors(java.util.stream.Collectors) org.haiku.haikudepotserver.dataobjects(org.haiku.haikudepotserver.dataobjects) Value(org.springframework.beans.factory.annotation.Value) Strings(com.google.common.base.Strings) Component(org.springframework.stereotype.Component) NaturalLanguageService(org.haiku.haikudepotserver.naturallanguage.model.NaturalLanguageService) Preconditions(com.google.common.base.Preconditions) FeedService(org.haiku.haikudepotserver.feed.model.FeedService) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) MessageSource(org.springframework.context.MessageSource) StringUtils(org.apache.commons.lang3.StringUtils) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) ObjectContext(org.apache.cayenne.ObjectContext)

Example 2 with GetAllMessagesRequest

use of org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesRequest in project haikudepotserver by haiku.

the class MiscelaneousApiIT method testGetAllMessages.

@Test
public void testGetAllMessages() throws Exception {
    // ------------------------------------
    GetAllMessagesResult result = miscellaneousApi.getAllMessages(new GetAllMessagesRequest(NaturalLanguage.CODE_ENGLISH));
    // ------------------------------------
    Assertions.assertThat(result.messages.get("test.it")).isEqualTo("Test line for integration testing");
}
Also used : GetAllMessagesResult(org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesResult) GetAllMessagesRequest(org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesRequest) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 AutoJsonRpcServiceImpl (com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 ObjectContext (org.apache.cayenne.ObjectContext)1 ServerRuntime (org.apache.cayenne.configuration.server.ServerRuntime)1 StringUtils (org.apache.commons.lang3.StringUtils)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 org.haiku.haikudepotserver.api1.model.miscellaneous (org.haiku.haikudepotserver.api1.model.miscellaneous)1 GetAllMessagesRequest (org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesRequest)1 GetAllMessagesResult (org.haiku.haikudepotserver.api1.model.miscellaneous.GetAllMessagesResult)1 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 org.haiku.haikudepotserver.dataobjects (org.haiku.haikudepotserver.dataobjects)1 FeedService (org.haiku.haikudepotserver.feed.model.FeedService)1 FeedSpecification (org.haiku.haikudepotserver.feed.model.FeedSpecification)1 NaturalLanguageService (org.haiku.haikudepotserver.naturallanguage.model.NaturalLanguageService)1 ContributorsService (org.haiku.haikudepotserver.support.ContributorsService)1 RuntimeInformationService (org.haiku.haikudepotserver.support.RuntimeInformationService)1 Test (org.junit.jupiter.api.Test)1