mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-02-03 15:32:43 +00:00
Compare commits
3 Commits
@openstapp
...
5f67c57c8b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f67c57c8b | ||
|
|
6b06de4019 | ||
| 56331fe4ff |
6
.changeset/new-yaks-drop.md
Normal file
6
.changeset/new-yaks-drop.md
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@openstapps/backend": patch
|
||||||
|
"@openstapps/logger": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Updated nodemailer dependency
|
||||||
@@ -69,7 +69,7 @@
|
|||||||
"nock": "13.3.1",
|
"nock": "13.3.1",
|
||||||
"node-cache": "5.1.2",
|
"node-cache": "5.1.2",
|
||||||
"node-cron": "3.0.2",
|
"node-cron": "3.0.2",
|
||||||
"nodemailer": "6.9.1",
|
"nodemailer": "6.9.9",
|
||||||
"prom-client": "14.1.1",
|
"prom-client": "14.1.1",
|
||||||
"promise-queue": "2.2.5",
|
"promise-queue": "2.2.5",
|
||||||
"uuid": "8.3.2"
|
"uuid": "8.3.2"
|
||||||
@@ -106,6 +106,9 @@
|
|||||||
"entry": [
|
"entry": [
|
||||||
"src/cli.ts"
|
"src/cli.ts"
|
||||||
],
|
],
|
||||||
|
"loader": {
|
||||||
|
".groovy": "text"
|
||||||
|
},
|
||||||
"sourcemap": true,
|
"sourcemap": true,
|
||||||
"clean": true,
|
"clean": true,
|
||||||
"target": "es2022",
|
"target": "es2022",
|
||||||
|
|||||||
65
backend/backend/src/storage/elasticsearch/diff-index.groovy
Normal file
65
backend/backend/src/storage/elasticsearch/diff-index.groovy
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
void traverse(def a, def b, ArrayList path, HashMap result) {
|
||||||
|
if (a instanceof Map && b instanceof Map) {
|
||||||
|
for (key in a.keySet()) {
|
||||||
|
path.add(key);
|
||||||
|
traverse(a.get(key), b.get(key), path, result);
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
}
|
||||||
|
} else if (a instanceof List && b instanceof List) {
|
||||||
|
int la = a.size();
|
||||||
|
int lb = b.size();
|
||||||
|
int max = la > lb ? la : lb;
|
||||||
|
for (int i = 0; i < max; i++) {
|
||||||
|
path.add(i);
|
||||||
|
if (i < la && i < lb) {
|
||||||
|
traverse(a[i], b[i], path, result);
|
||||||
|
} else if (i >= la) {
|
||||||
|
result.added.add(path.toArray());
|
||||||
|
} else {
|
||||||
|
result.removed.add(path.toArray());
|
||||||
|
}
|
||||||
|
path.remove(path.size() - 1);
|
||||||
|
}
|
||||||
|
} else if (a == null && b != null) {
|
||||||
|
result.removed.add(path.toArray());
|
||||||
|
} else if (a != null && b == null) {
|
||||||
|
result.added.add(path.toArray());
|
||||||
|
} else if (!a.equals(b)) {
|
||||||
|
result.changed.add(path.toArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def to;
|
||||||
|
def from;
|
||||||
|
|
||||||
|
for (state in states) {
|
||||||
|
if (state.index.equals(params.newIndex)) {
|
||||||
|
to = state.doc;
|
||||||
|
} else {
|
||||||
|
from = state.doc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap result = [
|
||||||
|
'added': [],
|
||||||
|
'removed': [],
|
||||||
|
'changed': []
|
||||||
|
];
|
||||||
|
|
||||||
|
traverse(to, from, new ArrayList(), result);
|
||||||
|
|
||||||
|
if (to == null && from != null) {
|
||||||
|
result.status = 'removed';
|
||||||
|
} else if (to != null && from == null) {
|
||||||
|
result.status = 'added';
|
||||||
|
} else if (
|
||||||
|
result.added.size() == 0 &&
|
||||||
|
result.removed.size() == 0 &&
|
||||||
|
result.changed.size() == 0
|
||||||
|
) {
|
||||||
|
result.status = 'unchanged';
|
||||||
|
} else {
|
||||||
|
result.status = 'changed';
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
@@ -47,6 +47,7 @@ import {
|
|||||||
import {noUndefined} from './util/no-undefined.js';
|
import {noUndefined} from './util/no-undefined.js';
|
||||||
import {retryCatch, RetryOptions} from './util/retry.js';
|
import {retryCatch, RetryOptions} from './util/retry.js';
|
||||||
import {Feature, Point, Polygon} from 'geojson';
|
import {Feature, Point, Polygon} from 'geojson';
|
||||||
|
import indexDiffScript from './diff-index.groovy';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A database interface for elasticsearch
|
* A database interface for elasticsearch
|
||||||
@@ -239,6 +240,42 @@ export class Elasticsearch implements Database {
|
|||||||
.then(it => Object.entries(it).map(([name]) => name))
|
.then(it => Object.entries(it).map(([name]) => name))
|
||||||
.catch(() => [] as string[]);
|
.catch(() => [] as string[]);
|
||||||
|
|
||||||
|
if (activeIndices.length <= 1) {
|
||||||
|
const result = await this.client.transform.previewTransform({
|
||||||
|
source: {
|
||||||
|
index: [...activeIndices, index],
|
||||||
|
query: {match_all: {}},
|
||||||
|
},
|
||||||
|
dest: {index: 'compare'},
|
||||||
|
pivot: {
|
||||||
|
group_by: {
|
||||||
|
uid: {terms: {field: 'uid.raw'}},
|
||||||
|
},
|
||||||
|
aggregations: {
|
||||||
|
compare: {
|
||||||
|
scripted_metric: {
|
||||||
|
map_script: `
|
||||||
|
state.index = doc['_index'];
|
||||||
|
state.doc = params['_source'];`,
|
||||||
|
combine_script: `
|
||||||
|
state.index = state.index[0];
|
||||||
|
return state;
|
||||||
|
`,
|
||||||
|
reduce_script: {
|
||||||
|
source: indexDiffScript,
|
||||||
|
params: {
|
||||||
|
newIndex: index,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(JSON.stringify(result.preview, null, 2))
|
||||||
|
}
|
||||||
|
|
||||||
await this.client.indices.updateAliases({
|
await this.client.indices.updateAliases({
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// initialize the sort value with the maximum
|
||||||
|
double price = Double.MAX_VALUE;
|
||||||
|
|
||||||
|
// if we have any offers
|
||||||
|
if (params._source.containsKey(params.field)) {
|
||||||
|
// iterate through all offers
|
||||||
|
for (offer in params._source[params.field]) {
|
||||||
|
// if this offer contains a role specific price
|
||||||
|
if (offer.containsKey('prices') && offer.prices.containsKey(params.universityRole)) {
|
||||||
|
// if the role specific price is smaller than the cheapest we found
|
||||||
|
if (offer.prices[params.universityRole] < price) {
|
||||||
|
// set the role specific price as cheapest for now
|
||||||
|
price = offer.prices[params.universityRole];
|
||||||
|
}
|
||||||
|
} else { // we have no role specific price for our role in this offer
|
||||||
|
// if the default price of this offer is lower than the cheapest we found
|
||||||
|
if (offer.price < price) {
|
||||||
|
// set this price as the cheapest
|
||||||
|
price = offer.price;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// return cheapest price for our role
|
||||||
|
return price;
|
||||||
@@ -13,7 +13,8 @@
|
|||||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
import {SortOptions} from '@elastic/elasticsearch/lib/api/types.js';
|
||||||
import {SCPriceSort, SCSportCoursePriceGroup, SCThingsField} from '@openstapps/core';
|
import {SCPriceSort} from '@openstapps/core';
|
||||||
|
import priceSortScript from './price-sort.groovy';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a price sort to elasticsearch syntax
|
* Converts a price sort to elasticsearch syntax
|
||||||
@@ -23,47 +24,11 @@ export function buildPriceSort(sort: SCPriceSort): SortOptions {
|
|||||||
return {
|
return {
|
||||||
_script: {
|
_script: {
|
||||||
order: sort.order,
|
order: sort.order,
|
||||||
script: buildPriceSortScript(sort.arguments.universityRole, sort.arguments.field),
|
script: {
|
||||||
|
source: priceSortScript,
|
||||||
|
params: sort.arguments,
|
||||||
|
},
|
||||||
type: 'number' as const,
|
type: 'number' as const,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a script for sorting search results by prices
|
|
||||||
* @param universityRole User group which consumes university services
|
|
||||||
* @param field Field in which wanted offers with prices are located
|
|
||||||
*/
|
|
||||||
export function buildPriceSortScript(
|
|
||||||
universityRole: keyof SCSportCoursePriceGroup,
|
|
||||||
field: SCThingsField,
|
|
||||||
): string {
|
|
||||||
return `
|
|
||||||
// initialize the sort value with the maximum
|
|
||||||
double price = Double.MAX_VALUE;
|
|
||||||
|
|
||||||
// if we have any offers
|
|
||||||
if (params._source.containsKey('${field}')) {
|
|
||||||
// iterate through all offers
|
|
||||||
for (offer in params._source.${field}) {
|
|
||||||
// if this offer contains a role specific price
|
|
||||||
if (offer.containsKey('prices') && offer.prices.containsKey('${universityRole}')) {
|
|
||||||
// if the role specific price is smaller than the cheapest we found
|
|
||||||
if (offer.prices.${universityRole} < price) {
|
|
||||||
// set the role specific price as cheapest for now
|
|
||||||
price = offer.prices.${universityRole};
|
|
||||||
}
|
|
||||||
} else { // we have no role specific price for our role in this offer
|
|
||||||
// if the default price of this offer is lower than the cheapest we found
|
|
||||||
if (offer.price < price) {
|
|
||||||
// set this price as the cheapest
|
|
||||||
price = offer.price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return cheapest price for our role
|
|
||||||
return price;
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|||||||
6
backend/backend/src/types.d.ts
vendored
Normal file
6
backend/backend/src/types.d.ts
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
declare module '*.groovy' {
|
||||||
|
const content: string;
|
||||||
|
export default content;
|
||||||
|
}
|
||||||
|
|
||||||
|
export {};
|
||||||
0
examples/minimal-connector/app.js
Normal file → Executable file
0
examples/minimal-connector/app.js
Normal file → Executable file
@@ -31,7 +31,7 @@
|
|||||||
"@types/nodemailer": "6.4.7",
|
"@types/nodemailer": "6.4.7",
|
||||||
"chalk": "5.2.0",
|
"chalk": "5.2.0",
|
||||||
"flatted": "3.2.7",
|
"flatted": "3.2.7",
|
||||||
"nodemailer": "6.9.1"
|
"nodemailer": "6.9.9"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@openstapps/eslint-config": "workspace:*",
|
"@openstapps/eslint-config": "workspace:*",
|
||||||
|
|||||||
14
pnpm-lock.yaml
generated
14
pnpm-lock.yaml
generated
@@ -134,8 +134,8 @@ importers:
|
|||||||
specifier: 3.0.2
|
specifier: 3.0.2
|
||||||
version: 3.0.2
|
version: 3.0.2
|
||||||
nodemailer:
|
nodemailer:
|
||||||
specifier: 6.9.1
|
specifier: 6.9.9
|
||||||
version: 6.9.1
|
version: 6.9.9
|
||||||
prom-client:
|
prom-client:
|
||||||
specifier: 14.1.1
|
specifier: 14.1.1
|
||||||
version: 14.1.1
|
version: 14.1.1
|
||||||
@@ -1990,8 +1990,8 @@ importers:
|
|||||||
specifier: 3.2.7
|
specifier: 3.2.7
|
||||||
version: 3.2.7
|
version: 3.2.7
|
||||||
nodemailer:
|
nodemailer:
|
||||||
specifier: 6.9.1
|
specifier: 6.9.9
|
||||||
version: 6.9.1
|
version: 6.9.9
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@openstapps/eslint-config':
|
'@openstapps/eslint-config':
|
||||||
specifier: workspace:*
|
specifier: workspace:*
|
||||||
@@ -8631,8 +8631,8 @@ packages:
|
|||||||
node-releases@2.0.19:
|
node-releases@2.0.19:
|
||||||
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
resolution: {integrity: sha512-xxOWJsBKtzAq7DY0J+DTzuz58K8e7sJbdgwkbMWQe8UYB6ekmsQ45q0M/tJDsGaZmbC+l7n57UV8Hl5tHxO9uw==}
|
||||||
|
|
||||||
nodemailer@6.9.1:
|
nodemailer@6.9.9:
|
||||||
resolution: {integrity: sha512-qHw7dOiU5UKNnQpXktdgQ1d3OFgRAekuvbJLcdG5dnEo/GtcTHRYM7+UfJARdOFU9WUQO8OiIamgWPmiSFHYAA==}
|
resolution: {integrity: sha512-dexTll8zqQoVJEZPwQAKzxxtFn0qTnjdQTchoU6Re9BUUGBJiOy3YMn/0ShTW6J5M0dfQ1NeDeRTTl4oIWgQMA==}
|
||||||
engines: {node: '>=6.0.0'}
|
engines: {node: '>=6.0.0'}
|
||||||
|
|
||||||
non-layered-tidy-tree-layout@2.0.2:
|
non-layered-tidy-tree-layout@2.0.2:
|
||||||
@@ -19780,7 +19780,7 @@ snapshots:
|
|||||||
|
|
||||||
node-releases@2.0.19: {}
|
node-releases@2.0.19: {}
|
||||||
|
|
||||||
nodemailer@6.9.1: {}
|
nodemailer@6.9.9: {}
|
||||||
|
|
||||||
non-layered-tidy-tree-layout@2.0.2:
|
non-layered-tidy-tree-layout@2.0.2:
|
||||||
optional: true
|
optional: true
|
||||||
|
|||||||
Reference in New Issue
Block a user