Révision 3171
tmp/org.txm.backtomedia.rcp/src/org/txm/backtomedia/commands/function/BackToMedia.java (revision 3171) | ||
---|---|---|
230 | 230 |
return null; |
231 | 231 |
} |
232 | 232 |
|
233 |
|
|
234 |
|
|
233 | 235 |
/** |
234 | 236 |
* Uses word ids + text + corpus to build a start-end word positions array and finally uses Media preferences |
235 | 237 |
* |
... | ... | |
284 | 286 |
} |
285 | 287 |
} |
286 | 288 |
|
289 |
|
|
287 | 290 |
/** |
288 | 291 |
* given a start-end word position build a segment to play using Media preferences of corpus or TXM preferences |
289 | 292 |
* |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/OkapiSaphirAPI.groovy (revision 3171) | ||
---|---|---|
1 |
package org.txm.macro.projects.antract; |
|
2 |
|
|
3 |
import java.io.BufferedReader; |
|
4 |
import java.io.IOException; |
|
5 |
import java.io.InputStreamReader; |
|
6 |
import java.io.UnsupportedEncodingException; |
|
7 |
import java.net.HttpURLConnection; |
|
8 |
import java.net.MalformedURLException; |
|
9 |
import java.net.URL; |
|
10 |
import java.net.URLConnection; |
|
11 |
import java.net.URLEncoder; |
|
12 |
import java.util.List; |
|
13 |
import java.util.Map; |
|
14 |
|
|
15 |
import org.eclipse.swt.widgets.Display; |
|
16 |
import org.eclipse.swt.widgets.Shell; |
|
17 |
import org.txm.rcp.messages.TXMUIMessages; |
|
18 |
import org.txm.rcp.swt.dialog.UsernamePasswordDialog; |
|
19 |
import org.txm.rcp.utils.JobHandler; |
|
20 |
import org.txm.utils.io.IOUtils; |
|
21 |
import java.io.DataOutputStream; |
|
22 |
import sun.net.www.http.*; |
|
23 |
|
|
24 |
public class OkapiSaphirAPI { |
|
25 |
|
|
26 |
public static final String baseUrl = "https://okapi.ina.fr/antract/api/saphir/"; |
|
27 |
public static final String okapiUrl = "https://okapi.ina.fr/antract/html/resource_587884135/resource_996999332.html"; |
|
28 |
public static boolean debug = true; |
|
29 |
|
|
30 |
public static String login(String user, String password) { |
|
31 |
URL url1; |
|
32 |
try { |
|
33 |
url1 = new URL(baseUrl+"user/login?user="+URLEncoder.encode(user, "UTF-8")+"&password="+URLEncoder.encode(password, "UTF-8")); |
|
34 |
|
|
35 |
HttpURLConnection conn = (HttpURLConnection)url1.openConnection(); |
|
36 |
|
|
37 |
if (debug) System.out.println("conn1: "+conn); |
|
38 |
|
|
39 |
conn.setRequestMethod("GET"); |
|
40 |
conn.connect(); |
|
41 |
|
|
42 |
int code = conn.getResponseCode(); |
|
43 |
if (code != HttpURLConnection.HTTP_OK) { |
|
44 |
System.out.println("Error: during login: "+code); |
|
45 |
return ""; |
|
46 |
} |
|
47 |
|
|
48 |
String sessionID = getOkapiSessionID(conn) |
|
49 |
if (sessionID.length() == 0) { |
|
50 |
if (debug) System.out.println("Error: not connected no session ID found"); |
|
51 |
return ""; |
|
52 |
} |
|
53 |
|
|
54 |
String content1 = getContent(conn); |
|
55 |
if (!content1.contains("Welcome "+user)) { |
|
56 |
if (debug) System.out.println("Error: not connected, welcome message not found: "+content1); |
|
57 |
return ""; |
|
58 |
} |
|
59 |
|
|
60 |
conn.disconnect(); |
|
61 |
|
|
62 |
return sessionID; |
|
63 |
} catch (Exception e) { |
|
64 |
// TODO Auto-generated catch block |
|
65 |
e.printStackTrace(); |
|
66 |
return ""; |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
public static String update_corpus(String sessionID, String corpusID, String ids) { |
|
71 |
return create_or_update_corpus(sessionID, corpusID, null, ids); |
|
72 |
} |
|
73 |
|
|
74 |
public static String create_corpus(String sessionID, String title, String ids) { |
|
75 |
return create_or_update_corpus(sessionID, null, title, ids); |
|
76 |
} |
|
77 |
|
|
78 |
public static String create_or_update_corpus(String sessionID, String corpusID, String title, String ids) { |
|
79 |
URL url2; |
|
80 |
String action = ""; |
|
81 |
try { |
|
82 |
if (ids == null || ids.length() == 0) { |
|
83 |
if (debug) System.out.println("Error create_or_update_corpus needs a lsit of IDs '|' separated."); |
|
84 |
return ""; |
|
85 |
} |
|
86 |
|
|
87 |
if (title != null && title.length() > 0) { |
|
88 |
action = "create"; |
|
89 |
} else if (corpusID != null && corpusID.length() > 0) { |
|
90 |
action = "update"; |
|
91 |
} else { |
|
92 |
if (debug) System.out.println("Error create_or_update_corpus needs a title or a corpus ID."); |
|
93 |
return ""; |
|
94 |
} |
|
95 |
|
|
96 |
url2 = new URL(baseUrl+"create_corpus"); |
|
97 |
|
|
98 |
if (debug) System.out.println("Requesting: "+action+" : "+url2); |
|
99 |
HttpURLConnection conn2 = (HttpURLConnection) url2.openConnection(); |
|
100 |
conn2.setRequestMethod("POST"); |
|
101 |
conn2.setRequestProperty("session", sessionID); |
|
102 |
|
|
103 |
if (debug) System.out.println("Writing POST..."); |
|
104 |
|
|
105 |
conn2.setDoOutput(true); |
|
106 |
DataOutputStream wr = new DataOutputStream(conn2.getOutputStream()); |
|
107 |
String str = "" |
|
108 |
if (action == "create") { |
|
109 |
str += "title="+title |
|
110 |
} else if (action == "update") { |
|
111 |
str += "uri="+corpusID |
|
112 |
} |
|
113 |
str += "&content="+ids |
|
114 |
if (debug) println "POST="+str |
|
115 |
wr.writeBytes(str); |
|
116 |
wr.flush(); |
|
117 |
wr.close(); |
|
118 |
|
|
119 |
conn2.connect() |
|
120 |
|
|
121 |
if (debug) System.out.println("getResponseCode..."); |
|
122 |
int code2 = conn2.getResponseCode(); |
|
123 |
if (code2 != HttpURLConnection.HTTP_OK) { |
|
124 |
if (debug) System.out.println("Error: during corpus "+action+" error='"+code2+"' and command="+url2); |
|
125 |
return ""; |
|
126 |
} |
|
127 |
if (debug) System.out.println("getContent..."); |
|
128 |
String content2 = getContent(conn2); |
|
129 |
|
|
130 |
conn2.disconnect(); |
|
131 |
|
|
132 |
return content2; |
|
133 |
} catch (Exception e) { |
|
134 |
e.printStackTrace(); |
|
135 |
return ""; |
|
136 |
} |
|
137 |
} |
|
138 |
|
|
139 |
public static String getCorpusAccessURL(String corpusID, String title) { |
|
140 |
|
|
141 |
String url = okapiUrl+"?linkedObjectUri="+URLEncoder.encode(corpusID, "UTF-8") |
|
142 |
|
|
143 |
if (title != null && title.length() > 0) { |
|
144 |
url += "&linkedObjectLabel="+URLEncoder.encode(title, "UTF-8") |
|
145 |
} |
|
146 |
} |
|
147 |
|
|
148 |
public static String get_user_corpus(String sessionID, String user, String lang, String limit, String offset) { |
|
149 |
URL url2; |
|
150 |
String action = ""; |
|
151 |
try { |
|
152 |
if (user == null || user.length() == 0) { |
|
153 |
if (debug) System.out.println("Error get_user_corpus needs a user."); |
|
154 |
return ""; |
|
155 |
} |
|
156 |
|
|
157 |
String urlString = baseUrl+"get_user_corpus?user="+URLEncoder.encode(user, "UTF-8"); |
|
158 |
|
|
159 |
if (lang != null && lang.length() > 0) { |
|
160 |
urlString += "&lang="+URLEncoder.encode(lang, "UTF-8"); |
|
161 |
} |
|
162 |
if (limit != null && lang.length() > 0) { |
|
163 |
urlString += "&limit="+URLEncoder.encode(limit, "UTF-8"); |
|
164 |
} |
|
165 |
if (offset != null && offset.length() > 0) { |
|
166 |
urlString += "&offset="+URLEncoder.encode(offset, "UTF-8"); |
|
167 |
} |
|
168 |
|
|
169 |
url2 = new URL(urlString); |
|
170 |
if (debug) System.out.println("Requesting get_user_corpus: "+action+" : "+url2); |
|
171 |
HttpURLConnection conn2 = (HttpURLConnection) url2.openConnection(); |
|
172 |
conn2.setRequestMethod("GET"); |
|
173 |
conn2.setRequestProperty("session", sessionID); |
|
174 |
conn2.connect(); |
|
175 |
int code2 = conn2.getResponseCode(); |
|
176 |
if (code2 != HttpURLConnection.HTTP_OK) { |
|
177 |
if (debug) System.out.println("Error: during corpus "+action+": "+code2+" and command="+url2); |
|
178 |
return ""; |
|
179 |
} |
|
180 |
|
|
181 |
String content2 = getContent(conn2); |
|
182 |
|
|
183 |
conn2.disconnect(); |
|
184 |
|
|
185 |
return content2; |
|
186 |
} catch (Exception e) { |
|
187 |
e.printStackTrace(); |
|
188 |
return ""; |
|
189 |
} |
|
190 |
} |
|
191 |
|
|
192 |
public static void main(String[] args) throws Exception { |
|
193 |
|
|
194 |
String ids = "AFE86000904|AFE86000904|AFE86000904"; |
|
195 |
String title = "txmtest"; |
|
196 |
String corpusID = "http://www.campus-AAR.fr/corpus_1307765428"; |
|
197 |
String user = 'USER'; |
|
198 |
String password = 'PASSWORD'; |
|
199 |
|
|
200 |
String sessionID = OkapiSaphirAPI.login(user, password); |
|
201 |
if (sessionID.length() > 0) { |
|
202 |
System.out.println(OkapiSaphirAPI.get_user_corpus(sessionID, user, null, null, null)); |
|
203 |
|
|
204 |
String newCorpusID = OkapiSaphirAPI.create_corpus(sessionID, title, "AFE86000905"); |
|
205 |
System.out.println("corpus created: "+newCorpusID); |
|
206 |
println "Access URL: "+OkapiSaphirAPI.getCorpusAccessURL(newCorpusID) |
|
207 |
//System.out.println("Updating: "+update_corpus(sessionID, corpusID, "AFE86000905")); |
|
208 |
} |
|
209 |
|
|
210 |
} |
|
211 |
|
|
212 |
public static String getOkapiSessionID(URLConnection conn) throws Exception { |
|
213 |
|
|
214 |
String encoding = "UTF-8"; |
|
215 |
Map<String, List<String>> header1 = conn.getHeaderFields(); |
|
216 |
// retrieve the okapi session id |
|
217 |
List<String> cookies = header1.get("Set-Cookie"); |
|
218 |
if (cookies == null) { |
|
219 |
if (debug) System.out.println("Error: not connected, 'Set-Cookie' not found"); |
|
220 |
return ""; |
|
221 |
} |
|
222 |
String sessionID = ""; |
|
223 |
for (String c : cookies) { |
|
224 |
if (c.startsWith("okapi=")) { |
|
225 |
sessionID = c.substring("okapi=".length(), c.indexOf(";", "okapi=".length())); |
|
226 |
} |
|
227 |
} |
|
228 |
|
|
229 |
return sessionID |
|
230 |
} |
|
231 |
|
|
232 |
public static String getContent(URLConnection conn) throws Exception { |
|
233 |
|
|
234 |
String encoding = "UTF-8"; |
|
235 |
Map<String, List<String>> header1 = conn.getHeaderFields(); |
|
236 |
List<String> contentType = header1.get("Content-Type"); |
|
237 |
if (contentType != null) { |
|
238 |
for (String c : contentType) { |
|
239 |
if (c.contains("charset=")) { |
|
240 |
encoding = c.substring(c.indexOf("charset=") + 8, c.length()); |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
|
|
245 |
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), encoding)); |
|
246 |
StringBuilder buffer = new StringBuilder(); |
|
247 |
String line = reader.readLine(); |
|
248 |
while (line != null) { |
|
249 |
buffer.append(line+"\n"); |
|
250 |
line = reader.readLine(); |
|
251 |
} |
|
252 |
reader.close(); |
|
253 |
return buffer.toString(); |
|
254 |
} |
|
255 |
|
|
256 |
//TODO remove this and call UsernamePasswordDialog.initializeCredentials |
|
257 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details) { |
|
258 |
|
|
259 |
if (System.getProperty(userKey) == null |
|
260 |
|| System.getProperty(passwordKey) == null) { |
|
261 |
|
|
262 |
Shell shell = Display.getCurrent().getActiveShell(); |
|
263 |
if (shell == null) { |
|
264 |
System.out.println("Error: could not open crendetial dialog on current Thread."); |
|
265 |
return false; |
|
266 |
} |
|
267 |
|
|
268 |
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, [userKey != null, passwordKey != null ] as boolean[], target); |
|
269 |
if (userKey != null) dialog.setUsername(System.getProperty(userKey)); |
|
270 |
dialog.setTitle(title); |
|
271 |
dialog.setDetails(TXMUIMessages.bind(TXMUIMessages.loginToP0, details)); |
|
272 |
if (dialog.open() == UsernamePasswordDialog.OK) { |
|
273 |
if (userKey != null) System.setProperty(userKey, dialog.getUser()); |
|
274 |
if (passwordKey != null) System.setProperty(passwordKey, dialog.getPassword()); |
|
275 |
return true; |
|
276 |
} |
|
277 |
else { |
|
278 |
System.out.println("Cancel credential settings"); |
|
279 |
return false; |
|
280 |
} |
|
281 |
} |
|
282 |
return true; |
|
283 |
} |
|
284 |
|
|
285 |
//TODO remove this and call UsernamePasswordDialog.initializeCredentials |
|
286 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details, JobHandler monitor) { |
|
287 |
|
|
288 |
final def ret = [false] |
|
289 |
|
|
290 |
monitor.syncExec(new Runnable() { |
|
291 |
public void run() { |
|
292 |
System.out.println("Opening credential dialog..."); |
|
293 |
try { |
|
294 |
ret[0] = initializeCredentials(userKey, passwordKey, target, title, details); |
|
295 |
} catch(Throwable t) { |
|
296 |
t.printStackTrace(); |
|
297 |
} |
|
298 |
} |
|
299 |
}); |
|
300 |
return ret[0]; |
|
301 |
} |
|
302 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterIdentifiantsSujetsMacro.groovy (revision 3171) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
11 |
|
|
12 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
13 |
println "Erreur: la sélection n'est pas un corpus." |
|
14 |
return false |
|
15 |
} |
|
16 |
|
|
17 |
CQPCorpus corpus = corpusViewSelection |
|
18 |
corpus.compute() |
|
19 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
20 |
|
|
21 |
String parentCorpusName = parentCorpus.getCqpId() |
|
22 |
|
|
23 |
def struct_prop = null |
|
24 |
def finalValues = [] |
|
25 |
def ids = null |
|
26 |
|
|
27 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
28 |
|
|
29 |
struct_prop = corpus.getStructuralUnit("div").getProperty("id") |
|
30 |
values = struct_prop.getValues(corpus) |
|
31 |
for (def id : values) { |
|
32 |
if (id.startsWith("AFE")) { |
|
33 |
finalValues << id |
|
34 |
} |
|
35 |
} |
|
36 |
|
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
|
|
39 |
struct_prop = corpus.getStructuralUnit("notice").getProperty("identifiantdelanotice") |
|
40 |
def values = struct_prop.getValues(corpus) |
|
41 |
|
|
42 |
def struct_prop2 = corpus.getStructuralUnit("notice").getProperty("typedenotice") |
|
43 |
def qr = corpus.query(new CQLQuery("<notice_typedenotice=\"Notice sujet\">[]"), "TMP", false) |
|
44 |
int[] positions = qr.getStarts() |
|
45 |
int[] strucs = CQPSearchEngine.getCqiClient().cpos2Struc(struct_prop2.getQualifiedName(), positions) |
|
46 |
String sujetsIDS = CQPSearchEngine.getCqiClient().struc2Str(struct_prop.getQualifiedName(), strucs) |
|
47 |
for (String id : values) { |
|
48 |
int idx = sujetsIDS.indexOf(id) |
|
49 |
if (idx > 0) { |
|
50 |
finalValues << id // this id is actually in the sujetsIDS |
|
51 |
} |
|
52 |
} |
|
53 |
|
|
54 |
} else { |
|
55 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
56 |
return false |
|
57 |
} |
|
58 |
|
|
59 |
ids = finalValues.sort().join("|") |
|
60 |
|
|
61 |
println "Liste des identifiants (${finalValues.size()}) : "+ids |
|
62 |
|
|
63 |
monitor.syncExec(new Runnable() { |
|
64 |
public void run() { |
|
65 |
IOClipboard.write(ids) |
|
66 |
} |
|
67 |
}) |
|
68 |
|
|
69 |
return ids |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/AjouterDesSujetsAuCorpusOkapiMacro.groovy (revision 3171) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.macro.projects.antract.OkapiSaphirAPI |
|
11 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
12 |
|
|
13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
|
14 |
|
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
16 |
println "Erreur: la sélection n'est pas un corpus." |
|
17 |
return false |
|
18 |
} |
|
19 |
|
|
20 |
@Field @Option(name="identifiant_du_corpus_okapi_a_modifier", usage="Identifiant Okapi du corpus à modifier", widget="String", required=false, def="") |
|
21 |
def identifiant_du_corpus_okapi_a_modifier |
|
22 |
|
|
23 |
if (!ParametersDialog.open(this)) return; |
|
24 |
|
|
25 |
CQPCorpus corpus = corpusViewSelection |
|
26 |
corpus.compute() |
|
27 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
28 |
|
|
29 |
String parentCorpusName = parentCorpus.getCqpId() |
|
30 |
|
|
31 |
def struct_prop = null |
|
32 |
def finalValues = [] |
|
33 |
def ids = null |
|
34 |
|
|
35 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
36 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
39 |
} else { |
|
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 |
// set Okapi user&password |
|
45 |
if (OkapiSaphirAPI.initializeCredentials(BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, |
|
46 |
"OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
|
47 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, dialog.getUser()); |
|
48 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, dialog.getPassword()); |
|
49 |
} |
|
50 |
else { |
|
51 |
println "Cancel corpus update" |
|
52 |
return null; |
|
53 |
} |
|
54 |
|
|
55 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
|
56 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
|
57 |
|
|
58 |
// start the Okapi session |
|
59 |
String sessionID = OkapiSaphirAPI.login(user, password) |
|
60 |
if (sessionID.length() > 0) { |
|
61 |
String corpusID = OkapiSaphirAPI.update_corpus(sessionID, identifiant_du_corpus_okapi_a_modifier, ids) |
|
62 |
if (sessionID.length() > 0 && sessionID.startsWith("http")) { |
|
63 |
println "Okapi corpus $identifiant_du_corpus_okapi_a_modifier updated with "+ids |
|
64 |
} else { |
|
65 |
println "Error: Okapi corpus not updated: "+sessionID |
|
66 |
} |
|
67 |
} else { |
|
68 |
println "Error: Okapi session not started. Resetting credentials." |
|
69 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
|
70 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
|
71 |
} |
tmp/org.txm.groovy.core/src/groovy/org/txm/macro/projects/antract/ExporterLeCorpusVersOkapiMacro.groovy (revision 3171) | ||
---|---|---|
1 |
// Copyright © 2021 ENS-LYON |
|
2 |
// Licensed under the terms of the GNU General Public License version 3 (http://www.gnu.org/licenses/gpl-3.0.html) |
|
3 |
// @author mdecorde |
|
4 |
|
|
5 |
// STANDARD DECLARATIONS |
|
6 |
package org.txm.macro.projects.antract |
|
7 |
|
|
8 |
import org.txm.searchengine.cqp.corpus.CQPCorpus |
|
9 |
import org.txm.searchengine.cqp.corpus.query.CQLQuery |
|
10 |
import org.txm.macro.projects.antract.OkapiSaphirAPI |
|
11 |
import org.txm.searchengine.cqp.CQPSearchEngine |
|
12 |
|
|
13 |
import org.txm.backtomedia.preferences.BackToMediaPreferences |
|
14 |
|
|
15 |
if (!(corpusViewSelection instanceof CQPCorpus)) { |
|
16 |
println "Erreur: la sélection n'est pas un corpus." |
|
17 |
return false |
|
18 |
} |
|
19 |
|
|
20 |
@Field @Option(name="titre_du_nouveau_corpus_okapi", usage="Nom du corpus à créer", widget="String", required=false, def="") |
|
21 |
def titre_du_nouveau_corpus_okapi |
|
22 |
|
|
23 |
if (!ParametersDialog.open(this)) return; |
|
24 |
|
|
25 |
CQPCorpus corpus = corpusViewSelection |
|
26 |
corpus.compute() |
|
27 |
CQPCorpus parentCorpus = corpus.getMainCorpus() |
|
28 |
|
|
29 |
String parentCorpusName = parentCorpus.getCqpId() |
|
30 |
|
|
31 |
def struct_prop = null |
|
32 |
def finalValues = [] |
|
33 |
def ids = null |
|
34 |
|
|
35 |
if (parentCorpusName.startsWith("AF-VOIX-OFF-")) { |
|
36 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
37 |
} else if (parentCorpusName.startsWith("AFNOTICES") || parentCorpusName.startsWith("AF-NOTICES")) { |
|
38 |
ids = gse.run(ExporterIdentifiantsSujetsMacro, ["args":[:], "corpusViewSelection":corpusViewSelection, "monitor":monitor]) |
|
39 |
} else { |
|
40 |
println "Erreur: le corpus n'est pas un corpus d'AF-VOIX-OFF ni AFNOTICE" |
|
41 |
return false |
|
42 |
} |
|
43 |
|
|
44 |
if (!OkapiSaphirAPI.initializeCredentials(BackToMediaPreferences.MEDIA_AUTH_LOGIN, BackToMediaPreferences.MEDIA_AUTH_PASSWORD, |
|
45 |
"OKAPI - Antract", "You must authenticate to access the okapi corpus API", "OKAPI - Antract", monitor)) { |
|
46 |
println "Cancel corpus export" |
|
47 |
return null; |
|
48 |
} |
|
49 |
|
|
50 |
String user = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN) |
|
51 |
String password = System.getProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD) |
|
52 |
|
|
53 |
String sessionID = OkapiSaphirAPI.login(user, password) |
|
54 |
if (sessionID.length() > 0) { |
|
55 |
String corpusID = OkapiSaphirAPI.create_corpus(sessionID, titre_du_nouveau_corpus_okapi, ids) |
|
56 |
if (sessionID.length() > 0 && sessionID.startsWith("http")) { |
|
57 |
println "New Okapi corpus $titre_du_nouveau_corpus_okapi created: "+corpusID |
|
58 |
} else { |
|
59 |
println "Error: Okapi corpus not created: "+corpusID |
|
60 |
} |
|
61 |
} else { |
|
62 |
println "Error: Okapi session not started. Resetting credentials." |
|
63 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_LOGIN, "") |
|
64 |
System.setProperty(BackToMediaPreferences.MEDIA_AUTH_PASSWORD, "") |
|
65 |
} |
tmp/org.txm.setups/pushTXMUpdateToGIT.sh (revision 3171) | ||
---|---|---|
17 | 17 |
TXMGITLOCAL="dist/$VERSION/main/$LEVEL" |
18 | 18 |
TXMGIT=$TXMGITROOT/$TXMGITLOCAL |
19 | 19 |
|
20 |
mkdir -p $TXMGIT |
|
21 |
|
|
20 | 22 |
if [ ! -d "$TXMGIT" ]; then |
21 | 23 |
echo "** Error the GIT directory does not exists: $TXMGIT" |
22 | 24 |
exit 1; |
tmp/org.txm.rcp/src/main/java/org/txm/rcp/swt/dialog/UsernamePasswordDialog.java (revision 3171) | ||
---|---|---|
8 | 8 |
import org.eclipse.swt.layout.GridLayout; |
9 | 9 |
import org.eclipse.swt.widgets.Composite; |
10 | 10 |
import org.eclipse.swt.widgets.Control; |
11 |
import org.eclipse.swt.widgets.Display; |
|
11 | 12 |
import org.eclipse.swt.widgets.Label; |
12 | 13 |
import org.eclipse.swt.widgets.Shell; |
13 | 14 |
import org.eclipse.swt.widgets.Text; |
14 | 15 |
import org.txm.rcp.messages.TXMUIMessages; |
16 |
import org.txm.rcp.utils.JobHandler; |
|
15 | 17 |
|
16 | 18 |
/** |
17 | 19 |
* SWT/JFace in Action |
... | ... | |
175 | 177 |
public void setTitle(String title) { |
176 | 178 |
this.title = title; |
177 | 179 |
} |
180 |
|
|
181 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details) { |
|
182 |
|
|
183 |
if (System.getProperty(userKey) == null |
|
184 |
|| System.getProperty(passwordKey) == null) { |
|
185 |
|
|
186 |
Shell shell = Display.getCurrent().getActiveShell(); |
|
187 |
if (shell == null) { |
|
188 |
System.out.println("Error: could not open crendetial dialog on current Thread."); |
|
189 |
return false; |
|
190 |
} |
|
191 |
|
|
192 |
UsernamePasswordDialog dialog = new UsernamePasswordDialog(shell, new boolean[]{userKey != null, passwordKey != null}, target); |
|
193 |
if (userKey != null) dialog.setUsername(System.getProperty(userKey)); |
|
194 |
dialog.setTitle(title); |
|
195 |
dialog.setDetails(TXMUIMessages.bind(TXMUIMessages.loginToP0, details)); |
|
196 |
if (dialog.open() == UsernamePasswordDialog.OK) { |
|
197 |
if (userKey != null) System.setProperty(userKey, dialog.getUser()); |
|
198 |
if (passwordKey != null) System.setProperty(passwordKey, dialog.getPassword()); |
|
199 |
return true; |
|
200 |
} |
|
201 |
else { |
|
202 |
System.out.println("Cancel credential settings"); |
|
203 |
return false; |
|
204 |
} |
|
205 |
} |
|
206 |
return false; |
|
207 |
} |
|
208 |
|
|
209 |
public static boolean initializeCredentials(String userKey, String passwordKey, String target, String title, String details, JobHandler monitor) { |
|
210 |
|
|
211 |
final Boolean ret[] = new Boolean[1]; |
|
212 |
ret[0] = false; |
|
213 |
|
|
214 |
monitor.syncExec(new Runnable() { |
|
215 |
public void run() { |
|
216 |
System.out.println("Opening credential dialog..."); |
|
217 |
try { |
|
218 |
ret[0] = initializeCredentials(userKey, passwordKey, target, title, details); |
|
219 |
} catch(Throwable t) { |
|
220 |
t.printStackTrace(); |
|
221 |
} |
|
222 |
} |
|
223 |
}); |
|
224 |
return ret[0]; |
|
225 |
} |
|
178 | 226 |
} |
Formats disponibles : Unified diff