use of com.agiletec.aps.system.common.entity.model.attribute.DateAttribute in project entando-core by entando.
the class EntitySearchFilter method getInstance.
public static EntitySearchFilter getInstance(IApsEntity prototype, Properties props) {
EntitySearchFilter filter = null;
try {
String key = props.getProperty(KEY_PARAM);
String roleName = props.getProperty(ROLE_PARAM);
if (null == key && null == roleName) {
return null;
}
boolean isAttributeFilter = Boolean.parseBoolean(props.getProperty(FILTER_TYPE_PARAM));
filter = new EntitySearchFilter();
boolean isDateAttribute = false;
if (!isAttributeFilter) {
filter.setKey(key);
String dataType = props.getProperty(DATA_TYPE_PARAM);
if (null == dataType) {
dataType = DATA_TYPE_STRING;
}
setValues(filter, props, dataType);
} else {
AttributeInterface attr = null;
if (null != key) {
attr = (AttributeInterface) prototype.getAttribute(key);
filter.setKey(key);
} else {
attr = (AttributeInterface) prototype.getAttributeByRole(roleName);
filter.setRoleName(roleName);
}
filter.setAttributeFilter(true);
if (null != attr) {
String dataType = null;
if (attr instanceof DateAttribute) {
dataType = DATA_TYPE_DATE;
isDateAttribute = true;
} else if (attr instanceof ITextAttribute || attr instanceof BooleanAttribute) {
dataType = DATA_TYPE_STRING;
} else if (attr instanceof NumberAttribute) {
dataType = DATA_TYPE_NUMBER;
}
setValues(filter, props, dataType);
} else
throw new ApsSystemException("ERROR: Entity type '" + prototype.getTypeCode() + "' and attribute '" + key + "' not recognized");
}
if (isDateAttribute) {
String valueDateDelay = props.getProperty(EntitySearchFilter.VALUE_DATE_DELAY_PARAM);
filter.setValueDateDelay(null != valueDateDelay ? Integer.valueOf(valueDateDelay) : null);
String endDateDelay = props.getProperty(EntitySearchFilter.END_DATE_DELAY_PARAM);
filter.setEndDateDelay(null != endDateDelay ? Integer.valueOf(endDateDelay) : null);
String startDateDelay = props.getProperty(EntitySearchFilter.START_DATE_DELAY_PARAM);
filter.setStartDateDelay(null != startDateDelay ? Integer.valueOf(startDateDelay) : null);
}
String order = props.getProperty(EntitySearchFilter.ORDER_PARAM);
filter.setOrder(order);
} catch (ApsSystemException | NumberFormatException t) {
_logger.error("Error on creation of filter instance", t);
throw new RuntimeException("Error on creation of filter instance", t);
}
return filter;
}
Aggregations