Search in sources :

Example 36 with IApsEntity

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;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter)

Example 37 with IApsEntity

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;
}
Also used : DataObjectModel(org.entando.entando.aps.system.services.dataobjectmodel.DataObjectModel) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 38 with IApsEntity

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;
}
Also used : UserFilterOptionBean(org.entando.entando.aps.system.services.dataobject.widget.UserFilterOptionBean) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) Lang(com.agiletec.aps.system.services.lang.Lang) Properties(java.util.Properties)

Example 39 with IApsEntity

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;
}
Also used : PagedMetadata(org.entando.entando.web.common.model.PagedMetadata) EntityTypeShortDto(org.entando.entando.aps.system.services.entity.model.EntityTypeShortDto) ArrayList(java.util.ArrayList) SearcherDaoPaginatedResult(com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult) BeanComparator(org.apache.commons.beanutils.BeanComparator) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 40 with IApsEntity

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);
    }
}
Also used : BeanPropertyBindingResult(org.springframework.validation.BeanPropertyBindingResult) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) ValidationConflictException(org.entando.entando.web.common.exceptions.ValidationConflictException)

Aggregations

IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)70 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)24 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)12 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)11 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)11 ArrayList (java.util.ArrayList)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 List (java.util.List)4 BeanComparator (org.apache.commons.beanutils.BeanComparator)4 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)3 ListAttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 Widget (com.agiletec.aps.system.services.page.Widget)2 ApsProperties (com.agiletec.aps.util.ApsProperties)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2