这里,遇到了一个debug:

 @Override
    public void setPrimaryPartyLocation(PartyLocation partyLocation) {
        if (!getPartyLocations().contains(partyLocation)) {
            throw new IllegalArgumentException("Party location passed is not known to this party");
        }
        for (PartyLocation loc : getPartyLocations()) {
            loc.setPrimaryLocation(false);
        }
        partyLocation.setPrimaryLocation(true);
    }

底层调用该方法时,getPartyLocations总是未null,而partyLocation参数又是有值的,所以,导致无法setPrimaryLocation成功。一直想调用entity.setLocations,但是,没办法调用该方法。

经过simon帮忙分析,最后,添加上

party.addLocation(location,false);

因为,该方法内部实现了entity.setLocations方法。

总结原因:entity未setLocations,去getLocations的时候,肯定是拿不到数据的。

要学习simon教我的debug调试功能,找到自己需要完善的代码。希望自己慢慢的掌握debug。

private void updateAndCreateLocations(PersonDto dto, Person entity) throws DuplicateLocationException{
        Set<String> titleSet = new HashSet<>();
        if(Objects.isNull(dto.getPartyLocations())){
            return;
        }

        for(PartyLocationDto partyLocationDto : dto.getPartyLocations()){
            if(StringUtils.isNotBlank(partyLocationDto.getLocationTitle())){
                String trimmedTitle = partyLocationDto.getLocationTitle().trim();
                if(!titleSet.add(trimmedTitle)) {
                    throw new DuplicateLocationException("DuplicateLocation Exception");
                }
            }
        }
        for(PartyLocationDto partyLocationDto : dto.getPartyLocations()){
            if(StringUtils.isBlank(partyLocationDto.getLocationTitle())){
                break;
            }
            Integer locationId = Integer.parseInt(partyLocationDto.getId());
            Party party = (Party)entity;
            PartyLocation location;
            if(locationId<1){
                location = new PartyLocationEntity(party,partyLocationDto.getLocationTitle());
                party.addLocation(location,false);
                if(partyLocationDto.isPrimaryLocation()){
                    entity.setPrimaryPartyLocation(location);
                }
            }else{
                location = crmManager.findPartyLocation(locationId);
                party.addLocation(location,false); //entity has not locations.
                if(partyLocationDto.isPrimaryLocation()){
                    entity.setPrimaryPartyLocation(location);
                }
            }
            populatePartyLocation(location, partyLocationDto);

        }
    }

PartyLocation的Post请求,可以更新已有的,但是不能添加一个新的partyLocation。

因此,这里需要再写一个partyLocation的post请求,这样,就可以实现新增一个新的PartyLocation了。---待完成。

05-19 20:50