Re-added logging to LocalDB to resolve merge conflict

This commit is contained in:
Kai S. K. Engelbart 2019-12-05 16:10:28 +01:00
parent 2831b9a7a3
commit 6cf8c462b9

View File

@ -9,6 +9,7 @@ import java.io.ObjectOutputStream;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
import javax.xml.datatype.DatatypeConfigurationException; import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory; import javax.xml.datatype.DatatypeFactory;
@ -43,6 +44,8 @@ public class LocalDB {
private Sync sync = objectFactory.createSync(); private Sync sync = objectFactory.createSync();
private Sync readMessages = objectFactory.createSync(); private Sync readMessages = objectFactory.createSync();
private static final Logger logger = Logger.getLogger(LocalDB.class.getSimpleName());
/** /**
* Constructs an empty local database. * Constructs an empty local database.
* *
@ -85,13 +88,13 @@ public class LocalDB {
localDB.createNewFile(); localDB.createNewFile();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
System.err.println("unable to save the messages"); logger.warning("unable to save the messages");
} }
try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(localDB))) { try (ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(localDB))) {
out.writeObject(chats); out.writeObject(chats);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();
System.err.println("unable to save the messages"); logger.warning("unable to save the messages");
} }
} }
@ -141,7 +144,7 @@ public class LocalDB {
sync.getMessages().addAll(readMessages.getMessages()); sync.getMessages().addAll(readMessages.getMessages());
readMessages.getMessages().clear(); readMessages.getMessages().clear();
System.out.println(sync.getMessages().size()); logger.info(String.format("Filled sync with %d messages.", sync.getMessages().size()));
return sync; return sync;
} }
@ -189,24 +192,24 @@ public class LocalDB {
break; break;
case READ: case READ:
// Update local Messages to state READ // Update local Messages to state READ
System.out.println("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId() logger.info("Message with ID: " + returnSync.getMessages().get(i).getMetadata().getMessageId()
+ "was initialized to be set to READ in localDB."); + "was initialized to be set to READ in localDB.");
for (int j = 0; j < getChats().size(); j++) { for (int j = 0; j < getChats().size(); j++) {
if (getChats().get(j).getRecipient().getID() == returnSync.getMessages().get(i).getMetadata().getRecipient()) { if (getChats().get(j).getRecipient().getID() == returnSync.getMessages().get(i).getMetadata().getRecipient()) {
System.out.println("Chat with: " + getChats().get(j).getRecipient().getID() + "was selected."); logger.info("Chat with: " + getChats().get(j).getRecipient().getID() + "was selected.");
for (int k = 0; k < getChats().get(j).getModel().getSize(); k++) { for (int k = 0; k < getChats().get(j).getModel().getSize(); k++) {
if (getChats().get(j).getModel().get(k).getMetadata().getMessageId() == returnSync.getMessages() if (getChats().get(j).getModel().get(k).getMetadata().getMessageId() == returnSync.getMessages()
.get(i) .get(i)
.getMetadata() .getMetadata()
.getMessageId()) { .getMessageId()) {
System.out.println("Message with ID: " + getChats().get(j).getModel().get(k).getMetadata().getMessageId() logger.info("Message with ID: " + getChats().get(j).getModel().get(k).getMetadata().getMessageId()
+ "was selected."); + "was selected.");
getChats().get(j) getChats().get(j)
.getModel() .getModel()
.get(k) .get(k)
.getMetadata() .getMetadata()
.setState(returnSync.getMessages().get(i).getMetadata().getState()); .setState(returnSync.getMessages().get(i).getMetadata().getState());
System.out.println( logger.info(
"Message State is now: " + getChats().get(j).getModel().get(k).getMetadata().getState().toString()); "Message State is now: " + getChats().get(j).getModel().get(k).getMetadata().getState().toString());
} }
} }
@ -222,7 +225,7 @@ public class LocalDB {
for (Chat chat : getChats()) for (Chat chat : getChats())
if (user.getID() == chat.getRecipient().getID()) { if (user.getID() == chat.getRecipient().getID()) {
chat.getRecipient().setStatus(user.getStatus()); chat.getRecipient().setStatus(user.getStatus());
System.out.println(chat.getRecipient().getStatus()); logger.info(chat.getRecipient().getStatus().toString());
} }
sync.getMessages().clear(); sync.getMessages().clear();
@ -273,7 +276,7 @@ public class LocalDB {
for (Chat chat : getChats()) for (Chat chat : getChats())
for (int i = 0; i < chat.getModel().size(); i++) for (int i = 0; i < chat.getModel().size(); i++)
if (chat.getModel().get(i).getMetadata().getState() == MessageState.WAITING) { if (chat.getModel().get(i).getMetadata().getState() == MessageState.WAITING) {
System.out.println("Got Waiting Message"); logger.info("Got Waiting Message");
sync.getMessages().add(chat.getModel().get(i)); sync.getMessages().add(chat.getModel().get(i));
} }
} }