use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class DataObjectModelAction method getAllowedAttributeMethods.
public List<String> getAllowedAttributeMethods(DataObject prototype, String attributeName) {
List<String> methods = new ArrayList<String>();
try {
AttributeInterface attribute = (AttributeInterface) prototype.getAttribute(attributeName);
if (null == attribute) {
throw new ApsSystemException("Null Attribute '" + attributeName + "' for Data Type '" + prototype.getTypeCode() + "' - '" + prototype.getTypeDescr());
}
String methodsString = this.getAllowedPublicAttributeMethods().getProperty(attribute.getType());
if (null != methodsString) {
String[] methodsArray = methodsString.split(";");
methods = Arrays.asList(methodsArray);
} else {
BeanInfo beanInfo = Introspector.getBeanInfo(attribute.getClass(), AbstractAttribute.class);
PropertyDescriptor[] prDescrs = beanInfo.getPropertyDescriptors();
for (int i = 0; i < prDescrs.length; i++) {
PropertyDescriptor propertyDescriptor = prDescrs[i];
if (null != propertyDescriptor.getReadMethod()) {
methods.add(propertyDescriptor.getDisplayName());
}
}
}
} catch (Throwable t) {
_logger.error("error in getAllowedAttributeMethods", t);
}
return methods;
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface 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.AttributeInterface in project entando-core by entando.
the class TestLinkAttributeAction method testChooseLink_2.
public void testChooseLink_2() throws Throwable {
String contentId = "EVN191";
String contentOnSessionMarker = this.extractSessionMarker(contentId, ApsAdminSystemConstants.EDIT);
this.executeEdit(contentId, "admin");
this.initContentAction("/do/jacms/Content", "chooseLink", contentOnSessionMarker);
this.addParameter("attributeName", "LinkCorrelati");
this.addParameter("elementIndex", "0");
this.addParameter("langCode", "it");
String result = this.executeAction();
// FALLIMENTO PER LISTA VUOTA
assertEquals(BaseAction.FAILURE, result);
Content currentContent = this.getContentOnEdit(contentOnSessionMarker);
MonoListAttribute monoListAttribute = (MonoListAttribute) currentContent.getAttribute("LinkCorrelati");
List<AttributeInterface> attributes = monoListAttribute.getAttributes();
assertEquals(0, attributes.size());
this.initContentAction("/do/jacms/Content", "addListElement", contentOnSessionMarker);
this.addParameter("attributeName", "LinkCorrelati");
this.addParameter("listLangCode", "it");
result = this.executeAction();
assertEquals("chooseLink", result);
currentContent = this.getContentOnEdit(contentOnSessionMarker);
monoListAttribute = (MonoListAttribute) currentContent.getAttribute("LinkCorrelati");
attributes = monoListAttribute.getAttributes();
assertEquals(1, attributes.size());
this.initContentAction("/do/jacms/Content", "chooseLink", contentOnSessionMarker);
this.addParameter("attributeName", "LinkCorrelati");
this.addParameter("elementIndex", "0");
this.addParameter("langCode", "it");
result = this.executeAction();
assertEquals(Action.SUCCESS, result);
HttpSession session = this.getRequest().getSession();
assertEquals("LinkCorrelati", session.getAttribute(ILinkAttributeActionHelper.ATTRIBUTE_NAME_SESSION_PARAM));
assertEquals("it", session.getAttribute(ILinkAttributeActionHelper.LINK_LANG_CODE_SESSION_PARAM));
assertNotNull(session.getAttribute(ILinkAttributeActionHelper.LIST_ELEMENT_INDEX_SESSION_PARAM));
assertEquals(new Integer(0), session.getAttribute(ILinkAttributeActionHelper.LIST_ELEMENT_INDEX_SESSION_PARAM));
currentContent = this.getContentOnEdit(contentOnSessionMarker);
assertNotNull(currentContent);
assertEquals("EVN191", currentContent.getId());
assertEquals("Evento 1", currentContent.getDescription());
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class LinkAttributeActionHelper method joinLink.
@Override
public void joinLink(String[] destinations, int destType, HttpServletRequest request) {
HttpSession session = request.getSession();
Content currentContent = getContent(request);
String attributeName = (String) session.getAttribute(ATTRIBUTE_NAME_SESSION_PARAM);
AttributeInterface attribute = (AttributeInterface) currentContent.getAttribute(attributeName);
joinLink(attribute, destinations, destType, request);
removeSessionParams(session);
}
use of com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface in project entando-core by entando.
the class LinkAttributeActionHelper method initSessionParams.
@Override
public void initSessionParams(ILinkAttributeAction action, HttpServletRequest request) {
AttributeInterface attribute = null;
HttpSession session = request.getSession();
if (null != action.getParentAttributeName()) {
attribute = (AttributeInterface) getContent(request).getAttribute(action.getParentAttributeName());
session.setAttribute(ATTRIBUTE_NAME_SESSION_PARAM, action.getParentAttributeName());
session.setAttribute(INCLUDED_ELEMENT_NAME_SESSION_PARAM, action.getAttributeName());
} else {
attribute = (AttributeInterface) getContent(request).getAttribute(action.getAttributeName());
session.setAttribute(ATTRIBUTE_NAME_SESSION_PARAM, action.getAttributeName());
}
if (action.getElementIndex() >= 0) {
session.setAttribute(LIST_ELEMENT_INDEX_SESSION_PARAM, new Integer(action.getElementIndex()));
}
session.setAttribute(LINK_LANG_CODE_SESSION_PARAM, action.getLangCode());
LinkAttribute linkAttribute = (LinkAttribute) getLinkAttribute(attribute, request);
session.setAttribute(SYMBOLIC_LINK_SESSION_PARAM, linkAttribute.getSymbolicLink());
}
Aggregations