Skip to content

Commit cae0da6

Browse files
committed
3.2
Fix for changed date format in cloud API Fix in storage of sizes of database, could in rare cases interfere with other settings. Automatically select the latest database. New Icon
1 parent c807189 commit cae0da6

11 files changed

Lines changed: 96 additions & 54 deletions

File tree

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
<launch4jConfig>
33
<dontWrapJar>false</dontWrapJar>
44
<headerType>gui</headerType>
5-
<jar>C:\Users\Chris de Gelder\Documents\GitHub\BackupRestoreTool\src\out\MendixBackupRestoreTool.jar</jar>
6-
<outfile>C:\Users\Chris de Gelder\Documents\GitHub\BackupRestoreTool\src\out\MendixBackupRestoreTool.exe</outfile>
5+
<jar>C:\Users\Chris de Gelder\Documents\GitHub\BackupRestoreTool\MendixBackupRestore\out\MendixBackupRestoreTool.jar</jar>
6+
<outfile>C:\Users\Chris de Gelder\Documents\GitHub\BackupRestoreTool\MendixBackupRestore\out\MendixBackupRestoreTool.exe</outfile>
77
<errTitle></errTitle>
88
<cmdLine></cmdLine>
99
<chdir>.</chdir>

out/MendixBackupRestoreTool.exe

-58.9 KB
Binary file not shown.

out/MendixBackupRestoreTool.jar

191 KB
Binary file not shown.

src/images/backup.png

201 Bytes
Loading

src/images/mendix.png

3.73 KB
Loading

