use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.
the class TestContentManager method testLoadOrderedPublicEvents_4.
public void testLoadOrderedPublicEvents_4() throws Throwable {
Content masterContent = this._contentManager.loadContent("EVN193", true);
masterContent.setId(null);
DateAttribute dateAttribute = (DateAttribute) masterContent.getAttribute("DataInizio");
dateAttribute.setDate(DateConverter.parseDate("17/06/2019", "dd/MM/yyyy"));
try {
this._contentManager.saveContent(masterContent);
this._contentManager.insertOnLineContent(masterContent);
this.waitNotifyingThread();
EntitySearchFilter filterForDate = new EntitySearchFilter("DataInizio", true);
filterForDate.setOrder(EntitySearchFilter.DESC_ORDER);
EntitySearchFilter[] filters = { filterForDate };
List<String> contents = _contentManager.loadPublicContentsId("EVN", null, filters, null);
String[] expectedFreeOrderedContentsId = { "EVN194", masterContent.getId(), "EVN193", "EVN24", "EVN23", "EVN25", "EVN20", "EVN21", "EVN192", "EVN191" };
assertEquals(expectedFreeOrderedContentsId.length, contents.size());
for (int i = 0; i < expectedFreeOrderedContentsId.length; i++) {
assertEquals(expectedFreeOrderedContentsId[i], contents.get(i));
}
} catch (Throwable t) {
throw t;
} finally {
if (null != masterContent.getId() && !"EVN193".equals(masterContent.getId())) {
this._contentManager.removeOnLineContent(masterContent);
this._contentManager.deleteContent(masterContent);
}
}
}
use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute 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.DateAttribute in project entando-core by entando.
the class DateAttributeValidationRules method validate.
@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
if (this.isEmpty()) {
return errors;
}
try {
Date attributeValue = ((DateAttribute) attribute).getDate();
if (null == attributeValue) {
return errors;
}
Date startValue = (this.getRangeStart() != null) ? (Date) this.getRangeStart() : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
if (null != startValue && attributeValue.before(startValue)) {
AttributeFieldError error = new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
String allowedDate = DateConverter.getFormattedDate(startValue, DATE_PATTERN);
error.setMessage("Date less than " + allowedDate);
errors.add(error);
}
Date endValue = (this.getRangeEnd() != null) ? (Date) this.getRangeEnd() : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
if (null != endValue && attributeValue.after(endValue)) {
AttributeFieldError error = new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
String allowedDate = DateConverter.getFormattedDate(endValue, DATE_PATTERN);
error.setMessage("Date greater than " + allowedDate);
errors.add(error);
}
Date value = (this.getValue() != null) ? (Date) this.getValue() : this.getOtherAttributeValue(attribute, this.getValueAttribute());
if (null != value && !attributeValue.equals(value)) {
AttributeFieldError error = new AttributeFieldError(attribute, FieldError.NOT_EQUALS_THAN_ALLOWED, tracer);
String allowedDate = DateConverter.getFormattedDate(value, DATE_PATTERN);
error.setMessage("Date not equals than " + allowedDate);
errors.add(error);
}
} catch (Throwable t) {
_logger.error("Error validating Attribute '{}'", attribute.getName(), t);
throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
}
return errors;
}
use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute 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.DateAttribute in project entando-core by entando.
the class UserProfileManagerIntegrationTest method createProfile.
private IUserProfile createProfile(String name, String surname, String email, Date birthdate, String language) {
IUserProfile profile = this.profileManager.getDefaultProfileType();
MonoTextAttribute nameAttr = (MonoTextAttribute) profile.getAttribute("fullname");
nameAttr.setText(name + " " + surname);
MonoTextAttribute emailAttr = (MonoTextAttribute) profile.getAttribute("email");
emailAttr.setText(email);
DateAttribute birthdateAttr = (DateAttribute) profile.getAttribute("birthdate");
birthdateAttr.setDate(birthdate);
MonoTextAttribute languageAttr = (MonoTextAttribute) profile.getAttribute("language");
languageAttr.setText(language);
((UserProfile) profile).setPublicProfile(true);
return profile;
}
Aggregations