Commit 1011364c authored by Kapilraj Thangeswaran's avatar Kapilraj Thangeswaran

Ajout conversion de plusieurs hdoc et mise à jour readme

parent e978707d
......@@ -12,24 +12,53 @@ Kapilraj Thangeswaran
This module is able to extract data from a file in Hdoc format and insert them into MongoDB.
## Dependencies
In order to make this project work you have to install Node.js from the following link : https://nodejs.org/en/
- In order to make this module work you have to download and install Node.js from the [Node.js download page](https://nodejs.org/en/).
- If needed, download and install MongoDB from the [MongoDB download page](https://www.mongodb.com/download-center#community).
## Instructions
- Install dependencies.
- Then edit the file "config.json" in the "mongo" folder (for more details, please check "Mongo configuration")
- Execute run.bat or run.sh
1. Install dependencies
2. Edit "config.json" file from "mongo" folder (for more details, please check "Mongo configuration")
3. Execute run.bat or run.sh
## Mongo configuration
## Web
This module provides a Web application to access MongoDB and execute simples requests.
1. Launch MongoDB using `mongod.exe --rest --jsonp` command from "MongoDB/Server/3.2/bin" folder.
2. Edit "config.json" file from "web" folder (for more details, please check "MongoDB configuration")
3. Open "index.html" in "web" folder
## MongoDB configuration
### In "mongo" folder
Use "config.json" in the "mongo" folder to specify :
- url : your mongodb's url
- url : mongodb's url
- database : the database you are using
- collection : the collection you are using
- request : the request you want to perform (for allowed requests, please check "Supported requests")
```javascript
{
"url" : "mongodb://localhost:27017/",
"database" : "database",
"collection" : "collection",
"request" : "insert"
}
```
### In "web" folder
Use "config.json" in the "web" folder to specify :
- url : mongodb's url
- database : the database you are using
- collection : the collection you are using
- request : the request you want to perform (for allowed requests, please check "Supported requests")
```javascript
{
"url" : "mongodb://localhost:27017/",
"database" : "database",
"collection" : "collection",
}
```
## Supported requests
- insert
## User stories
En tant qu’utilisateur rédigeant des documents sous opale, je veux récupérer les exercices corrigés d’un sujet donné dans le but de les réutiliser.
En tant qu’utilisateur rédigeant des documents sous opale, je veux récupérer les cours d’un auteur précis dans le but d’utiliser ses cours comme références.
En tant qu’utilisateur universitaire, je souhaite mettre à disposition mes exercices sur internet de manière structuré dans le but de permettre à d’autre utilisateurs universitaires de les trouver, par thème, auteur ou contenu et de les réutiliser.
- En tant qu’utilisateur rédigeant des documents sous opale, je veux récupérer les exercices corrigés d’un sujet donné dans le but de les réutiliser.
- En tant qu’utilisateur rédigeant des documents sous opale, je veux récupérer les cours d’un auteur précis dans le but d’utiliser ses cours comme références.
- En tant qu’utilisateur universitaire, je souhaite mettre à disposition mes exercices sur internet de manière structuré dans le but de permettre à d’autre utilisateurs universitaires de les trouver, par thème, auteur ou contenu et de les réutiliser.
<project name="hdoc_to_optim" default="insertion">
<project name="hdoc_to_mongo" default="insertion">
<property file="build.properties"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib.jar"/>
</classpath>
</taskdef>
<target name="preparation">
<mkdir dir="${tmpdir}"/>
<chmod perm="777" dir="${tmpdir}"></chmod>
......@@ -10,29 +16,48 @@
<chmod perm="777" dir="${outputPath}"></chmod>
</target>
<target name="unzipSource" depends="preparation">
<fileset dir="${inputPath}" id="hdocFile">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="hdocFilePath" pathsep="" refid="hdocFile" />
<echo>Entry file : ${hdocFilePath}</echo>
<target name="main" depends="preparation">
<for param="file">
<path>
<fileset dir="${inputPath}" includes="*.hdoc"/>
</path>
<sequential>
<var name="fileName" unset="true"/>
<basename file="@{file}" property="fileName"/>
<antcall target="unzipHdoc">
<param name="file" value="${fileName}"/>
</antcall>
<antcall target="convertHdoc">
<param name="file" value="${fileName}"/>
</antcall>
<antcall target="clean" />
</sequential>
</for>
</target>
<target name="unzipHdoc">
<echo>Unzip ${inputPath}/${file}</echo>
<!--unzips the hdoc to be converted-->
<unzip dest="${tmpdir}" src ="${hdocFilePath}"/>
<unzip dest="${tmpdir}" src="${inputPath}/${file}"/>
</target>
<target name="convertHdoc" depends="unzipSource">
<xslt in="${tmpdir}/content.xml" out="${outputPath}/result.json" style="xsl/main.xsl"/>
<target name="convertHdoc">
<echo>Convert ${inputPath}/${file}</echo>
<basename property="basename" file="${inputPath}/${file}" suffix=".hdoc"/>
<xslt in="${tmpdir}/content.xml" out="${outputPath}/${basename}.json" style="xsl/main.xsl"/>
</target>
<target name="insertion" depends="convertHdoc">
<target name="clean">
<delete dir="${tmpdir}" />
</target>
<target name="insertion" depends="main">
<exec executable="node" dir="mongo">
<arg line="main.js"/>
</exec>
</target>
<target name="clean" depends="unzipSource">
<delete dir="${tmpdir}" />
</target>
</project>
\ No newline at end of file
......@@ -3,28 +3,30 @@ const config = JSON.parse(fs.readFileSync('config.json'));
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const ObjectId = require('mongodb').ObjectID;
console.log(config['url'] + "/" + config['database']);
var url = config['url'];
var url = config.url;
if(url.slice(-1) == "/") {
url += config['database'];
url += config.database;
} else {
url += "/" + config['database'];
url += "/" + config.database;
}
const resultFile = '../output/result.json';
const outputFolder = "../output";
var insertDocument = function(db, collection, json, callback) {
db.collection(collection).insertOne(json, function(err, result) {
db.collection(collection).insertOne(json, function(err, result) {
assert.equal(err, null);
console.log("Inserted a document into the " + collection + " collection.");
console.log(json.title + " inserted into " + collection + " collection.");
callback();
});
};
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
if(config['request'] === 'insert') {
insertDocument(db, config['collection'], JSON.parse(fs.readFileSync(resultFile)), function() {
db.close();
});
}
assert.equal(null, err);
fs.readdir(outputFolder, (err, files) => {
files.forEach(file => {
if(config.request === 'insert') {
insertDocument(db, config.collection, JSON.parse(fs.readFileSync(outputFolder + "/" + file)), function(){});
}
});
db.close();
});
});
\ No newline at end of file
Markdown is supported
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