@Override
public void save(Party party, Access access) {
if( party == null )
throw new ApplicationException("数据为空,不能进行保存!");
Party original = null;
boolean inserted = StringUtil.clean( party.getIdentity() ) == null;
if( party instanceof Organization && !isUniqueName( party ) )
throw new ApplicationException("名称["+party.getName()+"]已经存在!");
if( party instanceof Person ){
Person p = ((Person) party);
if( p.getCountry() != null
&& StringUtils.isEmpty(p.getCountry().getIdentity()))
p.setCountry(null);
if( p.getSecondaryGeo() != null
&& StringUtils.isEmpty(p.getSecondaryGeo().getIdentity()) )
p.setSecondaryGeo(null);
if( p.getThirdGeo() != null
&& StringUtils.isEmpty(p.getThirdGeo().getIdentity()) )
p.setThirdGeo(null);
if( p.getFourthGeo() != null
&& StringUtils.isEmpty(p.getFourthGeo().getIdentity()) )
p.setFourthGeo(null);
}
if( inserted ){
party.setId( sequenceManager.nextSequenceNumber( party ) );
dao.create( party );
}else{
Party old = dao.read( party );
if( old != null ){
original = old.clone();
ReflectionUtil.assign(party, old);
dao.update( old );
}
}