use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.
the class ApiI18nLabelInterface method addLabel.
public void addLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException, ApsSystemException {
try {
this.checkLabels(jaxbI18nLabel);
String key = jaxbI18nLabel.getKey();
ApsProperties labelGroups = this.getI18nManager().getLabelGroup(key);
if (null != labelGroups) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label with key '" + key + "' already exists", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
this.getI18nManager().addLabelGroup(key, labels);
} catch (ApiException | ApsSystemException ae) {
_logger.error("Error adding label", ae);
throw new ApsSystemException("Error adding labels", ae);
}
}
use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.
the class ApiI18nLabelInterface method updateLabel.
public void updateLabel(JAXBI18nLabel jaxbI18nLabel) throws ApiException, ApsSystemException {
try {
this.checkLabels(jaxbI18nLabel);
String key = jaxbI18nLabel.getKey();
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);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
this.getI18nManager().updateLabelGroup(key, labels);
} catch (ApiException ae) {
throw new ApiException("Error updating label", ae);
} catch (ApsSystemException t) {
_logger.error("Error updating label", t);
throw new ApsSystemException("Error updating labels", t);
}
}
use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.
the class ApiI18nLabelInterface method checkLabels.
protected void checkLabels(JAXBI18nLabel jaxbI18nLabel) throws ApiException {
try {
String key = jaxbI18nLabel.getKey();
if (null == key || key.trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label key required", Response.Status.CONFLICT);
}
ApsProperties labels = jaxbI18nLabel.extractLabels();
if (null == labels || labels.isEmpty()) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list can't be empty", Response.Status.CONFLICT);
}
Lang defaultLang = this.getLangManager().getDefaultLang();
Object defaultLangValue = labels.get(defaultLang.getCode());
if (null == defaultLangValue || defaultLangValue.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label list must contain a label for the default language '" + defaultLang.getCode() + "'", Response.Status.CONFLICT);
}
Iterator<Object> labelCodeIter = labels.keySet().iterator();
while (labelCodeIter.hasNext()) {
Object langCode = labelCodeIter.next();
Object value = labels.get(langCode);
if (null == value || value.toString().trim().length() == 0) {
throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Label for the language '" + langCode + "' is empty", Response.Status.CONFLICT);
}
}
} catch (ApiException ae) {
throw new ApiException("Error in method checkLabels ", ae);
}
}
use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.
the class ApiI18nLabelInterface method deleteLabel.
public void deleteLabel(Properties properties) throws ApsSystemException, ApiException {
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);
}
this.getI18nManager().deleteLabelGroup(key);
} catch (ApiException | ApsSystemException ae) {
_logger.error("Error deleting label", ae);
throw new ApsSystemException("Error deleting labels", ae);
}
}
use of com.agiletec.aps.util.ApsProperties in project entando-core by entando.
the class JAXBI18nLabel method extractLabels.
public ApsProperties extractLabels() {
ApsProperties properties = new ApsProperties();
if (null != this.getLabels()) {
for (int i = 0; i < this.getLabels().size(); i++) {
JAXBLabel jAXBLabel = this.getLabels().get(i);
properties.put(jAXBLabel.getLangCode(), jAXBLabel.getValue());
}
}
return properties;
}
Aggregations