Search in sources :

Example 6 with IEntityManager

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

the class AbstractEntityService method updateEntityType.

protected synchronized O updateEntityType(String entityManagerCode, EntityTypeDtoRequest request, BindingResult bindingResult) {
    IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
    try {
        if (null == entityManager.getEntityPrototype(request.getCode())) {
            this.addError(EntityTypeValidator.ERRCODE_ENTITY_TYPE_DOES_NOT_EXIST, bindingResult, new String[] { request.getCode() }, "entityType.notExists");
            return null;
        }
        IDtoBuilder<I, O> builder = this.getEntityTypeFullDtoBuilder(entityManager);
        I entityPrototype = this.createEntityType(entityManager, request, bindingResult);
        if (bindingResult.hasErrors()) {
            return null;
        } else {
            ((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entityPrototype);
            I newPrototype = (I) entityManager.getEntityPrototype(request.getCode());
            O newType = builder.convert(newPrototype);
            newType.setStatus(String.valueOf(entityManager.getStatus(request.getCode())));
            return newType;
        }
    } catch (Throwable e) {
        logger.error("Error updating entity type", e);
        throw new RestServerError("error updating entity type", e);
    }
}
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 7 with IEntityManager

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

the class AbstractEntityService method extractEntityManager.

protected IEntityManager extractEntityManager(String entityManagerCode) {
    IEntityManager entityManager = null;
    List<IEntityManager> managers = this.getEntityManagers();
    for (IEntityManager manager : managers) {
        if (((IManager) manager).getName().equals(entityManagerCode)) {
            entityManager = manager;
            break;
        }
    }
    if (null == entityManager) {
        logger.warn("no entity manager found with code {}", entityManagerCode);
        throw new RestRourceNotFoundException("entityManagerCode", entityManagerCode);
    }
    return entityManager;
}
Also used : RestRourceNotFoundException(org.entando.entando.aps.system.exception.RestRourceNotFoundException) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager)

Example 8 with IEntityManager

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

the class TestEntityManagersAction method executeSaveAttribute.

private String executeSaveAttribute(String username, String attributeName, String attributeTypeCode, String entityTypeCode, int strutsAction, Object maxLength, Object minLength, String entityManagerName) throws Throwable {
    IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
    IApsEntity entityType = entityManager.getEntityPrototype(entityTypeCode);
    this.setUserOnSession(username);
    this.initAction("/do/Entity/Attribute", "saveAttribute");
    this.addParameter("attributeName", attributeName);
    this.addParameter("strutsAction", strutsAction);
    this.addParameter("attributeTypeCode", attributeTypeCode);
    if (null != maxLength) {
        this.addParameter("maxLength", maxLength.toString());
    }
    if (null != minLength) {
        this.addParameter("minLength", minLength.toString());
    }
    this.getRequest().getSession().setAttribute(IEntityTypeConfigAction.ENTITY_TYPE_ON_EDIT_SESSION_PARAM, entityType);
    this.getRequest().getSession().setAttribute(IEntityTypeConfigAction.ENTITY_TYPE_MANAGER_SESSION_PARAM, entityManagerName);
    return this.executeAction();
}
Also used : IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 9 with IEntityManager

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

the class TestEntityManagersAction method testSaveNewAttribute.

public void testSaveNewAttribute() throws Throwable {
    // Search an entity manager
    String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
    if (null == defNames || defNames.length == 0)
        return;
    String entityManagerName = defNames[0];
    IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
    // get the entites managed by the ApsEntityManager
    Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
    if (null == entities || entities.size() == 0)
        return;
    List<String> enitiesTypeCodes = new ArrayList<String>();
    enitiesTypeCodes.addAll(entities.keySet());
    // get the first entity type code available
    String entityTypeCode = enitiesTypeCodes.get(0);
    try {
        // wrong name
        String attributeName = "wrong name";
        String attributeTypeCode = "Monotext";
        int strutsAction = ApsAdminSystemConstants.ADD;
        String result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
        assertEquals(Action.INPUT, result);
        EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
        Map<String, List<String>> fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("attributeName"));
        // wrong length
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 3, 5, entityManagerName);
        assertEquals(Action.INPUT, result);
        fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("minLength"));
        // insert ok
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 5, 3, entityManagerName);
        assertEquals(Action.SUCCESS, result);
        IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
        assertTrue(entity.getAttributeMap().containsKey("right_name"));
        // duplicate attribute name
        attributeName = "right_name";
        result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
        assertEquals(Action.INPUT, result);
        fieldErrors = action.getFieldErrors();
        assertEquals(1, fieldErrors.size());
        assertTrue(fieldErrors.containsKey("attributeName"));
    } catch (Throwable t) {
    // nothing to do
    } finally {
        IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
        entity.getAttributeMap().remove("right_name");
        ((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entity);
    }
}
Also used : ArrayList(java.util.ArrayList) IEntityManager(com.agiletec.aps.system.common.entity.IEntityManager) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ArrayList(java.util.ArrayList) List(java.util.List) IEntityTypesConfigurer(com.agiletec.aps.system.common.entity.IEntityTypesConfigurer) EntityAttributeConfigAction(com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)

Example 10 with IEntityManager

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

the class EntityManagersAction method reloadEntityManagerReferences.

@Override
public String reloadEntityManagerReferences() {
    try {
        String entityManagerName = this.getEntityManagerName();
        IEntityManager entityManager = (IEntityManager) this.getBeanFactory().getBean(entityManagerName);
        String typeCode = null;
        entityManager.reloadEntitiesReferences(typeCode);
    } catch (Throwable t) {
        _logger.error("reloadEntityManagerReferences", t);
        // ApsSystemUtils.logThrowable(t, this, "reloadEntityManagerReferences");
        return FAILURE;
    }
    return SUCCESS;
}
Also used : 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