Search in sources :

Example 6 with ApiException

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

the class ApiContentModelInterface 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);
    }
    ContentModel model = this.getContentModelManager().getContentModel(id);
    if (null == model) {
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
    }
    try {
        this.getContentModelManager().removeContentModel(model);
    } catch (Throwable t) {
        _logger.error("Error deleting model", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteModel");
        throw new ApsSystemException("Error deleting model", t);
    }
}
Also used : ContentModel(com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 7 with ApiException

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

the class ApiContentModelInterface method getModel.

public ContentModel getModel(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);
    }
    ContentModel model = this.getContentModelManager().getContentModel(id);
    if (null == model) {
        throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Model with id '" + idString + "' does not exist", Response.Status.CONFLICT);
    }
    return model;
}
Also used : ContentModel(com.agiletec.plugins.jacms.aps.system.services.contentmodel.ContentModel) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 8 with ApiException

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

the class ApiResourceInterface method addResource.

public StringApiResponse addResource(JAXBResource jaxbResource, Properties properties) throws ApiException, Throwable {
    StringApiResponse response = new StringApiResponse();
    BaseResourceDataBean bean = null;
    try {
        UserDetails user = (UserDetails) properties.get(SystemConstants.API_USER_PARAMETER);
        this.check(jaxbResource, user, response, true);
        if (null != response.getErrors() && !response.getErrors().isEmpty()) {
            return response;
        }
        bean = jaxbResource.createBataBean(this.getCategoryManager());
        String id = bean.getResourceId();
        if (null != id && id.trim().length() > 0) {
            Pattern pattern = Pattern.compile("^[a-zA-Z]+$");
            Matcher matcher = pattern.matcher(id);
            if (!matcher.matches()) {
                throw new ApiException(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "The resourceId can contain only alphabetic characters", Response.Status.CONFLICT);
            }
        }
        this.getResourceManager().addResource(bean);
        response.setResult(IResponseBuilder.SUCCESS);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("error in addResource", t);
        throw new ApsSystemException("Error into API method", t);
    } finally {
        if (null != bean && null != bean.getFile()) {
            bean.getFile().delete();
        }
    }
    return response;
}
Also used : Pattern(java.util.regex.Pattern) UserDetails(com.agiletec.aps.system.services.user.UserDetails) Matcher(java.util.regex.Matcher) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) BaseResourceDataBean(com.agiletec.plugins.jacms.aps.system.services.resource.model.BaseResourceDataBean) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 9 with ApiException

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

the class ApiEntityTypeInterface method addEntityType.

public StringApiResponse addEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        IEntityManager manager = this.getEntityManager();
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
        if (null != masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' already exists");
        }
        if (typeCode == null || typeCode.length() != 3) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Invalid type code - '" + typeCode + "'");
        }
        Map<String, AttributeInterface> attributes = manager.getEntityAttributePrototypes();
        IApsEntity newEntityType = jaxbEntityType.buildEntityType(manager.getEntityClass(), attributes);
        this.checkNewEntityType(jaxbEntityType, newEntityType, response);
        ((IEntityTypesConfigurer) manager).addEntityPrototype(newEntityType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error extracting entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityType");
        throw new ApsSystemException("Error extracting entity type", t);
    }
    return response;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) StringApiResponse(org.entando.entando.aps.system.services.api.model.StringApiResponse) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 10 with ApiException

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

the class ApiEntityTypeInterface method getEntityType.

public JAXBEntityType getEntityType(Properties properties) throws Throwable {
    JAXBEntityType jaxbEntityType = null;
    try {
        IEntityManager manager = this.getEntityManager();
        String typeCode = properties.getProperty(this.getTypeCodeParamName());
        IApsEntity masterEntityType = manager.getEntityPrototype(typeCode);
        if (null == masterEntityType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' does not exist");
        }
        jaxbEntityType = this.createJAXBEntityType(masterEntityType);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error extracting entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityType");
        throw new ApsSystemException("Error extracting entity type", t);
    }
    return jaxbEntityType;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) 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