Search in sources :

Example 41 with ApiException

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

the class ResponseBuilder method createResponse.

@Override
@Deprecated
public Object createResponse(String resourceName, Properties parameters) throws ApsSystemException {
    Object apiResponse = null;
    try {
        ApiMethod method = this.extractApiMethod(ApiMethod.HttpMethod.GET, null, resourceName);
        apiResponse = this.createResponse(method, parameters);
    } catch (ApiException e) {
        _logger.error("Error creating response for method GET, resource '{}'", resourceName, e);
        if (apiResponse == null) {
            apiResponse = new StringApiResponse();
        }
        ((AbstractApiResponse) apiResponse).addErrors(e.getErrors());
    }
    return apiResponse;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 42 with ApiException

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

the class ResponseBuilder method invokePutPostDeleteMethod.

protected Object invokePutPostDeleteMethod(ApiMethod apiMethod, Object bean, Properties parameters, Object bodyObject) throws ApiException, Throwable {
    Object result = null;
    try {
        if (apiMethod.getHttpMethod().equals(ApiMethod.HttpMethod.DELETE)) {
            result = this.invokeDeleteMethod(apiMethod, bean, parameters);
        } else {
            result = this.invokePutPostMethod(apiMethod, bean, parameters, bodyObject);
        }
        if (null != result)
            return result;
        StringApiResponse response = new StringApiResponse();
        response.setResult(SUCCESS, null);
        result = response;
    } catch (NoSuchMethodException e) {
        _logger.error("No such method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass(), e);
        throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Method not supported - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
    } catch (InvocationTargetException e) {
        if (e.getTargetException() instanceof ApiException) {
            throw (ApiException) e.getTargetException();
        } else {
            _logger.error("Error invoking method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass());
            throw new ApiException(IApiErrorCodes.API_METHOD_ERROR, "Error invoking Method - " + this.buildApiSignature(apiMethod), Response.Status.INTERNAL_SERVER_ERROR);
        }
    } catch (Throwable t) {
        _logger.error("Error invoking method '{}' of class '{}'", apiMethod.getSpringBeanMethod(), bean.getClass(), t);
        throw t;
    }
    return result;
}
Also used : StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) InvocationTargetException(java.lang.reflect.InvocationTargetException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 43 with ApiException

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

the class ResponseBuilder method invoke.

@Override
@Deprecated
public Object invoke(String resourceName, Properties parameters) throws ApiException, ApsSystemException {
    Object result = null;
    try {
        ApiMethod api = this.extractApiMethod(ApiMethod.HttpMethod.GET, null, resourceName);
        this.checkParameter(api, parameters);
        Object bean = this.extractBean(api);
        result = this.invokeGetMethod(api, bean, "", parameters, true);
    } catch (ApiException ae) {
        _logger.error("Error invoking method GET for resource '{}'", resourceName, ae);
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error invoking method GET for resource '{}'", resourceName, t);
        throw new ApsSystemException("Error invoking method GET for resource '" + resourceName + "'", t);
    }
    return result;
}
Also used : ApiMethod(org.entando.entando.aps.system.services.api.model.ApiMethod) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 44 with ApiException

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

the class ApiDataObjectInterface method updateDataObjectText.

public void updateDataObjectText(JAXBDataObjectAttribute jaxbDataObjectAttribute, Properties properties) throws ApiException, Throwable {
    try {
        String dataId = jaxbDataObjectAttribute.getDataId();
        DataObject masterDataObject = this.getDataObjectManager().loadDataObject(jaxbDataObjectAttribute.getDataId(), true);
        if (null == masterDataObject) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + dataId + "' does not exist", Response.Status.CONFLICT);
        }
        String attributeName = jaxbDataObjectAttribute.getAttributeName();
        AttributeInterface attribute = (AttributeInterface) masterDataObject.getAttribute(attributeName);
        if (null == attribute) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' does not exist into DataObject " + dataId, Response.Status.CONFLICT);
        } else if (!(attribute instanceof ITextAttribute)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject Attribute with code '" + attributeName + "' isn't a Text Atttribute", Response.Status.CONFLICT);
        }
        String langCode = jaxbDataObjectAttribute.getLangCode();
        String value = jaxbDataObjectAttribute.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.getDataObjectManager().insertDataObject(masterDataObject);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error updating DataObject attribute", t);
        throw new ApsSystemException("Error updating DataObject attribute", t);
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) 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) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 45 with ApiException

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

the class ApiDataObjectInterface method extractDataObjects.

protected List<String> extractDataObjects(Properties properties) throws Throwable {
    List<String> contentsId = null;
    try {
        ApiDataObjectListBean bean = this.buildSearchBean(properties);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        contentsId = this.getDataObjectListHelper().getDataTypesId(bean, user);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in extractDataObjects", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return contentsId;
}
Also used : ApiDataObjectListBean(org.entando.entando.aps.system.services.dataobject.api.model.ApiDataObjectListBean) UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) 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