001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2012 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.client.tide.data;
022
023 import java.util.ArrayList;
024 import java.util.List;
025
026 import org.granite.logging.Logger;
027
028 /**
029 * Holds conflict data when locally changed data is in conflict with data coming from the server
030 *
031 * @author William DRAI
032 */
033 public class Conflicts {
034
035 @SuppressWarnings("unused")
036 private static Logger log = Logger.getLogger("org.granite.client.tide.data.Conflicts");
037
038 private EntityManager entityManager;
039
040 private List<Conflict> conflicts = new ArrayList<Conflict>();
041
042
043
044 public Conflicts(EntityManager entityManager) {
045 this.entityManager = entityManager;
046 }
047
048 public void addConflict(Identifiable localEntity, Identifiable receivedEntity, List<String> properties) {
049 Conflict conflict = new Conflict(this, localEntity, receivedEntity, properties);
050 conflicts.add(conflict);
051 }
052
053 public List<Conflict> getConflicts() {
054 return conflicts;
055 }
056
057 public boolean isEmpty() {
058 return conflicts.size() == 0;
059 }
060
061 public boolean isAllResolved() {
062 for (Conflict c : conflicts) {
063 if (!c.isResolved())
064 return false;
065 }
066 return true;
067 }
068
069 public void acceptClient(Conflict conflict) {
070 entityManager.acceptConflict(conflict, true);
071 }
072
073 public void acceptAllClient() {
074 for (Conflict c : conflicts)
075 acceptClient(c);
076 }
077
078 public void acceptServer(Conflict conflict) {
079 entityManager.acceptConflict(conflict, false);
080 }
081
082 public void acceptAllServer() {
083 for (Conflict c : conflicts)
084 acceptServer(c);
085 }
086 }