Search in sources :

Example 1 with JAXBI18nLabel

use of org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel in project entando-core by entando.

the class ApiI18nLabelInterface method getLabel.

public JAXBI18nLabel getLabel(Properties properties) throws ApiException, ApsSystemException {
    JAXBI18nLabel jaxbI18nLabel = null;
    try {
        String key = properties.getProperty("key");
        ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
        if (null == labelGroups) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' does not exist", Response.Status.CONFLICT);
        }
        jaxbI18nLabel = new JAXBI18nLabel(key, labelGroups);
    } catch (ApiException ae) {
        throw ae;
    } catch (ApsSystemException t) {
        _logger.error("error loading labels", t);
        throw new ApsSystemException("Error loading labels", t);
    }
    return jaxbI18nLabel;
}
Also used : JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 2 with JAXBI18nLabel

use of org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel in project entando-core by entando.

the class TestApiI18nLabelInterface method testGetLabel.

protected JAXBI18nLabel testGetLabel(MediaType mediaType, String username, String key) throws Throwable {
    ApiResource contentResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
    ApiMethod getMethod = contentResource.getGetMethod();
    Properties properties = super.createApiProperties(username, "en", mediaType);
    properties.put("key", key);
    Object result = this.getResponseBuilder().createResponse(getMethod, properties);
    assertNotNull(result);
    ApiI18nLabelInterface apiLabelInterface = (ApiI18nLabelInterface) this.getApplicationContext().getBean("ApiI18nLabelInterface");
    Object singleResult = apiLabelInterface.getLabel(properties);
    assertNotNull(singleResult);
    String toString = this.marshall(singleResult, mediaType);
    InputStream stream = new ByteArrayInputStream(toString.getBytes());
    JAXBI18nLabel jaxbLabel = (JAXBI18nLabel) UnmarshalUtils.unmarshal(super.getApplicationContext(), JAXBI18nLabel.class, stream, mediaType);
    assertNotNull(jaxbLabel);
    return jaxbLabel;
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 3 with JAXBI18nLabel

use of org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel in project entando-core by entando.

the class TestApiI18nLabelInterface method testCreateNewLabel.

protected void testCreateNewLabel(MediaType mediaType) throws Throwable {
    String key = "TEST_LABEL_KEY";
    String label = this._i18nManager.getLabel(key, "it");
    assertNull(label);
    ApsProperties labels = new ApsProperties();
    labels.put("en", "Test label");
    labels.put("it", "Label di Test");
    JAXBI18nLabel jaxbLabel = new JAXBI18nLabel(key, labels);
    ApiResource labelResource = this.getApiCatalogManager().getResource("core", "i18nlabel");
    ApiMethod postMethod = labelResource.getPostMethod();
    Properties properties = super.createApiProperties("admin", "it", mediaType);
    try {
        Object response = this.getResponseBuilder().createResponse(postMethod, jaxbLabel, properties);
        assertNotNull(response);
        assertTrue(response instanceof StringApiResponse);
        assertEquals(IResponseBuilder.SUCCESS, ((StringApiResponse) response).getResult());
        label = this._i18nManager.getLabel(key, "it");
        assertEquals("Label di Test", label);
    } catch (Exception e) {
        throw e;
    } finally {
        this._i18nManager.deleteLabelGroup(key);
    }
}
Also used : ApiResource(org.entando.entando.aps.system.services.api.model.ApiResource) JAXBI18nLabel(org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel) ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

ApsProperties (com.agiletec.aps.util.ApsProperties)3 JAXBI18nLabel (org.entando.entando.aps.system.services.i18n.model.JAXBI18nLabel)3 Properties (java.util.Properties)2 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)2 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)2 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)1