Skip to content

Commit 963410a

Browse files
authored
Nebula query engine
The Nebula project (https://github.com/jongpie/NebulaFramework) has added a lot of new features for dynamic querying, but it's currently dependent on the rest of the Nebula framework. The query engine from Nebula has been ported so that it's a freestanding project that can be deployed without the rest of the framework.
1 parent 92accfa commit 963410a

File tree

81 files changed

+3095
-1360
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+3095
-1360
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ node_js:
44
install:
55
- npm install -g jsforce-metadata-tools
66
script:
7-
- jsforce-deploy --checkOnly -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT --pollInterval $POLL_INTERVAL--verbose
7+
- jsforce-deploy --checkOnly -u $DEPLOYMENT_USERNAME -p $DEPLOYMENT_PASSWORD$DEPLOYMENT_TOKEN -D $TRAVIS_BUILD_DIR/src -l $DEPLOYMENT_LOGIN_URL --rollbackOnError true --testLevel $DEPLOYMENT_TEST_LEVEL --pollTimeout $POLL_TIMEOUT --pollInterval $POLL_INTERVAL--verbose

README.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
# Apex Query Generator
2-
<a target="_blank" href="https://githubsfdeploy.herokuapp.com?owner=jongpie&repo=ApexQueryGenerator">
2+
<a target="_blank" href="https://githubsfdeploy.herokuapp.com">
33
<img alt="Deploy to Salesforce"
44
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/src/main/webapp/resources/img/deploy.png">
55
</a>
66

7-
## Issue
8-
--Coming soon--
7+
## Overview
8+
This is an freestanding version of the [Nebula framework's](https://github.com/jongpie/NebulaFramework/) query engine - it has been updated to remove any dependencies on the rest of the Nebula framework.
99

10-
## Goals
11-
The overall goal of the project is to help auto-generate dynamic SOQL for commonly used queries
12-
* Provide a structure to centralise frequently used queries for each SObject
13-
* Provide a configurable way to change the query fields, while still preventing accidental deletion of fields being used
14-
* Provide a way to create a WHERE statement as a string in Apex, while still preventing accidental deletion of fields being used
15-
16-
## Implementation
17-
--Coming soon--
18-
19-
### Example Implementation: LeadQueryRepository.cls
10+
## Features
11+
The overall goal of the project is to generate dynamic SOQL & SOSL queries. Features currently include
12+
* Leverage field-level security to dynamically include fields
13+
* Dynamically include filter conditions (not possible with standard SOQL/SOSL)
14+
* Retain Salesforce's compilation-time errors for invalid fields while still taking advantage of dynamic queries - this helps avoid issues with deleting fields, misspelled field names, etc that can occur when working with strings and dynamic queries
15+
* Support for nearly all SOQL & SOSL features & keywords, including date literals, aggregate results and more
16+
* Easy-to-use query caching

src/classes/AccountRepository_Tests.cls

Lines changed: 0 additions & 118 deletions
This file was deleted.

src/classes/CollectionUtils.cls

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*************************************************************************************************
2+
* This file is part of the Nebula Framework project, released under the MIT License. *
3+
* See LICENSE file or go to https://github.com/jongpie/NebulaFramework for full license details. *
4+
*************************************************************************************************/
5+
6+
/**
7+
*
8+
* @group Utils
9+
*
10+
* @description A utility class to help with dealing with collections (lists, sets & maps)
11+
*
12+
*/
13+
public without sharing class CollectionUtils {
14+
15+
/**
16+
* @description Returns the last item in a list
17+
* @param listOfItems the list to check
18+
* @return The last Object in the provided list
19+
* @example
20+
* List<String> myList = new List<String>{'A', B', 'C'};
21+
* String lastItem = CollectionUtils.getLastItem(myList);
22+
* System.assertEquals('C', lastItem);
23+
*/
24+
public static Object getLastItem(List<Object> listOfItems) {
25+
Integer indexOfItem = listOfItems.size() - 1;
26+
return listOfItems[indexOfItem];
27+
}
28+
29+
/**
30+
* @description Removes the last item in the provided list & returns the item
31+
* @param listOfItems the list to check
32+
* @return The last Object in the provided list
33+
* @example
34+
* List<String> myList = new List<String>{'A', B', 'C'};
35+
* System.assertEquals(3, myList.size());
36+
* String lastItem = CollectionUtils.getLastItem(myList);
37+
* System.assertEquals('C', lastItem);
38+
* System.assertEquals(2, myList.size());
39+
*/
40+
public static Object pop(List<Object> listToSplice) {
41+
return splice(listToSplice, listToSplice.size() - 1);
42+
}
43+
44+
/**
45+
* @description Removes the item in the specified index from the provided list & returns the item
46+
* @param listOfItems The list to check
47+
* @param indexOfItem The index of the item to remove
48+
* @return The Object at the specified index
49+
* @example
50+
* List<String> myList = new List<String>{'A', B', 'C'};
51+
* System.assertEquals(3, myList.size());
52+
* String itemToRemove = CollectionUtils.splice(myList, 1);
53+
* System.assertEquals('B', itemToRemove);
54+
* System.assertEquals(2, myList.size());
55+
*/
56+
public static Object splice(List<Object> listToSplice, Integer indexOfItem) {
57+
Object itemToRemove = listToSplice[indexOfItem];
58+
listToSplice.remove(indexOfItem);
59+
return itemToRemove;
60+
}
61+
62+
/**
63+
* @description Determines if the provided input is a type of collection (list, set or map)
64+
* @param input The Object to check
65+
* @return true if the item is a type of collection, otherwise returns false
66+
* @example
67+
* List<String> myList = new List<String>{'A', 'B', 'C'};
68+
* System.assert(CollectionUtils.isCollection(myList));
69+
*/
70+
public static Boolean isCollection(Object input) {
71+
return isList(input) || isSet(input) || isMap(input);
72+
}
73+
74+
public static Boolean isList(Object input) {
75+
// If we can cast the object to a list of objects, then it's a list
76+
try {
77+
Object convertedInput = (List<Object>)input;
78+
return true;
79+
} catch(System.TypeException ex) {
80+
return false;
81+
}
82+
}
83+
84+
public static Boolean isSet(Object input) {
85+
// We can't cast the object to a set of objects
86+
// But if we try to cast it to a list of objects & it's a set,
87+
// then a TypeException is thrown so we know it's a set
88+
try {
89+
Object convertedInput = (List<Object>)input;
90+
return false;
91+
} catch(System.TypeException ex) {
92+
return ex.getMessage().contains('Set<');
93+
}
94+
}
95+
96+
public static Boolean isMap(Object input) {
97+
// We can't cast the object to a map of objects
98+
// But if we try to cast it to a list of objects & it's a map,
99+
// then a TypeException is thrown so we know it's a map
100+
try {
101+
Object convertedInput = (List<Object>)input;
102+
return false;
103+
} catch(System.TypeException ex) {
104+
return ex.getMessage().contains('Map<');
105+
}
106+
}
107+
108+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3-
<apiVersion>38.0</apiVersion>
3+
<apiVersion>40.0</apiVersion>
44
<status>Active</status>
55
</ApexClass>

0 commit comments

Comments
 (0)