[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Phpgroupware-cvs] sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyn
From: |
nomail |
Subject: |
[Phpgroupware-cvs] sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java, 1.3 |
Date: |
Mon, 28 Jun 2004 12:08:20 +0200 |
Update of /sync/sync4j/de/probusiness/pbgroupware/sync
Modified Files:
Branch:
PHPGwSyncStrategy.java
date: 2004/06/28 10:08:20; author: mleonhardt; state: Exp; lines: +182 -50
Log Message:
- updated s4j-syncmodul
=====================================================================
Index: sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java
diff -u sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java:1.2
sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java:1.3
--- sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java:1.2
Wed Jun 9 18:35:09 2004
+++ sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java Mon Jun
28 10:08:20 2004
@@ -19,6 +19,8 @@
import sync4j.framework.security.*;
import sync4j.server.engine.*;
+import java.lang.reflect.*;
+
/**
* @author ChristianW
*
@@ -208,6 +210,12 @@
final Vector params = new Vector();
params.add(syncItemA.getKey().getKeyAsString());
final Object clientData =
syncItemA.getPropertyValue(SyncItem.PROPERTY_BINARY_CONTENT);
+ final ModificationCommand cmd = (ModificationCommand)
syncItemA.getPropertyValue(SyncItemHelper.PROPERTY_COMMAND);
+ if (clientData == null) {
+ return new SyncOperationStatus[] {
+ new
Sync4jOperationStatusError(operation, sources[1], cmd, new Exception("no
content found for A-item"))
+ };
+ }
log.finer("found client-item; data is of type (" +
clientData.getClass().getName() + ")");
if (clientData instanceof String) {
params.add(clientData);
@@ -228,7 +236,6 @@
catch (final SyncSourceException e) {
log.severe("Error executing sync operation: " +
e.getMessage());
log.throwing(getClass().getName(),
"execSyncOperation", e);
- final ModificationCommand cmd =
(ModificationCommand)
syncItemA.getPropertyValue(SyncItemHelper.PROPERTY_COMMAND);
return new SyncOperationStatus[] {
new
Sync4jOperationStatusError(operation, sources[1], cmd, e)
};
@@ -341,8 +348,12 @@
}
// private final Collection executeBulkDelete(final Collection ops) {
-// // TODO
-// return null;
+// for (final Iterator it = ops.iterator(); it.hasNext();) {
+// final SyncOperation op = (SyncOperation) it.next();
+// final Principal owner = op.getOwner();
+// log.fine("bulkdelete: " + op.toString());
+// }
+// return ops;
// }
private final Object executeXMLRPC(final Principal principal, final
SyncSource source, final String methodname, final Vector params) throws
SyncSourceException {
@@ -371,58 +382,167 @@
return op;
}
- private static final void publishSourceInfo(final Principal principal,
final SyncSource clsource) {
- final SyncSourceInfo info = clsource.getInfo();
- final ContentType[] supportedTypes = info.getSupportedTypes();
- final int len = supportedTypes.length;
- final Vector xrtypes = new Vector(len);
- for (int i = 0; i < len; i++) {
- final ContentType type = supportedTypes[i];
- final Hashtable xrtype = new Hashtable();
- xrtype.put(CONTENT_TYPE_KEY_TYPE, type.getType());
- xrtype.put(CONTENT_TYPE_KEY_VERSION, type.getVersion());
- xrtypes.add(xrtype);
- }
- if (xrtypes.isEmpty()) {
- final ContentType type = info.getPreferredType();
- final Hashtable xrtype = new Hashtable();
- xrtype.put(CONTENT_TYPE_KEY_TYPE, type.getType());
- xrtype.put(CONTENT_TYPE_KEY_VERSION, type.getVersion());
- xrtypes.add(xrtype);
- }
-
-
- final Vector params = new Vector();
- // prepend device_id to parameter-list
- params.add(((Sync4jPrincipal) principal).getId());
- params.add(xrtypes);
- // prepare ipc-dispatch
- final Vector fparams = new Vector();
- fparams.add("sync.setSourceInfoSupportedTypes");
- fparams.add(params);
- try {
-
PHPGwSyncXMLRPCClient.getInstance().execute("phpgwapi.ipc_manager.execIPC",
fparams);
- }
- catch (final SyncSourceException e) {
- log.throwing(PHPGwSyncStrategy.class.getName(), "error
publishing SyncSourceInfo.supportedTypes", e);
- }
- }
+// removed because sync4j doesn't fill the Info-Records till Version 2.0 ! ;-(
+// private static final void publishSourceInfo(final Principal principal,
final SyncSource clsource) {
+// final SyncSourceInfo info = clsource.getInfo();
+// final ContentType[] supportedTypes = info.getSupportedTypes();
+// final int len = supportedTypes.length;
+// final Vector xrtypes = new Vector(len);
+// for (int i = 0; i < len; i++) {
+// final ContentType type = supportedTypes[i];
+// final Hashtable xrtype = new Hashtable();
+// xrtype.put(CONTENT_TYPE_KEY_TYPE, type.getType());
+// xrtype.put(CONTENT_TYPE_KEY_VERSION, type.getVersion());
+// xrtypes.add(xrtype);
+// }
+// if (xrtypes.isEmpty()) {
+// final ContentType type = info.getPreferredType();
+// final Hashtable xrtype = new Hashtable();
+// xrtype.put(CONTENT_TYPE_KEY_TYPE, type.getType());
+// xrtype.put(CONTENT_TYPE_KEY_VERSION, type.getVersion());
+// xrtypes.add(xrtype);
+// }
+//
+//
+// final Vector params = new Vector();
+// // prepend device_id to parameter-list
+// params.add(((Sync4jPrincipal) principal).getId());
+// params.add(xrtypes);
+// // prepare ipc-dispatch
+// final Vector fparams = new Vector();
+// fparams.add("sync.setSourceInfoSupportedTypes");
+// fparams.add(params);
+// try {
+//
PHPGwSyncXMLRPCClient.getInstance().execute("phpgwapi.ipc_manager.execIPC",
fparams);
+// }
+// catch (final SyncSourceException e) {
+// log.throwing(PHPGwSyncStrategy.class.getName(), "error
publishing SyncSourceInfo.supportedTypes", e);
+// }
+// }
- /* (non-Javadoc)
- * @see
sync4j.framework.engine.SyncStrategy#prepareFastSync(sync4j.framework.engine.source.SyncSource[],
java.security.Principal, java.sql.Timestamp)
+ /**
+ * Checks the given SyncItem lists and creates the needed SyncOperations
+ * following the rules described in the class descriprio and in the .
+ *
+ * @param principal who has requested the synchronization
+ * @param AmBm
+ * @param AmBBm
+ * @param AAmBm
+ *
+ * @return an ArrayList containing all the collected sync operations
*/
- public SyncOperation[] prepareFastSync(final SyncSource[] sources,
final Principal principal, final java.sql.Timestamp since) throws SyncException
{
- publishSourceInfo(principal, sources[0]);
- return super.prepareFastSync(sources, principal, since);
- }
+ protected ArrayList checkSyncOperations(Principal principal,
+
List Am ,
+
List Bm ,
+
List AmBm ,
+
List AmBBm ,
+
List AAmBm ) {
+ SyncItemMapping mapping = null;
+ SyncItem syncItemA = null, syncItemB = null;
+ SyncItem[] all;
+ SyncSource SourceA = null;
+
+ final SyncSource[] sources = getSources();
+ SourceA = sources[1];
+
+ log.fine("checkSyncOperations: AAmBm has keycount: " +
AAmBm.size());
+ Iterator i = AAmBm.iterator();
+ while (i.hasNext()) {
+ mapping = (SyncItemMapping)i.next();
+
+ syncItemA = mapping.getSyncItemA();
+ syncItemB = mapping.getSyncItemB();
+ // workaround hack for the conflicterror with new
entries in source B
+ if
(syncItemB.getKey().getKeyValue().toString().charAt(0) == '_') {
+ log.fine("checkSyncOperations: removing mapping
with B-key " + syncItemB.getKey().getKeyValue());
+ i.remove();
+ }
+ }
+
+// log.fine("checkSyncOperations: Bm has keycount: " + Bm.size());
+//
+// try {
+// all = SourceA.getAllSyncItems(principal);
+// } catch (SyncSourceException e) {
+// all = null;
+// log.fine("checkSyncOperations: failed getting All Items
of source A!");
+// }
+//
+// log.fine("checkSyncOperations: Source A has keycount: " +
all.length);
+//
+// for (int j=0; ((all != null) && (j<all.length)); ++j) {
+// log.fine("checkSyncOperations output all SyncItemKeys
from source A: " + all[j].getKey());
+// }
+//
+// i = Bm.iterator();
+// while (i.hasNext()) {
+// syncItemB = (SyncItem)i.next();
+//
+// try {
+// syncItemA =
SourceA.getSyncItemFromId(principal, syncItemB.getKey());
+// } catch (SyncSourceException e) {
+// log.severe("Error getting SyncItem from Source
A " + e.getMessage());
+// syncItemA = null;
+// };
+//
+// // workaround hack for the conflicterror with new
entries in source B
+// log.fine("checkSyncOperations: found B-key " +
syncItemB.getKey().getKeyValue());
+// if (syncItemA != null) {
+// log.fine("checkSyncOperations: corresponding
A-key " + syncItemA.getKey().getKeyValue());
+// } else {
+// log.fine("checkSyncOperations: Item A not
found!");
+//
+// ArrayList unchangedSyncItems = null;
+// try {
+// unchangedSyncItems =
getUnchangedSyncItems((MemorySyncSource) SourceA);
+// }
+// catch (final Exception e) {
+// // wenn der Code hier wirklich ankommt, dann
lief etwas ganz
+// // grob schief, denn das bedeutet entweder,
dass die verwendete
+// // Version der MemorySyncSource kein Field
"unchangedSyncItems"
+// // hat[1], dieses einen anderen Typ hat, als
erwartet[2] oder ein
+// // installierter SecurityManager den Zugriff
geperrt hat[3]
+// // Die Exceptions, zwecks einzelnem Fangen
waeren:
+// // [1] java.lang.NoSuchFieldException
+// // [2] java.lang.ClassCastException
+// // [3] java.lang.IllegalAccessException
+// //
+// // Meine Empfehlung: Einfach loggen und mit
dem naechsten
+// // weitermachen:
+//
log.throwing(PHPGwSyncStrategy.class.getName(), "checkSyncOperations", e);
+// }
+// final SyncItem SynchronizedItem =
+// new SyncItemImpl(SourceA, syncItemB.getKey(),
SyncItemState.SYNCHRONIZED);
+// unchangedSyncItems.add(SynchronizedItem);
+// syncItemA = SynchronizedItem;
+// log.fine("checkSyncOperations: new Item A
created!");
+// mapping = new
SyncItemMapping(syncItemB.getKey());
+// mapping.setMapping(syncItemA, syncItemB);
+// AAmBm.add(mapping);
+// log.fine("checkSyncOperations: Mapping added to
AAmBm");
+// }
+// }
+ return super.checkSyncOperations(principal, Am, Bm, AmBm,
AmBBm, AAmBm);
+ }
+
/* (non-Javadoc)
- * @see
sync4j.framework.engine.SyncStrategy#prepareSlowSync(sync4j.framework.engine.source.SyncSource[],
java.security.Principal)
+ * @see
sync4j.framework.engine.SyncStrategy#prepareFastSync(sync4j.framework.engine.source.SyncSource[],
java.security.Principal, java.sql.Timestamp)
*/
- public SyncOperation[] prepareSlowSync(final SyncSource[] sources,
final Principal principal) throws SyncException {
- publishSourceInfo(principal, sources[0]);
- return super.prepareSlowSync(sources, principal);
- }
+// removed because sync4j doesn't fill the Info-Records till Version 2.0 !
;-(
+// public SyncOperation[] prepareFastSync(final SyncSource[] sources,
final Principal principal, final java.sql.Timestamp since) throws SyncException
{
+// publishSourceInfo(principal, sources[0]);
+// return super.prepareFastSync(sources, principal, since);
+// }
+//
+// /* (non-Javadoc)
+// * @see
sync4j.framework.engine.SyncStrategy#prepareSlowSync(sync4j.framework.engine.source.SyncSource[],
java.security.Principal)
+// */
+// removed because sync4j doesn't fill the Info-Records till Version 2.0 !
;-(
+// public SyncOperation[] prepareSlowSync(final SyncSource[] sources,
final Principal principal) throws SyncException {
+// publishSourceInfo(principal, sources[0]);
+// return super.prepareSlowSync(sources, principal);
+// }
/* (non-Javadoc)
* @see
sync4j.framework.engine.SyncStrategy#sync(sync4j.framework.engine.SyncOperation[])
@@ -477,4 +597,16 @@
}
return (SyncOperationStatus[]) status.toArray(new
SyncOperationStatus[status.size()]);
}
+
+ private static final ArrayList getUnchangedSyncItems(
+ final MemorySyncSource source) throws
NoSuchFieldException,
+
IllegalAccessException {
+ final Field unchangedSyncItemsField =
+
MemorySyncSource.class.getDeclaredField("unchangedSyncItems");
+ unchangedSyncItemsField.setAccessible(true);
+ final ArrayList unchangedSyncItems =
+ (ArrayList) unchangedSyncItemsField.get(source);
+ unchangedSyncItemsField.setAccessible(false);
+ return unchangedSyncItems;
+ }
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Phpgroupware-cvs] sync/sync4j/de/probusiness/pbgroupware/sync/PHPGwSyncStrategy.java, 1.3,
nomail <=