use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class UserProfile method getValue.
private Object getValue(AttributeInterface attribute) {
if (null == attribute)
return "";
if (attribute.isTextAttribute()) {
return ((ITextAttribute) attribute).getText();
} else if (attribute instanceof NumberAttribute) {
return ((NumberAttribute) attribute).getValue();
} else if (attribute instanceof BooleanAttribute) {
return ((BooleanAttribute) attribute).getValue();
} else if (attribute instanceof DateAttribute) {
return ((DateAttribute) attribute).getDate();
} else if (!attribute.isSimple()) {
String text = "";
List<AttributeInterface> attributes = ((AbstractComplexAttribute) attribute).getAttributes();
for (int i = 0; i < attributes.size(); i++) {
if (i > 0)
text += ",";
AttributeInterface attributeElem = attributes.get(i);
text += this.getValue(attributeElem);
}
return text;
}
return null;
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class TestValidateContent method testValidate_3.
public void testValidate_3() throws Throwable {
try {
Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
emailAttribute.setText("wrongEmailAddress", null);
List<FieldError> errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
assertEquals("Monotext:email", error.getFieldCode());
assertEquals(FieldError.INVALID_FORMAT, error.getErrorCode());
} catch (Throwable t) {
throw t;
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute 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.model.attribute.ITextAttribute in project entando-core by entando.
the class TestListAttributeAction method verifyText.
private void verifyText(List<AttributeInterface> attributes, String[] expected) {
assertEquals(expected.length, attributes.size());
for (int i = 0; i < attributes.size(); i++) {
ITextAttribute textAttribute = (ITextAttribute) attributes.get(i);
assertEquals(expected[i], textAttribute.getText());
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class ContentActionHelper method updateEntity.
@Override
public void updateEntity(IApsEntity entity, HttpServletRequest request) {
Content content = (Content) entity;
try {
if (null != content) {
String descr = request.getParameter("descr");
if (descr != null) {
content.setDescription(descr.trim());
}
String status = request.getParameter("status");
if (status != null) {
content.setStatus(status);
}
if (null == content.getId()) {
String mainGroup = request.getParameter("mainGroup");
if (mainGroup != null) {
request.getSession().setAttribute(ContentActionConstants.SESSION_PARAM_NAME_CURRENT_CONTENT_GROUP, mainGroup);
}
}
super.updateEntity(content, request);
String description = content.getDescription();
if (null == description || description.trim().length() == 0) {
ITextAttribute titleAttribute = (ITextAttribute) content.getAttributeByRole(JacmsSystemConstants.ATTRIBUTE_ROLE_TITLE);
if (null != titleAttribute && StringUtils.isNotEmpty(titleAttribute.getText())) {
content.setDescription(titleAttribute.getText());
}
}
}
} catch (Throwable t) {
_logger.error("ContentActionHelper - updateContent", t);
throw new RuntimeException("Error updating Content", t);
}
}
Aggregations