private void handleWriteUniqueVerifyException( Entity entity, WriteUniqueVerifyException wuve ) throws DuplicateUniquePropertyExistsException { // we may have multiple conflicts, but caller expects only one Map<String, Field> violiations = wuve.getViolations(); if ( violiations != null ) { Field conflict = violiations.get( violiations.keySet().iterator().next() ); throw new DuplicateUniquePropertyExistsException( entity.getType(), conflict.getName(), conflict.getValue() ); } else { throw new DuplicateUniquePropertyExistsException( entity.getType(), "Unknown property name", "Unknown property value" ); } }
private void confirmUniqueFieldsAkka( MvccEntity mvccEntity, UUID version, ApplicationScope scope, String region ) { final Entity entity = mvccEntity.getEntity().get(); try { akkaUvService.confirmUniqueValues( scope, entity, version, region ); } catch (UniqueValueException e) { Map<String, Field> violations = new HashMap<>(); violations.put( e.getField().getName(), e.getField() ); throw new WriteUniqueVerifyException( mvccEntity, scope, violations ); } } }
@Test public void writeWithUniqueValues() { ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) ); EntityCollectionManager manager = factory.createCollectionManager( context ); { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); Observable<Entity> observable = manager.write( newEntity, null ); Entity returned = observable.toBlocking().lastOrDefault( null ); } { try { Entity newEntity = new Entity( new SimpleId( "test" ) ); newEntity.setField( new IntegerField( "count", 5, true ) ); manager.write( newEntity, null ).toBlocking().last(); fail( "Write should have thrown an exception" ); } catch ( Exception ex ) { WriteUniqueVerifyException e = ( WriteUniqueVerifyException ) ex; assertEquals( 1, e.getViolations().size() ); } } }
private void verifyUniqueFieldsAkka(CollectionIoEvent<MvccEntity> ioevent) { MvccValidationUtils.verifyMvccEntityWithEntity( ioevent.getEvent() ); final MvccEntity mvccEntity = ioevent.getEvent(); final Entity entity = mvccEntity.getEntity().get(); final ApplicationScope applicationScope = ioevent.getEntityCollection(); String authoritativeRegion = ioevent.getAuthoritativeRegion(); if ( StringUtils.isEmpty(authoritativeRegion) ) { authoritativeRegion = uniqueValuesFig.getAuthoritativeRegion(); } if ( StringUtils.isEmpty(authoritativeRegion) ) { authoritativeRegion = actorSystemFig.getRegionLocal(); } try { akkaUvService.reserveUniqueValues( applicationScope, entity, mvccEntity.getVersion(), authoritativeRegion ); } catch (UniqueValueException e) { Map<String, Field> violations = new HashMap<>(); violations.put( e.getField().getName(), e.getField() ); throw new WriteUniqueVerifyException( mvccEntity, applicationScope, violations ); } }
assertTrue( !e.getViolations().isEmpty() );
throw new WriteUniqueVerifyException(mvccEntity, scope, preWriteUniquenessViolations ); throw new WriteUniqueVerifyException( mvccEntity, ioevent.getEntityCollection(), uniquenessViolations );