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 {
createContents();
shlGenesysMagic.open();
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()) {
if (!display.readAndDispatch()) {
......
......@@ -22,12 +22,15 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang.StringUtils;
import org.genesys2.anno.model.Column;
import org.genesys2.anno.model.ColumnDataType;
import org.genesys2.anno.model.DatabaseSettings;
import org.genesys2.anno.model.InstCodeSettings;
import org.genesys2.anno.model.OAuthSettings;
import org.genesys2.anno.model.Settings;
import org.genesys2.anno.parser.CsvDataSourceSheet;
......@@ -94,6 +97,12 @@ public class DwcaBuilder extends AbstractModelObject {
JSONObject settings = new JSONObject();
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()) {
JSONObject file = new JSONObject();
JSONArray sheets = new JSONArray();
......@@ -302,22 +311,39 @@ public class DwcaBuilder extends AbstractModelObject {
}
}
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.setAccessToken(jsonSettings.getString("accessToken"));
oAuthSettings.setApiUrl(jsonSettings.getString("apiUrl"));
oAuthSettings.setAuthorizationEndpoint(jsonSettings.getString("authorizationEndpoint"));
oAuthSettings.setClientKey(jsonSettings.getString("clientKey"));
oAuthSettings.setClientSecret(jsonSettings.getString("clientSecret"));
oAuthSettings.setScope(StringUtils.defaultIfBlank(jsonSettings.getString("scope"), "read,write"));
if (jsonSettings.has("refreshToken")) {
oAuthSettings.setRefreshToken(jsonSettings.getString("refreshToken"));
oAuthSettings.setAccessToken(jsonOauthSettings.getString("accessToken"));
oAuthSettings.setApiUrl(jsonOauthSettings.getString("apiUrl"));
oAuthSettings.setAuthorizationEndpoint(jsonOauthSettings.getString("authorizationEndpoint"));
oAuthSettings.setClientKey(jsonOauthSettings.getString("clientKey"));
oAuthSettings.setClientSecret(jsonOauthSettings.getString("clientSecret"));
oAuthSettings.setScope(StringUtils.defaultIfBlank(jsonOauthSettings.getString("scope"), "read,write"));
if (jsonOauthSettings.has("refreshToken")) {
oAuthSettings.setRefreshToken(jsonOauthSettings.getString("refreshToken"));
}
oAuthSettings.setServerUrl(jsonSettings.getString("serverUrl"));
oAuthSettings.setTokenEndpoint(jsonSettings.getString("tokenEndpoint"));
oAuthSettings.setServerUrl(jsonOauthSettings.getString("serverUrl"));
oAuthSettings.setTokenEndpoint(jsonOauthSettings.getString("tokenEndpoint"));
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;
......
......@@ -222,16 +222,6 @@ public class SettingsDialog extends Dialog {
instCodesGroup.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
composite.setSize(composite.computeSize(SWT.DEFAULT, tabFolder.getSize().y - tabContents.getSize().y - 32));
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) {
......
package org.genesys2.anno.model;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.Properties;
import org.genesys2.anno.gui.AbstractModelObject;
import java.util.Set;
import java.util.TreeSet;
public class InstCodeSettings extends LoadableSettings {
private static String instCodesPropName = "instCodes";
private static String isBlackListPropName = "isBlackList";
public class InstCodeSettings extends AbstractModelObject {
private Set<String> instCodes = new TreeSet<>();
private boolean isBlackList = false;
......@@ -33,27 +27,4 @@ public class InstCodeSettings extends LoadableSettings {
firePropertyChange("isBlackList", null, this.isBlackList);
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 @@
*/
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 InstCodeSettings instCodeSettings = new InstCodeSettings();
......@@ -39,16 +39,4 @@ public class Settings extends LoadableSettings {
firePropertyChange("instCodeSettings", null, this.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