Commit 9ab319ac authored by Viacheslav Pavlov's avatar Viacheslav Pavlov Committed by Matija Obreza

INSTCODE blacklist/whitelist in workspace.json file

parent 577f1761
...@@ -309,12 +309,6 @@ public class AppWindow { ...@@ -309,12 +309,6 @@ public class AppWindow {
createContents(); createContents();
shlGenesysMagic.open(); shlGenesysMagic.open();
shlGenesysMagic.layout(); shlGenesysMagic.layout();
try {
System.err.println("Trying to load props");
settings.load(workspacePath + "/local.properties");
} catch (IOException e) {
System.err.println("Failed to load props: " + e.getMessage());
}
while (!shlGenesysMagic.isDisposed()) { while (!shlGenesysMagic.isDisposed()) {
if (!display.readAndDispatch()) { if (!display.readAndDispatch()) {
......
...@@ -22,12 +22,15 @@ import java.io.FileReader; ...@@ -22,12 +22,15 @@ import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.genesys2.anno.model.Column; import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDataType; import org.genesys2.anno.model.ColumnDataType;
import org.genesys2.anno.model.DatabaseSettings; import org.genesys2.anno.model.DatabaseSettings;
import org.genesys2.anno.model.InstCodeSettings;
import org.genesys2.anno.model.OAuthSettings; import org.genesys2.anno.model.OAuthSettings;
import org.genesys2.anno.model.Settings; import org.genesys2.anno.model.Settings;
import org.genesys2.anno.parser.CsvDataSourceSheet; import org.genesys2.anno.parser.CsvDataSourceSheet;
...@@ -94,6 +97,12 @@ public class DwcaBuilder extends AbstractModelObject { ...@@ -94,6 +97,12 @@ public class DwcaBuilder extends AbstractModelObject {
JSONObject settings = new JSONObject(); JSONObject settings = new JSONObject();
settings.put("oauthSettings", oauthSettings); settings.put("oauthSettings", oauthSettings);
JSONObject instCodeSettings = new JSONObject();
instCodeSettings.put("instCodes", sourceSettings.getInstCodeSettings().getInstCodes());
instCodeSettings.put("isBlackList", sourceSettings.getInstCodeSettings().isBlackList());
settings.put("instCodeSettings", instCodeSettings);
for (IDataSource sourceFile : getFileRoots()) { for (IDataSource sourceFile : getFileRoots()) {
JSONObject file = new JSONObject(); JSONObject file = new JSONObject();
JSONArray sheets = new JSONArray(); JSONArray sheets = new JSONArray();
...@@ -302,22 +311,39 @@ public class DwcaBuilder extends AbstractModelObject { ...@@ -302,22 +311,39 @@ public class DwcaBuilder extends AbstractModelObject {
} }
} }
if (root.has("settings")) { if (root.has("settings")) {
JSONObject jsonSettings = root.getJSONObject("settings").getJSONObject("oauthSettings"); JSONObject jsonSettings = root.getJSONObject("settings");
JSONObject jsonOauthSettings = jsonSettings.getJSONObject("oauthSettings");
OAuthSettings oAuthSettings = new OAuthSettings(); OAuthSettings oAuthSettings = new OAuthSettings();
oAuthSettings.setAccessToken(jsonSettings.getString("accessToken")); oAuthSettings.setAccessToken(jsonOauthSettings.getString("accessToken"));
oAuthSettings.setApiUrl(jsonSettings.getString("apiUrl")); oAuthSettings.setApiUrl(jsonOauthSettings.getString("apiUrl"));
oAuthSettings.setAuthorizationEndpoint(jsonSettings.getString("authorizationEndpoint")); oAuthSettings.setAuthorizationEndpoint(jsonOauthSettings.getString("authorizationEndpoint"));
oAuthSettings.setClientKey(jsonSettings.getString("clientKey")); oAuthSettings.setClientKey(jsonOauthSettings.getString("clientKey"));
oAuthSettings.setClientSecret(jsonSettings.getString("clientSecret")); oAuthSettings.setClientSecret(jsonOauthSettings.getString("clientSecret"));
oAuthSettings.setScope(StringUtils.defaultIfBlank(jsonSettings.getString("scope"), "read,write")); oAuthSettings.setScope(StringUtils.defaultIfBlank(jsonOauthSettings.getString("scope"), "read,write"));
if (jsonSettings.has("refreshToken")) { if (jsonOauthSettings.has("refreshToken")) {
oAuthSettings.setRefreshToken(jsonSettings.getString("refreshToken")); oAuthSettings.setRefreshToken(jsonOauthSettings.getString("refreshToken"));
} }
oAuthSettings.setServerUrl(jsonSettings.getString("serverUrl")); oAuthSettings.setServerUrl(jsonOauthSettings.getString("serverUrl"));
oAuthSettings.setTokenEndpoint(jsonSettings.getString("tokenEndpoint")); oAuthSettings.setTokenEndpoint(jsonOauthSettings.getString("tokenEndpoint"));
settings.setOauthSettings(oAuthSettings); settings.setOauthSettings(oAuthSettings);
InstCodeSettings instCodeSettings = new InstCodeSettings();
if (jsonSettings.has("instCodeSettings")) {
JSONObject jsonInstCodeSettings = jsonSettings.getJSONObject("instCodeSettings");
instCodeSettings.setBlackList(jsonInstCodeSettings.getBoolean("isBlackList"));
JSONArray jsonInstCodes = jsonInstCodeSettings.getJSONArray("instCodes");
Set<String> instCodes = new HashSet<>();
for (int i = 0; i < jsonInstCodes.length(); i++) {
instCodes.add(jsonInstCodes.getString(i));
}
instCodeSettings.setInstCodes(instCodes);
}
settings.setInstCodeSettings(instCodeSettings);
} }
this.workspaceFilename = filePath; this.workspaceFilename = filePath;
......
...@@ -222,16 +222,6 @@ public class SettingsDialog extends Dialog { ...@@ -222,16 +222,6 @@ public class SettingsDialog extends Dialog {
instCodesGroup.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT)); instCodesGroup.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
composite.setSize(composite.computeSize(SWT.DEFAULT, tabFolder.getSize().y - tabContents.getSize().y - 32)); composite.setSize(composite.computeSize(SWT.DEFAULT, tabFolder.getSize().y - tabContents.getSize().y - 32));
tabContents.setMinSize(composite.getSize()); tabContents.setMinSize(composite.getSize());
shell.addListener(SWT.Close, new Listener() {
public void handleEvent(Event event) {
try {
settings.save(workspacePath + "/local.properties");
} catch (IOException err) {
System.err.println("Failed to save props: " + err.getMessage());
}
}
});
} }
private void renderAdvancedControllSection(Composite composite) { private void renderAdvancedControllSection(Composite composite) {
......
package org.genesys2.anno.model; package org.genesys2.anno.model;
import java.io.FileInputStream; import org.genesys2.anno.gui.AbstractModelObject;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
public class InstCodeSettings extends LoadableSettings { public class InstCodeSettings extends AbstractModelObject {
private static String instCodesPropName = "instCodes";
private static String isBlackListPropName = "isBlackList";
private Set<String> instCodes = new TreeSet<>(); private Set<String> instCodes = new TreeSet<>();
private boolean isBlackList = false; private boolean isBlackList = false;
...@@ -33,27 +27,4 @@ public class InstCodeSettings extends LoadableSettings { ...@@ -33,27 +27,4 @@ public class InstCodeSettings extends LoadableSettings {
firePropertyChange("isBlackList", null, this.isBlackList); firePropertyChange("isBlackList", null, this.isBlackList);
isBlackList = blackList; isBlackList = blackList;
} }
@Override
public void save(String propFilePath) throws IOException {
firePropertyChange("instCodeSettings", null, this);
Properties prop = new Properties();
prop.setProperty(instCodesPropName, this.getInstCodes().toString());
prop.setProperty(isBlackListPropName, String.valueOf(this.isBlackList()));
prop.store(new FileOutputStream(propFilePath), "Inst codes filtering saved");
}
@Override
public LoadableSettings load(String propFilePath) throws IOException {
Properties prop = new Properties();
prop.load(new FileInputStream(propFilePath));
if (!prop.isEmpty()) {
this.instCodes = new TreeSet<>(Arrays.asList(prop.getProperty(instCodesPropName).replaceAll("[,\\[\\]]", "").split(" +")));
this.isBlackList = Boolean.valueOf(prop.getProperty(isBlackListPropName));
}
firePropertyChange("instCodeSettings", null, this);
return this;
}
} }
package org.genesys2.anno.model;
import org.genesys2.anno.gui.AbstractModelObject;
import java.io.IOException;
public abstract class LoadableSettings extends AbstractModelObject {
public abstract void save(String propFilePath) throws IOException;
public abstract LoadableSettings load(String propFilePath) throws IOException;
}
...@@ -15,9 +15,9 @@ ...@@ -15,9 +15,9 @@
*/ */
package org.genesys2.anno.model; package org.genesys2.anno.model;
import java.io.IOException; import org.genesys2.anno.gui.AbstractModelObject;
public class Settings extends LoadableSettings { public class Settings extends AbstractModelObject {
private OAuthSettings oauthSettings = new OAuthSettings(); private OAuthSettings oauthSettings = new OAuthSettings();
private InstCodeSettings instCodeSettings = new InstCodeSettings(); private InstCodeSettings instCodeSettings = new InstCodeSettings();
...@@ -39,16 +39,4 @@ public class Settings extends LoadableSettings { ...@@ -39,16 +39,4 @@ public class Settings extends LoadableSettings {
firePropertyChange("instCodeSettings", null, this.instCodeSettings); firePropertyChange("instCodeSettings", null, this.instCodeSettings);
this.instCodeSettings = instCodeSettings; this.instCodeSettings = instCodeSettings;
} }
@Override
public void save(String propFilePath) throws IOException {
instCodeSettings.save(propFilePath);
}
@Override
public LoadableSettings load(String propFilePath) throws IOException {
setInstCodeSettings((InstCodeSettings)instCodeSettings.load(propFilePath));
return this;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment