Search in sources :

Example 31 with ApiException

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

the class ApiDataObjectInterface method getDataObject.

public JAXBDataObject getDataObject(Properties properties) throws ApiException, Throwable {
    JAXBDataObject jaxbDataObject = null;
    String id = properties.getProperty("id");
    try {
        String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
        DataObject mainDataObject = this.getPublicDataObject(id);
        jaxbDataObject = this.getJAXBDataObjectInstance(mainDataObject, langCode);
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        if (null == user) {
            user = this.getUserManager().getGuestUser();
        }
        if (!this.getDataObjectAuthorizationHelper().isAuth(user, mainDataObject)) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Required DataObject '" + id + "' does not allowed", Response.Status.FORBIDDEN);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObject", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return jaxbDataObject;
}
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) JAXBDataObject(org.entando.entando.aps.system.services.dataobject.api.model.JAXBDataObject) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 32 with ApiException

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

the class ApiDataObjectInterface method updateDataObject.

public StringApiResponse updateDataObject(JAXBDataObject jaxbDataObject, Properties properties) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbDataObject.getTypeCode();
        DataObject prototype = (DataObject) this.getDataObjectManager().getEntityPrototype(typeCode);
        if (null == prototype) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject type with code '" + typeCode + "' does not exist", Response.Status.CONFLICT);
        }
        DataObject content = (DataObject) jaxbDataObject.buildEntity(prototype, this.getCategoryManager());
        DataObject masterData = this.getDataObjectManager().loadDataObject(content.getId(), false);
        if (null == masterData) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject with code '" + content.getId() + "' does not exist", Response.Status.CONFLICT);
        } else if (!masterData.getMainGroup().equals(content.getMainGroup())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid main group " + content.getMainGroup() + " not equals then master " + masterData.getMainGroup(), Response.Status.CONFLICT);
        }
        response = this.validateAndSaveDataObject(content, properties);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating DataObject", t);
        throw new ApsSystemException("Error updating 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) 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 33 with ApiException

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

the class ApiDataObjectInterface method getDataObjectToHtml.

public String getDataObjectToHtml(Properties properties) throws ApiException, Throwable {
    String render = null;
    String id = properties.getProperty("id");
    String modelId = properties.getProperty("modelId");
    try {
        if (null == modelId || modelId.trim().length() == 0) {
            return null;
        }
        DataObject mainDataObject = this.getPublicDataObject(id);
        Integer modelIdInteger = this.checkModel(modelId, mainDataObject);
        if (null != modelIdInteger) {
            String langCode = properties.getProperty(SystemConstants.API_LANG_CODE_PARAMETER);
            render = this.getRenderedDataObject(id, modelIdInteger, langCode);
        }
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in getDataObjectToHtml", t);
        throw new ApsSystemException("Error into API method", t);
    }
    return render;
}
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 34 with ApiException

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

the class ApiDataObjectModelInterface method deleteModel.

public void deleteModel(Properties properties) throws ApiException, Throwable {
    String idString = properties.getProperty("id");
    int id = 0;
    try {
        id = Integer.parseInt(idString);
    } catch (NumberFormatException e) {
        throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Invalid number format for 'id' parameter - '" + idString + "'", Response.Status.CONFLICT);
    }
    DataObjectModel model = this.getDataObjectModelManager().getDataObjectModel(id);
    if (null == model) {
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
    }
    try {
        this.getDataObjectModelManager().removeDataObjectModel(model);
    } catch (Throwable t) {
        _logger.error("Error deleting model", t);
        throw new ApsSystemException("Error deleting model", t);
    }
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 35 with ApiException

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

the class ApiGuiFragmentInterface method addGuiFragment.

public void addGuiFragment(JAXBGuiFragment jaxbGuiFragment) throws ApiException, Throwable {
    try {
        if (null != this.getGuiFragmentManager().getGuiFragment(jaxbGuiFragment.getCode())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "GuiFragment with code " + jaxbGuiFragment.getCode() + " already exists", Response.Status.CONFLICT);
        }
        GuiFragment guiFragment = jaxbGuiFragment.getGuiFragment();
        if (StringUtils.isBlank(guiFragment.getCurrentGui())) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "one between A and B must be valued", Response.Status.CONFLICT);
        }
        this.getGuiFragmentManager().addGuiFragment(guiFragment);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error adding new fragment", t);
        throw t;
    }
}
Also used : GuiFragment(org.entando.entando.aps.system.services.guifragment.GuiFragment) 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