Search in sources :

Example 11 with ApiError

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

the class ApiRestStatusServer method buildErrorResponse.

private StringApiResponse buildErrorResponse(ApiMethod.HttpMethod httpMethod, String namespace, String resourceName, Throwable t) {
    StringBuilder buffer = new StringBuilder();
    buffer.append("Method '").append(httpMethod).append("' Namespace '").append(namespace).append("' Resource '").append(resourceName).append("'");
    _logger.error("Error building api response  - {}", buffer.toString(), t);
    StringApiResponse response = new StringApiResponse();
    ApiError error = new ApiError(IApiErrorCodes.SERVER_ERROR, "Error building response - " + buffer.toString(), Response.Status.INTERNAL_SERVER_ERROR);
    response.addError(error);
    response.setResult(IResponseBuilder.FAILURE, null);
    return response;
}
Also used : ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse)

Example 12 with ApiError

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

the class ApiDataObjectInterface method validateAndSaveDataObject.

protected StringApiResponse validateAndSaveDataObject(DataObject dataObject, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getDataObjectAuthorizationHelper().isAuth(user, dataObject)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
        }
        List<ApiError> errors = this.validate(dataObject);
        if (errors.size() > 0) {
            response.addErrors(errors);
            response.setResult(IResponseBuilder.FAILURE, null);
            return response;
        }
        String insertString = properties.getProperty("insert");
        boolean insert = (null != insertString) ? Boolean.parseBoolean(insertString) : false;
        if (!insert) {
            this.getDataObjectManager().saveDataObject(dataObject);
        } else {
            this.getDataObjectManager().insertDataObject(dataObject);
        }
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("error in validateAndSaveDataObject", t);
        throw new ApsSystemException("Error adding dataObject", t);
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 13 with ApiError

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

the class ApiContentInterface method validateAndSaveContent.

protected StringApiResponse validateAndSaveContent(Content content, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getContentAuthorizationHelper().isAuth(user, content)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
        }
        List<ApiError> errors = this.validate(content);
        if (errors.size() > 0) {
            response.addErrors(errors);
            response.setResult(IResponseBuilder.FAILURE, null);
            return response;
        }
        String insertOnLineString = properties.getProperty("insertOnLine");
        boolean insertOnLine = (null != insertOnLineString) ? Boolean.parseBoolean(insertOnLineString) : false;
        if (!insertOnLine) {
            this.getContentManager().saveContent(content);
        } else {
            this.getContentManager().insertOnLineContent(content);
        }
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("error in validateAndSaveContent", t);
        throw new ApsSystemException("Error adding content", t);
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 14 with ApiError

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

the class ApiContentInterface method validate.

private List<ApiError> validate(Content content) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        if (null == content.getMainGroup()) {
            errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null", Response.Status.CONFLICT));
        }
        List<FieldError> fieldErrors = content.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 content", t);
        throw new ApsSystemException("Error validating content", 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 15 with ApiError

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

the class ApiContentInterface method deleteContent.

public StringApiResponse deleteContent(Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String id = properties.getProperty("id");
        Content masterContent = this.getContentManager().loadContent(id, false);
        if (null == masterContent) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + id + "' does not exist", Response.Status.CONFLICT);
        }
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getContentAuthorizationHelper().isAuth(user, masterContent)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content groups makes the new content not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
        }
        List<String> references = ((ContentUtilizer) this.getContentManager()).getContentUtilizers(id);
        if (references != null && references.size() > 0) {
            boolean found = false;
            for (int i = 0; i < references.size(); i++) {
                String reference = references.get(i);
                ContentRecordVO record = this.getContentManager().loadContentVO(reference);
                if (null != record) {
                    found = true;
                    response.addError(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Content " + id + " referenced to content " + record.getId() + " - '" + record.getDescr() + "'", Response.Status.CONFLICT));
                }
            }
            if (found) {
                response.setResult(IResponseBuilder.FAILURE, null);
                return response;
            }
        }
        if (masterContent.isOnLine()) {
            this.getContentManager().removeOnLineContent(masterContent);
        }
        String removeWorkVersionString = properties.getProperty("removeWorkVersion");
        boolean removeWorkVersion = (null != removeWorkVersionString) ? Boolean.parseBoolean(removeWorkVersionString) : false;
        if (removeWorkVersion) {
            this.getContentManager().deleteContent(masterContent);
        }
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting content", t);
        throw new ApsSystemException("Error deleting content", t);
    }
    return response;
}
Also used : ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ContentUtilizer(com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer) 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) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

ApiError (org.entando.entando.aps.system.services.api.model.ApiError)21 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)13 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)10 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)9 ArrayList (java.util.ArrayList)8 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)3 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)3 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)2 ContentModel (com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel)2 AbstractApiResponse (org.entando.entando.aps.system.services.api.model.AbstractApiResponse)2 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)2 DataObjectModel (org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel)2 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 DefaultJAXBAttributeType (com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType)1 ContentUtilizer (com.agiletec.plugins.jacms.aps.system.services.content.ContentUtilizer)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 ResourceUtilizer (com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)1