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();
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations