Downloads Documentation Community Contribute Demo






Show Sidebar
Login | Register

Changeset 5209

Show
Ignore:
Timestamp:
08/08/08 16:03:20 (3 months ago)
Author:
mseaton
Message:

openmrs-synchronization branch: fix classcastexception

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • openmrs/branches/data_synchronization_bidirectional/src/api/org/openmrs/api/db/hibernate/HibernateSynchronizationInterceptor.java

    r5203 r5209  
    372372                        log.debug("onSave: " + state.toString()); 
    373373                 
    374                 boolean isGuidAssigned = assignGUID((Synchronizable) entity, state, propertyNames, SyncItemState.NEW); 
     374                boolean isGuidAssigned = assignGUID(entity, state, propertyNames, SyncItemState.NEW); 
    375375 
    376376                // explicitly bail out if sync is disabled 
     
    421421                        log.debug("onFlushDirty: " + entity.getClass().getName()); 
    422422                 
    423                 boolean isGuidAssigned = assignGUID((Synchronizable) entity, currentState, propertyNames, SyncItemState.UPDATED); 
     423                boolean isGuidAssigned = assignGUID(entity, currentState, propertyNames, SyncItemState.UPDATED); 
    424424 
    425425                // explicitly bail out if sync is disabled 
     
    619619         * @return True if data was altered, false otherwise. 
    620620         */ 
    621         protected boolean assignGUID(Synchronizable entity, Object[] currentState, String[] propertyNames, SyncItemState state) throws SyncException { 
     621        protected boolean assignGUID(Object entity, Object[] currentState, String[] propertyNames, SyncItemState state) throws SyncException { 
    622622                 
    623623                /* 
     
    627627                 * session and then saved anew; as in obs edit 
    628628                 */ 
    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                        } 
    637640                } 
    638641 
     
    642645                        if ("guid".equalsIgnoreCase(propName)) { 
    643646                                String guidToAssign = null; 
    644                                 if (state != SyncItemState.NEW) { // attempt to fetch first 
    645                                         guidToAssign = this.fetchGuid(entity); 
     647                                if (state != SyncItemState.NEW && entity instanceof Synchronizable) { // attempt to fetch first 
     648                                        guidToAssign = this.fetchGuid((Synchronizable)entity); 
    646649                                } 
    647650                                if (StringUtils.hasText(guidToAssign)) {