BrightSide Workbench Full Report + Source Code
Matchings.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.matching;
20 
21 import org.turro.string.Strings;
22 import org.turro.action.IProcess;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.plugin.contacts.IContact;
25 import org.turro.reflection.Instances;
26 
31 public class Matchings {
32 
33  public static void process() {
34  for(IProcess process : Instances.cached().byAnnotation(ElephantMatching.class, IProcess.class)) {
35  process.startProcess();
36  }
37  }
38 
39  public static void processFor(Object entity) {
40  for(IProcess process : Instances.cached().byAnnotation(ElephantMatching.class, IProcess.class)) {
41  if(process.itsMine(entity)) {
42  process.startProcessFor(entity);
43  }
44  }
45  }
46 
47  public static void addJoin(WhereClause wc, String table, String entityRoot, String entityId, IContact contact, String sortOrder) {
48  String entityPath = "concat('/" + entityRoot + "/', " + entityRoot + "." + entityId + ")";
49  String relatedPath = "/contact/" + contact.getId();
50  wc.addClause("left outer join " + table + " matching");
51  wc.addClause("on matching.entityPath = " + entityPath + " and matching.concept = :matchconcept");
52  wc.addClause("and matching.relatedPath = '" + relatedPath +"'");
53  wc.addNamedValue("matchconcept", Strings.isBlank(sortOrder) ? "*" : sortOrder);
54  }
55 
56  public static String getOrdering() {
57  return "matching.matching desc";
58  }
59 
60  private Matchings() {
61  }
62 
63 }
void addNamedValue(String name, Object value)
static String getOrdering()
Definition: Matchings.java:56
static void addJoin(WhereClause wc, String table, String entityRoot, String entityId, IContact contact, String sortOrder)
Definition: Matchings.java:47
static void processFor(Object entity)
Definition: Matchings.java:39