Search in sources :

Example 11 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiResourceInterface method addResource.

public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, true);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        String id = bean.getResourceId();
        if (null != id && id.trim().length() > 0) {
            Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
            Matcher matcher = pattern.matcher(id);
            if (!matcher.matches()) {
                throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
            }
        }
        this.getResourceManager().addResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in addResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : Pattern(java.util.regex.Pattern) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Matcher(java.util.regex.Matcher) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 12 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ApiResourceInterface method updateResource.

public StringApiResponse updateResource(JAXBResource jaxbResource, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, false);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        this.getResourceManager().updateResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (Throwable t) {
        _logger.error("error in updateResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse)

Example 13 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class CmsPageManagerWrapper method getContentUtilizers.

@Override
public List getContentUtilizers(String contentId) throws ApsSystemException {
    List<IPage> pages = new ArrayList<IPage>();
    try {
        IPage root = this.getPageManager().getOnlineRoot();
        this.searchContentUtilizers(root, pages, contentId);
    } catch (Throwable t) {
        _logger.error("Error loading referenced pages", t);
        throw new ApsSystemException("Error loading referenced pages with content " + contentId, t);
    }
    return pages;
}
Also used : IPage(com.agiletec.aps.system.services.page.IPage) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 14 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class ContentViewerWidgetValidator method validate.

@Override
public BeanPropertyBindingResult validate(WidgetConfigurationRequest widget, IPage page) {
    BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(widget, widget.getClass().getSimpleName());
    try {
        logger.debug("validating widget {} for page {}", widget.getCode(), page.getCode());
        String contentId = WidgetValidatorCmsHelper.extractConfigParam(widget, WIDGET_CONFIG_KEY_CONTENT_ID);
        WidgetValidatorCmsHelper.validateSingleContentOnPage(widget.getCode(), page, contentId, this.getContentManager(), bindingResult);
        this.validateContentModel(widget, bindingResult);
    } catch (ApsSystemException e) {
        logger.error("error in validate wiget {} in page {}", widget.getCode(), page.getCode());
        throw new RestServerError("error in widget config validation", e);
    }
    return bindingResult;
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) RestServerError(org.entando.entando.aps.system.exception.RestServerError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 15 with ApsSystemException

use of com.agiletec.aps.system.exception.ApsSystemException in project entando-core by entando.

the class RowContentListTag method getContents.

protected List<Properties> getContents(RequestContext reqCtx) throws ApsSystemException {
    List<Properties> contents = null;
    try {
        Widget currentWidget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET);
        if (null == currentWidget || null == currentWidget.getConfig()) {
            return new ArrayList<Properties>();
        }
        String widgetConfig = currentWidget.getConfig().getProperty("contents");
        contents = RowContentListHelper.fromParameterToContents(widgetConfig);
        if (StringUtils.isBlank(widgetConfig)) {
            return contents;
        }
    } catch (Throwable t) {
        _logger.error("Error extracting contents", t);
        throw new ApsSystemException("Error extracting contents", t);
    }
    return contents;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) ArrayList(java.util.ArrayList) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) Properties(java.util.Properties)

Aggregations

ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)452 ArrayList (java.util.ArrayList)53 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)48 RestServerError (org.entando.entando.aps.system.exception.RestServerError)39 ApsProperties (com.agiletec.aps.util.ApsProperties)26 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)23 HashMap (java.util.HashMap)23 UserDetails (com.agiletec.aps.system.services.user.UserDetails)21 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)21 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)20 Date (java.util.Date)20 StringReader (java.io.StringReader)18 IPage (com.agiletec.aps.system.services.page.IPage)17 List (java.util.List)17 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)16 File (java.io.File)16 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)16 Widget (com.agiletec.aps.system.services.page.Widget)15 IOException (java.io.IOException)15 Cache (org.springframework.cache.Cache)15