Skip to content

Commit 4a34839

Browse files
authored
Merge pull request #756 from bserdar/saved-search
Saved search
2 parents e092d59 + 728ac85 commit 4a34839

File tree

15 files changed

+1329
-19
lines changed

15 files changed

+1329
-19
lines changed

config/src/main/java/com/redhat/lightblue/config/CrudConfiguration.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import com.fasterxml.jackson.databind.JsonNode;
2828
import com.fasterxml.jackson.databind.node.ArrayNode;
29+
import com.fasterxml.jackson.databind.node.ObjectNode;
2930

3031
import com.redhat.lightblue.util.JsonInitializable;
3132

@@ -44,6 +45,7 @@ public class CrudConfiguration implements JsonInitializable, Serializable {
4445
public static final transient String FILENAME = "lightblue-crud.json";
4546

4647
private ControllerConfiguration controllers[];
48+
private SavedSearchConfiguration savedSearch;
4749
private boolean validateRequests = false;
4850
private int bulkParallelExecutions = 3;
4951

@@ -63,6 +65,10 @@ public void setBulkParallelExecutions(int i) {
6365
bulkParallelExecutions = i;
6466
}
6567

68+
public SavedSearchConfiguration getSavedSearch() {
69+
return savedSearch;
70+
}
71+
6672
/**
6773
* @return the controllers
6874
*/
@@ -117,6 +123,12 @@ public void initializeFromJson(JsonNode node) {
117123
if (x != null) {
118124
bulkParallelExecutions = x.intValue();
119125
}
126+
127+
x = node.get("savedSearch");
128+
if(x instanceof ObjectNode) {
129+
savedSearch=new SavedSearchConfiguration();
130+
savedSearch.initializeFromJson(x);
131+
}
120132
}
121133
}
122134
}

config/src/main/java/com/redhat/lightblue/config/LightblueFactory.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ public final class LightblueFactory implements Serializable {
8282
private transient volatile Factory factory;
8383
private transient volatile JsonTranslator jsonTranslator = null;
8484
private transient volatile Map<String, LockingSupport> lockingMap = null;
85+
private transient volatile CrudConfiguration crudConfiguration=null;
8586

8687
public LightblueFactory(DataSourcesConfiguration datasources) {
8788
this(datasources, null, null);
@@ -121,10 +122,9 @@ private synchronized void initializeMediator()
121122
}
122123
}
123124