src/main/java/com/ccdg/app/MendixBackupRestoreTool.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected void createContents() {
7676
shell = new Shell();
7777

7878
shell.setMinimumSize(new Point(200, 39));
79-
shell.setImage(SWTResourceManager.getImage(MendixBackupRestoreTool.class, "/images/backup.png")); //$NON-NLS-1$
79+
shell.setImage(SWTResourceManager.getImage(MendixBackupRestoreTool.class, "/images/mendix.png")); //$NON-NLS-1$
8080
shell.setSize(1024, 635);
8181
shell.setText(Messages.getString("MendixBackupRestoreTool.MendixBackupTool")); //$NON-NLS-1$
8282
shell.setLayout(new FormLayout());
@@ -183,20 +183,7 @@ public void shellIconified(ShellEvent arg0) {
183183

184184

185185
final List environmentlist = new List(shell, SWT.BORDER);
186-
environmentlist.addSelectionListener(new SelectionAdapter() {
187-
@Override
188-
public void widgetSelected(SelectionEvent e) {
189-
btnCreateBackupOn.setEnabled(true);
190-
mendixUtil.setCursorWait(shell);
191-
try {
192-
if (environmentlist.getSelectionIndex() >= 0 && environmentlist.getSelectionIndex() < environmentlist.getItemCount()) {
193-
mendixUtil.GetBackupList(applist.getSelectionIndex(), environmentlist.getItem(environmentlist.getSelectionIndex()));
194-
}
195-
} finally {
196-
mendixUtil.setCursorDefault(shell);
197-
}
198-
}
199-
});
186+
200187
Label lblEnvironment = new Label(shell, SWT.NONE);
201188
FormData fd_environmentlist = new FormData();
202189
fd_environmentlist.top = new FormAttachment(applist, 0, SWT.TOP);
@@ -223,7 +210,7 @@ public void widgetSelected(SelectionEvent e) {
223210
btnSettings.addSelectionListener(new SelectionAdapter() {
224211
@Override
225212
public void widgetSelected(SelectionEvent e) {
226-
213+
227214
SettingsDialog dialog = new SettingsDialog(shell, SWT.APPLICATION_MODAL, mendixUtil);
228215
Point pt = display.getCursorLocation();
229216
dialog.setLocation(pt);
@@ -329,7 +316,27 @@ public void widgetSelected(SelectionEvent e) {
329316
}
330317
});
331318
btnRestoreBackup.setText(Messages.getString("MendixBackupRestoreTool.RestoreBackup")); //$NON-NLS-1$
332-
319+
320+
environmentlist.addSelectionListener(new SelectionAdapter() {
321+
@Override
322+
public void widgetSelected(SelectionEvent e) {
323+
btnCreateBackupOn.setEnabled(true);
324+
if (environmentlist.getSelectionIndex() >= 0 && environmentlist.getSelectionIndex() < environmentlist.getItemCount()) {
325+
mendixUtil.setCursorWait(shell);
326+
try {
327+
if (mendixUtil.GetBackupList(applist.getSelectionIndex(), environmentlist.getItem(environmentlist.getSelectionIndex()))) {
328+
backuplist.select(0);
329+
btnGetBackup.setEnabled(true);
330+
btnRestoreBackup.setEnabled(true);
331+
btnDownloadBackup.setEnabled(true);
332+
}
333+
} finally {
334+
mendixUtil.setCursorDefault(shell);
335+
}
336+
}
337+
}
338+
});
339+
333340

334341
// label Mendix Backup Tool
335342
Label lblMendixBackupTool = new Label(shell, SWT.NONE);
@@ -341,10 +348,9 @@ public void widgetSelected(SelectionEvent e) {
341348
fd_lblMendixBackupTool.top = new FormAttachment(0, 10);
342349
fd_lblMendixBackupTool.left = new FormAttachment(0, 10);
343350
lblMendixBackupTool.setLayoutData(fd_lblMendixBackupTool);
344-
lblMendixBackupTool.setFont(SWTResourceManager.getFont("Segoe UI", 23, SWT.BOLD)); //$NON-NLS-1$
351+
lblMendixBackupTool.setFont(SWTResourceManager.getFont("Segoe UI", 23, SWT.BOLD));
345352
lblMendixBackupTool.setText(Messages.getString("MendixBackupRestoreTool.MendixBackupRestoreTool")); //$NON-NLS-1$
346-
347-
353+
348354
applist.addSelectionListener(new SelectionAdapter() {
349355
@Override
350356
public void widgetSelected(SelectionEvent e) {
@@ -357,7 +363,6 @@ public void widgetSelected(SelectionEvent e) {
357363
mendixUtil.getEnvironmentList(applist.getSelectionIndex(), environmentlist);
358364
}
359365
});
360-
361366

362367
// label applications
363368
FormData fd_lblApplications = new FormData();

src/main/java/com/ccdg/app/MendixUtil.java

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,15 @@
1919
import java.nio.file.LinkOption;
2020
import java.nio.file.Path;
2121
import java.nio.file.Paths;
22-
import java.sql.*;
22+
import java.sql.Connection;
23+
import java.sql.DatabaseMetaData;
24+
import java.sql.DriverManager;
25+
import java.sql.ResultSet;
26+
import java.sql.Statement;
2327
import java.text.SimpleDateFormat;
2428
import java.util.ArrayList;
2529
import java.util.Collections;
30+
import java.util.Date;
2631
import java.util.HashMap;
2732
import java.util.Map;
2833
import java.util.concurrent.TimeUnit;
@@ -73,11 +78,12 @@ public class MendixUtil {
7378
private static final String MENDIX_USER_NAME = "Mendix-UserName";
7479
private static final String DBPASSWORD = "password";
7580
private static final String DBUSERNAME = "username";
76-
private static final String PGDIR = "PGDIR"; // postgres directory
77-
private static final String PGPORT = "PGPORT"; // postgres port
78-
private static final String DLDIR = "DOWNLOADDIR";
81+
private static final String PGDIR = "pgdir"; // postgres directory
82+
private static final String PGPORT = "pgport"; // postgres port
83+
private static final String DLDIR = "donwnloaddir";
7984
private static final String MXAPIUSER = "mxapiuser";
8085
private static final String BACKUPNAMING = "backupnaming";
86+
private static final String SIZEPREFIX = "lastdownloadsize_";
8187
private static final String MRUPREFIX = "mru";
8288
private static final String APP_ID = "AppId";
8389
// symmetric key for storage
@@ -208,7 +214,7 @@ private boolean tryCustomDirectory(final String directory) {
208214
* @param list SWT List of applications
209215
*/
210216
public void restorePreferences(List list, String filter) {
211-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
217+
Preferences prefs = getPreferences();
212218

213219
// second parameter is default value
214220
apiuser = prefs.get(MXAPIUSER, "");
@@ -319,7 +325,7 @@ public void setUserAndKey(String apiUser, String apiKey, String userName, String
319325
this.postgresDirectory = postgresDirectory;
320326
this.postgresPort = postgresPort;
321327
this.downloadDirectory = downloadDirectory;
322-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
328+
Preferences prefs = getPreferences();
323329

324330
prefs.put(MXAPIUSER, apiUser);
325331
prefs.put(DBUSERNAME, userName);
@@ -340,7 +346,7 @@ public void setUserAndKey(String apiUser, String apiKey, String userName, String
340346
* @param backupNaming string with tokens {environment} and {date}
341347
*/
342348
public void setBackupNaming(String backupNaming) {
343-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
349+
Preferences prefs = getPreferences();
344350
this.backupNaming = backupNaming;
345351
prefs.put(BACKUPNAMING, backupNaming);
346352
}
@@ -377,10 +383,9 @@ public String getPostgresVersion() {
377383
* @param createdOn Date of the backup
378384
* @return Unique databasename
379385
*/
380-
public String getTargetDatabaseName(String appid, String environment, Long createdOn) {
381-
Date date = new Date(createdOn);
386+
public String getTargetDatabaseName(String appid, String environment, Date createdOn) {
382387
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
383-
String strDate= formatter.format(date);
388+
String strDate= formatter.format(createdOn);
384389
String dbName = appid + backupNaming.replace("{environment}", environment).replace("{date}", strDate);
385390
String ext = getNonExistingDatabaseExt(dbName);
386391
return dbName + ext;
@@ -599,8 +604,9 @@ public int AppIndexByAppName(String appName) {
599604
*
600605
* @param selectionCount selected line of list
601606
* @param environment selected environment (production, acceptance, test)
607+
* return true is list has at least one item.
602608
*/
603-
public void GetBackupList(int selectionCount, String environment ) {
609+
public boolean GetBackupList(int selectionCount, String environment ) {
604610
if (selectionCount >= 0) {
605611
int appIndex = AppIndexByListIndex(selectionCount);
606612
String appid = apps.getJSONObject(appIndex).getString(APP_ID);
@@ -621,23 +627,27 @@ public void GetBackupList(int selectionCount, String environment ) {
621627
consoleWrite(result);
622628
this.backups = new JSONArray(result);
623629
SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm");
630+
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
624631
for (int i = 0; i < backups.length(); i++) {
625632
// if a backup is being created createdon is null
626633
if (!backups.getJSONObject(i).isNull(CREATED_ON)) {
627-
backuplist.add(dt1.format(new Date(backups.getJSONObject(i).getLong(CREATED_ON))));
634+
backuplist.add(dt1.format(parser.parse(backups.getJSONObject(i).getString(CREATED_ON))));
628635
}
629636
}
637+
return backups.length() > 0;
630638
} else {
631639
consoleWrite("Error getting backuplist");
632640
consoleWrite(result);
641+
return false;
633642
}
634643
} catch (Exception e) {
635644
consoleWrite("Error getting list " + e.getMessage());
636645
e.printStackTrace();
637646
}
647+
} else {
648+
return false;
638649
}
639-
640-
650+
return false;
641651
}
642652
/**
643653
* Retrieve the backup link of the OnlyDatabase from the json and download the file into downloads
@@ -664,13 +674,13 @@ public void run()
664674
if (apps != null) {
665675
String appid = "";
666676
String backupid = "";
667-
Long createdOn = 0L;
677+
Date createdOn = null;
668678
try {
669679
appid = apps.getJSONObject(AppIndexByListIndex(selectedAppIndex)).getString(APP_ID);
670680
backupid = backups.getJSONObject(selectedBackupIndex).getString(SNAPSHOT_ID);
671681
// if a backup is being created createdon is null
672682
if (!backups.getJSONObject(selectedBackupIndex).isNull(CREATED_ON)) {
673-
createdOn = backups.getJSONObject(selectedBackupIndex).getLong(CREATED_ON);
683+
createdOn = parseJSONDate(backups.getJSONObject(selectedBackupIndex).getString(CREATED_ON));
674684
}
675685
} catch (Exception exp) {
676686
consoleWrite("Error getting list " + exp.getMessage());
@@ -710,8 +720,7 @@ public void run()
710720
String dbFilename = filename;
711721
String extractDirectory = null;
712722
if (includeDocuments) {
713-
// todo extract dir terugkrijgen
714-
// files verplaatsen naar doel documenten directory
723+
// todo get extract dir - move file to target directory
715724
extractDirectory = extractTarGz(filename);
716725
dbFilename = extractDirectory + File.separator +"db" + File.separator + "db.backup";
717726
}
@@ -855,10 +864,10 @@ public void run()
855864
if (apps != null) {
856865
String appid = apps.getJSONObject(AppIndexByListIndex(selectedAppIndex)).getString(APP_ID);
857866
String backupid = backups.getJSONObject(selectedBackupIndex).getString(SNAPSHOT_ID);
858-
Long createdOn = 0l;
867+
Date createdOn = null;
859868
// if a backup is being created createdon is null
860869
if (!backups.getJSONObject(selectedBackupIndex).isNull(CREATED_ON)) {
861-
createdOn = backups.getJSONObject(selectedBackupIndex).getLong(CREATED_ON);
870+
createdOn = parseJSONDate(backups.getJSONObject(selectedBackupIndex).getString(CREATED_ON));
862871
}
863872
OkHttpClient client = getClient(60);
864873

@@ -987,7 +996,7 @@ public void ShowMessage(String message, Shell shell) {
987996
*
988997
* @param message Message to write
989998
*/
990-
private void consoleWrite(String message) {
999+
void consoleWrite(String message) {
9911000
display.asyncExec (new Runnable () {
9921001
public void run () {
9931002
if (consoleList != null && message != null) {
@@ -1109,7 +1118,7 @@ public String downloadFile(String fileURL, String appid, String environment, Str
11091118
URL url;
11101119
try {
11111120
url = new URL(fileURL);
1112-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
1121+
Preferences prefs = getPreferences();
11131122
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
11141123
int responseCode = httpConn.getResponseCode();
11151124

@@ -1163,7 +1172,7 @@ public String downloadFile(String fileURL, String appid, String environment, Str
11631172
}
11641173
}
11651174
// store for next time progress bar
1166-
prefs.putLong(appid+ext, totalbytesRead);
1175+
prefs.putLong(SIZEPREFIX+appid+ext, totalbytesRead);
11671176
} catch (IOException e) {
11681177
consoleWrite("Error " + e.getMessage());
11691178
e.printStackTrace();
@@ -1288,7 +1297,7 @@ public void OpenBrowser(String path, int selectedApp) {
12881297
*/
12891298

12901299
public String[] getMRUItems() {
1291-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
1300+
Preferences prefs = getPreferences();
12921301

12931302
ArrayList<String> mrulist = new ArrayList<String>();
12941303
for (int i = 0; i<MAX_MRU; i++) {
@@ -1302,13 +1311,21 @@ public String[] getMRUItems() {
13021311
}
13031312
return mrulist.toArray(new String[mrulist.size()]);
13041313
}
1314+
1315+
/**
1316+
* Get the preferences storage
1317+
* @return Preferences
1318+
*/
1319+
private Preferences getPreferences() {
1320+
return Preferences.userNodeForPackage(MendixUtil.class);
1321+
}
13051322
/**
13061323
* Add an app to the MRU list, max 6 items. Latest item is not put on top.
13071324
* @param appindex index of application
13081325
*/
13091326

13101327
public void addMRU(int appindex) {
1311-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
1328+
Preferences prefs = getPreferences();
13121329

13131330
// shift them up.
13141331
for (int i=MAX_MRU; i>=0; i--) {
@@ -1321,12 +1338,30 @@ public void addMRU(int appindex) {
13211338
*/
13221339

13231340
public void clearMRU() {
1324-
Preferences prefs = Preferences.userNodeForPackage(MendixUtil.class);
1341+
Preferences prefs = getPreferences();
13251342
for (int i = MAX_MRU; i>=0; i--) {
13261343
prefs.putInt(MRUPREFIX+i, -1);
13271344
}
1328-
13291345
}
1346+
1347+
/**
1348+
* Parse the XML date from JSON
1349+
* Returns Date
1350+
*/
13301351

1352+
public java.util.Date parseJSONDate(String jsonDate) {
1353+
if (jsonDate != null && !jsonDate.isEmpty()) {
1354+
try {
1355+
SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
1356+
return parser.parse(jsonDate);
1357+
} catch (Exception e) {
1358+
consoleWrite("Error parsing date " + jsonDate);
1359+
return null;
1360+
}
1361+
} else {
1362+
return null;
1363+
}
1364+
1365+
}
13311366

13321367
}

src/main/java/com/ccdg/app/SettingsDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void widgetSelected(SelectionEvent e) {
142142
Label lblCopyrightChrisDe = new Label(shlSettings, SWT.NONE);
143143
lblCopyrightChrisDe.setToolTipText("");
144144
lblCopyrightChrisDe.setBounds(18, 341, 221, 23);
145-
lblCopyrightChrisDe.setText("V 3.1 - Chris de Gelder");
145+
lblCopyrightChrisDe.setText("V 3.2 - Chris de Gelder");
146146

147147
lblPostgresDirectory = new Label(shlSettings, SWT.NONE);
148148
lblPostgresDirectory.setText("Postgres directory (no bin)");

target/classes/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/main/
2+
/images/
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Generated by Maven Integration for Eclipse
2-
#Fri Feb 05 13:39:40 CET 2021
3-
m2e.projectLocation=C\:\\Users\\Chris de Gelder\\Documents\\GitHub\\BackupRestoreTool\\src
4-
m2e.projectName=MendixBackupRestore
2+
#Wed Mar 03 11:19:14 CET 2021
3+
m2e.projectLocation=C\:\\Users\\Chris de Gelder\\Documents\\GitHub\\BackupRestoreTool\\MendixBackupRestore
4+
m2e.projectName=MendixBackupRestoreTool
55
groupId=com.ccdg.app
66
artifactId=MendixBackupRestoreTool
77
version=3.1

0 commit comments

Comments
 (0)