Search in sources :

Example 56 with ApiException

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

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

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

Example 59 with ApiException

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

the class ApiContentInterface method buildSearchBean.

protected ApiContentListBean buildSearchBean(Properties properties) throws ApiException, Throwable {
    ApiContentListBean bean = null;
    try {
        String contentType = properties.getProperty("contentType");
        if (null == this.getContentManager().getSmallContentTypesMap().get(contentType)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Content Type '" + contentType + "' does not exist", Response.Status.CONFLICT);
        }
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String filtersParam = properties.getProperty("filters");
        EntitySearchFilter[] filters = this.getContentListHelper().getFilters(contentType, filtersParam, langCode);
        String[] categoryCodes = null;
        String categoriesParam = properties.getProperty("categories");
        if (null != categoriesParam && categoriesParam.trim().length() > 0) {
            categoryCodes = categoriesParam.split(IContentListHelper.CATEGORIES_SEPARATOR);
        }
        bean = new ApiContentListBean(contentType, filters, categoryCodes);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in buildSearchBean", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return bean;
}
Also used : ApiContentListBean(org.entando.entando.plugins.jacms.aps.system.services.api.model.ApiContentListBean) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 60 with ApiException

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

the class ApiResourceInterface method deleteResource.

private StringApiResponse deleteResource(Properties properties, ResourceInterface resource) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String id = properties.getProperty("id");
        if (null == resource) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Resource 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.getAuthorizationManager().isAuthOnGroup(user, resource.getMainGroup())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Resource not allowed for user '" + user.getUsername() + "' - resource group '" + resource.getMainGroup() + "'", Response.Status.FORBIDDEN);
        }
        List<String> references = ((ResourceUtilizer) this.getContentManager()).getResourceUtilizers(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, "Resource " + id + " referenced to content " + record.getId() + " - '" + record.getDescr() + "'", Response.Status.CONFLICT));
                }
            }
            if (found) {
                response.setResult(IResponseBuilder.FAILURE, null);
                return response;
            }
        }
        this.getResourceManager().deleteResource(resource);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error deleting resource", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteResource");
        throw new ApsSystemException("Error deleting resource", t);
    }
    return response;
}
Also used : UserDetails(com.agiletec.aps.system.services.user.UserDetails) ContentRecordVO(com.agiletec.plugins.jacms.aps.system.services.content.model.ContentRecordVO) 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) ResourceUtilizer(com.agiletec.plugins.jacms.aps.system.services.resource.ResourceUtilizer)

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