Révision 5
projets/BCCCC/.classpath (revision 5) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<classpath> |
|
3 |
<classpathentry kind="src" path="src"/> |
|
4 |
<classpathentry kind="src" output="test-classes" path="test"/> |
|
5 |
<classpathentry kind="con" path="com.google.gwt.eclipse.core.GWT_CONTAINER"/> |
|
6 |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> |
|
7 |
<classpathentry kind="lib" path="war/WEB-INF/lib/smartgwt-skins.jar"/> |
|
8 |
<classpathentry kind="lib" path="war/WEB-INF/lib/smartgwt.jar"/> |
|
9 |
<classpathentry kind="lib" path="war/WEB-INF/lib/gwt-servlet.jar"/> |
|
10 |
<classpathentry kind="lib" path="war/WEB-INF/lib/hsqldb.jar"/> |
|
11 |
<classpathentry kind="lib" path="war/WEB-INF/lib/servlet-2_3-fcs-classfiles.zip"/> |
|
12 |
<classpathentry kind="lib" path="war/WEB-INF/lib/sqltool.jar"/> |
|
13 |
<classpathentry kind="output" path="war/WEB-INF/classes"/> |
|
14 |
</classpath> |
projets/BCCCC/.project (revision 5) | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
<projectDescription> |
|
3 |
<name>BCCCC</name> |
|
4 |
<comment></comment> |
|
5 |
<projects> |
|
6 |
</projects> |
|
7 |
<buildSpec> |
|
8 |
<buildCommand> |
|
9 |
<name>org.eclipse.wst.common.project.facet.core.builder</name> |
|
10 |
<arguments> |
|
11 |
</arguments> |
|
12 |
</buildCommand> |
|
13 |
<buildCommand> |
|
14 |
<name>org.eclipse.jdt.core.javabuilder</name> |
|
15 |
<arguments> |
|
16 |
</arguments> |
|
17 |
</buildCommand> |
|
18 |
<buildCommand> |
|
19 |
<name>com.google.gdt.eclipse.core.webAppProjectValidator</name> |
|
20 |
<arguments> |
|
21 |
</arguments> |
|
22 |
</buildCommand> |
|
23 |
<buildCommand> |
|
24 |
<name>com.google.gwt.eclipse.core.gwtProjectValidator</name> |
|
25 |
<arguments> |
|
26 |
</arguments> |
|
27 |
</buildCommand> |
|
28 |
</buildSpec> |
|
29 |
<natures> |
|
30 |
<nature>org.eclipse.jdt.core.javanature</nature> |
|
31 |
<nature>com.google.gwt.eclipse.core.gwtNature</nature> |
|
32 |
<nature>org.eclipse.wst.common.project.facet.core.nature</nature> |
|
33 |
</natures> |
|
34 |
</projectDescription> |
projets/BCCCC/db/bccc.script (revision 5) | ||
---|---|---|
1 |
SET DATABASE UNIQUE NAME HSQLDB4E0077E43C |
|
2 |
SET DATABASE GC 0 |
|
3 |
SET DATABASE DEFAULT RESULT MEMORY ROWS 0 |
|
4 |
SET DATABASE EVENT LOG LEVEL 0 |
|
5 |
SET DATABASE TRANSACTION CONTROL LOCKS |
|
6 |
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED |
|
7 |
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE |
|
8 |
SET DATABASE TEXT TABLE DEFAULTS '' |
|
9 |
SET DATABASE SQL NAMES FALSE |
|
10 |
SET DATABASE SQL REFERENCES FALSE |
|
11 |
SET DATABASE SQL SIZE TRUE |
|
12 |
SET DATABASE SQL TYPES FALSE |
|
13 |
SET DATABASE SQL TDC DELETE TRUE |
|
14 |
SET DATABASE SQL TDC UPDATE TRUE |
|
15 |
SET DATABASE SQL TRANSLATE TTI TYPES TRUE |
|
16 |
SET DATABASE SQL CONCAT NULLS TRUE |
|
17 |
SET DATABASE SQL UNIQUE NULLS TRUE |
|
18 |
SET DATABASE SQL CONVERT TRUNCATE TRUE |
|
19 |
SET DATABASE SQL AVG SCALE 0 |
|
20 |
SET DATABASE SQL DOUBLE NAN TRUE |
|
21 |
SET FILES WRITE DELAY 500 MILLIS |
|
22 |
SET FILES BACKUP INCREMENT TRUE |
|
23 |
SET FILES CACHE SIZE 10000 |
|
24 |
SET FILES CACHE ROWS 50000 |
|
25 |
SET FILES SCALE 32 |
|
26 |
SET FILES LOB SCALE 32 |
|
27 |
SET FILES DEFRAG 0 |
|
28 |
SET FILES NIO TRUE |
|
29 |
SET FILES NIO SIZE 256 |
|
30 |
SET FILES LOG TRUE |
|
31 |
SET FILES LOG SIZE 50 |
|
32 |
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e' |
|
33 |
ALTER USER SA SET LOCAL TRUE |
|
34 |
CREATE SCHEMA PUBLIC AUTHORIZATION DBA |
|
35 |
SET SCHEMA PUBLIC |
|
36 |
CREATE MEMORY TABLE PUBLIC.TERRAINS(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),LIEU VARCHAR(45),PARTICIPANTS INTEGER,DATE VARCHAR(45)) |
|
37 |
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1 |
|
38 |
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC |
|
39 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC |
|
40 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC |
|
41 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC |
|
42 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC |
|
43 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC |
|
44 |
GRANT DBA TO SA |
|
45 |
SET SCHEMA SYSTEM_LOBS |
|
46 |
INSERT INTO BLOCKS VALUES(0,2147483647,0) |
projets/BCCCC/db/bcccc.script (revision 5) | ||
---|---|---|
1 |
SET DATABASE UNIQUE NAME HSQLDB4E0077559C |
|
2 |
SET DATABASE GC 0 |
|
3 |
SET DATABASE DEFAULT RESULT MEMORY ROWS 0 |
|
4 |
SET DATABASE EVENT LOG LEVEL 0 |
|
5 |
SET DATABASE TRANSACTION CONTROL LOCKS |
|
6 |
SET DATABASE DEFAULT ISOLATION LEVEL READ COMMITTED |
|
7 |
SET DATABASE TRANSACTION ROLLBACK ON CONFLICT TRUE |
|
8 |
SET DATABASE TEXT TABLE DEFAULTS '' |
|
9 |
SET DATABASE SQL NAMES FALSE |
|
10 |
SET DATABASE SQL REFERENCES FALSE |
|
11 |
SET DATABASE SQL SIZE TRUE |
|
12 |
SET DATABASE SQL TYPES FALSE |
|
13 |
SET DATABASE SQL TDC DELETE TRUE |
|
14 |
SET DATABASE SQL TDC UPDATE TRUE |
|
15 |
SET DATABASE SQL TRANSLATE TTI TYPES TRUE |
|
16 |
SET DATABASE SQL CONCAT NULLS TRUE |
|
17 |
SET DATABASE SQL UNIQUE NULLS TRUE |
|
18 |
SET DATABASE SQL CONVERT TRUNCATE TRUE |
|
19 |
SET DATABASE SQL AVG SCALE 0 |
|
20 |
SET DATABASE SQL DOUBLE NAN TRUE |
|
21 |
SET FILES WRITE DELAY 0 |
|
22 |
SET FILES BACKUP INCREMENT TRUE |
|
23 |
SET FILES CACHE SIZE 10000 |
|
24 |
SET FILES CACHE ROWS 50000 |
|
25 |
SET FILES SCALE 32 |
|
26 |
SET FILES LOB SCALE 32 |
|
27 |
SET FILES DEFRAG 0 |
|
28 |
SET FILES NIO TRUE |
|
29 |
SET FILES NIO SIZE 256 |
|
30 |
SET FILES LOG TRUE |
|
31 |
SET FILES LOG SIZE 50 |
|
32 |
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e' |
|
33 |
ALTER USER SA SET LOCAL TRUE |
|
34 |
CREATE SCHEMA PUBLIC AUTHORIZATION DBA |
|
35 |
SET SCHEMA PUBLIC |
|
36 |
CREATE MEMORY TABLE PUBLIC.TERRAINS(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),LIEU VARCHAR(45),PARTICIPANTS INTEGER,DATE VARCHAR(45)) |
|
37 |
CREATE MEMORY TABLE PUBLIC.PROJETS(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),LIEN VARCHAR(45),ID_DISCIPLINE INTEGER) |
|
38 |
CREATE MEMORY TABLE PUBLIC.DISCIPLINES(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),DESC VARCHAR(45)) |
|
39 |
CREATE MEMORY TABLE PUBLIC.PRODUIT_PAR_PROJET(ID_PROJET INTEGER,ID_TERRAIN INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_PROJET) REFERENCES PUBLIC.PROJETS(ID)) |
|
40 |
CREATE MEMORY TABLE PUBLIC.PARTICIPANTS(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),ROLE VARCHAR(45)) |
|
41 |
CREATE MEMORY TABLE PUBLIC.PARTICIPE(ID_PARTICIPANT INTEGER,ID_PROJET INTEGER) |
|
42 |
CREATE MEMORY TABLE PUBLIC.EVALUATIONS(ID INTEGER PRIMARY KEY,COMMENTAIRE VARCHAR(45),ID_TERRAIN INTEGER,ID_PARTICIPANT INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_PARTICIPANT) REFERENCES PUBLIC.PARTICIPANTS(ID)) |
|
43 |
CREATE MEMORY TABLE PUBLIC.RETOURS(ID INTEGER PRIMARY KEY,TYPE VARCHAR(45),LIEN VARCHAR(45),ID_TERRAIN INTEGER,ID_DONNEE INTEGER,ID_PARTICIPANT INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_PARTICIPANT) REFERENCES PUBLIC.PARTICIPANTS(ID)) |
|
44 |
CREATE MEMORY TABLE PUBLIC.TYPES(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),DESC VARCHAR(45)) |
|
45 |
CREATE MEMORY TABLE PUBLIC.EST_DE_TYPE(ID_TYPE INTEGER,ID_TERRAIN INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_TYPE) REFERENCES PUBLIC.TYPES(ID)) |
|
46 |
CREATE MEMORY TABLE PUBLIC.KEYWORDS(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),DESC VARCHAR(45)) |
|
47 |
CREATE MEMORY TABLE PUBLIC.A_POUR_KEYWORD(ID_KEYWORD INTEGER,ID_TERRAIN INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_KEYWORD) REFERENCES PUBLIC.KEYWORDS(ID)) |
|
48 |
CREATE MEMORY TABLE PUBLIC.MATERIAUX(ID INTEGER PRIMARY KEY,NAME VARCHAR(45),LIEN_RAVI VARCHAR(45),TYPE VARCHAR(45),MOBILE BOOLEAN) |
|
49 |
CREATE MEMORY TABLE PUBLIC.UTILISE_PAR(ID_MATERIEL INTEGER,ID_TERRAIN INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_MATERIEL) REFERENCES PUBLIC.MATERIAUX(ID)) |
|
50 |
CREATE MEMORY TABLE PUBLIC.DOCUMENTATIONS(ID INTEGER PRIMARY KEY,ID_TYPE_DOCUMENTATION VARCHAR(45),LIEN VARCHAR(45)) |
|
51 |
CREATE MEMORY TABLE PUBLIC.DOCUMENTE(ID_DOCUMENT INTEGER,ID_TERRAIN INTEGER,FOREIGN KEY(ID_TERRAIN) REFERENCES PUBLIC.TERRAINS(ID),FOREIGN KEY(ID_DOCUMENT) REFERENCES PUBLIC.DOCUMENTATIONS(ID)) |
|
52 |
ALTER TABLE PUBLIC.PROJETS ADD FOREIGN KEY(ID_DISCIPLINE) REFERENCES PUBLIC.DISCIPLINES(ID) |
|
53 |
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1 |
|
54 |
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC |
|
55 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC |
|
56 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.YES_OR_NO TO PUBLIC |
|
57 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.TIME_STAMP TO PUBLIC |
|
58 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CARDINAL_NUMBER TO PUBLIC |
|
59 |
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.CHARACTER_DATA TO PUBLIC |
|
60 |
GRANT DBA TO SA |
|
61 |
SET SCHEMA SYSTEM_LOBS |
|
62 |
INSERT INTO BLOCKS VALUES(0,2147483647,0) |
projets/BCCCC/db/bccc.properties (revision 5) | ||
---|---|---|
1 |
#HSQL Database Engine 2.3.2 |
|
2 |
#Wed Jun 17 09:44:49 CEST 2015 |
|
3 |
version=2.3.2 |
|
4 |
modified=no |
projets/BCCCC/db/bcccc.properties (revision 5) | ||
---|---|---|
1 |
#HSQL Database Engine 2.3.2 |
|
2 |
#Wed Jun 17 12:07:49 CEST 2015 |
|
3 |
version=2.3.2 |
|
4 |
modified=no |
projets/BCCCC/mydatabase.properties (revision 5) | ||
---|---|---|
1 |
#HSQL Database Engine 2.3.2 |
|
2 |
#Wed Jun 17 09:35:19 CEST 2015 |
|
3 |
version=2.3.2 |
|
4 |
modified=yes |
projets/BCCCC/src/org/ccc/bcccc/server/ConfigDB.java (revision 5) | ||
---|---|---|
1 |
/* |
|
2 |
* Authors: Matthieu Decorde |
|
3 |
* |
|
4 |
* COPYRIGHT 2015 ICAR - CCC |
|
5 |
* |
|
6 |
* This software is free software: you can redistribute it |
|
7 |
* and/or modify it under the terms of the GNU General Public |
|
8 |
* License as published by the Free Software Foundation, |
|
9 |
* either version 2 of the License, or (at your option) any |
|
10 |
* later version. |
|
11 |
* |
|
12 |
* This software is distributed in the hope that it will be |
|
13 |
* useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
* PURPOSE. See the GNU General Public License for more |
|
16 |
* details. |
|
17 |
* |
|
18 |
*/ |
|
19 |
package org.ccc.bcccc.server; |
|
20 |
|
|
21 |
import java.io.BufferedReader; |
|
22 |
import java.io.BufferedWriter; |
|
23 |
import java.io.File; |
|
24 |
import java.io.FileReader; |
|
25 |
import java.io.FileWriter; |
|
26 |
import java.io.IOException; |
|
27 |
import java.util.HashMap; |
|
28 |
|
|
29 |
// TODO: Auto-generated Javadoc |
|
30 |
/** |
|
31 |
* The Class ConfigDB. |
|
32 |
*/ |
|
33 |
public class ConfigDB { |
|
34 |
|
|
35 |
/** The Constant HOMEDIR. */ |
|
36 |
public static final File HOMEDIR = new File(System.getProperty("user.home"), "bcccc"); |
|
37 |
|
|
38 |
/** The Constant config_db_file. */ |
|
39 |
protected static final File config_db_file = new File(HOMEDIR, "config.txt"); |
|
40 |
|
|
41 |
/** The Constant ADMIN. */ |
|
42 |
public static final String ADMIN = "ADMIN"; |
|
43 |
|
|
44 |
/** The Constant CONTACT. */ |
|
45 |
public static final String CONTACT = "CONTACT"; |
|
46 |
|
|
47 |
|
|
48 |
/** The Constant db. */ |
|
49 |
protected static final HashMap<String, String> db = new HashMap<String, String>(); |
|
50 |
|
|
51 |
/** The loaded. */ |
|
52 |
protected static boolean loaded = false; |
|
53 |
|
|
54 |
|
|
55 |
static { |
|
56 |
HOMEDIR.mkdir(); |
|
57 |
if (!HOMEDIR.exists()) { |
|
58 |
GreetingServiceImpl.log.severe("Fail to create HOMEDIR config directory "+HOMEDIR); |
|
59 |
} else { |
|
60 |
// load values at start up |
|
61 |
try { |
|
62 |
load(); |
|
63 |
} catch (IOException e) { |
|
64 |
GreetingServiceImpl.log.severe("Fail to load config from "+config_db_file+" : "+e); |
|
65 |
e.printStackTrace(); |
|
66 |
} |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* Load. |
|
72 |
* |
|
73 |
* @throws IOException Signals that an I/O exception has occurred. |
|
74 |
*/ |
|
75 |
public static void load() throws IOException { |
|
76 |
if (!config_db_file.exists()) { // create a sample users.txt |
|
77 |
GreetingServiceImpl.log.severe("ConfigDB: the "+config_db_file+" file is missing creating a sample one."); |
|
78 |
BufferedWriter writer = new BufferedWriter(new FileWriter(config_db_file)); |
|
79 |
writer.write(ADMIN+"\tadmin@ens-lyon.fr\n"); |
|
80 |
writer.write(CONTACT+"\tmatthieu.decorde@ens-lyon.Fr\n"); |
|
81 |
writer.close(); |
|
82 |
} |
|
83 |
|
|
84 |
BufferedReader reader = new BufferedReader(new FileReader(config_db_file)); |
|
85 |
String line = reader.readLine(); |
|
86 |
while (line != null) { |
|
87 |
String[] split = line.split("\t",2); |
|
88 |
db.put(split[0], split[1]); |
|
89 |
line = reader.readLine(); |
|
90 |
} |
|
91 |
reader.close(); |
|
92 |
loaded = true; |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* Gets the admin. |
|
97 |
* |
|
98 |
* @return the admin |
|
99 |
*/ |
|
100 |
public static String getAdmin() { |
|
101 |
return db.get(ADMIN); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Gets the contact. |
|
106 |
* |
|
107 |
* @return the contact |
|
108 |
*/ |
|
109 |
public static String getContact() { |
|
110 |
return db.get(CONTACT); |
|
111 |
} |
|
112 |
} |
projets/BCCCC/src/org/ccc/bcccc/server/HSQLDB.java (revision 5) | ||
---|---|---|
1 |
/* |
|
2 |
* Authors: Matthieu Decorde |
|
3 |
* |
|
4 |
* COPYRIGHT 2015 ICAR - CCC |
|
5 |
* |
|
6 |
* This software is free software: you can redistribute it |
|
7 |
* and/or modify it under the terms of the GNU General Public |
|
8 |
* License as published by the Free Software Foundation, |
|
9 |
* either version 2 of the License, or (at your option) any |
|
10 |
* later version. |
|
11 |
* |
|
12 |
* This software is distributed in the hope that it will be |
|
13 |
* useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
* PURPOSE. See the GNU General Public License for more |
|
16 |
* details. |
|
17 |
* |
|
18 |
*/ |
|
19 |
package org.ccc.bcccc.server; |
|
20 |
|
|
21 |
import java.sql.Connection; |
|
22 |
import java.sql.DriverManager; |
|
23 |
import java.sql.PreparedStatement; |
|
24 |
import java.sql.ResultSet; |
|
25 |
import java.sql.SQLException; |
|
26 |
|
|
27 |
// TODO: Auto-generated Javadoc |
|
28 |
/** |
|
29 |
* The Class HSQLDB. |
|
30 |
*/ |
|
31 |
public class HSQLDB { |
|
32 |
|
|
33 |
/** The con. */ |
|
34 |
private Connection con; |
|
35 |
|
|
36 |
/** |
|
37 |
* Inits the. |
|
38 |
* |
|
39 |
* @return true, if successful |
|
40 |
*/ |
|
41 |
public boolean init() { |
|
42 |
try { |
|
43 |
Class.forName("org.hsqldb.jdbc.JDBCDriver"); |
|
44 |
} catch (ClassNotFoundException e) { |
|
45 |
e.printStackTrace(System.out); |
|
46 |
return false; |
|
47 |
} |
|
48 |
try { |
|
49 |
con = DriverManager.getConnection("jdbc:hsqldb:file:db/bcccc;shutdown=true;hsqldb.write_delay=false","SA",""); |
|
50 |
//con = DriverManager.getConnection("jdbc:hsqldb:mydatabase","SA",""); |
|
51 |
|
|
52 |
con.createStatement().executeUpdate("create table terrains (id integer, primary key(id), name varchar(45),lieu varchar(45), participants integer, date varchar(45))"); |
|
53 |
|
|
54 |
con.createStatement().executeUpdate("create table projets (id integer, primary key(id), name varchar(45),lien varchar(45), id_discipline integer)"); |
|
55 |
con.createStatement().executeUpdate("create table disciplines (id integer, primary key(id), name varchar(45),desc varchar(45))"); |
|
56 |
con.createStatement().executeUpdate("alter table projets add foreign key(id_discipline) references disciplines(id)"); |
|
57 |
con.createStatement().executeUpdate("create table produit_par_projet (id_projet integer, id_terrain integer)"); |
|
58 |
con.createStatement().executeUpdate("alter table produit_par_projet add foreign key(id_terrain) references terrains(id)"); |
|
59 |
con.createStatement().executeUpdate("alter table produit_par_projet add foreign key(id_projet) references projets(id)"); |
|
60 |
|
|
61 |
con.createStatement().executeUpdate("create table participants (id integer, primary key(id), name varchar(45),role varchar(45))"); |
|
62 |
con.createStatement().executeUpdate("create table participe (id_participant integer, id_projet integer)"); |
|
63 |
|
|
64 |
con.createStatement().executeUpdate("create table evaluations (id integer, primary key(id), commentaire varchar(45), id_terrain integer, id_participant integer)"); |
|
65 |
con.createStatement().executeUpdate("alter table evaluations add foreign key(id_terrain) references terrains(id)"); |
|
66 |
con.createStatement().executeUpdate("alter table evaluations add foreign key(id_participant) references participants(id)"); |
|
67 |
con.createStatement().executeUpdate("create table retours (id integer, primary key(id), type varchar(45), lien varchar(45), id_terrain integer, id_donnee integer, id_participant integer)"); |
|
68 |
con.createStatement().executeUpdate("alter table retours add foreign key(id_terrain) references terrains(id)"); |
|
69 |
con.createStatement().executeUpdate("alter table retours add foreign key(id_participant) references participants(id)"); |
|
70 |
|
|
71 |
con.createStatement().executeUpdate("create table types (id integer, primary key(id), name varchar(45),desc varchar(45))"); |
|
72 |
con.createStatement().executeUpdate("create table est_de_type (id_type integer, id_terrain integer)"); |
|
73 |
con.createStatement().executeUpdate("alter table est_de_type add foreign key(id_terrain) references terrains(id)"); |
|
74 |
con.createStatement().executeUpdate("alter table est_de_type add foreign key(id_type) references types(id)"); |
|
75 |
|
|
76 |
con.createStatement().executeUpdate("create table keywords (id integer, primary key(id), name varchar(45),desc varchar(45))"); |
|
77 |
con.createStatement().executeUpdate("create table a_pour_keyword (id_keyword integer, id_terrain integer)"); |
|
78 |
con.createStatement().executeUpdate("alter table a_pour_keyword add foreign key(id_terrain) references terrains(id)"); |
|
79 |
con.createStatement().executeUpdate("alter table a_pour_keyword add foreign key(id_keyword) references keywords(id)"); |
|
80 |
|
|
81 |
con.createStatement().executeUpdate("create table materiaux (id integer, primary key(id), name varchar(45),lien_ravi varchar(45), type varchar(45), mobile boolean)"); |
|
82 |
con.createStatement().executeUpdate("create table utilise_par (id_materiel integer, id_terrain integer)"); |
|
83 |
con.createStatement().executeUpdate("alter table utilise_par add foreign key(id_terrain) references terrains(id)"); |
|
84 |
con.createStatement().executeUpdate("alter table utilise_par add foreign key(id_materiel) references materiaux(id)"); |
|
85 |
|
|
86 |
con.createStatement().executeUpdate("create table documentations (id integer, primary key(id), id_type_documentation varchar(45),lien varchar(45))"); |
|
87 |
con.createStatement().executeUpdate("create table documente (id_document integer, id_terrain integer)"); |
|
88 |
con.createStatement().executeUpdate("alter table documente add foreign key(id_terrain) references terrains(id)"); |
|
89 |
con.createStatement().executeUpdate("alter table documente add foreign key(id_document) references documentations(id)"); |
|
90 |
|
|
91 |
// con.createStatement().executeUpdate("create table contacts (name varchar(45),email varchar(45),phone varchar(45))"); |
|
92 |
|
|
93 |
// PreparedStatement pst; |
|
94 |
// pst = con.prepareStatement("insert into contacts values(?,?,?)"); |
|
95 |
// pst.clearParameters(); |
|
96 |
// pst.setString(1, "name value"); |
|
97 |
// pst.setString(2, "email value"); |
|
98 |
// pst.setString(3, "phone value"); |
|
99 |
// int i = pst.executeUpdate(); |
|
100 |
// |
|
101 |
con.commit(); |
|
102 |
|
|
103 |
} catch (SQLException e) { |
|
104 |
e.printStackTrace(System.out); |
|
105 |
return false; |
|
106 |
} |
|
107 |
|
|
108 |
return true; |
|
109 |
} |
|
110 |
|
|
111 |
/** |
|
112 |
* Prints the db. |
|
113 |
*/ |
|
114 |
public void printDB() { |
|
115 |
PreparedStatement pst; |
|
116 |
try { |
|
117 |
System.out.println("listing terrains..."); |
|
118 |
pst = con.prepareStatement("select * from terrains"); |
|
119 |
|
|
120 |
pst.clearParameters(); |
|
121 |
ResultSet rs=pst.executeQuery(); |
|
122 |
while(rs.next()){ |
|
123 |
System.out.println("id="+rs.getString(1)); |
|
124 |
System.out.println("name="+rs.getString(2)); |
|
125 |
System.out.println("lieu="+rs.getString(3)); |
|
126 |
System.out.println("participants="+rs.getString(4)); |
|
127 |
System.out.println("date="+rs.getString(5)); |
|
128 |
} |
|
129 |
} catch (SQLException e) { |
|
130 |
// TODO Auto-generated catch block |
|
131 |
e.printStackTrace(); |
|
132 |
} |
|
133 |
} |
|
134 |
|
|
135 |
/** |
|
136 |
* The main method. |
|
137 |
* |
|
138 |
* @param args the arguments |
|
139 |
*/ |
|
140 |
public static void main(String[] args) { |
|
141 |
HSQLDB db = new HSQLDB(); |
|
142 |
if (db.init()) { |
|
143 |
System.out.println("DB ready."); |
|
144 |
db.printDB(); |
|
145 |
//db.close(); |
|
146 |
} else { |
|
147 |
System.out.println("DB init fail."); |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
/** |
|
152 |
* Close. |
|
153 |
*/ |
|
154 |
private void close() { |
|
155 |
try { |
|
156 |
|
|
157 |
con.close(); |
|
158 |
} catch (SQLException e) { |
|
159 |
// TODO Auto-generated catch block |
|
160 |
e.printStackTrace(); |
|
161 |
} |
|
162 |
} |
|
163 |
} |
projets/BCCCC/src/org/ccc/bcccc/server/GreetingServiceImpl.java (revision 5) | ||
---|---|---|
1 |
/* |
|
2 |
* Authors: Matthieu Decorde |
|
3 |
* |
|
4 |
* COPYRIGHT 2015 ICAR - CCC |
|
5 |
* |
|
6 |
* This software is free software: you can redistribute it |
|
7 |
* and/or modify it under the terms of the GNU General Public |
|
8 |
* License as published by the Free Software Foundation, |
|
9 |
* either version 2 of the License, or (at your option) any |
|
10 |
* later version. |
|
11 |
* |
|
12 |
* This software is distributed in the hope that it will be |
|
13 |
* useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
* PURPOSE. See the GNU General Public License for more |
|
16 |
* details. |
|
17 |
* |
|
18 |
*/ |
|
19 |
package org.ccc.bcccc.server; |
|
20 |
|
|
21 |
import java.util.ArrayList; |
|
22 |
import java.util.Arrays; |
|
23 |
import java.util.HashMap; |
|
24 |
import java.util.List; |
|
25 |
import java.util.logging.Logger; |
|
26 |
import java.util.regex.Pattern; |
|
27 |
|
|
28 |
import org.ccc.bcccc.client.GreetingService; |
|
29 |
import org.ccc.bcccc.shared.K; |
|
30 |
import org.ccc.bcccc.shared.TerrainRecord; |
|
31 |
import org.ccc.bcccc.shared.TerrainRecordAndRights; |
|
32 |
import org.eclipse.jetty.util.log.Log; |
|
33 |
|
|
34 |
import com.google.gwt.user.server.rpc.RemoteServiceServlet; |
|
35 |
|
|
36 |
// TODO: Auto-generated Javadoc |
|
37 |
/** |
|
38 |
* The server-side implementation of the RPC service. |
|
39 |
*/ |
|
40 |
public class GreetingServiceImpl extends RemoteServiceServlet implements GreetingService { |
|
41 |
|
|
42 |
/** The log. */ |
|
43 |
public static Logger log = Logger.getGlobal(); |
|
44 |
|
|
45 |
/** The Constant serialVersionUID. */ |
|
46 |
private static final long serialVersionUID = 8258170818449828341L; |
|
47 |
|
|
48 |
/** The connected users. */ |
|
49 |
static HashMap<String, String> connectedUsers = new HashMap<String, String>(); |
|
50 |
|
|
51 |
/** The records. */ |
|
52 |
static RecordsDB records = new RecordsDB(); |
|
53 |
|
|
54 |
/** The users db. */ |
|
55 |
static UsersDB usersDB = new UsersDB(); |
|
56 |
|
|
57 |
/* (non-Javadoc) |
|
58 |
* @see org.ccc.bcccc.client.GreetingService#createRecord(org.ccc.bcccc.shared.TerrainRecord) |
|
59 |
*/ |
|
60 |
@Override |
|
61 |
public Boolean createRecord(TerrainRecord newRecord) { |
|
62 |
log.info("createRecord: "+newRecord); |
|
63 |
if (isLogged()) { |
|
64 |
|
|
65 |
newRecord.uniq_id = System.currentTimeMillis(); |
|
66 |
|
|
67 |
if (records.containsKey(newRecord.uniq_id)) { |
|
68 |
log.warning("createRecord: record already exists: "+newRecord.uniq_id); |
|
69 |
return false; |
|
70 |
} else { |
|
71 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
72 |
String user = connectedUsers.get(session); |
|
73 |
newRecord.user = user; |
|
74 |
|
|
75 |
records.put(newRecord.uniq_id, newRecord); |
|
76 |
|
|
77 |
if (!records.containsUser(user)) records.registerUser(user); |
|
78 |
records.setRecordToUser(user, newRecord.uniq_id); |
|
79 |
if (records.save(newRecord)) { |
|
80 |
log.info("createRecord: record created: "+newRecord.uniq_id); |
|
81 |
return true; |
|
82 |
} else { |
|
83 |
log.info("createRecord: record NOT created: "+newRecord.uniq_id); |
|
84 |
return false; |
|
85 |
} |
|
86 |
} |
|
87 |
} else { |
|
88 |
log.warning("createRecord: user is NOT logged."); |
|
89 |
return false; |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/* (non-Javadoc) |
|
94 |
* @see org.ccc.bcccc.client.GreetingService#deleteRecord(java.lang.Long) |
|
95 |
*/ |
|
96 |
@Override |
|
97 |
public Boolean deleteRecord(Long ID) { |
|
98 |
log.info("deleteRecord: "+ID); |
|
99 |
if (isLogged()) { |
|
100 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
101 |
String user = connectedUsers.get(session); |
|
102 |
|
|
103 |
log.info("deleteRecord: "+user); |
|
104 |
|
|
105 |
if (!records.containsKey(ID)) { |
|
106 |
log.warning("deleteRecord: record does not exists "+ID); |
|
107 |
return false; |
|
108 |
} else { |
|
109 |
if (records.isRecordSetToUser(user, ID) || user.equals(ConfigDB.getAdmin())) { |
|
110 |
|
|
111 |
log.info("deleteRecord: ok "+ID); |
|
112 |
|
|
113 |
TerrainRecord record = records.get(ID); |
|
114 |
records.remove(ID); |
|
115 |
records.unsetRecordToUser(user, ID); |
|
116 |
records.save(record); |
|
117 |
return true; |
|
118 |
} else { |
|
119 |
log.warning("deleteRecord: user has not the rigths "+user); |
|
120 |
return false; |
|
121 |
} |
|
122 |
} |
|
123 |
} else { |
|
124 |
log.warning("deleteRecord: user is NOT logged."); |
|
125 |
return false; |
|
126 |
} |
|
127 |
} |
|
128 |
|
|
129 |
/* (non-Javadoc) |
|
130 |
* @see org.ccc.bcccc.client.GreetingService#getMyRecords() |
|
131 |
*/ |
|
132 |
@Override |
|
133 |
public ArrayList<TerrainRecord> getMyRecords() { |
|
134 |
log.info("getMyRecords"); |
|
135 |
|
|
136 |
if (isLogged()) { |
|
137 |
|
|
138 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
139 |
String user = connectedUsers.get(session); |
|
140 |
|
|
141 |
log.info("getMyRecords: "+user); |
|
142 |
|
|
143 |
ArrayList<Long> userRecordsID = records.getUserRecordIDs(user); |
|
144 |
|
|
145 |
ArrayList<TerrainRecord> my_records = new ArrayList<TerrainRecord>(); |
|
146 |
|
|
147 |
if (userRecordsID != null) { |
|
148 |
for (Long recordKey : records.keySet()) { |
|
149 |
if (userRecordsID.contains(recordKey)) { |
|
150 |
TerrainRecord r = records.get(recordKey); |
|
151 |
my_records.add(r); |
|
152 |
} |
|
153 |
} |
|
154 |
} |
|
155 |
return my_records; |
|
156 |
} else { |
|
157 |
log.warning("getMyRecords: user is NOT logged."); |
|
158 |
return new ArrayList<TerrainRecord>(); |
|
159 |
} |
|
160 |
} |
|
161 |
|
|
162 |
/* (non-Javadoc) |
|
163 |
* @see org.ccc.bcccc.client.GreetingService#getRecord(java.lang.Long) |
|
164 |
*/ |
|
165 |
@Override |
|
166 |
public TerrainRecordAndRights getRecord(Long ID) { |
|
167 |
log.info("getRecord: "+ID); |
|
168 |
|
|
169 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
170 |
String user = connectedUsers.get(session); |
|
171 |
|
|
172 |
TerrainRecordAndRights r = new TerrainRecordAndRights(records.get(ID)); |
|
173 |
if (user != null) { |
|
174 |
if (user.equals(ConfigDB.getAdmin())) { |
|
175 |
r.deletable = true; |
|
176 |
r.editable = true; |
|
177 |
r.validable = r.record.mustBeValidated; |
|
178 |
} else if (user.equals(r.record.user)) { |
|
179 |
r.deletable = true; |
|
180 |
r.editable = true; |
|
181 |
} |
|
182 |
} |
|
183 |
return r; |
|
184 |
} |
|
185 |
|
|
186 |
/** |
|
187 |
* get all records. |
|
188 |
* |
|
189 |
* @return the records |
|
190 |
*/ |
|
191 |
@Override |
|
192 |
public ArrayList<TerrainRecord> getRecords() { |
|
193 |
log.info("getRecords"); |
|
194 |
ArrayList<TerrainRecord> all_records = new ArrayList<TerrainRecord>(records.values()); |
|
195 |
|
|
196 |
boolean mustRemoveNonValidatedRecords = true; |
|
197 |
|
|
198 |
if (isLogged()) { |
|
199 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
200 |
String user = connectedUsers.get(session); |
|
201 |
|
|
202 |
if (user.equals(ConfigDB.getAdmin())) mustRemoveNonValidatedRecords = false; |
|
203 |
} |
|
204 |
|
|
205 |
if (mustRemoveNonValidatedRecords) { |
|
206 |
log.info("Removing non validated records from "+all_records.size()+" records..."); |
|
207 |
for (int i = 0 ; i < all_records.size() ; i++) { |
|
208 |
TerrainRecord record = all_records.get(i); |
|
209 |
if (record.mustBeValidated) { |
|
210 |
all_records.remove(i); |
|
211 |
log.fine("Remove "+record); |
|
212 |
i--; |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
|
|
217 |
return all_records; |
|
218 |
} |
|
219 |
|
|
220 |
/* (non-Javadoc) |
|
221 |
* @see org.ccc.bcccc.client.GreetingService#getRecordsWithComplexCritera(java.util.HashMap) |
|
222 |
*/ |
|
223 |
@Override |
|
224 |
public ArrayList<TerrainRecord> getRecordsWithComplexCritera(HashMap<String, String> critera) { |
|
225 |
log.info("getRecordWithComplexCritera: "+critera); |
|
226 |
ArrayList<TerrainRecord> searched_records = new ArrayList<TerrainRecord>(); |
|
227 |
|
|
228 |
String words = addBackSlash(critera.get(K.WORDS)).replace(" ", "|"); |
|
229 |
Pattern p = null; |
|
230 |
if (words.length() > 0) { |
|
231 |
try { |
|
232 |
p = Pattern.compile(words); |
|
233 |
} catch(Exception e) { |
|
234 |
log.warning("Error while compiling search pattern with "+words+": "+e); |
|
235 |
p = null; |
|
236 |
} |
|
237 |
} |
|
238 |
List<String> types = new ArrayList<String>(); |
|
239 |
if (critera.get(K.TYPES).length() > 0) |
|
240 |
types= Arrays.asList(critera.get(K.TYPES).split(",")); |
|
241 |
|
|
242 |
List<String> dispositifs = new ArrayList<String>(); |
|
243 |
if (critera.get(K.DISPOSITIFS).length() > 0) |
|
244 |
dispositifs = Arrays.asList(critera.get(K.DISPOSITIFS).split(",")); |
|
245 |
|
|
246 |
List<String> supports = new ArrayList<String>(); |
|
247 |
if (critera.get(K.SUPPORTS).length() > 0) |
|
248 |
supports = Arrays.asList(critera.get(K.SUPPORTS).split(",")); |
|
249 |
|
|
250 |
List<String> projets = new ArrayList<String>(); |
|
251 |
if (critera.get(K.PROJECTS).length() > 0) |
|
252 |
projets = Arrays.asList(critera.get(K.PROJECTS).split(",")); |
|
253 |
|
|
254 |
int persons = Integer.parseInt(critera.get(K.NUMBEROFPARTICIPANTS)); |
|
255 |
|
|
256 |
log.info("getRecordWithComplexCritera: WORDS="+words+", TYPES="+types+" DISPOSITIFS="+dispositifs+" SUPPORTS="+supports+" PROJECTS="+projets+" NUMBEROFPARTICIPANTS="+persons); |
|
257 |
|
|
258 |
for (TerrainRecord record : records.values()) { |
|
259 |
if (p != null && p.matcher(record.short_description).find()) { |
|
260 |
searched_records.add(record); |
|
261 |
log.info("Found "+record+" with words critera "+words); |
|
262 |
} else if (persons > 0 && record.numberOfParticipants >= persons) { |
|
263 |
searched_records.add(record); |
|
264 |
log.info("Found "+record+" with persons critera "+persons); |
|
265 |
} else if (types.size() > 0 && inter(record.types, types)) { |
|
266 |
searched_records.add(record); |
|
267 |
log.info("Found "+record+" with types critera "+types); |
|
268 |
} else if (dispositifs.size() > 0 && inter(record.dispositifs, dispositifs)) { |
|
269 |
searched_records.add(record); |
|
270 |
log.info("Found "+record+" with dispositifs critera "+dispositifs); |
|
271 |
} else if (projets.size() > 0) { |
|
272 |
searched_records.add(record); |
|
273 |
log.info("Found "+record+" with projets critera "+projets); |
|
274 |
} else if (supports.size() > 0 && inter(record.supports, supports)) { |
|
275 |
searched_records.add(record); |
|
276 |
log.info("Found "+record+" with supports critera "+supports); |
|
277 |
} |
|
278 |
} |
|
279 |
|
|
280 |
return searched_records; |
|
281 |
} |
|
282 |
|
|
283 |
/** The chars. */ |
|
284 |
private static String chars = "^$<>|\\\"{()}?+*."; //$NON-NLS-1$ |
|
285 |
|
|
286 |
/** |
|
287 |
* Adds the back slash. |
|
288 |
* |
|
289 |
* @param squery the squery |
|
290 |
* @return the string |
|
291 |
*/ |
|
292 |
public static String addBackSlash(String squery) { |
|
293 |
if ("\"".equals(squery)) return "\"\\\"\""; //$NON-NLS-1$ //$NON-NLS-2$ |
|
294 |
StringBuffer buff = new StringBuffer(); |
|
295 |
for(int i = 0 ; i < squery.length() ; i++) { |
|
296 |
int j = chars.indexOf(squery.charAt(i)); |
|
297 |
if ( j >= 0 ) |
|
298 |
buff.append("\\"+squery.charAt(i)); //$NON-NLS-1$ |
|
299 |
else |
|
300 |
buff.append(squery.charAt(i)); |
|
301 |
} |
|
302 |
return buff.toString(); |
|
303 |
} |
|
304 |
|
|
305 |
/** |
|
306 |
* Inter. |
|
307 |
* |
|
308 |
* @param big the big |
|
309 |
* @param little the little |
|
310 |
* @return true, if successful |
|
311 |
*/ |
|
312 |
public static boolean inter(List big, List little) { |
|
313 |
for (Object o : little) { |
|
314 |
for(Object o2 : big) |
|
315 |
if (o2.toString().equals(o)) return true; |
|
316 |
} |
|
317 |
return false; |
|
318 |
} |
|
319 |
|
|
320 |
/* (non-Javadoc) |
|
321 |
* @see org.ccc.bcccc.client.GreetingService#getRecordsWithSimpleCritera(java.util.HashMap) |
|
322 |
*/ |
|
323 |
@Override |
|
324 |
public ArrayList<TerrainRecord> getRecordsWithSimpleCritera(HashMap<String, String> critera) { |
|
325 |
log.info("getRecordWithSimpleCritera"); |
|
326 |
ArrayList<TerrainRecord> searched_records = new ArrayList<TerrainRecord>(); |
|
327 |
|
|
328 |
for (Long recordKey : records.keySet()) { |
|
329 |
if (Math.random() > 0.7) { |
|
330 |
searched_records.add(records.get(recordKey)); |
|
331 |
} |
|
332 |
} |
|
333 |
|
|
334 |
return searched_records; |
|
335 |
} |
|
336 |
|
|
337 |
/** |
|
338 |
* load records from database. |
|
339 |
* |
|
340 |
* @return user@eta if user is actually logged |
|
341 |
* @throws IllegalArgumentException the illegal argument exception |
|
342 |
*/ |
|
343 |
public String hello() throws IllegalArgumentException { |
|
344 |
log.info("hello"); |
|
345 |
|
|
346 |
try { |
|
347 |
records.loadAll(); // load if needed |
|
348 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
349 |
String user = GreetingServiceImpl.connectedUsers.get(session); |
|
350 |
return user; |
|
351 |
} catch(Exception e) { |
|
352 |
Log.warn(e.getMessage()); |
|
353 |
e.printStackTrace(); |
|
354 |
} |
|
355 |
return null; |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Test if the associated HTTP session is shiboleted. |
|
360 |
* |
|
361 |
* @return the boolean |
|
362 |
*/ |
|
363 |
@Override |
|
364 |
public Boolean isLogged() { |
|
365 |
log.info("isLogged"); |
|
366 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
367 |
return connectedUsers.containsKey(session); |
|
368 |
} |
|
369 |
|
|
370 |
/* (non-Javadoc) |
|
371 |
* @see org.ccc.bcccc.client.GreetingService#logIn(java.lang.String, java.lang.String, java.lang.String) |
|
372 |
*/ |
|
373 |
@Override |
|
374 |
public Boolean logIn(String login, String eta, String mdp) { |
|
375 |
log.info("logIn: "+login+"@"+eta); |
|
376 |
//if (mdp == null || !mdp.equals("lol")) return false; // TODO: replace with a shibboleth access |
|
377 |
if (!usersDB.test(login+"@"+eta, mdp)) { |
|
378 |
log.warning("logIn: wrong password/login: "+login+"@"+eta); |
|
379 |
return false; |
|
380 |
} |
|
381 |
|
|
382 |
// System.setProperty("javax.net.ssl.trustStore", "..."); |
|
383 |
// System.setProperty("javax.net.ssl.keyStore", "..."); |
|
384 |
// System.setProperty("javax.net.ssl.keyStorePassword", "..."); |
|
385 |
|
|
386 |
//System.out.println("Header names: "+this.getThreadLocalRequest().getHeaderNames()); |
|
387 |
// Enumeration<String> headerNames = this.getThreadLocalRequest().getHeaderNames(); |
|
388 |
// System.out.println("Listing names: "); |
|
389 |
// while (headerNames.hasMoreElements()) { |
|
390 |
// String name = headerNames.nextElement(); |
|
391 |
// System.out.println(" Name: "+name+"\tValue: "+this.getThreadLocalRequest().getHeader(name)); |
|
392 |
// |
|
393 |
// } |
|
394 |
// String uniqueID = this.getThreadLocalRequest().getHeader("Shib-SwissEP-UniqueID"); |
|
395 |
// System.out.println("uniqueID: "+uniqueID); |
|
396 |
// Test an affiliation |
|
397 |
// if (request.getHeader("Shib-EP-Affiliation").equals("staff")){...} |
|
398 |
|
|
399 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
400 |
connectedUsers.put(session, login+"@"+eta); |
|
401 |
log.info("logIn: ok "+login+"@"+eta); |
|
402 |
return true; |
|
403 |
} |
|
404 |
|
|
405 |
/* (non-Javadoc) |
|
406 |
* @see org.ccc.bcccc.client.GreetingService#logOut() |
|
407 |
*/ |
|
408 |
@Override |
|
409 |
public Boolean logOut() { |
|
410 |
log.info("logOut"); |
|
411 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
412 |
connectedUsers.remove(session); |
|
413 |
return true; |
|
414 |
} |
|
415 |
|
|
416 |
/* (non-Javadoc) |
|
417 |
* @see org.ccc.bcccc.client.GreetingService#updateRecord(java.lang.Long, org.ccc.bcccc.shared.TerrainRecord) |
|
418 |
*/ |
|
419 |
@Override |
|
420 |
public Boolean updateRecord(Long ID, TerrainRecord content) { |
|
421 |
log.info("updateRecord: "+ID+" "+content); |
|
422 |
if (isLogged()) { |
|
423 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
424 |
String user = connectedUsers.get(session); |
|
425 |
|
|
426 |
log.info("updateRecord: user="+user); |
|
427 |
|
|
428 |
if (records.containsKey(ID)) { |
|
429 |
log.warning("updateRecord: record does not exists: "+ID); |
|
430 |
return false; |
|
431 |
} else { |
|
432 |
if (records.isRecordSetToUser(user, ID)) { |
|
433 |
log.info("updateRecord: updating record: "+ID); |
|
434 |
TerrainRecord record = records.get(ID); |
|
435 |
|
|
436 |
if (record.mustBeValidated) { |
|
437 |
log.warning("updateRecord: record needs to be validatd before: "+ID); |
|
438 |
return false; |
|
439 |
} |
|
440 |
record.setDetailFields(content.numberOfParticipants, content.place, content.types, content.keywords, content.dispositifs, content.documentations, content.supports, content.reports, content.publications); |
|
441 |
record.setInfoFields(content.name, content.project, content.date, content.short_description, content.user); |
|
442 |
return records.save(record); |
|
443 |
|
|
444 |
} else { |
|
445 |
log.warning("updateRecord: user "+user+" can't edit record "+ID); |
|
446 |
return false; |
|
447 |
} |
|
448 |
} |
|
449 |
} else { |
|
450 |
log.warning("updateRecord: user is NOT logged"); |
|
451 |
return false; |
|
452 |
} |
|
453 |
} |
|
454 |
|
|
455 |
/* (non-Javadoc) |
|
456 |
* @see org.ccc.bcccc.client.GreetingService#setValidateRecordValue(java.lang.Long, java.lang.Boolean) |
|
457 |
*/ |
|
458 |
@Override |
|
459 |
public boolean setValidateRecordValue(Long ID, Boolean newValue) { |
|
460 |
log.info("validateRecord: "+ID+": "+newValue); |
|
461 |
if (isLogged()) { |
|
462 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
463 |
String user = connectedUsers.get(session); |
|
464 |
|
|
465 |
log.info("validateRecord: user="+user); |
|
466 |
|
|
467 |
if (user.equals(ConfigDB.getAdmin())) { |
|
468 |
log.info("validateRecord: user is admin"); |
|
469 |
TerrainRecord record = records.get(ID); |
|
470 |
record.mustBeValidated = newValue; |
|
471 |
return records.save(records.get(ID)); |
|
472 |
} else { |
|
473 |
log.warning("validateRecord: user is NOT admin"); |
|
474 |
return false; |
|
475 |
} |
|
476 |
} else { |
|
477 |
log.warning("validateRecord: user is NOT logged"); |
|
478 |
return false; |
|
479 |
} |
|
480 |
} |
|
481 |
|
|
482 |
/* (non-Javadoc) |
|
483 |
* @see org.ccc.bcccc.client.GreetingService#isAdmin() |
|
484 |
*/ |
|
485 |
@Override |
|
486 |
public Boolean isAdmin() { |
|
487 |
log.info("isAdmin"); |
|
488 |
if (isLogged()) { |
|
489 |
String session = this.getThreadLocalRequest().getSession().getId(); |
|
490 |
String user = connectedUsers.get(session); |
|
491 |
|
|
492 |
return user.equals(ConfigDB.getAdmin()); |
|
493 |
} else { |
|
494 |
return false; |
|
495 |
} |
|
496 |
} |
|
497 |
} |
projets/BCCCC/src/org/ccc/bcccc/server/RecordsDB.java (revision 5) | ||
---|---|---|
1 |
/* |
|
2 |
* Authors: Matthieu Decorde |
|
3 |
* |
|
4 |
* COPYRIGHT 2015 ICAR - CCC |
|
5 |
* |
|
6 |
* This software is free software: you can redistribute it |
|
7 |
* and/or modify it under the terms of the GNU General Public |
|
8 |
* License as published by the Free Software Foundation, |
|
9 |
* either version 2 of the License, or (at your option) any |
|
10 |
* later version. |
|
11 |
* |
|
12 |
* This software is distributed in the hope that it will be |
|
13 |
* useful, but WITHOUT ANY WARRANTY; without even the implied |
|
14 |
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
15 |
* PURPOSE. See the GNU General Public License for more |
|
16 |
* details. |
|
17 |
* |
|
18 |
*/ |
|
19 |
package org.ccc.bcccc.server; |
|
20 |
|
|
21 |
import java.io.File; |
|
22 |
import java.io.FileInputStream; |
|
23 |
import java.text.DateFormat; |
|
24 |
import java.text.SimpleDateFormat; |
|
25 |
import java.util.ArrayList; |
|
26 |
import java.util.HashMap; |
|
27 |
|
|
28 |
import javax.xml.parsers.DocumentBuilder; |
|
29 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
30 |
import javax.xml.transform.Transformer; |
|
31 |
import javax.xml.transform.TransformerFactory; |
|
32 |
import javax.xml.transform.dom.DOMSource; |
|
33 |
import javax.xml.transform.stream.StreamResult; |
|
34 |
|
|
35 |
import org.ccc.bcccc.shared.Data; |
|
36 |
import org.ccc.bcccc.shared.Dispositif; |
|
37 |
import org.ccc.bcccc.shared.DocumentUnit; |
|
38 |
import org.ccc.bcccc.shared.K; |
|
39 |
import org.ccc.bcccc.shared.TerrainRecord; |
|
40 |
import org.w3c.dom.Document; |
|
41 |
import org.w3c.dom.Element; |
|
42 |
import org.w3c.dom.NodeList; |
|
43 |
|
|
44 |
// TODO: Auto-generated Javadoc |
|
45 |
/** |
|
46 |
* The Class RecordsDB. |
|
47 |
*/ |
|
48 |
public class RecordsDB extends HashMap<Long, TerrainRecord> { |
|
49 |
|
|
50 |
/** The Constant serialVersionUID. */ |
|
51 |
private static final long serialVersionUID = -1902619207859271728L; |
|
52 |
|
|
53 |
// TODO: replace this shit with a SGBD access |
|
54 |
/** The all users record ids. */ |
|
55 |
// TODO: a record is not a String -> create the CCCRecord object |
|
56 |
HashMap<String, ArrayList<Long>> allUsersRecordIDS = new HashMap<String, ArrayList<Long>>(); |
|
57 |
|
|
58 |
/** The Constant RECORD_EXT. */ |
|
59 |
public final static String RECORD_EXT = ".record.xml"; |
|
60 |
|
|
61 |
/** The Constant recordsDB. */ |
|
62 |
public final static File recordsDB = new File(ConfigDB.HOMEDIR, "records"); |
|
63 |
|
|
64 |
/** The Constant formatter. */ |
|
65 |
public static final DateFormat formatter = new SimpleDateFormat("YYYY-MM-DD"); |
|
66 |
|
|
67 |
/** The loaded. */ |
|
68 |
boolean loaded = false; |
|
69 |
|
|
70 |
/** |
|
71 |
* Instantiates a new records db. |
|
72 |
*/ |
|
73 |
public RecordsDB() { |
|
74 |
// this.put("test1", new TerrainRecord().setInfoFields("test1", "projet A", new Date(), "desc test1", "A")); |
|
75 |
// this.put("test2", new TerrainRecord().setInfoFields("test2", "projet A", new Date(), "desc test1", "A")); |
|
76 |
// this.put("test3", new TerrainRecord().setInfoFields("test3", "projet B", new Date(), "desc test1", "A")); |
|
77 |
// this.put("test4", new TerrainRecord().setInfoFields("test4", "projet B", new Date(), "desc test1", "A")); |
|
78 |
// this.put("test5", new TerrainRecord().setInfoFields("test5", "projet C", new Date(), "desc test1", "A")); |
|
79 |
// this.put("test6", new TerrainRecord().setInfoFields("test6", "projet D", new Date(), "desc test1", "A")); |
|
80 |
// this.put("test7", new TerrainRecord().setInfoFields("test7", "projet B", new Date(), "desc test1", "A")); |
|
81 |
// this.put("test8", new TerrainRecord().setInfoFields("test8", "projet A", new Date(), "desc test1", "A")); |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Contains user. |
|
86 |
* |
|
87 |
* @param user the user |
|
88 |
* @return true, if successful |
|
89 |
*/ |
|
90 |
public boolean containsUser(String user) { |
|
91 |
return allUsersRecordIDS.containsKey(user); |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Register user. |
|
96 |
* |
|
97 |
* @param user the user |
|
98 |
* @return the array list |
|
99 |
*/ |
|
100 |
public ArrayList<Long> registerUser(String user) { |
|
101 |
return allUsersRecordIDS.put(user, new ArrayList<Long>()); |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Gets the user record i ds. |
|
106 |
* |
|
107 |
* @param user the user |
|
108 |
* @return the user record i ds |
|
109 |
*/ |
|
110 |
public ArrayList<Long> getUserRecordIDs(String user) { |
|
111 |
return allUsersRecordIDS.get(user); |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Sets the record to user. |
|
116 |
* |
|
117 |
* @param user the user |
|
118 |
* @param uniq_id the uniq_id |
|
119 |
* @return true, if successful |
|
120 |
*/ |
|
121 |
public boolean setRecordToUser(String user, long uniq_id) { |
|
122 |
return allUsersRecordIDS.get(user).add(uniq_id); |
|
123 |
} |
|
124 |
|
|
125 |
/** |
|
126 |
* Unset record to user. |
|
127 |
* |
|
128 |
* @param user the user |
|
129 |
* @param recordID the record id |
|
130 |
* @return true, if successful |
|
131 |
*/ |
|
132 |
public boolean unsetRecordToUser(String user, Long recordID) { |
|
133 |
return allUsersRecordIDS.get(user).remove(recordID); |
|
134 |
} |
|
135 |
|
|
136 |
/** |
|
137 |
* Checks if is record set to user. |
|
138 |
* |
|
139 |
* @param user the user |
|
140 |
* @param recordID the record id |
|
141 |
* @return true, if is record set to user |
|
142 |
*/ |
|
143 |
public boolean isRecordSetToUser(String user, Long recordID) { |
|
144 |
return allUsersRecordIDS.get(user).contains(recordID); |
|
145 |
} |
|
146 |
|
|
147 |
|
|
148 |
/** |
|
149 |
* Load all. |
|
150 |
*/ |
|
151 |
public void loadAll() { |
|
152 |
if (loaded) return; |
|
153 |
|
|
154 |
recordsDB.mkdir(); |
|
155 |
File[] files = recordsDB.listFiles(); |
|
156 |
if (files != null) |
|
157 |
for (File recordDB : files) { |
|
158 |
if (recordDB.getName().endsWith(RECORD_EXT)) { |
|
159 |
TerrainRecord record = new TerrainRecord(); |
|
160 |
|
|
161 |
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); |
|
162 |
DocumentBuilder builder = null; |
|
163 |
try { |
|
164 |
builder = builderFactory.newDocumentBuilder(); |
|
165 |
|
|
166 |
Document document = builder.parse(new FileInputStream(recordDB)); |
|
167 |
Element rootElement = document.getDocumentElement(); |
|
168 |
|
|
169 |
String uniq_id_str = rootElement.getAttribute(K.UNIQID); |
|
170 |
String name = rootElement.getAttribute(K.ID); |
|
171 |
String project = rootElement.getAttribute(K.PROJECT); |
|
172 |
String date_str = rootElement.getAttribute(K.DATE); |
|
173 |
String year_str = rootElement.getAttribute(K.YEAR); |
|
174 |
String user = rootElement.getAttribute(K.USER); |
|
175 |
String numberOfParticipants_str = rootElement.getAttribute(K.NUMBEROFPARTICIPANTS); |
|
176 |
String place = rootElement.getAttribute(K.PLACE); |
|
177 |
String mustBeValidated_str = rootElement.getAttribute(K.MUSTBEVALIDATED); |
|
178 |
|
|
179 |
record.uniq_id = Long.parseLong(uniq_id_str); |
|
180 |
record.name = name; |
|
181 |
record.project = project; |
|
182 |
record.place = place; |
|
183 |
record.user = user; |
|
184 |
record.numberOfParticipants = Integer.parseInt(numberOfParticipants_str); |
|
185 |
record.date = formatter.parse(date_str); |
|
186 |
record.year = Integer.parseInt(year_str); |
|
187 |
record.mustBeValidated = Boolean.parseBoolean(mustBeValidated_str); |
|
188 |
|
|
189 |
// get description |
|
190 |
NodeList nodes = rootElement.getElementsByTagName(K.DESC); |
|
191 |
for (int i=0; i<nodes.getLength(); i++){ |
|
192 |
Element node = (Element)(nodes.item(i)); |
|
193 |
String desc = node.getTextContent(); |
|
194 |
record.short_description = desc; |
|
195 |
} |
|
196 |
|
|
197 |
// get types |
|
198 |
NodeList types = rootElement.getElementsByTagName(K.TYPE); |
|
199 |
for (int i=0; i<types.getLength(); i++){ |
|
200 |
Element node = (Element)(types.item(i)); |
|
201 |
String type = node.getTextContent(); |
|
202 |
record.types.add(type); |
|
203 |
} |
|
204 |
|
|
205 |
// get keywords |
|
206 |
NodeList keywords = rootElement.getElementsByTagName(K.KEYWORD); |
|
207 |
for (int i=0; i<keywords.getLength(); i++){ |
|
208 |
Element node = (Element)(keywords.item(i)); |
|
209 |
String keyword = node.getTextContent(); |
|
210 |
record.keywords.add(keyword); |
|
211 |
} |
|
212 |
|
|
213 |
// get dispositifs |
|
214 |
NodeList dispositifs = rootElement.getElementsByTagName(K.DISPOSITIF); |
|
215 |
for (int i=0; i<dispositifs.getLength(); i++){ |
|
216 |
Element node = (Element)(dispositifs.item(i)); |
|
217 |
String dname = node.getAttribute(K.NAME); |
|
218 |
String url = node.getAttribute(K.URL); |
|
219 |
boolean mobile = Boolean.parseBoolean(node.getAttribute(K.MOBILE)); |
|
220 |
record.dispositifs.add(new Dispositif(dname, url, mobile)); |
|
221 |
} |
|
222 |
|
|
223 |
// get supports |
|
224 |
NodeList supports = rootElement.getElementsByTagName(K.SUPPORT); |
|
225 |
for (int i=0; i<supports.getLength(); i++){ |
|
226 |
Element node = (Element)(supports.item(i)); |
|
227 |
String type = node.getAttribute(K.TYPE); |
|
228 |
String url = node.getAttribute(K.URL); |
|
229 |
record.supports.add(new Data(type, url)); |
|
230 |
} |
|
231 |
|
|
232 |
// get documentations |
|
233 |
NodeList documentations = rootElement.getElementsByTagName(K.DOCUMENTATION); |
|
234 |
for (int i=0; i<documentations.getLength(); i++){ |
|
235 |
Element node = (Element)(documentations.item(i)); |
|
236 |
String type = node.getAttribute(K.TYPE); |
|
237 |
String dname = node.getAttribute(K.NAME); |
|
238 |
String url = node.getAttribute(K.URL); |
|
239 |
record.documentations.add(new DocumentUnit(type, url, dname)); |
|
240 |
} |
|
241 |
|
|
242 |
this.put(record.uniq_id, record); |
|
243 |
if (!this.containsUser(record.user)) this.registerUser(record.user); |
|
244 |
this.setRecordToUser(record.user, record.uniq_id); |
|
245 |
|
|
246 |
|
|
247 |
} catch (Exception e) { |
|
248 |
GreetingServiceImpl.log.warning("Fail to load record: "+recordDB+" "+e); |
|
249 |
e.printStackTrace(); |
|
250 |
} |
|
251 |
} |
|
252 |
} |
|
253 |
loaded = true; |
|
254 |
} |
|
255 |
|
|
256 |
/** |
|
257 |
* If record is not registered then it'll be deleted from file system. |
|
258 |
* |
|
259 |
* @param record the record |
|
260 |
* @return true, if successful |
|
261 |
*/ |
|
262 |
public boolean save(TerrainRecord record) { |
|
263 |
|
|
264 |
File recordDB = new File(recordsDB, record.uniq_id+".record.xml"); // TODO: create uniq_id then the use will be allow to rename records |
|
265 |
recordsDB.mkdir(); |
|
266 |
if (!this.containsKey(record.uniq_id)) { // must be deleted |
|
267 |
recordDB.delete(); |
|
268 |
return true; |
|
269 |
} |
|
270 |
|
|
271 |
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); |
|
272 |
DocumentBuilder builder = null; |
|
273 |
try { |
|
274 |
builder = builderFactory.newDocumentBuilder(); |
|
275 |
Document doc = builder.newDocument(); |
|
276 |
Element rootElement = doc.createElement(K.RECORD); |
|
277 |
doc.appendChild(rootElement); |
|
278 |
|
|
279 |
rootElement.setAttribute(K.UNIQID, Long.toString(record.uniq_id)); |
|
280 |
rootElement.setAttribute(K.ID, record.name); |
|
281 |
rootElement.setAttribute(K.PROJECT, record.project); |
|
282 |
rootElement.setAttribute(K.USER, record.user); |
|
283 |
rootElement.setAttribute(K.DATE, formatter.format(record.date)); |
|
284 |
rootElement.setAttribute(K.YEAR, Integer.toString(record.year)); |
|
285 |
rootElement.setAttribute(K.NUMBEROFPARTICIPANTS, Integer.toString(record.numberOfParticipants)); |
|
286 |
rootElement.setAttribute(K.PLACE, record.place); |
|
287 |
rootElement.setAttribute(K.MUSTBEVALIDATED, Boolean.toString(record.mustBeValidated)); |
|
288 |
|
|
289 |
Element descriptionElement = doc.createElement(K.DESC); |
|
290 |
rootElement.appendChild(descriptionElement); |
|
291 |
descriptionElement.setTextContent(record.short_description); |
|
292 |
|
|
293 |
for (String v : record.types) { |
|
294 |
Element e = doc.createElement(K.TYPE); |
|
295 |
e.setTextContent(v); |
|
296 |
rootElement.appendChild(e); |
Formats disponibles : Unified diff