BrightSide Workbench Full Report + Source Code
Rankings.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.ranking;
20 
21 import org.turro.string.Strings;
22 import org.turro.action.IProcess;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.reflection.Instances;
25 
30 public class Rankings {
31 
32  public static void process() {
33  for(IProcess process : Instances.cached().byAnnotation(ElephantRanking.class, IProcess.class)) {
34  process.startProcess();
35  }
36  }
37 
38  public static void processFor(Object entity) {
39  for(IProcess process : Instances.cached().byAnnotation(ElephantRanking.class, IProcess.class)) {
40  if(process.itsMine(entity)) {
41  process.startProcessFor(entity);
42  }
43  }
44  }
45 
46  public static void addJoin(WhereClause wc, String table, String entityRoot, String entityId, String sortOrder) {
47  String entityPath = "concat('/" + entityRoot + "/', " + entityRoot + "." + entityId + ")";
48  wc.addClause("left outer join " + table + " ranking on ranking.entityPath = " + entityPath + " and ranking.concept = :rankconcept");
49  wc.addNamedValue("rankconcept", Strings.isBlank(sortOrder) ? "*" : sortOrder);
50  }
51 
52  public static String getOrdering() {
53  return "ranking.ranking desc";
54  }
55 
56  private Rankings() {
57  }
58 
59 }
void addNamedValue(String name, Object value)
static String getOrdering()
Definition: Rankings.java:52
static void addJoin(WhereClause wc, String table, String entityRoot, String entityId, String sortOrder)
Definition: Rankings.java:46
static void processFor(Object entity)
Definition: Rankings.java:38