124-
private synchronized void initializeFactory()
125-
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException {
126-
if (factory == null) {
127-
LOGGER.debug("Initializing factory");
125+
private synchronized void initializeCrudConfiguration()
126+
throws IOException {
127+
if(crudConfiguration==null) {
128128
JsonNode root = crudNode;
129129
if (root == null) {
130130
try (InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(CrudConfiguration.FILENAME)) {
@@ -134,31 +134,38 @@ private synchronized void initializeFactory()
134134
root = JsonUtils.json(is, true);
135135
}
136136
} else {
137-
LOGGER.debug("Using passed in node to initialize factory");
137+
LOGGER.debug("Using passed in node to initialize crud configuration");
138138
}
139-
LOGGER.debug("Initializing factory from {}", root);
140-
139+
LOGGER.debug("crud configuration: {}", root);
141140
// convert root to Configuration object
142-
CrudConfiguration configuration = new CrudConfiguration();
143-
configuration.initializeFromJson(root);
141+
crudConfiguration = new CrudConfiguration();
142+
crudConfiguration.initializeFromJson(root);
143+
// validate
144+
if (!crudConfiguration.isValid()) {
145+
throw new IllegalStateException(CrudConstants.ERR_CONFIG_NOT_VALID + " - " + CrudConfiguration.FILENAME);
146+
}
147+
}
148+
}
149+
150+
private synchronized void initializeFactory()
151+
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException {
152+
if (factory == null) {
153+
LOGGER.debug("Initializing factory");
154+
if(crudConfiguration==null)
155+
initializeCrudConfiguration();
144156

145157
// Set validation flag for all crud requests
146-
getJsonTranslator().setValidation(Request.class, configuration.isValidateRequests());
158+
getJsonTranslator().setValidation(Request.class, crudConfiguration.isValidateRequests());
147159

148160
Factory f = new Factory();
149-
f.setBulkParallelExecutions(configuration.getBulkParallelExecutions());
161+
f.setBulkParallelExecutions(crudConfiguration.getBulkParallelExecutions());
150162
f.addFieldConstraintValidators(new DefaultFieldConstraintValidators());
151163

152164
// Add default interceptors
153165
new UIDInterceptor().register(f.getInterceptors());
154166
new GeneratedFieldInterceptor().register(f.getInterceptors());
155167

156-
// validate
157-
if (!configuration.isValid()) {
158-
throw new IllegalStateException(CrudConstants.ERR_CONFIG_NOT_VALID + " - " + CrudConfiguration.FILENAME);
159-
}
160-
161-
for (ControllerConfiguration x : configuration.getControllers()) {
168+
for (ControllerConfiguration x : crudConfiguration.getControllers()) {
162169
ControllerFactory cfactory = x.getControllerFactory().newInstance();
163170
CRUDController controller = cfactory.createController(x, datasources);
164171
injectDependencies(controller);
@@ -341,6 +348,12 @@ public Mediator getMediator()
341348
return mediator;
342349
}
343350

351+
public CrudConfiguration getCrudConfiguration() throws IOException {
352+
if(crudConfiguration==null)
353+
initializeCrudConfiguration();
354+
return crudConfiguration;
355+
}
356+
344357
public Locking getLocking(String domain)
345358
throws ClassNotFoundException, IllegalAccessException, InvocationTargetException, IOException, NoSuchMethodException, InstantiationException {
346359
if (lockingMap == null) {
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2013 Red Hat, Inc. and/or its affiliates.
3+
4+
This file is part of lightblue.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.redhat.lightblue.config;
20+
21+
import java.io.Serializable;
22+
23+
import com.fasterxml.jackson.databind.JsonNode;
24+
25+
import com.redhat.lightblue.util.JsonInitializable;
26+
27+
/**
28+
* Saves search configuration
29+
* <ul>
30+
* <li>entity: Saved search entity name</li>
31+
* <li>entityVersion: The saved search entity version, or null if default</li>
32+
* <li>cacheConfig: Guava cache spec @see <a href="http://google.github.io/guava/releases/21.0/api/docs/com/google/common/cache/CacheBuilderSpec.html"> </li>
33+
* </ul>
34+
*/
35+
public class SavedSearchConfiguration implements JsonInitializable, Serializable {
36+
37+
private static final long serialVersionUID = 1l;
38+
39+
private String entity="savedSearch";
40+
private String entityVersion;
41+
private String cacheConfig;
42+
43+
public String getEntity() {
44+
return entity;
45+
}
46+
47+
public String getEntityVersion() {
48+
return entityVersion;
49+
}
50+
51+
public String getCacheConfig() {
52+
return cacheConfig;
53+
}
54+
55+
@Override
56+
public void initializeFromJson(JsonNode node) {
57+
if (node != null) {
58+
JsonNode x = node.get("entity");
59+
if(x!=null) {
60+
entity=x.asText();
61+
x=node.get("entityVersion");
62+
if(x!=null)
63+
entityVersion=x.asText();
64+
}
65+
66+
x=node.get("cache");
67+
if(x!=null) {
68+
cacheConfig=x.asText();
69+
}
70+
}
71+
}
72+
}

crud/src/main/java/com/redhat/lightblue/mediator/Mediator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public class Mediator {
9191

9292
private static final Path OBJECT_TYPE_PATH = new Path("objectType");
9393

94-
private final Metadata metadata;
95-
private final Factory factory;
94+
public final Metadata metadata;
95+
public final Factory factory;
9696

9797
public Mediator(Metadata md,
9898
Factory factory) {

misc/pom.xml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!--
2+
Copyright 2013 Red Hat, Inc. and/or its affiliates.
3+
4+
This file is part of lightblue.
5+
6+
This program is free software: you can redistribute it and/or modify
7+
it under the terms of the GNU General Public License as published by
8+
the Free Software Foundation, either version 3 of the License, or
9+
(at your option) any later version.
10+
11+
This program is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
GNU General Public License for more details.
15+
16+
You should have received a copy of the GNU General Public License
17+
along with this program. If not, see <http://www.gnu.org/licenses />.
18+
--><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
<parent>
21+
<groupId>com.redhat.lightblue</groupId>
22+
<artifactId>lightblue-core-pom</artifactId>
23+
<version>2.9.0-SNAPSHOT</version>
24+
</parent>
25+
<groupId>com.redhat.lightblue</groupId>
26+
<version>2.9.0-SNAPSHOT</version>
27+
<artifactId>lightblue-core-misc</artifactId>
28+
<packaging>jar</packaging>
29+
<name>lightblue-core: ${project.groupId}|${project.artifactId}</name>
30+
<dependencies>
31+
<dependency>
32+
<groupId>com.redhat.lightblue</groupId>
33+
<artifactId>lightblue-core-crud</artifactId>
34+
<version>2.9.0-SNAPSHOT</version>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.redhat.lightblue</groupId>
38+
<artifactId>lightblue-core-config</artifactId>
39+
<version>2.9.0-SNAPSHOT</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.slf4j</groupId>
43+
<artifactId>slf4j-simple</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
<build>
48+
</build>
49+
</project>

0 commit comments

Comments
 (0)