Changeset 5209
- Timestamp:
- 08/08/08 16:03:20 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/api/db/hibernate/HibernateSynchronizationInterceptor.java
r5203 r5209 372 372 log.debug("onSave: " + state.toString()); 373 373 374 boolean isGuidAssigned = assignGUID( (Synchronizable)entity, state, propertyNames, SyncItemState.NEW);374 boolean isGuidAssigned = assignGUID(entity, state, propertyNames, SyncItemState.NEW); 375 375 376 376 // explicitly bail out if sync is disabled … … 421 421 log.debug("onFlushDirty: " + entity.getClass().getName()); 422 422 423 boolean isGuidAssigned = assignGUID( (Synchronizable)entity, currentState, propertyNames, SyncItemState.UPDATED);423 boolean isGuidAssigned = assignGUID(entity, currentState, propertyNames, SyncItemState.UPDATED); 424 424 425 425 // explicitly bail out if sync is disabled … … 619 619 * @return True if data was altered, false otherwise. 620 620 */ 621 protected boolean assignGUID( Synchronizableentity, Object[] currentState, String[] propertyNames, SyncItemState state) throws SyncException {621 protected boolean assignGUID(Object entity, Object[] currentState, String[] propertyNames, SyncItemState state) throws SyncException { 622 622 623 623 /* … … 627 627 * session and then saved anew; as in obs edit 628 628 */ 629 if (state == SyncItemState.NEW && entity.getGuid() != null && entity.getLastRecordGuid() == null) { 630 entity.setGuid(null); 631 } 632 633 // If entity already has a GUID on this server, no need to assign a new one 634 if (StringUtils.hasText(entity.getGuid())) { 635 if (log.isDebugEnabled()) log.debug("Entity: " + entity + " already has a GUID assigned: " + entity.getGuid()); 636 return false; 629 if (entity instanceof Synchronizable) { 630 Synchronizable syncEntity = (Synchronizable) entity; 631 if (state == SyncItemState.NEW && syncEntity.getGuid() != null && syncEntity.getLastRecordGuid() == null) { 632 syncEntity.setGuid(null); 633 } 634 635 // If entity already has a GUID on this server, no need to assign a new one 636 if (StringUtils.hasText(syncEntity.getGuid())) { 637 if (log.isDebugEnabled()) log.debug("Entity: " + syncEntity + " already has a GUID assigned: " + syncEntity.getGuid()); 638 return false; 639 } 637 640 } 638 641 … … 642 645 if ("guid".equalsIgnoreCase(propName)) { 643 646 String guidToAssign = null; 644 if (state != SyncItemState.NEW ) { // attempt to fetch first645 guidToAssign = this.fetchGuid( entity);647 if (state != SyncItemState.NEW && entity instanceof Synchronizable) { // attempt to fetch first 648 guidToAssign = this.fetchGuid((Synchronizable)entity); 646 649 } 647 650 if (StringUtils.hasText(guidToAssign)) {