use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class EntityTypesAction method checkDelete.
private String checkDelete() throws Throwable {
IApsEntity entityType = this.getEntityPrototype(this.getEntityTypeCode());
if (null == entityType) {
String[] args = { this.getEntityTypeCode() };
this.addFieldError("entityTypeCode", this.getText("error.entityTypeCode.is.null", args));
return INPUT;
}
EntitySearchFilter typeCodeFilter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, entityType.getTypeCode(), false);
EntitySearchFilter[] filters = { typeCodeFilter };
List<String> entityIds = this.getEntityManager().searchId(filters);
if (null != entityIds && !entityIds.isEmpty()) {
this.setReferences(entityIds);
return "hasReferences";
}
return null;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class DataObjectModelValidator method validateBody.
public int validateBody(DataObjectModelRequest request, boolean isPut, Errors errors) {
Long dataModelId = Long.parseLong(request.getModelId());
String typeCode = request.getType();
try {
IApsEntity prototype = this.dataObjectManager.getEntityPrototype(typeCode);
if (null == prototype) {
errors.rejectValue("type", (isPut) ? ERRCODE_PUT_DATAOBJECTTYPE_DOES_NOT_EXIST : ERRCODE_POST_DATAOBJECTTYPE_DOES_NOT_EXIST, new String[] { typeCode }, "dataObjectModel.type.doesNotExist");
return 404;
}
if (StringUtils.isEmpty(request.getModel())) {
errors.rejectValue("model", ERRCODE_DATAOBJECT_MODEL_INVALID, new String[] {}, "dataObjectModel.model.notBlank");
return 400;
}
if (isPut) {
DataObjectModel dataModel = this.dataObjectModelManager.getDataObjectModel(dataModelId);
if (null == dataModel) {
errors.rejectValue("modelId", ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, new String[] { String.valueOf(dataModelId) }, "dataObjectModel.doesNotExist");
return 404;
} else if (!dataModel.getDataType().equals(typeCode)) {
errors.rejectValue("type", ERRCODE_PUT_EXTRACTED_MISMATCH, new String[] { typeCode, dataModel.getDataType() }, "dataObjectModel.type.doesNotMachWithModel");
return 400;
}
}
} catch (Exception e) {
throw new RuntimeException("Error extracting model", e);
}
return 0;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class FilterUtils method getUserFilter.
public UserFilterOptionBean getUserFilter(String dataObjectType, IEntityFilterBean bean, IDataObjectManager dataObjectManager, String dateFormat, RequestContext reqCtx) {
UserFilterOptionBean filter = null;
try {
IApsEntity prototype = dataObjectManager.createDataObject(dataObjectType);
Properties props = new Properties();
props.setProperty(UserFilterOptionBean.PARAM_KEY, bean.getKey());
props.setProperty(UserFilterOptionBean.PARAM_IS_ATTRIBUTE_FILTER, String.valueOf(bean.isAttributeFilter()));
Lang currentLang = (Lang) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_LANG);
Integer currentFrame = (Integer) reqCtx.getExtraParam(SystemConstants.EXTRAPAR_CURRENT_FRAME);
filter = new UserFilterOptionBean(props, prototype, currentFrame, currentLang, dateFormat, reqCtx.getRequest());
} catch (Throwable t) {
_logger.error("Error creating user filter", t);
// ApsSystemUtils.logThrowable(t, FilterUtils.class, "getUserFilter", "Error creating user filter");
}
return filter;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class AbstractEntityService method getShortEntityTypes.
protected PagedMetadata<EntityTypeShortDto> getShortEntityTypes(String entityManagerCode, RestListRequest requestList) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
List<IApsEntity> entityTypes = new ArrayList<>(entityManager.getEntityPrototypes().values());
Map<String, String> fieldMapping = this.getEntityTypeFieldNameMapping();
entityTypes.stream().filter(i -> this.filterObjects(i, requestList.getFilter(), fieldMapping));
Collections.sort(entityTypes, new BeanComparator(this.getFieldName(requestList.getSort(), fieldMapping)));
if (!RestListRequest.DIRECTION_VALUE_DEFAULT.equals(requestList.getDirection())) {
Collections.reverse(entityTypes);
}
List<IApsEntity> sublist = requestList.getSublist(entityTypes);
SearcherDaoPaginatedResult<IApsEntity> result = new SearcherDaoPaginatedResult(entityTypes.size(), sublist);
PagedMetadata<EntityTypeShortDto> pagedMetadata = new PagedMetadata<>(requestList, result);
List<EntityTypeShortDto> body = this.getEntityTypeShortDtoBuilder().convert(sublist);
for (EntityTypeShortDto entityTypeShortDto : body) {
String code = entityTypeShortDto.getCode();
entityTypeShortDto.setStatus(String.valueOf(entityManager.getStatus(code)));
}
pagedMetadata.setBody(body);
return pagedMetadata;
}
use of com.agiletec.aps.system.common.entity.model.IApsEntity in project entando-core by entando.
the class AbstractEntityService method deleteEntityType.
protected void deleteEntityType(String entityManagerCode, String entityTypeCode) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
try {
IApsEntity entityType = entityManager.getEntityPrototype(entityTypeCode);
if (null == entityType) {
return;
}
List<String> ids = entityManager.searchId(entityTypeCode, null);
if (null != ids && ids.size() > 0) {
BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(entityType, "entityType");
bindingResult.reject(EntityTypeValidator.ERRCODE_ENTITY_TYPE_REFERENCES, new Object[] { entityTypeCode }, "entityType.cannot.delete.references");
throw new ValidationConflictException(bindingResult);
}
((IEntityTypesConfigurer) entityManager).removeEntityPrototype(entityTypeCode);
} catch (ApsSystemException e) {
logger.error("Error in delete entityType {}", entityTypeCode, e);
throw new RestServerError("error in delete entityType", e);
}
}
Aggregations