Search in sources :

Example 1 with DefaultJAXBAttributeType

use of com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType in project entando-core by entando.

the class JAXBEntityType method buildEntityType.

public IApsEntity buildEntityType(Class entityClass, Map<String, AttributeInterface> attributes) throws ApiException, Throwable {
    List<ApiError> errors = new ArrayList<ApiError>();
    IApsEntity entityType = null;
    try {
        entityType = (IApsEntity) entityClass.newInstance();
        entityType.setTypeCode(this.getTypeCode());
        entityType.setTypeDescr(this.getTypeDescription());
        List<DefaultJAXBAttributeType> jabxAttributes = this.getAttributes();
        for (int i = 0; i < jabxAttributes.size(); i++) {
            try {
                DefaultJAXBAttributeType jaxbAttributeType = jabxAttributes.get(i);
                AttributeInterface attribute = jaxbAttributeType.createAttribute(attributes);
                if (null != entityType.getAttribute(attribute.getName())) {
                    throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "Attribute '" + attribute.getName() + "' already defined");
                }
                entityType.addAttribute(attribute);
            } catch (ApiException e) {
                errors.addAll(e.getErrors());
            }
        }
    } catch (Throwable t) {
        _logger.error("error in buildEntityType", t);
        // ApsSystemUtils.logThrowable(t, this, "buildEntityType");
        throw t;
    }
    if (!errors.isEmpty())
        throw new ApiException(errors);
    return entityType;
}
Also used : ArrayList(java.util.ArrayList) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApiError(org.entando.entando.aps.system.services.api.model.ApiError) DefaultJAXBAttributeType(com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Aggregations

IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)1 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 DefaultJAXBAttributeType (com.agiletec.aps.system.common.entity.model.attribute.DefaultJAXBAttributeType)1 ArrayList (java.util.ArrayList)1 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)1 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)1