Search in sources :

Example 46 with ApiException

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

the class ApiDataObjectInterface method getDataObjectsToHtml.

public String getDataObjectsToHtml(Properties properties) throws Throwable {
    StringBuilder render = new StringBuilder();
    try {
        String modelId = properties.getProperty("modelId");
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        String dataType = properties.getProperty("dataType");
        DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(dataType);
        Integer modelIdInteger = this.checkModel(modelId, prototype);
        if (null == modelIdInteger) {
            return null;
        }
        List<String> dataObjectsId = this.extractDataObjects(properties);
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        render.append(this.getItemsStartElement());
        for (int i = 0; i < dataObjectsId.size(); i++) {
            render.append(this.getItemStartElement());
            String renderedData = this.getRenderedDataObject(dataObjectsId.get(i), modelIdInteger, langCode);
            if (null != renderedData) {
                render.append(renderedData);
            }
            render.append(this.getItemEndElement());
        }
        render.append(this.getItemsEndElement());
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObjectsToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render.toString();
}
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 47 with ApiException

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

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

the class ApiDataObjectInterface method buildSearchBean.

protected ApiDataObjectListBean buildSearchBean(Properties properties) throws ApiException, Throwable {
    ApiDataObjectListBean bean = null;
    try {
        String dataType = properties.getProperty("dataType");
        if (null == this.getDataObjectManager().getSmallDataTypesMap().get(dataType)) {
            throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "DataObject Type '" + dataType + "' does not exist", Response.Status.CONFLICT);
        }
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        String filtersParam = properties.getProperty("filters");
        EntitySearchFilter[] filters = this.getDataObjectListHelper().getFilters(dataType, filtersParam, langCode);
        String[] categoryCodes = null;
        String categoriesParam = properties.getProperty("categories");
        if (null != categoriesParam && categoriesParam.trim().length() > 0) {
            categoryCodes = categoriesParam.split(IDataTypeListHelper.CATEGORIES_SEPARATOR);
        }
        bean = new ApiDataObjectListBean(dataType, 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 : ApiDataObjectListBean(org.entando.entando.aps.system.services.dataobject.api.model.ApiDataObjectListBean) 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 49 with ApiException

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

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

the class ApiWidgetTypeInterface method addWidgetType.

public void addWidgetType(JAXBWidgetType jaxbWidgetType) throws ApiException, Throwable {
    List<GuiFragment> addedFragments = new ArrayList<GuiFragment>();
    List<GuiFragment> updatedFragments = new ArrayList<GuiFragment>();
    try {
        WidgetType widgetType = this.getWidgetTypeManager().getWidgetType(jaxbWidgetType.getCode());
        if (null != widgetType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "WidgetType with code " + jaxbWidgetType.getCode() + " already exists", Response.Status.CONFLICT);
        }
        widgetType = jaxbWidgetType.getNewWidgetType(this.getWidgetTypeManager());
        if (!widgetType.isLogic() && StringUtils.isBlank(jaxbWidgetType.getGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Gui is mandatory", Response.Status.CONFLICT);
        }
        if (widgetType.isLogic() && (StringUtils.isNotBlank(jaxbWidgetType.getGui()) || (null != jaxbWidgetType.getFragments() && jaxbWidgetType.getFragments().size() > 0))) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Fragment mustn't be added on the new logic widget type", Response.Status.CONFLICT);
        }
        if (widgetType.isLogic() && this.isInternalServletWidget(widgetType.getParentType().getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Logic type with parent 'Internal Servlet' widget mustn't be added", Response.Status.CONFLICT);
        }
        this.getWidgetTypeManager().addWidgetType(widgetType);
        if (!widgetType.isLogic()) {
            this.checkAndSaveFragment(widgetType, jaxbWidgetType, true, null, addedFragments, updatedFragments);
        }
    } catch (ApiException ae) {
        this.revertPreviousObject(null, addedFragments, updatedFragments);
        throw ae;
    } catch (Throwable t) {
        this.revertPreviousObject(null, addedFragments, updatedFragments);
        this.getWidgetTypeManager().deleteWidgetType(jaxbWidgetType.getCode());
        _logger.error("Error adding new widget type", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) JAXBGuiFragment(org.entando.entando.aps.system.services.guifragment.api.JAXBGuiFragment) ArrayList(java.util.ArrayList) WidgetType(org.entando.entando.aps.system.services.widgettype.WidgetType) 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