Skip to content
Snippets Groups Projects
Commit d4227b5f authored by Moises Sacal's avatar Moises Sacal
Browse files
parent f15711b8
1 merge request!1integrate solr object creation into library
......@@ -2,7 +2,10 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="ad75bb9b-12db-4cad-af64-4c68cecdb87b" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/test/catalog.lib.spec.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/lib/CatalogSolr.js" beforeDir="false" afterPath="$PROJECT_DIR$/lib/CatalogSolr.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/test/catalog.spec.js" beforeDir="false" afterPath="$PROJECT_DIR$/test/catalog.create.spec.js" afterDir="false" />
</list>
<ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" />
......@@ -15,41 +18,47 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/lib/CatalogSolr.js">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/test-data/CATALOG.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="22" column="28" selection-start-line="22" selection-start-column="28" selection-end-line="22" selection-end-column="28" />
<state relative-caret-position="236">
<caret line="31" column="12" selection-start-line="31" selection-start-column="8" selection-end-line="31" selection-end-column="12" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/package.json">
<entry file="file://$PROJECT_DIR$/test/catalog.create.spec.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="120">
<caret line="8" column="28" selection-start-line="8" selection-end-line="9" />
<state relative-caret-position="431">
<caret line="148" column="46" selection-start-line="148" selection-start-column="42" selection-end-line="148" selection-end-column="46" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="255">
<caret line="24" lean-forward="true" selection-start-line="24" selection-end-line="24" />
</first_editor>
<second_editor />
<entry file="file://$PROJECT_DIR$/test/catalog.lib.spec.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="495">
<caret line="33" column="3" lean-forward="true" selection-start-line="33" selection-start-column="3" selection-end-line="33" selection-end-column="3" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/generate-datacrates.js">
<entry file="file://$PROJECT_DIR$/lib/CatalogSolr.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="530">
<caret line="166" column="7" lean-forward="true" selection-start-line="166" selection-start-column="7" selection-end-line="166" selection-end-column="7" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="350">
<caret line="25" column="13" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
<state relative-caret-position="227">
<caret line="16" column="15" lean-forward="true" selection-start-line="16" selection-start-column="15" selection-end-line="16" selection-end-column="15" />
</state>
</provider>
</entry>
......@@ -57,8 +66,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/commit-to-solr.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1695">
<caret line="113" column="11" lean-forward="true" selection-start-line="113" selection-start-column="11" selection-end-line="113" selection-end-column="11" />
<state relative-caret-position="355">
<caret line="76" column="20" selection-start-line="76" selection-start-column="8" selection-end-line="76" selection-end-column="20" />
</state>
</provider>
</entry>
......@@ -82,19 +91,20 @@
<option value="$PROJECT_DIR$/lib/Catalog.js" />
<option value="$PROJECT_DIR$/test-data/recordTypes.json" />
<option value="$PROJECT_DIR$/test-data/CATALOG.json" />
<option value="$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json" />
<option value="$APPLICATION_CONFIG_DIR$/scratches/scratch_3.js" />
<option value="$PROJECT_DIR$/test-data/CatalogSolr.json" />
<option value="$PROJECT_DIR$/fields.json" />
<option value="$PROJECT_DIR$/test/catalog.spec.js" />
<option value="$PROJECT_DIR$/test-data/fields.json" />
<option value="$PROJECT_DIR$/lib/CatalogSolr.js" />
<option value="$PROJECT_DIR$/.gitignore" />
<option value="$PROJECT_DIR$/generate-datacrates.js" />
<option value="$PROJECT_DIR$/config.json" />
<option value="$PROJECT_DIR$/package.json" />
<option value="$PROJECT_DIR$/commit-to-solr.js" />
<option value="$PROJECT_DIR$/README.md" />
<option value="$PROJECT_DIR$/commit-to-solr.js" />
<option value="$PROJECT_DIR$/test/catalog.lib.spec.js" />
<option value="$PROJECT_DIR$/lib/CatalogSolr.js" />
<option value="$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json" />
</list>
</option>
</component>
......@@ -172,14 +182,26 @@
</list>
</option>
</component>
<component name="RunManager" selected="Node.js.commit-to-solr">
<component name="RunManager" selected="Mocha.catalog.lib.spec.js">
<configuration name="commit-to-solr" type="NodeJSConfigurationType" path-to-js-file="commit-to-solr.js" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
<configuration name="generate-datacrates" type="NodeJSConfigurationType" application-parameters="--d $PROJECT_DIR$/../../peppermint/publication/public --n 100000" path-to-js-file="generate-datacrates.js" working-dir="$PROJECT_DIR$">
<method v="2" />
</configuration>
<configuration name="catalog.spec.js" type="mocha-javascript-test-runner">
<configuration name="catalog.create.spec.js" type="mocha-javascript-test-runner">
<node-interpreter>project</node-interpreter>
<node-options />
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
<working-directory>$PROJECT_DIR$</working-directory>
<pass-parent-env>true</pass-parent-env>
<ui>bdd</ui>
<extra-mocha-options />
<test-kind>TEST_FILE</test-kind>
<test-file>$PROJECT_DIR$/test/catalog.create.spec.js</test-file>
<method v="2" />
</configuration>
<configuration name="catalog.lib.spec.js" type="mocha-javascript-test-runner">
<node-interpreter>project</node-interpreter>
<node-options />
<mocha-package>$PROJECT_DIR$/node_modules/mocha</mocha-package>
......@@ -188,11 +210,12 @@
<ui>bdd</ui>
<extra-mocha-options />
<test-kind>TEST_FILE</test-kind>
<test-file>$PROJECT_DIR$/test/catalog.spec.js</test-file>
<test-file>$PROJECT_DIR$/test/catalog.lib.spec.js</test-file>
<method v="2" />
</configuration>
<list>
<item itemvalue="Mocha.catalog.spec.js" />
<item itemvalue="Mocha.catalog.create.spec.js" />
<item itemvalue="Mocha.catalog.lib.spec.js" />
<item itemvalue="Node.js.commit-to-solr" />
<item itemvalue="Node.js.generate-datacrates" />
</list>
......@@ -208,47 +231,48 @@
<option name="presentableId" value="Default" />
<updated>1558421147646</updated>
<workItem from="1558421149207" duration="30478000" />
<workItem from="1558654598476" duration="85668000" />
<workItem from="1558654598476" duration="88527000" />
</task>
<servers />
</component>
<component name="TestHistory">
<history-entry file="catalog_spec_js - 2019.05.29 at 14h 50m 34s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 34m 16s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 29m 39s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 35m 51s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 29m 51s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 40m 01s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 31m 49s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 40m 19s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 31m 51s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 41m 31s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 33m 16s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 42m 34s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 34m 30s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 43m 10s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 35m 20s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 43m 23s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 35m 32s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 44m 11s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
<history-entry file="catalog_spec_js - 2019.05.29 at 15h 35m 38s.xml">
<configuration name="catalog.spec.js" configurationId="mocha-javascript-test-runner" />
<history-entry file="catalog_lib_spec_js - 2019.05.31 at 16h 44m 21s.xml">
<configuration name="catalog.lib.spec.js" configurationId="mocha-javascript-test-runner" />
</history-entry>
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="116146000" />
<option name="totallyTimeSpent" value="119005000" />
</component>
<component name="ToolWindowManager">
<frame x="1441" y="-277" width="1920" height="1177" extended-state="6" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.15654951" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
......@@ -256,13 +280,13 @@
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.3281106" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.28847927" />
<window_info active="true" anchor="bottom" id="Debug" order="3" visible="true" weight="0.28847927" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info active="true" anchor="bottom" id="Terminal" order="9" visible="true" weight="0.23778802" />
<window_info anchor="bottom" id="Terminal" order="9" weight="0.23778802" />
<window_info anchor="bottom" id="Event Log" order="10" side_tool="true" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
......@@ -285,51 +309,54 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test/catalog.spec.js">
<entry file="file://$PROJECT_DIR$/test-data/CatalogSolr.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1761">
<caret column="20" selection-end-line="1" />
<state relative-caret-position="-17">
<caret line="27" column="31" selection-start-line="27" selection-start-column="5" selection-end-line="27" selection-end-column="31" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test-data/fields.json">
<entry file="file://$PROJECT_DIR$/node_modules/lodash/lodash.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="5" column="24" lean-forward="true" selection-start-line="5" selection-start-column="24" selection-end-line="5" selection-end-column="24" />
<state relative-caret-position="489">
<caret line="521" lean-forward="true" selection-start-line="521" selection-end-line="521" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test-data/CATALOG.json">
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="329">
<caret line="45" column="9" selection-start-line="45" selection-start-column="9" selection-end-line="45" selection-end-column="9" />
<state relative-caret-position="45">
<caret line="3" column="20" lean-forward="true" selection-start-line="3" selection-start-column="20" selection-end-line="3" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test-data/CatalogSolr.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-17">
<caret line="27" column="31" selection-start-line="27" selection-start-column="5" selection-end-line="27" selection-end-column="31" />
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="255">
<caret line="24" lean-forward="true" selection-start-line="24" selection-end-line="24" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json">
<entry file="file://$PROJECT_DIR$/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="915">
<caret line="61" column="20" selection-start-line="61" selection-start-column="20" selection-end-line="61" selection-end-column="20" />
<state relative-caret-position="135">
<caret line="9" selection-start-line="9" selection-end-line="9" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/node_modules/lodash/lodash.js">
<entry file="file://$PROJECT_DIR$/test-data/CATALOG.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="489">
<caret line="521" lean-forward="true" selection-start-line="521" selection-end-line="521" />
<state relative-caret-position="236">
<caret line="31" column="12" selection-start-line="31" selection-start-column="8" selection-end-line="31" selection-end-column="12" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/generate-datacrates.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="350">
<state relative-caret-position="375">
<caret line="25" column="13" selection-start-line="25" selection-start-column="13" selection-end-line="25" selection-end-column="13" />
</state>
</provider>
......@@ -348,41 +375,45 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/test-data/fields.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="75">
<caret line="5" column="24" lean-forward="true" selection-start-line="5" selection-start-column="24" selection-end-line="5" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/commit-to-solr.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1695">
<caret line="113" column="11" lean-forward="true" selection-start-line="113" selection-start-column="11" selection-end-line="113" selection-end-column="11" />
<state relative-caret-position="355">
<caret line="76" column="20" selection-start-line="76" selection-start-column="8" selection-end-line="76" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/.gitignore">
<entry file="file://$PROJECT_DIR$/test/catalog.create.spec.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="45">
<caret line="3" column="20" lean-forward="true" selection-start-line="3" selection-start-column="20" selection-end-line="3" selection-end-column="20" />
<state relative-caret-position="431">
<caret line="148" column="46" selection-start-line="148" selection-start-column="42" selection-end-line="148" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/README.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="255">
<caret line="24" lean-forward="true" selection-start-line="24" selection-end-line="24" />
</first_editor>
<second_editor />
<entry file="file://$PROJECT_DIR$/lib/CatalogSolr.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="530">
<caret line="166" column="7" lean-forward="true" selection-start-line="166" selection-start-column="7" selection-end-line="166" selection-end-column="7" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config.json">
<entry file="file://$PROJECT_DIR$/test/catalog.lib.spec.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="135">
<caret line="9" selection-start-line="9" selection-end-line="9" />
<state relative-caret-position="495">
<caret line="33" column="3" lean-forward="true" selection-start-line="33" selection-start-column="3" selection-end-line="33" selection-end-column="3" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/lib/CatalogSolr.js">
<entry file="file://$PROJECT_DIR$/test-data/FARMTOFREEWAYS_CATALOG.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="150">
<caret line="22" column="28" selection-start-line="22" selection-start-column="28" selection-end-line="22" selection-end-column="28" />
<state relative-caret-position="227">
<caret line="16" column="15" lean-forward="true" selection-start-line="16" selection-start-column="15" selection-end-line="16" selection-end-column="15" />
</state>
</provider>
</entry>
......
......@@ -143,6 +143,32 @@ class CatalogSolr {
return base;
}
createSolrObject(catalog, jsonld, root, config) {
//Peter's idea is to convert everything into an array then it is safer to work to convert
const graph = _.each(jsonld[root], (g) => {
return catalog.ensureObjArray(g);
});
const solrObject = {};
_.each(config, (field, type) => {
let graphElement = _.filter(graph, (g) => {
return _.find(g['@type'], (gg) => gg === type) ? g : undefined;
});
if (graphElement) {
_.each(graphElement, (ge) => {
if (Array.isArray(solrObject[type])) {
solrObject[type].push(catalog.getGraphElement(config[type], graph, ge));
} else {
solrObject[type] = [catalog.getGraphElement(config[type], graph, ge)];
}
});
}
});
return solrObject;
}
}
module.exports = CatalogSolr;
\ No newline at end of file
File moved
const assert = require('assert');
const _ = require('lodash');
const path = require('path');
const fs = require('fs-extra');
const CatalogSolr = require('../lib/CatalogSolr');
function jsonRecord(basePath, fileName) {
try {
const entryPath = path.join(basePath, fileName);
if (fs.existsSync(entryPath)) {
let entryJson = fs.readFileSync(entryPath).toString();
return JSON.parse(entryJson);
}
} catch (e) {
console.error(e.message);
process.exit(-1);
}
}
describe('create solr object', function () {
const fieldsPath = path.join(process.cwd(), 'test-data', 'fields.json');
let catalog = new CatalogSolr();
const fields = require(fieldsPath);
catalog.setConfig(fields);
it('should use library to create a solr object', function () {
const ca = jsonRecord(process.cwd(), path.join('test-data', 'FARMTOFREEWAYS_CATALOG.json'));
const solrObject = catalog.createSolrObject(catalog, ca, '@graph', fields);
assert.strictEqual(solrObject['Dataset'][0]['record_format_s'], 'Dataset','Dataset not loaded');
});
});
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment