Search in sources :

Example 66 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class TestApiWidgetTypeInterface method testInvokeUpdateJaxbNoLogicWidgetType.

private void testInvokeUpdateJaxbNoLogicWidgetType(String widgetTypeCode, ApsProperties titles, boolean removeParametersFromCall, String customSingleGui, boolean expectedSuccess) throws Throwable {
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToEdit = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    ApsProperties originalTitles = widgetType.getTitles();
    try {
        JAXBWidgetType jaxbWidgetType = this.getJaxbWidgetType(widgetTypeToEdit);
        if (StringUtils.isNotBlank(customSingleGui)) {
            jaxbWidgetType.setGui(customSingleGui);
        }
        if (null != titles) {
            jaxbWidgetType.setTitles(titles);
        }
        if (removeParametersFromCall) {
            jaxbWidgetType.setTypeParameters(null);
        }
        this._apiWidgetTypeInterface.updateWidgetType(jaxbWidgetType);
        if (!expectedSuccess) {
            fail();
        }
        WidgetType extractedWidgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
        assertNotNull(extractedWidgetType);
        assertEquals(widgetType.getMainGroup(), extractedWidgetType.getMainGroup());
        assertEquals(titles, extractedWidgetType.getTitles());
        assertEquals(widgetType.getTypeParameters(), extractedWidgetType.getTypeParameters());
        assertEquals(widgetType.isLocked(), extractedWidgetType.isLocked());
        if (StringUtils.isNotBlank(customSingleGui) && null == previousFragment) {
            assertNotNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
        }
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null == previousFragment) {
            List<String> codes = this._guiFragmentManager.getGuiFragmentCodesByWidgetType(widgetTypeCode);
            if (null != codes) {
                for (int i = 0; i < codes.size(); i++) {
                    String code = codes.get(i);
                    this._guiFragmentManager.deleteGuiFragment(code);
                }
            }
        } else {
            if (null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
                this._guiFragmentManager.addGuiFragment(previousFragment);
            } else {
                this._guiFragmentManager.updateGuiFragment(previousFragment);
            }
        }
        this._widgetTypeManager.updateWidgetType(widgetType.getCode(), originalTitles, widgetType.getConfig(), widgetType.getMainGroup());
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 67 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException in project entando-core by entando.

the class TestApiWidgetTypeInterface method testInvokeDeleteJaxbNoLogicWidgetType.

private void testInvokeDeleteJaxbNoLogicWidgetType(String widgetTypeCode, boolean expectedSuccess) throws Throwable {
    Properties properties = new Properties();
    properties.put(SystemConstants.API_USER_PARAMETER, super.getUser("admin"));
    properties.put("code", widgetTypeCode);
    WidgetType widgetType = this._widgetTypeManager.getWidgetType(widgetTypeCode);
    assertNotNull(widgetType);
    WidgetType widgetTypeToDelete = widgetType.clone();
    GuiFragment previousFragment = this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode);
    try {
        this._apiWidgetTypeInterface.deleteWidgetType(properties);
        if (!expectedSuccess) {
            fail();
        }
        assertNull(this._widgetTypeManager.getWidgetType(widgetTypeCode));
        assertNull(this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode));
    } catch (ApiException ae) {
        if (expectedSuccess) {
            fail();
        }
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != previousFragment && null == this._guiFragmentManager.getUniqueGuiFragmentByWidgetType(widgetTypeCode)) {
            this._guiFragmentManager.addGuiFragment(previousFragment);
        }
        if (null == this._widgetTypeManager.getWidgetType(widgetTypeCode)) {
            this._widgetTypeManager.addWidgetType(widgetTypeToDelete);
        }
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) Properties(java.util.Properties) ApsProperties(com.agiletec.aps.util.ApsProperties) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 68 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException 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 69 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException 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 70 with ApiException

use of org.entando.entando.aps.system.services.api.model.ApiException 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)

Aggregations

ApiException (org.entando.entando.aps.system.services.api.model.ApiException)80 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)49 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)13 ApsProperties (com.agiletec.aps.util.ApsProperties)12 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)10 ArrayList (java.util.ArrayList)9 GuiFragment (org.entando.entando.aps.system.services.guifragment.GuiFragment)9 WidgetType (org.entando.entando.aps.system.services.widgettype.WidgetType)9 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)7 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)7 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)7 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)5 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)5 Properties (java.util.Properties)4