use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class UserProfileAttributeTag method doStartTag.
@Override
public int doStartTag() throws JspException {
try {
IUserProfile profile = this.getUserProfile();
if (null == profile) {
return super.doStartTag();
}
Object value = null;
if (null != this.getAttributeRoleName()) {
ITextAttribute textAttribute = (ITextAttribute) profile.getAttributeByRole(this.getAttributeRoleName());
value = (null != textAttribute) ? textAttribute.getText() : null;
} else {
value = profile.getValue(this.getAttributeName());
}
if (null == value) {
return super.doStartTag();
}
if (this.getVar() != null) {
this.pageContext.setAttribute(this.getVar(), value);
} else {
if (this.getEscapeXml()) {
out(this.pageContext, this.getEscapeXml(), value);
} else {
this.pageContext.getOut().print(value);
}
}
} catch (Throwable t) {
_logger.error("error in doStartTag", t);
// ApsSystemUtils.logThrowable(t, this, "doStartTag");
throw new JspException("Error during tag initialization", t);
}
return super.doStartTag();
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class UserFilterOptionBean method getEntityFilter.
public EntitySearchFilter getEntityFilter() throws ApsSystemException {
EntitySearchFilter filter = null;
try {
if (!this.isAttributeFilter() || null == this.getFormFieldValues()) {
return null;
}
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute) {
String text = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
filter = new EntitySearchFilter(attribute.getName(), true, text, true);
if (attribute.isMultilingual()) {
filter.setLangCode(this.getCurrentLang().getCode());
}
} else if (attribute instanceof DateAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
Date startDate = DateConverter.parseDate(start, this.getDateFormat());
Date endDate = DateConverter.parseDate(end, this.getDateFormat());
filter = new EntitySearchFilter(attribute.getName(), true, startDate, endDate);
} else if (attribute instanceof BooleanAttribute) {
String value = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String ignore = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
if (null != ignore) {
return null;
} else if (null == value || value.equals("both")) {
// special option for three state Attribute
filter = new EntitySearchFilter(attribute.getName(), true);
filter.setNullOption(true);
} else {
filter = new EntitySearchFilter(attribute.getName(), true, value, false);
}
} else if (attribute instanceof NumberAttribute) {
String start = this.getFormFieldValues().get(this.getFormFieldNames()[0]);
String end = this.getFormFieldValues().get(this.getFormFieldNames()[1]);
BigDecimal startNumber = null;
try {
Integer startNumberInt = Integer.parseInt(start);
startNumber = new BigDecimal(startNumberInt);
} catch (Throwable t) {
}
BigDecimal endNumber = null;
try {
Integer endNumberInt = Integer.parseInt(end);
endNumber = new BigDecimal(endNumberInt);
} catch (Throwable t) {
}
filter = new EntitySearchFilter(attribute.getName(), true, startNumber, endNumber);
}
} catch (Throwable t) {
_logger.error("Error extracting entity search filters", t);
throw new ApsSystemException("Error extracting entity search filters", t);
}
return filter;
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class TestValidateContent method testValidate_4.
public void testValidate_4() throws Throwable {
String shortTitle = "short";
String longTitle = "Titolo che supera la lunghezza massima di cento caratteri; " + "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
try {
Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
textAttribute.setText(shortTitle, "it");
List<FieldError> errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
FieldError error = errors.get(0);
assertEquals("Text:it_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
textAttribute.setText(longTitle, "it");
errors = content.validate(this._groupManager);
assertEquals(1, errors.size());
error = errors.get(0);
assertEquals("Text:it_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
textAttribute.setText(shortTitle, "en");
errors = content.validate(this._groupManager);
assertEquals(2, errors.size());
error = errors.get(0);
assertEquals("Text:it_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
error = errors.get(1);
assertEquals("Text:en_Titolo", error.getFieldCode());
assertEquals(FieldError.INVALID_MIN_LENGTH, 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 UserFilterOptionBean method extractFormParameters.
protected void extractFormParameters(HttpServletRequest request) throws Throwable {
String[] formFieldNames = null;
try {
String frameIdSuffix = (null != this.getCurrentFrame()) ? "_frame" + this.getCurrentFrame().toString() : "";
if (!this.isAttributeFilter()) {
if (this.getKey().equals(KEY_FULLTEXT)) {
String fieldName = TYPE_METADATA + "_fulltext" + frameIdSuffix;
String[] fieldsSuffix = { "", "_option", "_attachSearch" };
formFieldNames = this.extractParams(fieldName, fieldsSuffix, frameIdSuffix, request);
} else if (this.getKey().equals(KEY_CATEGORY)) {
formFieldNames = new String[1];
formFieldNames[0] = TYPE_METADATA + "_category" + frameIdSuffix;
String value = request.getParameter(formFieldNames[0]);
this.addFormValue(formFieldNames[0], value, formFieldNames.length);
}
} else {
AttributeInterface attribute = this.getAttribute();
if (attribute instanceof ITextAttribute) {
String[] fieldsSuffix = { "_textFieldName" };
formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
} else if (attribute instanceof DateAttribute) {
String[] fieldsSuffix = { "_dateStartFieldName", "_dateEndFieldName" };
formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
this.checkRange(formFieldNames);
} else if (attribute instanceof BooleanAttribute) {
String[] fieldsSuffix = { "_booleanFieldName", "_booleanFieldName_ignore", "_booleanFieldName_control" };
formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
} else if (attribute instanceof NumberAttribute) {
String[] fieldsSuffix = { "_numberStartFieldName", "_numberEndFieldName" };
formFieldNames = this.extractAttributeParams(fieldsSuffix, frameIdSuffix, request);
this.checkRange(formFieldNames);
}
}
} catch (Throwable t) {
_logger.error("Error extracting form parameters", t);
throw new ApsSystemException("Error extracting form parameters", t);
}
this.setFormFieldNames(formFieldNames);
}
use of com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute in project entando-core by entando.
the class DataObjectActionHelper method updateEntity.
@Override
public void updateEntity(IApsEntity entity, HttpServletRequest request) {
DataObject dataObject = (DataObject) entity;
try {
if (null != dataObject) {
String descr = request.getParameter("descr");
if (descr != null) {
dataObject.setDescription(descr.trim());
}
String status = request.getParameter("status");
if (status != null) {
dataObject.setStatus(status);
}
if (null == dataObject.getId()) {
String mainGroup = request.getParameter("mainGroup");
if (mainGroup != null) {
request.getSession().setAttribute("dataObjectGroupOnSession", mainGroup);
}
}
super.updateEntity(dataObject, request);
String description = dataObject.getDescription();
if (null == description || description.trim().length() == 0) {
ITextAttribute titleAttribute = (ITextAttribute) dataObject.getAttributeByRole(SystemConstants.DATA_TYPE_ATTRIBUTE_ROLE_TITLE);
if (null != titleAttribute && StringUtils.isNotEmpty(titleAttribute.getText())) {
dataObject.setDescription(titleAttribute.getText());
}
}
}
} catch (Throwable t) {
_logger.error("DataObjectActionHelper - updateDataObject", t);
throw new RuntimeException("Error updating DataObject", t);
}
}
Aggregations