Search in sources :

Example 11 with IEntityTypesConfigurer

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

Example 12 with IEntityTypesConfigurer

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

the class ApiUserProfileTypeInterface method deleteUserProfileType.

public void deleteUserProfileType(Properties properties) throws ApiException, Throwable {
    try {
        String typeCode = properties.getProperty("typeCode");
        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");
        }
        EntitySearchFilter filter = new EntitySearchFilter(IEntityManager.ENTITY_TYPE_CODE_FILTER_KEY, false, typeCode, false);
        List<String> profileIds = this.getUserProfileManager().searchId(new EntitySearchFilter[] { filter });
        if (null != profileIds && !profileIds.isEmpty()) {
            throw new ApiException(IApiErrorCodes.API_VALIDATION_ERROR, "User profile type '" + typeCode + "' are used into " + profileIds.size() + " profiles");
        }
        ((IEntityTypesConfigurer) this.getUserProfileManager()).removeEntityPrototype(typeCode);
    } catch (ApiException ae) {
        throw ae;
    } catch (Throwable t) {
        _logger.error("Error deleting user Profile type", t);
        // ApsSystemUtils.logThrowable(t, this, "deleteProfileType");
        throw new ApsSystemException("Error deleting user Profile type", t);
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) EntitySearchFilter(com.agiletec.aps.system.common.entity.model.EntitySearchFilter) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) ApiException(org.entando.entando.aps.system.services.api.model.ApiException)

Example 13 with IEntityTypesConfigurer

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

the class TestJacmsEntityManagersAction method addEntityTypeForTest.

private void addEntityTypeForTest(String typeCode, String typeDescr) throws Throwable {
    assertNull(this._contentManager.getEntityPrototype(typeCode));
    IApsEntity prototype = this._contentManager.getEntityPrototype("ART");
    prototype.setTypeCode(typeCode);
    prototype.setTypeDescr(typeDescr);
    ((IEntityTypesConfigurer) this._contentManager).addEntityPrototype(prototype);
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 14 with IEntityTypesConfigurer

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

the class TestJacmsEntityTypeConfigAction method testSaveEntityType.

public void testSaveEntityType() throws Throwable {
    String typeCode = "TST";
    assertNull(this._contentManager.getEntityPrototype(typeCode));
    try {
        IApsEntity prototype = this._contentManager.getEntityPrototype("ART");
        prototype.setTypeCode(typeCode);
        prototype.setTypeDescr("Entity type Description");
        this.getRequest().getSession().setAttribute(IEntityTypeConfigAction.ENTITY_TYPE_MANAGER_SESSION_PARAM, JacmsSystemConstants.CONTENT_MANAGER);
        this.getRequest().getSession().setAttribute(IEntityTypeConfigAction.ENTITY_TYPE_OPERATION_ID_SESSION_PARAM, new Integer(ApsAdminSystemConstants.ADD));
        this.getRequest().getSession().setAttribute(IEntityTypeConfigAction.ENTITY_TYPE_ON_EDIT_SESSION_PARAM, prototype);
        String result = this.executeSaveEntityType(prototype.getTypeCode(), prototype.getTypeDescr());
        assertEquals(Action.SUCCESS, result);
        assertNotNull(this._contentManager.getEntityPrototype(typeCode));
        assertNull(this.getRequest().getSession().getAttribute(IEntityTypeConfigAction.ENTITY_TYPE_ON_EDIT_SESSION_PARAM));
        result = this.executeEditEntityPrototype(typeCode, JacmsSystemConstants.CONTENT_MANAGER);
        assertEquals(Action.SUCCESS, result);
        assertNotNull(this.getRequest().getSession().getAttribute(IEntityTypeConfigAction.ENTITY_TYPE_ON_EDIT_SESSION_PARAM));
    } catch (Throwable t) {
        throw t;
    } finally {
        if (null != this._contentManager.getEntityPrototype(typeCode)) {
            ((IEntityTypesConfigurer) this._contentManager).removeEntityPrototype(typeCode);
        }
    }
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)

Example 15 with IEntityTypesConfigurer

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

the class EntityTypeConfigAction method saveEntityType.

@Override
public String saveEntityType() {
    try {
        IApsEntity entityType = this.getEntityType();
        entityType.setDefaultLang(this.getLangManager().getDefaultLang().getCode());
        if (this.getOperationId() == ApsAdminSystemConstants.ADD) {
            ((IEntityTypesConfigurer) this.getEntityManager()).addEntityPrototype(entityType);
        } else {
            ((IEntityTypesConfigurer) this.getEntityManager()).updateEntityPrototype(entityType);
        }
        String entityManagerName = (String) this.getRequest().getSession().getAttribute(ENTITY_TYPE_MANAGER_SESSION_PARAM);
        this.setEntityManagerName(entityManagerName);
    } catch (Throwable t) {
        _logger.error("error in saveEntityType", t);
        // ApsSystemUtils.logThrowable(t, this, "saveEntityType");
        return FAILURE;
    } finally {
        this.getRequest().getSession().removeAttribute(ENTITY_TYPE_MANAGER_SESSION_PARAM);
        this.getRequest().getSession().removeAttribute(ENTITY_TYPE_OPERATION_ID_SESSION_PARAM);
        this.getRequest().getSession().removeAttribute(ENTITY_TYPE_ON_EDIT_SESSION_PARAM);
    }
    return SUCCESS;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) 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