Search in sources :

Example 86 with ApsSystemException

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

the class ApiDataObjectInterface method validate.

private List<ApiError> validate(DataObject dataObject) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        if (null == dataObject.getMainGroup()) {
            errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null", Response.Status.CONFLICT));
        }
        List<FieldError> fieldErrors = dataObject.validate(this.getGroupManager());
        if (null != fieldErrors) {
            for (int i = 0; i < fieldErrors.size(); i++) {
                FieldError fieldError = fieldErrors.get(i);
                if (fieldError instanceof AttributeFieldError) {
                    AttributeFieldError attributeError = (AttributeFieldError) fieldError;
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, attributeError.getFullMessage(), Response.Status.CONFLICT));
                } else {
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, fieldError.getMessage(), Response.Status.CONFLICT));
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating DataObject", t);
        throw new ApsSystemException("Error validating DataObject", t);
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) FieldError(com.agiletec.aps.system.common.entity.model.FieldError) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 87 with ApsSystemException

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

the class ApiDataObjectInterface method updateDataObject.

public StringApiResponse updateDataObject(JAXBDataObject jaxbDataObject, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbDataObject.getTypeCode();
        DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        DataObject content = (DataObject) jaxbDataObject.buildEntity(prototype, this.getCategoryManager());
        DataObject masterData = this.getDataObjectManager().loadDataObject(content.getId(), false);
        if (null == masterData) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
        } else if (!masterData.getMainGroup().equals(content.getMainGroup())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterData.getMainGroup(), Response.Status.CONFLICT);
        }
        response = this.validateAndSaveDataObject(content, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating DataObject", t);
        throw new ApsSystemException("Error updating DataObject", t);
    }
    return response;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 88 with ApsSystemException

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

the class ApiDataObjectInterface method getDataObjectToHtml.

public String getDataObjectToHtml(Properties properties) throws ApiException, Throwable {
    String render = null;
    String id = properties.getProperty("id");
    String modelId = properties.getProperty("modelId");
    try {
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        DataObject mainDataObject = this.getPublicDataObject(id);
        Integer modelIdInteger = this.checkModel(modelId, mainDataObject);
        if (null != modelIdInteger) {
            String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
            render = this.getRenderedDataObject(id, modelIdInteger, langCode);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObjectToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render;
}
Also used : JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 89 with ApsSystemException

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

the class BaseDataListHelper method getDataTypesId.

@Override
public // @CacheableInfo(groups = "T(com.agiletec.plugins.jacms.aps.system.JacmsSystemConstants).CONTENTS_ID_CACHE_GROUP_PREFIX.concat(#bean.contentType)", expiresInMinute = 30)
List<String> getDataTypesId(IDataTypeListBean bean, UserDetails user) throws Throwable {
    List<String> contentsId = null;
    try {
        if (null == bean.getDataType()) {
            throw new ApsSystemException("DataObject type not defined");
        }
        // this.getAllowedGroups(user);
        Collection<String> userGroupCodes = getAllowedGroupCodes(user);
        contentsId = this.getDataObjectManager().loadDataObjectsId(bean.getDataType(), bean.getCategories(), bean.getFilters(), userGroupCodes);
    } catch (Throwable t) {
        _logger.error("Error extracting DataObjects id", t);
        throw new ApsSystemException("Error extracting DataObjects id", t);
    }
    return contentsId;
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 90 with ApsSystemException

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

the class DataObjectListHelper method getConfiguredUserFilters.

@Override
public List<UserFilterOptionBean> getConfiguredUserFilters(IDataObjectListTagBean bean, RequestContext reqCtx) throws ApsSystemException {
    List<UserFilterOptionBean> userEntityFilters = null;
    try {
        Widget widget = (Widget) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_WIDGET);
        ApsProperties config = (null != widget) ? widget.getConfig() : null;
        if (null == config || null == config.getProperty(WIDGET_PARAM_CONTENT_TYPE)) {
            return null;
        }
        String dataObjectTypeCode = config.getProperty(WIDGET_PARAM_CONTENT_TYPE);
        IApsEntity prototype = this.getDataObjectManager().getEntityPrototype(dataObjectTypeCode);
        if (null == prototype) {
            _logger.error("Null dataObject type by code '{}'", dataObjectTypeCode);
            return null;
        }
        Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
        Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
        String userFilters = config.getProperty(WIDGET_PARAM_USER_FILTERS);
        if (null != userFilters && userFilters.length() > 0) {
            userEntityFilters = FilterUtils.getUserFilters(userFilters, currentFrame, currentLang, prototype, this.getUserFilterDateFormat(), reqCtx.getRequest());
        }
    } catch (Throwable t) {
        _logger.error("Error extracting user filters", t);
        throw new ApsSystemException("Error extracting user filters", t);
    }
    return userEntityFilters;
}
Also used : Widget(com.agiletec.aps.system.services.page.Widget) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) Lang(com.agiletec.aps.system.services.lang.Lang) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApsProperties(com.agiletec.aps.util.ApsProperties)

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