Search in sources :

Example 1 with IEntityTypesConfigurer

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

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

the class ApiEntityTypeInterface method updateEntityType.

public StringApiResponse updateEntityType(JAXBEntityType jaxbEntityType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbEntityType.getTypeCode();
        IApsEntity masterUserProfileType = this.getEntityManager().getEntityPrototype(typeCode);
        if (null == masterUserProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, this.getTypeLabel() + " with code '" + typeCode + "' doesn't exist");
        }
        Map<String, AttributeInterface> attributes = this.getEntityManager().getEntityAttributePrototypes();
        IApsEntity entityTypeToUpdate = jaxbEntityType.buildEntityType(this.getEntityManager().getEntityClass(), attributes);
        this.checkEntityTypeToUpdate(jaxbEntityType, entityTypeToUpdate, response);
        ((IEntityTypesConfigurer) this.getEntityManager()).updateEntityPrototype(entityTypeToUpdate);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating entity type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateEntityType");
        throw new ApsSystemException("Error updating entity type", t);
    }
    return response;
}
Also used : 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 3 with IEntityTypesConfigurer

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

the class ApiUserProfileTypeInterface method updateUserProfileType.

public StringApiResponse updateUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null == masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type with code '" + typeCode + "' doesn't exist");
        }
        Map<String, AttributeInterface> attributes = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).updateEntityPrototype(profileType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error updating user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "updateProfileType");
        throw new ApsSystemException("Error updating user profile type", t);
    }
    return response;
}
Also used : 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 4 with IEntityTypesConfigurer

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

the class ApiUserProfileTypeInterface method addUserProfileType.

public StringApiResponse addUserProfileType(JAXBUserProfileType jaxbProfileType) throws Throwable {
    StringApiResponse response = new StringApiResponse();
    try {
        String typeCode = jaxbProfileType.getTypeCode();
        IApsEntity masterProfileType = this.getUserProfileManager().getEntityPrototype(typeCode);
        if (null != masterProfileType) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User Profile type 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 = this.getUserProfileManager().getEntityAttributePrototypes();
        IApsEntity profileType = jaxbProfileType.buildEntityType(this.getUserProfileManager().getEntityClass(), attributes);
        ((IEntityTypesConfigurer) this.getUserProfileManager()).addEntityPrototype(profileType);
        response.setResult(IResponseBuilder.SUCCESS, null);
    } catch (ApiException ae) {
        response.addErrors(ae.getErrors());
        response.setResult(IResponseBuilder.FAILURE, null);
    } catch (Throwable t) {
        _logger.error("Error adding user profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "addProfileType");
        throw new ApsSystemException("Error adding user profile type", t);
    }
    return response;
}
Also used : 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 5 with IEntityTypesConfigurer

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

Aggregations

IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)19 IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)11 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)7 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)6 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)5 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)4 UserDetails (com.agiletec.aps.system.services.user.UserDetails)4 InputStream (java.io.InputStream)4 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)4 AbstractControllerIntegrationTest (org.entando.entando.web.AbstractControllerIntegrationTest)4 Test (org.junit.Test)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 RestServerError (org.entando.entando.aps.system.exception.RestServerError)3 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)2 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)2 UserProfile (org.entando.entando.aps.system.services.userprofile.model.UserProfile)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)1