Search in sources :

Example 51 with ApiException

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

the class ApiWidgetTypeInterface method getWidgetType.

public JAXBWidgetType getWidgetType(Properties properties) throws ApiException, Throwable {
    String widgetTypeCode = properties.getProperty("code");
    JAXBWidgetType jaxbWidgetType = null;
    try {
        WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(widgetTypeCode);
        if (null == widgetType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code '" + widgetTypeCode + "' does not exist", Response.Status.CONFLICT);
        }
        GuiFragment singleGuiFragment = null;
        List<GuiFragment> fragments = new ArrayList<GuiFragment>();
        if (!widgetType.isLogic()) {
            singleGuiFragment = this.getGuiFragmentManager().getUniqueGuiFragmentByWidgetType(widgetTypeCode);
        } else {
            List<String> fragmentCodes = this.getGuiFragmentManager().getGuiFragmentCodesByWidgetType(widgetTypeCode);
            if (null != fragmentCodes) {
                for (int i = 0; i < fragmentCodes.size(); i++) {
                    String fragmentCode = fragmentCodes.get(i);
                    GuiFragment fragment = this.getGuiFragmentManager().getGuiFragment(fragmentCode);
                    if (null != fragment) {
                        fragments.add(fragment);
                    }
                }
            }
        }
        jaxbWidgetType = new JAXBWidgetType(widgetType, singleGuiFragment, fragments);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error creating widget type - code '{}'", widgetTypeCode, t);
        throw t;
    }
    return jaxbWidgetType;
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 52 with ApiException

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

the class JAXBWidgetType method getModifiedWidgetType.

public WidgetType getModifiedWidgetType(IWidgetTypeManager widgetTypeManager) throws ApiException {
    WidgetType type = widgetTypeManager.getWidgetType(this.getCode());
    type.setTitles(this.getTitles());
    if (type.isLogic()) {
        ApsProperties configuration = this.getConfig();
        type.setConfig(configuration);
    } else {
        List<WidgetTypeParameter> parameters = this.getTypeParameters();
        if (null != parameters && !parameters.isEmpty()) {
            // type.setAction("configSimpleParameter");
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Parameters of existing widget mustn't been changed", Response.Status.CONFLICT);
        }
    }
    type.setMainGroup(this.getMainGroup());
    // type.setPluginCode(this.getPluginCode());
    return type;
}
Also used : WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) WidgetTypeParameter(org.entando.entando.aps.system.services.widgettype.WidgetTypeParameter) ApsProperties(com.agiletec.aps.util.ApsProperties) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 53 with ApiException

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

the class ApiContentInterface method getContentsToHtml.

public String getContentsToHtml(Properties properties) throws Throwable {
    StringBuilder render = new StringBuilder();
    try {
        String modelId = properties.getProperty("modelId");
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        String contentType = properties.getProperty("contentType");
        Content prototype = (Content) this.getContentManager().getEntityPrototype(contentType);
        Integer modelIdInteger = this.checkModel(modelId, prototype);
        if (null == modelIdInteger) {
            return null;
        }
        List<String> contentsId = this.extractContents(properties);
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        render.append(this.getItemsStartElement());
        for (int i = 0; i < contentsId.size(); i++) {
            render.append(this.getItemStartElement());
            String renderedContent = this.getRenderedContent(contentsId.get(i), modelIdInteger, langCode);
            if (null != renderedContent) {
                render.append(renderedContent);
            }
            render.append(this.getItemEndElement());
        }
        render.append(this.getItemsEndElement());
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getContentsToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render.toString();
}
Also used : Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 54 with ApiException

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

the class ApiContentInterface method getContent.

public JAXBContent getContent(Properties properties) throws ApiException, Throwable {
    JAXBContent jaxbContent = null;
    String id = properties.getProperty("id");
    try {
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        Content mainContent = this.getPublicContent(id);
        jaxbContent = this.getJAXBContentInstance(mainContent, langCode);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getContentAuthorizationHelper().isAuth(user, mainContent)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required content '" + id + "' does not allowed", Response.Status.FORBIDDEN);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getContent", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return jaxbContent;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 55 with ApiException

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

the class ApiContentInterface method updateContentText.

public void updateContentText(JAXBContentAttribute jaxbContentAttribute, Properties properties) throws ApiException, Throwable {
    try {
        String contentId = jaxbContentAttribute.getContentId();
        Content masterContent = this.getContentManager().loadContent(jaxbContentAttribute.getContentId(), true);
        if (null == masterContent) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + contentId + "' does not exist", Response.Status.CONFLICT);
        }
        String attributeName = jaxbContentAttribute.getAttributeName();
        AttributeInterface attribute = (AttributeInterface) masterContent.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' does not exist into content " + contentId, Response.Status.CONFLICT);
        } else if (!(attribute instanceof ITextAttribute)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
        }
        String langCode = jaxbContentAttribute.getLangCode();
        String value = jaxbContentAttribute.getValue();
        if (StringUtils.isEmpty(langCode) || StringUtils.isEmpty(value)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "LangCode or value is Empty", Response.Status.CONFLICT);
        }
        ((ITextAttribute) attribute).setText(value, langCode);
        this.getContentManager().insertOnLineContent(masterContent);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating content attribute", t);
        throw new ApsSystemException("Error updating content attribute", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) JAXBContent(org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

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