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;
}
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;
}
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);
}
}
Aggregations