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:
try {
ExchangeInformation remoteSyncInfo = new Gson().fromJson(diffieHellman.decrypt(qrData), ExchangeInformation.class);
syncInformation.populateRemoteExchangeInformation(remoteSyncInfo);
syncInformation.setRemote(remoteSyncInfo);
preferenceManager.addSyncInformation(syncInformation);
setSyncState(SyncState.DATA_EXCHANGE_DONE);
} catch (JsonSyntaxException e) {

View File

@ -44,9 +44,9 @@ public class NetworkTestActivity extends AppCompatActivity {
List<SyncInformation> syncInformationList = preferenceManager.getSyncInformationList();
for (SyncInformation syncInfo : syncInformationList) {
String authkey = syncInfo.getSyncServer().getAuthkey();
String authkey = syncInfo.getRemote().getServer().getAuthkey();
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
MaterialPreferenceText name = findViewById(R.id.name);
name.setSubtitle(syncInformation.getRemoteOrganisation().getName());
name.setSubtitle(syncInformation.getRemote().getOrganisation().getName());
MaterialPreferenceText uuid = findViewById(R.id.uuid);
uuid.setSubtitle(syncInformation.getRemoteOrganisation().getUuid());
uuid.setSubtitle(syncInformation.getRemote().getOrganisation().getUuid());
MaterialPreferenceText sector = findViewById(R.id.sector);
sector.setSubtitle(syncInformation.getRemoteOrganisation().getSector());
sector.setSubtitle(syncInformation.getRemote().getOrganisation().getSector());
MaterialPreferenceText description = findViewById(R.id.description);
description.setSubtitle(syncInformation.getRemoteOrganisation().getDescription());
description.setSubtitle(syncInformation.getRemote().getOrganisation().getDescription());
// settings
CheckBox allowSelfSigned = findViewById(R.id.checkbox_self_signed);
allowSelfSigned.setChecked(syncInformation.getSyncServer().getSelf_signed());
allowSelfSigned.setChecked(syncInformation.getRemote().getServer().getSelfSigned());
allowSelfSigned.setOnCheckedChangeListener((compoundButton, b) -> {
syncInformation.getSyncServer().setSelf_signed(b);
syncInformation.getRemote().getServer().setSelfSigned(b);
});
CheckBox push = findViewById(R.id.checkbox_push);
push.setChecked(syncInformation.getSyncServer().getPush());
push.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getSyncServer().setPush(b));
push.setChecked(syncInformation.getRemote().getServer().getPush());
push.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setPush(b));
CheckBox pull = findViewById(R.id.checkbox_pull);
pull.setChecked(syncInformation.getSyncServer().getPull());
pull.setOnCheckedChangeListener((compundButton, b) -> syncInformation.getSyncServer().setPull(b));
pull.setChecked(syncInformation.getRemote().getServer().getPull());
pull.setOnCheckedChangeListener((compundButton, b) -> syncInformation.getRemote().getServer().setPull(b));
CheckBox cache = findViewById(R.id.checkbox_cache);
cache.setChecked(syncInformation.getSyncServer().getCaching_enabled());
cache.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getSyncServer().setCaching_enabled(b));
cache.setChecked(syncInformation.getRemote().getServer().getCachingEnabled());
cache.setOnCheckedChangeListener((compoundButton, b) -> syncInformation.getRemote().getServer().setCachingEnabled(b));
// credentials

View File

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

View File

@ -42,7 +42,7 @@ public class SyncInfoAdapter extends RecyclerView.Adapter<SyncInfoAdapter.ViewHo
holder.dateMonth.setText(monthFormatter.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()) {
// case COMPLETE:

View File

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

View File

@ -3,18 +3,12 @@ package lu.circl.mispbump.models;
import androidx.annotation.NonNull;
import com.google.gson.annotations.SerializedName;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
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.
@ -24,10 +18,6 @@ public class SyncInformation {
private UUID uuid;
private Date date, lastModified;
@SerializedName("organisation")
private Organisation remoteOrganisation;
private User syncUser;
private Server syncServer;
private ExchangeInformation remote;
private ExchangeInformation local;
@ -70,25 +60,12 @@ public class SyncInformation {
return df.format(date);
}
public Organisation getRemoteOrganisation() {
return remoteOrganisation;
}
public void setRemoteOrganisation(Organisation organisation) {
this.remoteOrganisation = organisation;
}
public User getSyncUser() {
return syncUser;
public ExchangeInformation getRemote() {
return remote;
}
public void setSyncUser(User syncUser) {
this.syncUser = syncUser;
}
public Server getSyncServer() {
return syncServer;
}
public void setSyncServer(Server syncServer) {
this.syncServer = syncServer;
public void setRemote(ExchangeInformation remote) {
this.remote = remote;
}
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
@Override
public String toString() {
return "Sync Information: \n" +
"UUID = " + uuid + "\n" +
"Date = " + getSyncDateString() + "\n" +
remoteOrganisation.toString() + "\n" +
syncUser.toString() + "\n" +
syncServer.toString() + "\n" +
"Sync Date = " + getSyncDateString() + "\n" +
remote.toString() +
local.toString();
}
}

View File

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