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;
}
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;
}
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;
}
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);
}
}
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;
}
Aggregations