Search in sources :

Example 16 with StringApiResponse

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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 17 with StringApiResponse

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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 18 with StringApiResponse

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

the class ApiDataObjectInterface method deleteDataObject.

public StringApiResponse deleteDataObject(Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String id = properties.getProperty("id");
        DataObject masterDataObject = this.getDataObjectManager().loadDataObject(id, false);
        if (null == masterDataObject) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject 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.getDataObjectAuthorizationHelper().isAuth(user, masterDataObject)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject groups makes the new dataObject not allowed for user " + user.getUsername(), Response.Status.FORBIDDEN);
        }
        if (masterDataObject.isOnLine()) {
            this.getDataObjectManager().removeDataObject(masterDataObject);
        }
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting DataObject", t);
        throw new ApsSystemException("Error deleting 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) UserDetails(com.agiletec.aps.system.services.user.UserDetails) 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 19 with StringApiResponse

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

the class ApiContentInterface method updateContent.

public StringApiResponse updateContent(JAXBContent jaxbContent, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbContent.getTypeCode();
        Content prototype = (Content) this.getContentManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        Content content = (Content) jaxbContent.buildEntity(prototype, this.getCategoryManager());
        Content masterContent = this.getContentManager().loadContent(content.getId(), false);
        if (null == masterContent) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Content with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
        } else if (!masterContent.getMainGroup().equals(content.getMainGroup())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterContent.getMainGroup(), Response.Status.CONFLICT);
        }
        response = this.validateAndSaveContent(content, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating content", t);
        throw new ApsSystemException("Error updating content", t);
    }
    return response;
}
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) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 20 with StringApiResponse

use of org.entando.entando.aps.system.services.api.model.StringApiResponse 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)

Aggregations

StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)28 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)23 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)20 UserDetails (com.agiletec.aps.system.services.user.UserDetails)9 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)8 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)6 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)5 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 ApiMethod (org.entando.entando.aps.system.services.api.model.ApiMethod)4 JAXBContent (org.entando.entando.plugins.jacms.aps.system.services.api.model.JAXBContent)4 JAXBDataObject (org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 ContentRecordVO (com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO)2 BaseResourceDataBean (com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean)2 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)2 Properties (java.util.Properties)2 ApiResource (org.entando.entando.aps.system.services.api.model.ApiResource)2 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)1