use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.
the class AbstractEntityService method getShortEntityTypes.
protected PagedMetadata<EntityTypeShortDto> getShortEntityTypes(String entityManagerCode, RestListRequest requestList) {
IEntityManager entityManager = this.extractEntityManager(entityManagerCode);
List<IApsEntity> entityTypes = new ArrayList<>(entityManager.getEntityPrototypes().values());
Map<String, String> fieldMapping = this.getEntityTypeFieldNameMapping();
entityTypes.stream().filter(i -> this.filterObjects(i, requestList.getFilter(), fieldMapping));
Collections.sort(entityTypes, new BeanComparator(this.getFieldName(requestList.getSort(), fieldMapping)));
if (!RestListRequest.DIRECTION_VALUE_DEFAULT.equals(requestList.getDirection())) {
Collections.reverse(entityTypes);
}
List<IApsEntity> sublist = requestList.getSublist(entityTypes);
SearcherDaoPaginatedResult<IApsEntity> result = new SearcherDaoPaginatedResult(entityTypes.size(), sublist);
PagedMetadata<EntityTypeShortDto> pagedMetadata = new PagedMetadata<>(requestList, result);
List<EntityTypeShortDto> body = this.getEntityTypeShortDtoBuilder().convert(sublist);
for (EntityTypeShortDto entityTypeShortDto : body) {
String code = entityTypeShortDto.getCode();
entityTypeShortDto.setStatus(String.valueOf(entityManager.getStatus(code)));
}
pagedMetadata.setBody(body);
return pagedMetadata;
}
use of com.agiletec.aps.system.common.entity.IEntityManager 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);
}
}
use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.
the class EntityTypesInfoTag method getMasterObject.
@Override
protected Object getMasterObject(String keyValue) throws Throwable {
String managerNameValue = (String) super.findValue(keyValue, String.class);
try {
IEntityManager entityManager = (IEntityManager) ApsWebApplicationUtils.getBean(managerNameValue, this.pageContext);
if (null != entityManager) {
List<IApsEntity> entityTypes = new ArrayList<IApsEntity>();
Map<String, IApsEntity> typeMap = entityManager.getEntityPrototypes();
if (null != typeMap) {
BeanComparator c = new BeanComparator(this.getOrderBy());
entityTypes.addAll(typeMap.values());
Collections.sort(entityTypes, c);
}
return entityTypes;
} else {
_logger.debug("Null entity manager : service name '{}'", managerNameValue);
}
} catch (Throwable t) {
String message = "Error extracting entity types : entity manager '" + managerNameValue + "'";
_logger.error("Error extracting entity types : entity manager '{}'", managerNameValue, t);
// ApsSystemUtils.logThrowable(t, this, "getMasterObject", message);
throw new ApsSystemException(message, t);
}
return null;
}
use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.
the class TestEntityManagersAction method testEditAttribute.
public void testEditAttribute() 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);
List<AttributeInterface> attributes = entities.get(entityTypeCode).getAttributeList();
// get the first attribute
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface currentAttribute = attributes.get(i);
String attributeName = currentAttribute.getName();
String result = this.executeEditAttribute("admin", attributeName, entityTypeCode, entityManagerName);
assertEquals(Action.SUCCESS, result);
EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
assertEquals(currentAttribute.getType(), action.getAttributeTypeCode());
assertEquals(currentAttribute.isRequired(), action.getRequired().booleanValue());
assertEquals(currentAttribute.isSearchable(), action.getSearchable().booleanValue());
assertEquals(currentAttribute.getIndexingType().equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT), action.getIndexable().booleanValue());
if (currentAttribute.isTextAttribute()) {
ITextAttribute attr = (ITextAttribute) currentAttribute;
if (attr.getMaxLength() == -1) {
assertNull(action.getMaxLength());
} else {
assertEquals(attr.getMaxLength(), action.getMaxLength().intValue());
}
if (attr.getMinLength() == -1) {
assertNull(action.getMinLength());
} else {
assertEquals(attr.getMinLength(), action.getMinLength().intValue());
}
assertEquals(attr.getRegexp(), action.getRegexp());
}
assertEquals(ApsAdminSystemConstants.EDIT, action.getStrutsAction());
}
}
use of com.agiletec.aps.system.common.entity.IEntityManager in project entando-core by entando.
the class TestEntityManagersAction method testInitEditEntityType.
public void testInitEditEntityType() throws Throwable {
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);
Map<String, IApsEntity> entityPrototypes = entityManager.getEntityPrototypes();
if (null == entityPrototypes || entityPrototypes.size() == 0)
return;
IApsEntity realEntityPrototype = new ArrayList<IApsEntity>(entityPrototypes.values()).get(0);
String result = this.executeInitEditEntityType("supervisorCoach", entityManagerName, realEntityPrototype.getTypeCode());
assertEquals("userNotAllowed", result);
result = this.executeInitEditEntityType("admin", null, realEntityPrototype.getTypeCode());
assertEquals(Action.INPUT, result);
assertEquals(1, this.getAction().getFieldErrors().size());
assertEquals(1, this.getAction().getFieldErrors().get("entityManagerName").size());
if (null == entityPrototypes.get("XXX")) {
result = this.executeInitEditEntityType("admin", entityManagerName, "XXX");
assertEquals("wrongEntityType", result);
assertEquals(1, this.getAction().getFieldErrors().size());
assertEquals(1, this.getAction().getFieldErrors().get("entityTypeCode").size());
}
result = this.executeInitEditEntityType("admin", entityManagerName, null);
assertEquals("wrongEntityType", result);
assertEquals(1, this.getAction().getFieldErrors().size());
assertEquals(1, this.getAction().getFieldErrors().get("entityTypeCode").size());
result = this.executeInitEditEntityType("admin", entityManagerName, realEntityPrototype.getTypeCode());
assertEquals(Action.SUCCESS, result);
}
Aggregations