Search in sources :

Example 1 with DataObjectModel

use of org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel in project entando-core by entando.

the class DataObjectService method checkModel.

private boolean checkModel(boolean isDefault, String typeCode, String modelIdString, BindingResult bindingResult) {
    if (StringUtils.isEmpty(modelIdString)) {
        return false;
    }
    Long longId = null;
    try {
        longId = Long.parseLong(modelIdString);
    } catch (Exception e) {
        this.addError((isDefault ? DataTypeValidator.ERRCODE_INVALID_DEFAULT_MODEL : DataTypeValidator.ERRCODE_INVALID_LIST_MODEL), bindingResult, new String[] { typeCode, modelIdString }, "dataType.modelId.invalid");
        return false;
    }
    DataObjectModel model = this.getDataObjectModelManager().getDataObjectModel(longId);
    if (null == model) {
        this.addError((isDefault ? DataTypeValidator.ERRCODE_DEFAULT_MODEL_DOES_NOT_EXIST : DataTypeValidator.ERRCODE_LIST_MODEL_DOES_NOT_EXIST), bindingResult, new String[] { typeCode, modelIdString }, "dataType.modelId.doesNotExist");
        return false;
    } else if (model.getDataType().equals(typeCode)) {
        this.addError((isDefault ? DataTypeValidator.ERRCODE_DEFAULT_MODEL_MISMATCH : DataTypeValidator.ERRCODE_LIST_MODEL_MISMATCH), bindingResult, new String[] { typeCode, modelIdString, model.getDataType() }, "dataType.modelId.mismatch");
        return false;
    }
    return true;
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 2 with DataObjectModel

use of org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel in project entando-core by entando.

the class ApiDataObjectTypeInterface method checkDataObjectModel.

private boolean checkDataObjectModel(Integer modelId, DataObject dataObjectType, StringApiResponse response) {
    if (null == modelId) {
        return true;
    }
    DataObjectModel contentModel = this.getDataObjectModelManager().getDataObjectModel(modelId);
    if (null == contentModel) {
        ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject model with id '" + modelId + "' does not exist", Response.Status.ACCEPTED);
        response.addError(error);
        return false;
    }
    if (!dataObjectType.getTypeCode().equals(contentModel.getDataType())) {
        ApiError error = new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "DataObject model with id '" + modelId + "' is for DataObjects of type '" + contentModel.getDataType() + "'", Response.Status.ACCEPTED);
        response.addError(error);
        return false;
    }
    return true;
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 3 with DataObjectModel

use of org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel in project entando-core by entando.

the class ApiDataObjectModelInterface method getModels.

public StringListApiResponse getModels(Properties properties) throws ApiException, Throwable {
    StringListApiResponse response = new StringListApiResponse();
    try {
        List<DataObjectModel> models = null;
        String dataTypeParam = properties.getProperty("dataType");
        String dataType = (null != dataTypeParam && dataTypeParam.trim().length() > 0) ? dataTypeParam.trim() : null;
        if (null != dataType && null == this.getDataObjectManager().getSmallDataTypesMap().get(dataType)) {
            ApiError error = new ApiError(IApiErrorCodes.API_PARAMETER_VALIDATION_ERROR, "Content Type " + dataType + " does not exist", Response.Status.CONFLICT);
            response.addError(error);
            dataType = null;
        }
        if (null != dataType) {
            models = this.getDataObjectModelManager().getModelsForDataObjectType(dataType);
        } else {
            models = this.getDataObjectModelManager().getDataObjectModels();
        }
        List<String> list = new ArrayList<String>();
        if (null != models) {
            for (int i = 0; i < models.size(); i++) {
                DataObjectModel model = models.get(i);
                list.add(String.valueOf(model.getId()));
            }
        }
        response.setResult(list, null);
    } catch (Throwable t) {
        _logger.error("Error loading models", t);
        throw new ApsSystemException("Error loading models", t);
    }
    return response;
}
Also used : StringListApiResponse(org.entando.entando.aps.system.services.api.model.StringListApiResponse) ArrayList(java.util.ArrayList) DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 4 with DataObjectModel

use of org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel 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 5 with DataObjectModel

use of org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel in project entando-core by entando.

the class BaseDataObjectRenderer method getModelShape.

protected String getModelShape(long modelId) {
    DataObjectModel model = this.getDataObjectModelManager().getDataObjectModel(modelId);
    String shape = null;
    if (model != null) {
        shape = model.getShape();
    }
    if (shape == null) {
        shape = "DataObject model " + modelId + " undefined";
        _logger.error("DataObject model {} undefined", modelId);
    }
    return shape;
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel)

Aggregations

DataObjectModel (org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel)24 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)4 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 RequestContext (com.agiletec.aps.system.RequestContext)1 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)1 SmallDataType (org.entando.entando.aps.system.services.dataobject.model.SmallDataType)1 DataObjectRenderizationInfo (org.entando.entando.aps.system.services.dataobjectdispenser.DataObjectRenderizationInfo)1 Cache (org.springframework.cache.Cache)1