Search in sources :

Example 81 with ApsProperties

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 82 with ApsProperties

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 83 with ApsProperties

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);
    }
}
Also used : Lang(com.agiletec.aps.system.services.lang.Lang) ApiException(org.entando.entando.aps.system.services.api.model.ApiException) ApsProperties(com.agiletec.aps.util.ApsProperties)

Example 84 with ApsProperties

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);
    }
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 85 with ApsProperties

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;
}
Also used : ApsProperties(com.agiletec.aps.util.ApsProperties)

Aggregations

ApsProperties (com.agiletec.aps.util.ApsProperties)146 Widget (com.agiletec.aps.system.services.page.Widget)62 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)34 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)29 HashMap (java.util.HashMap)17 IPage (com.agiletec.aps.system.services.page.IPage)16 Lang (com.agiletec.aps.system.services.lang.Lang)14 PageModel (com.agiletec.aps.system.services.pagemodel.PageModel)10 Properties (java.util.Properties)9 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)9 List (java.util.List)8 RestServerError (org.entando.entando.aps.system.exception.RestServerError)8 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)7 Page (com.agiletec.aps.system.services.page.Page)6 PageMetadata (com.agiletec.aps.system.services.page.PageMetadata)6 NavigatorExpression (com.agiletec.aps.system.services.page.widget.NavigatorExpression)6 ArrayList (java.util.ArrayList)6 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)6 IWidgetTypeManager (org.entando.entando.aps.system.services.widgettype.IWidgetTypeManager)6 ValidationGenericException (org.entando.entando.web.common.exceptions.ValidationGenericException)6