private OrgPart addOrUpdate(
      ServiceContext context, ScopeDO scopeDO, Long orgId, Map<String, String> exts) {

    OrgDO orgDO = orgDAO.getById(orgId);

    if (!scopeDO.getScopeType().isAllowOrgPart()) {
      throw new ServiceException(
          messageSource.getMessage("validation.scope.orgPartNotAllowed", null, null));
    }

    if (orgDO == null) {
      throw new ServiceException(messageSource.getMessage("validation.org.required", null, null));
    }

    OrgPartDO orgPartDO = null;
    try {
      orgPartDO = orgPartDAO.findOrgPart(orgId, scopeDO.getScopeId());
      if (orgPartDO != null) {
        orgPartDO.setExtAttributes(exts);
      }
    } catch (EmptyResultDataAccessException e) {
      orgPartDO = null;
    }

    if (orgPartDO == null) {
      orgPartDO = new OrgPartDO();
      orgPartDO.setOrg(orgDO);
      orgPartDO.setScope(scopeDO);
      orgPartDO.setExtAttributes(exts);
      orgPartDAO.persist(orgPartDO);
    }

    storeExtFields(
        context,
        orgPartDO,
        orgPartExtDAO,
        EntityTypeCode.ORG_PART,
        orgPartDO.getScope().getScopeId());

    if (configService.isBooleanActive(
        context, scopeDO.getScopeId(), ConfigService.ORG_PART_DESCENDANT_CASCADE_ADD)) {
      orgPartDAO.createOrgPartsForDescendants(scopeDO.getScopeId(), orgDO.getOrgId());
    }

    return getMappingService().map(orgPartDO);
  }