Search in sources :

Example 16 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 17 with IApsEntity

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

the class TestEntityManagersAction method testGetEntityPrototypes.

public void testGetEntityPrototypes() throws Throwable {
    String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
    if (null == defNames || defNames.length == 0)
        return;
    this.setUserOnSession("admin");
    this.initAction("/do/Entity", "viewEntityTypes");
    this.addParameter("entityManagerName", defNames[0]);
    String result = this.executeAction();
    assertEquals(Action.SUCCESS, result);
    IEntityTypesAction action = (IEntityTypesAction) this.getAction();
    List<IApsEntity> entityPrototypes = action.getEntityPrototypes();
    assertNotNull(entityPrototypes);
    assertTrue(entityPrototypes.size() >= 0);
}
Also used : IEntityTypesAction(com.agiletec.apsadmin.system.entity.type.IEntityTypesAction) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 18 with IApsEntity

use of com.agiletec.aps.system.common.entity.model.IApsEntity 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 19 with IApsEntity

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

the class ApsEntityManager method updateEntityPrototype.

/**
 * Update an entity prototype on the catalog.
 *
 * @param entityType The entity type to update.
 * @throws ApsSystemException In case of error.
 */
@Override
public void updateEntityPrototype(IApsEntity entityType) throws ApsSystemException {
    if (null == entityType) {
        throw new ApsSystemException("Invalid entity type to update");
    }
    Map<String, IApsEntity> entityTypes = this.getEntityTypes();
    IApsEntity oldEntityType = entityTypes.get(entityType.getTypeCode());
    if (null == oldEntityType) {
        throw new ApsSystemException("No entity type to update with code '" + entityType.getTypeCode() + "' where found");
    }
    entityTypes.put(entityType.getTypeCode(), entityType);
    this.updateEntityPrototypes(entityTypes);
    this.verifyReloadingNeeded(oldEntityType, entityType);
    this.notifyEntityTypesChanging(oldEntityType, entityType, EntityTypesChangingEvent.UPDATE_OPERATION_CODE);
}
Also used : ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity)

Example 20 with IApsEntity

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

the class ApsEntityManager method getEntityPrototype.

@Override
public IApsEntity getEntityPrototype(String typeCode) {
    IApsEntity prototype = null;
    try {
        IApsEntity mainPrototype = this.getEntityTypeFactory().extractEntityType(typeCode, this.getEntityClass(), this.getConfigItemName(), this.getEntityTypeDom(), super.getName(), this.getEntityDom());
        if (null == mainPrototype) {
            return null;
        }
        prototype = mainPrototype.getEntityPrototype();
    } catch (Exception e) {
        logger.error("Error while extracting entity type {}", typeCode, e);
        throw new RuntimeException("Error while extracting entity type " + typeCode, e);
    }
    return prototype;
}
Also used : IApsEntity(com.agiletec.aps.system.common.entity.model.IApsEntity) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Aggregations

IApsEntity (com.agiletec.aps.system.common.entity.model.IApsEntity)70 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)24 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)16 IEntityManager (com.agiletec.aps.system.common.entity.IEntityManager)12 IEntityTypesConfigurer (com.agiletec.aps.system.common.entity.IEntityTypesConfigurer)11 ApiException (org.entando.entando.aps.system.services.api.model.ApiException)11 ArrayList (java.util.ArrayList)9 StringApiResponse (org.entando.entando.aps.system.services.api.model.StringApiResponse)6 EntitySearchFilter (com.agiletec.aps.system.common.entity.model.EntitySearchFilter)5 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)4 Lang (com.agiletec.aps.system.services.lang.Lang)4 List (java.util.List)4 BeanComparator (org.apache.commons.beanutils.BeanComparator)4 ListAttribute (com.agiletec.aps.system.common.entity.model.attribute.ListAttribute)3 ListAttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.ListAttributeInterface)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 IUserProfile (org.entando.entando.aps.system.services.userprofile.model.IUserProfile)3 Widget (com.agiletec.aps.system.services.page.Widget)2 ApsProperties (com.agiletec.aps.util.ApsProperties)2 EntityAttributeConfigAction (com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction)2