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