Search in sources :

Example 1 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager 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 2 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager 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)

Example 3 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.

the class ApiEntityTypeInterface method getEntityTypes.

public StringListApiResponse getEntityTypes(Properties properties) throws Throwable {
    StringListApiResponse response = new StringListApiResponse();
    try {
        IEntityManager manager = this.getEntityManager();
        Map<String, IApsEntity> prototypes = manager.getEntityPrototypes();
        List<String> codes = new ArrayList<String>();
        codes.addAll(prototypes.keySet());
        Collections.sort(codes);
        response.setResult(codes, null);
    } catch (Throwable t) {
        _logger.error("Error extracting entity type codes", t);
        // ApsSystemUtils.logThrowable(t, this, "getEntityTypes");
        throw new ApsSystemException("Error extracting entity type codes", t);
    }
    return response;
}
Also used : StringListApiResponse(org.entando.entando.aps.system.services.api.model.StringListApiResponse) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException)

Example 4 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.

the class AbstractEntityService method addEntityType.

protected synchronized O addEntityType(String entityManagerCode, EntityTypeDtoRequest bodyRequest, BindingResult bindingResult) {
    O response = null;
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        IDtoBuilder<I, O> builder = this.getEntityTypeFullDtoBuilder(entityManager);
        if (null != entityManager.getEntityPrototype(bodyRequest.getCode())) {
            this.addError(EntityTypeValidator.ERRCODE_ENTITY_TYPE_ALREADY_EXISTS, bindingResult, new String[] { bodyRequest.getCode() }, "entityType.exists");
        }
        I entityPrototype = this.createEntityType(entityManager, bodyRequest, bindingResult);
        if (bindingResult.hasErrors()) {
            return response;
        } else {
            ((IEntityTypesConfigurer) entityManager).addEntityPrototype(entityPrototype);
            response = builder.convert(entityPrototype);
        }
    } catch (Throwable e) {
        logger.error("Error adding entity type", e);
        throw new RestServerError("error add entity type", e);
    }
    return response;
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) RestServerError(org.entando.entando.aps.system.exception.RestServerError) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 5 with IEntityManager

use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.

the class AbstractEntityService method getFullEntityType.

protected O getFullEntityType(String entityManagerCode, String entityTypeCode) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    I entityType = (I) entityManager.getEntityPrototype(entityTypeCode);
    if (null == entityManager) {
        logger.warn("no entity type found with code {}", entityTypeCode);
        throw new RestRourceNotFoundException("entityTypeCode", entityTypeCode);
    }
    O type = this.convertEntityType(entityManager, entityType);
    type.setStatus(String.valueOf(entityManager.getStatus(entityTypeCode)));
    return type;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager)

Aggregations

IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)25 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)12 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)7 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 ArrayList (java.util.ArrayList)7 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)5 BeanComparator (org.apache.commons.beanutils.BeanComparator)5 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2 RestRourceNotFoundException (org.entando.entando.aps.system.exception.RestRourceNotFoundException)2 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)2 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)1 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)1 SearcherDaoPaginatedResult (com.agiletec.aps.system.common.model.dao.SearcherDaoPaginatedResult)1 List (java.util.List)1 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)1 StringListApiResponse (org.entando.entando.aps.system.services.api.model.StringListApiResponse)1