String param = term.getParam();
String filter = term.getValue();
if (path.equals("availability")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForEnum(alias + ".currentAvailability.availabilityType", op, filter, AvailabilityType.class,
true));
} else if (path.equals("category")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForEnum(alias + ".resourceType.category", op, filter, ResourceCategory.class, false));
} else if (path.equals("type")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForString(alias + ".resourceType.name", op, filter));
} else if (path.equals("plugin")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForString(alias + ".resourceType.plugin", op, filter));
} else if (path.equals("name")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForString(alias + ".name", op, filter));
} else if (path.equals("version")) {
return new SearchFragment(SearchFragment.Type.WHERE_CLAUSE, //
getJPQLForString(alias + ".version", op, filter));
} else if (path.equals("alerts")) {
return new SearchFragment( //
SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
+ " FROM Resource res " //
+ " JOIN res.alertDefinitions alertDef " //
+ " JOIN alertDef.alerts alert " //
+ " WHERE alert.ctime > "
+ AlertSearchAssistParam.getLastTime(param) //
+ (filter.equalsIgnoreCase("any") ? "" : " and "
+ getJPQLForEnum("alertDef.priority", op, filter, AlertPriority.class, false)) //
+ " GROUP BY res.id " //
+ "HAVING COUNT(alert) > 0 ");
} else if (path.equals("trait")) {
return new SearchFragment( //
SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
+ " FROM Resource res, MeasurementDataTrait trait " //
+ " JOIN res.schedules schedule " //
+ " WHERE trait.schedule = schedule " //
+ " AND schedule.definition.dataType = " + DataType.TRAIT.ordinal() //
+ " AND " + getJPQLForString("schedule.definition.name", RHQLComparisonOperator.EQUALS, param) //
+ " AND " + getJPQLForString("trait.value", op, filter));
} else if (path.equals("connection")) {
return new SearchFragment( //
SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
+ " FROM Resource res, PropertySimple simple, PropertyDefinitionSimple simpleDefinition " //
+ " JOIN res.resourceType.pluginConfigurationDefinition.propertyDefinitions definition " //
+ " JOIN res.pluginConfiguration.properties property " //
+ " WHERE simpleDefinition = definition " // only provide translations for simple properties
+ " AND simpleDefinition.type <> 'PASSWORD' " // do not allow searching by hidden/password fields
+ " AND property = simple " // join to simple for filter by 'stringValue' attribute
+ " AND " + getJPQLForString("definition.name", RHQLComparisonOperator.EQUALS, param) //
+ " AND " + getJPQLForString("simple.stringValue", op, filter));
} else if (path.equals("configuration")) {
return new SearchFragment( //
SearchFragment.Type.PRIMARY_KEY_SUBQUERY, "SELECT res.id" //
+ " FROM Resource res, PropertySimple simple, PropertyDefinitionSimple simpleDefinition " //
+ " JOIN res.resourceType.resourceConfigurationDefinition.propertyDefinitions definition " //
+ " JOIN res.resourceConfiguration.properties property " //
+ " WHERE simpleDefinition = definition " // only provide translations for simple properties