change sync model
pull/4/head
Felix Prahl-Kamps 2019-08-22 17:14:25 +02:00
parent 612615ff02
commit 95594b9d11
8 changed files with 93 additions and 181 deletions

View File

@ -275,7 +275,7 @@ public class ExchangeActivity extends AppCompatActivity {
case DATA_EXCHANGE: case DATA_EXCHANGE:
try { try {
ExchangeInformation remoteSyncInfo = new Gson().fromJson(diffieHellman.decrypt(qrData), ExchangeInformation.class); ExchangeInformation remoteSyncInfo = new Gson().fromJson(diffieHellman.decrypt(qrData), ExchangeInformation.class);
syncInformation.populateRemoteExchangeInformation(remoteSyncInfo); syncInformation.setRemote(remoteSyncInfo);
preferenceManager.addSyncInformation(syncInformation); preferenceManager.addSyncInformation(syncInformation);
setSyncState(SyncState.DATA_EXCHANGE_DONE); setSyncState(SyncState.DATA_EXCHANGE_DONE);
} catch (JsonSyntaxException e) { } catch (JsonSyntaxException e) {

View File

@ -44,9 +44,9 @@ public class NetworkTestActivity extends AppCompatActivity {
List<SyncInformation> syncInformationList = preferenceManager.getSyncInformationList(); List<SyncInformation> syncInformationList = preferenceManager.getSyncInformationList();
for (SyncInformation syncInfo : syncInformationList) { for (SyncInformation syncInfo : syncInformationList) {
String authkey = syncInfo.getSyncServer().getAuthkey(); String authkey = syncInfo.getRemote().getServer().getAuthkey();
String localUUID = syncInfo.getLocal().getOrganisation().getUuid(); String localUUID = syncInfo.getLocal().getOrganisation().getUuid();
String foreignUUID = syncInfo.getRemoteOrganisation().getUuid(); String foreignUUID = syncInfo.getRemote().getOrganisation().getUuid();
} }

View File

@ -121,37 +121,37 @@ public class SyncInfoDetailActivity extends AppCompatActivity {
// information // information
MaterialPreferenceText name = findViewById(R.id.name); MaterialPreferenceText name = findViewById(R.id.name);
name.setSubtitle(syncInformation.getRemoteOrganisation().getName()); name.setSubtitle(syncInformation.getRemote().getOrganisation().getName());
MaterialPreferenceText uuid = findViewById(R.id.uuid); MaterialPreferenceText uuid = findViewById(R.id.uuid);
uuid.setSubtitle(syncInformation.getRemoteOrganisation().getUuid()); uuid.setSubtitle(syncInformation.getRemote().getOrganisation().getUuid());
MaterialPreferenceText sector = findViewById(R.id.sector); MaterialPreferenceText sector = findViewById(R.id.sector);
sector.setSubtitle(syncInformation.getRemoteOrganisation().getSector()); sector.setSubtitle(syncInformation.getRemote().getOrganisation().getSector());
MaterialPreferenceText description = findViewById(R.id.description); MaterialPreferenceText description = findViewById(R.id.description);
description.setSubtitle(syncInformation.getRemoteOrganisation().getDescription()); description.setSubtitle(syncInformation.getRemote().getOrganisation().getDescription());
// settings // settings
CheckBox allowSelfSigned = findViewById(R.id.checkbox_self_signed); CheckBox allowSelfSigned = findViewById(R.id.checkbox_self_signed);
allowSelfSigned.setChecked(syncInformation.getSyncServer().getSelf_signed()); allowSelfSigned.setChecked(syncInformation.getRemote().getServer().getSelfSigned());
allowSelfSigned.setOnCheckedChangeListener((compoundButton, b) -> { allowSelfSigned.setOnCheckedChangeListener((compoundButton, b) -> {
syncInformation.getSyncServer().setSelf_signed(b); syncInformation.getRemote().getServer().setSelfSigned(b);
}); });
CheckBox push = findViewById(R.id.checkbox_push); CheckBox push = findViewById(R.id.checkbox_push);
push.setChecked(syncInformation.getSyncServer().getPush()); push.setChecked(syncInformation.getRemote().getServer().getPush());
push.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getSyncServer().setPush(b)); push.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setPush(b));
CheckBox pull = findViewById(R.id.checkbox_pull); CheckBox pull = findViewById(R.id.checkbox_pull);
pull.setChecked(syncInformation.getSyncServer().getPull()); pull.setChecked(syncInformation.getRemote().getServer().getPull());
pull.setOnCheckedChangeListener((compundButton, b) -> syncInformation.getSyncServer().setPull(b)); pull.setOnCheckedChangeListener((compundButton, b) -> syncInformation.getRemote().getServer().setPull(b));
CheckBox cache = findViewById(R.id.checkbox_cache); CheckBox cache = findViewById(R.id.checkbox_cache);
cache.setChecked(syncInformation.getSyncServer().getCaching_enabled()); cache.setChecked(syncInformation.getRemote().getServer().getCachingEnabled());
cache.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getSyncServer().setCaching_enabled(b)); cache.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setCachingEnabled(b));
// credentials // credentials

View File

@ -153,7 +153,7 @@ public class UploadActivity extends AppCompatActivity {
private User generateSyncUser(Organisation organisation) { private User generateSyncUser(Organisation organisation) {
User syncUser = syncInformation.getSyncUser(); User syncUser = syncInformation.getRemote().getSyncUser();
syncUser.setOrg_id(organisation.getId()); syncUser.setOrg_id(organisation.getId());
syncUser.setRole_id(6); syncUser.setRole_id(6);
@ -163,14 +163,14 @@ public class UploadActivity extends AppCompatActivity {
} }
private Server generateSyncServer() { private Server generateSyncServer() {
Server server = syncInformation.getSyncServer(); Server server = syncInformation.getRemote().getServer();
server.setName(syncInformation.getRemoteOrganisation().getName() + "'s Sync Server"); server.setName(syncInformation.getRemote().getOrganisation().getName() + "'s Sync Server");
server.setRemote_org_id(syncInformation.getRemoteOrganisation().getId()); server.setRemoteOrgId(syncInformation.getRemote().getOrganisation().getId());
server.setAuthkey(syncInformation.getLocal().getSyncUser().getAuthkey()); server.setAuthkey(syncInformation.getLocal().getSyncUser().getAuthkey());
server.setPull(syncInformation.getSyncServer().getPull()); server.setPull(syncInformation.getRemote().getServer().getPull());
server.setPush(syncInformation.getSyncServer().getPush()); server.setPush(syncInformation.getRemote().getServer().getPush());
server.setCaching_enabled(syncInformation.getSyncServer().getCaching_enabled()); server.setCachingEnabled(syncInformation.getRemote().getServer().getCachingEnabled());
server.setSelf_signed(syncInformation.getSyncServer().getCaching_enabled()); server.setSelfSigned(syncInformation.getRemote().getServer().getCachingEnabled());
return server; return server;
} }
@ -185,7 +185,7 @@ public class UploadActivity extends AppCompatActivity {
availableAction.done(); availableAction.done();
organisationAction.start(); organisationAction.start();
mispRest.addOrganisation(syncInformation.getRemoteOrganisation(), organisationCallback); mispRest.addOrganisation(syncInformation.getRemote().getOrganisation(), organisationCallback);
} else { } else {
availableAction.error(error); availableAction.error(error);
} }
@ -196,10 +196,10 @@ public class UploadActivity extends AppCompatActivity {
organisationAction.done(); organisationAction.done();
userAction.start(); userAction.start();
syncInformation.getRemoteOrganisation().setId(organisation.getId()); syncInformation.getRemote().getOrganisation().setId(organisation.getId());
mispRest.addUser(generateSyncUser(organisation), userCallback); mispRest.addUser(generateSyncUser(organisation), userCallback);
} else { } else {
mispRest.getOrganisation(syncInformation.getRemoteOrganisation().getUuid(), new MispRestClient.OrganisationCallback() { mispRest.getOrganisation(syncInformation.getRemote().getOrganisation().getUuid(), new MispRestClient.OrganisationCallback() {
@Override @Override
public void success(Organisation organisation) { public void success(Organisation organisation) {
organisationAdded(organisation); organisationAdded(organisation);
@ -241,7 +241,7 @@ public class UploadActivity extends AppCompatActivity {
Server serverToUpload = generateSyncServer(); Server serverToUpload = generateSyncServer();
for (Server server : servers) { for (Server server : servers) {
if (server.getRemote_org_id().equals(serverToUpload.getRemote_org_id())) { if (server.getRemoteOrgId().equals(serverToUpload.getRemoteOrgId())) {
// server already exists: override id to update instead // server already exists: override id to update instead
serverToUpload.setId(server.getId()); serverToUpload.setId(server.getId());
break; break;

View File

@ -42,7 +42,7 @@ public class SyncInfoAdapter extends RecyclerView.Adapter<SyncInfoAdapter.ViewHo
holder.dateMonth.setText(monthFormatter.format(item.getSyncDate())); holder.dateMonth.setText(monthFormatter.format(item.getSyncDate()));
holder.dateDay.setText(dayFormatter.format(item.getSyncDate())); holder.dateDay.setText(dayFormatter.format(item.getSyncDate()));
holder.orgName.setText(item.getRemoteOrganisation().getName()); holder.orgName.setText(item.getRemote().getOrganisation().getName());
// switch (item.getCurrentSyncStatus()) { // switch (item.getCurrentSyncStatus()) {
// case COMPLETE: // case COMPLETE:

View File

@ -143,33 +143,22 @@ public class DialogManager {
final AlertDialog.Builder adb = new AlertDialog.Builder(context); final AlertDialog.Builder adb = new AlertDialog.Builder(context);
adb.setTitle("Sync information received"); adb.setTitle("Sync information received");
adb.setMessage(syncInformation.getRemoteOrganisation().getName()); adb.setMessage(syncInformation.getRemote().getOrganisation().getName());
adb.setPositiveButton("Accept", new DialogInterface.OnClickListener() { adb.setPositiveButton("Accept", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.positive();
if (callback != null) {
callback.positive();
}
} }
}); });
adb.setNegativeButton("Reject", new DialogInterface.OnClickListener() { adb.setNegativeButton("Reject", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.negative();
if (callback != null) {
callback.negative();
}
} }
}); });
Activity act = (Activity) context; Activity act = (Activity) context;
act.runOnUiThread(new Runnable() { act.runOnUiThread(() -> adb.create().show());
@Override
public void run() {
adb.create().show();
}
});
} }
/** /**
@ -183,31 +172,20 @@ public class DialogManager {
adb.setTitle("Continue?"); adb.setTitle("Continue?");
adb.setMessage("Only continue if your partner already scanned this QR code"); adb.setMessage("Only continue if your partner already scanned this QR code");
adb.setPositiveButton("Continue", new DialogInterface.OnClickListener() { adb.setPositiveButton("Continue", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.positive();
if (callback != null) {
callback.positive();
}
} }
}); });
adb.setNegativeButton("Show QR code again", new DialogInterface.OnClickListener() { adb.setNegativeButton("Show QR code again", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.negative();
if (callback != null) {
callback.negative();
}
} }
}); });
Activity act = (Activity) context; Activity act = (Activity) context;
act.runOnUiThread(new Runnable() { act.runOnUiThread(() -> adb.create().show());
@Override
public void run() {
adb.create().show();
}
});
} }
/** /**
@ -218,21 +196,11 @@ public class DialogManager {
public static void loginHelpDialog(Context context) { public static void loginHelpDialog(Context context) {
final AlertDialog.Builder adb = new AlertDialog.Builder(context); final AlertDialog.Builder adb = new AlertDialog.Builder(context);
adb.setMessage(R.string.login_help_text); adb.setMessage(R.string.login_help_text);
adb.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { adb.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss());
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
Activity act = (Activity) context; Activity act = (Activity) context;
act.runOnUiThread(new Runnable() { act.runOnUiThread(() -> adb.create().show());
@Override
public void run() {
adb.create().show();
}
});
} }
public static void instanceNotAvailableDialog(Context context, final IDialogFeedback callback) { public static void instanceNotAvailableDialog(Context context, final IDialogFeedback callback) {
@ -240,31 +208,20 @@ public class DialogManager {
adb.setTitle("MISP not available"); adb.setTitle("MISP not available");
adb.setMessage("Your MISP instance is not available. Would you like to save?"); adb.setMessage("Your MISP instance is not available. Would you like to save?");
adb.setPositiveButton("Retry now", new DialogInterface.OnClickListener() { adb.setPositiveButton("Retry now", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.positive();
if (callback != null) {
callback.positive();
}
} }
}); });
adb.setNegativeButton("Save & retry later", new DialogInterface.OnClickListener() { adb.setNegativeButton("Save & retry later", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.negative();
if (callback != null) {
callback.negative();
}
} }
}); });
Activity act = (Activity) context; Activity act = (Activity) context;
act.runOnUiThread(new Runnable() { act.runOnUiThread(() -> adb.create().show());
@Override
public void run() {
adb.create().show();
}
});
} }
public static void deleteSyncInformationDialog(Context context, final IDialogFeedback callback) { public static void deleteSyncInformationDialog(Context context, final IDialogFeedback callback) {
@ -272,31 +229,20 @@ public class DialogManager {
adb.setTitle("Delete Sync Information?"); adb.setTitle("Delete Sync Information?");
adb.setMessage("This sync information will be deleted permanently"); adb.setMessage("This sync information will be deleted permanently");
adb.setPositiveButton("Delete", new DialogInterface.OnClickListener() { adb.setPositiveButton("Delete", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.positive();
if (callback != null) {
callback.positive();
}
} }
}); });
adb.setNegativeButton("Discard", new DialogInterface.OnClickListener() { adb.setNegativeButton("Discard", (dialog, which) -> {
@Override if (callback != null) {
public void onClick(DialogInterface dialog, int which) { callback.negative();
if (callback != null) {
callback.negative();
}
} }
}); });
Activity act = (Activity) context; Activity act = (Activity) context;
act.runOnUiThread(new Runnable() { act.runOnUiThread(() -> adb.create().show());
@Override
public void run() {
adb.create().show();
}
});
} }
/** /**
@ -307,6 +253,4 @@ public class DialogManager {
void negative(); void negative();
} }
} }

View File

@ -3,18 +3,12 @@ package lu.circl.mispbump.models;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import com.google.gson.annotations.SerializedName;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Calendar; import java.util.Calendar;
import java.util.Date; import java.util.Date;
import java.util.Locale; import java.util.Locale;
import java.util.UUID; import java.util.UUID;
import lu.circl.mispbump.models.restModels.Organisation;
import lu.circl.mispbump.models.restModels.Server;
import lu.circl.mispbump.models.restModels.User;
/** /**
* Class that holds the information needed synchronize two misp instances. * Class that holds the information needed synchronize two misp instances.
@ -24,10 +18,6 @@ public class SyncInformation {
private UUID uuid; private UUID uuid;
private Date date, lastModified; private Date date, lastModified;
@SerializedName("organisation")
private Organisation remoteOrganisation;
private User syncUser;
private Server syncServer;
private ExchangeInformation remote; private ExchangeInformation remote;
private ExchangeInformation local; private ExchangeInformation local;
@ -70,25 +60,12 @@ public class SyncInformation {
return df.format(date); return df.format(date);
} }
public Organisation getRemoteOrganisation() {
return remoteOrganisation;
}
public void setRemoteOrganisation(Organisation organisation) {
this.remoteOrganisation = organisation;
}
public User getSyncUser() { public ExchangeInformation getRemote() {
return syncUser; return remote;
} }
public void setSyncUser(User syncUser) { public void setRemote(ExchangeInformation remote) {
this.syncUser = syncUser; this.remote = remote;
}
public Server getSyncServer() {
return syncServer;
}
public void setSyncServer(Server syncServer) {
this.syncServer = syncServer;
} }
public ExchangeInformation getLocal() { public ExchangeInformation getLocal() {
@ -99,22 +76,13 @@ public class SyncInformation {
} }
public void populateRemoteExchangeInformation(ExchangeInformation exchangeInformation) {
this.remoteOrganisation = exchangeInformation.getOrganisation();
this.syncUser = exchangeInformation.getSyncUser();
this.syncServer = exchangeInformation.getServer();
}
@NonNull @NonNull
@Override @Override
public String toString() { public String toString() {
return "Sync Information: \n" + return "Sync Information: \n" +
"UUID = " + uuid + "\n" + "UUID = " + uuid + "\n" +
"Date = " + getSyncDateString() + "\n" + "Sync Date = " + getSyncDateString() + "\n" +
remoteOrganisation.toString() + "\n" + remote.toString() +
syncUser.toString() + "\n" +
syncServer.toString() + "\n" +
local.toString(); local.toString();
} }
} }

View File

@ -67,11 +67,11 @@ public class Server {
this.authkey = authkey; this.authkey = authkey;
} }
public Integer getOrg_id() { public Integer getOrgId() {
return org_id; return org_id;
} }
public void setOrg_id(Integer org_id) { public void setOrgId(Integer org_id) {
this.org_id = org_id; this.org_id = org_id;
} }
@ -91,19 +91,19 @@ public class Server {
this.pull = pull; this.pull = pull;
} }
public Object getLastpulledid() { public Object getLastpulledId() {
return lastpulledid; return lastpulledid;
} }
public void setLastpulledid(Object lastpulledid) { public void setLastpulledId(Object lastpulledid) {
this.lastpulledid = lastpulledid; this.lastpulledid = lastpulledid;
} }
public Object getLastpushedid() { public Object getLastpushedId() {
return lastpushedid; return lastpushedid;
} }
public void setLastpushedid(Object lastpushedid) { public void setLastpushedId(Object lastpushedid) {
this.lastpushedid = lastpushedid; this.lastpushedid = lastpushedid;
} }
@ -115,67 +115,67 @@ public class Server {
this.organization = organization; this.organization = organization;
} }
public Integer getRemote_org_id() { public Integer getRemoteOrgId() {
return remote_org_id; return remote_org_id;
} }
public void setRemote_org_id(Integer remote_org_id) { public void setRemoteOrgId(Integer remote_org_id) {
this.remote_org_id = remote_org_id; this.remote_org_id = remote_org_id;
} }
public Boolean getPublish_without_email() { public Boolean getPublishWithoutEmail() {
return publish_without_email; return publish_without_email;
} }
public void setPublish_without_email(Boolean publish_without_email) { public void setPublishWithoutEmail(Boolean publish_without_email) {
this.publish_without_email = publish_without_email; this.publish_without_email = publish_without_email;
} }
public Boolean getUnpublish_event() { public Boolean getUnpublishEvent() {
return unpublish_event; return unpublish_event;
} }
public void setUnpublish_event(Boolean unpublish_event) { public void setUnpublishEvent(Boolean unpublish_event) {
this.unpublish_event = unpublish_event; this.unpublish_event = unpublish_event;
} }
public Boolean getSelf_signed() { public Boolean getSelfSigned() {
return self_signed; return self_signed;
} }
public void setSelf_signed(Boolean self_signed) { public void setSelfSigned(Boolean self_signed) {
this.self_signed = self_signed; this.self_signed = self_signed;
} }
public String getPull_rules() { public String getPullRules() {
return pull_rules; return pull_rules;
} }
public void setPull_rules(String pull_rules) { public void setPullRules(String pull_rules) {
this.pull_rules = pull_rules; this.pull_rules = pull_rules;
} }
public String getPush_rules() { public String getPushRules() {
return push_rules; return push_rules;
} }
public void setPush_rules(String push_rules) { public void setPushRules(String push_rules) {
this.push_rules = push_rules; this.push_rules = push_rules;
} }
public Object getCert_file() { public Object getCertFile() {
return cert_file; return cert_file;
} }
public void setCert_file(Object cert_file) { public void setCertFile(Object cert_file) {
this.cert_file = cert_file; this.cert_file = cert_file;
} }
public Object getClient_cert_file() { public Object getClientCertFile() {
return client_cert_file; return client_cert_file;
} }
public void setClient_cert_file(Object client_cert_file) { public void setClientCertFile(Object client_cert_file) {
this.client_cert_file = client_cert_file; this.client_cert_file = client_cert_file;
} }
@ -187,27 +187,27 @@ public class Server {
this.internal = internal; this.internal = internal;
} }
public Boolean getSkip_proxy() { public Boolean getSkipProxy() {
return skip_proxy; return skip_proxy;
} }
public void setSkip_proxy(Boolean skip_proxy) { public void setSkipProxy(Boolean skip_proxy) {
this.skip_proxy = skip_proxy; this.skip_proxy = skip_proxy;
} }
public Boolean getCaching_enabled() { public Boolean getCachingEnabled() {
return caching_enabled; return caching_enabled;
} }
public void setCaching_enabled(Boolean caching_enabled) { public void setCachingEnabled(Boolean caching_enabled) {
this.caching_enabled = caching_enabled; this.caching_enabled = caching_enabled;
} }
public Boolean getCache_timestamp() { public Boolean getCacheTimestamp() {
return cache_timestamp; return cache_timestamp;
} }
public void setCache_timestamp(Boolean cache_timestamp) { public void setCacheTimestamp(Boolean cache_timestamp) {
this.cache_timestamp = cache_timestamp; this.cache_timestamp = cache_timestamp;
} }