public void createNewCodeDefinition(DbSession dbSession, String projectUuid, String mainBranchUuid,
    String defaultBranchName, String newCodeDefinitionType, @Nullable String newCodeDefinitionValue) {

    boolean isCommunityEdition = editionProvider.get().filter(EditionProvider.Edition.COMMUNITY::equals).isPresent();
    NewCodePeriodType newCodePeriodType = parseNewCodeDefinitionType(newCodeDefinitionType);

    NewCodePeriodDto dto = new NewCodePeriodDto();
    dto.setType(newCodePeriodType);
    dto.setProjectUuid(projectUuid);

    if (isCommunityEdition) {
      dto.setBranchUuid(mainBranchUuid);
    }

    getNewCodeDefinitionValueProjectCreation(newCodePeriodType, newCodeDefinitionValue, defaultBranchName).ifPresent(dto::setValue);

    if (!CaycUtils.isNewCodePeriodCompliant(dto.getType(), dto.getValue())) {
      throw new IllegalArgumentException("Failed to set the New Code Definition. The given value is not compatible with the Clean as You Code methodology. "
        + "Please refer to the documentation for compliant options.");
    }

    dbClient.newCodePeriodDao().insert(dbSession, dto);
  }
@Test
  public void createNewCodeDefinition_throw_IAE_if_type_is_not_allowed() {
    assertThatThrownBy(() -> newCodeDefinitionResolver.createNewCodeDefinition(dbSession, DEFAULT_PROJECT_ID, MAIN_BRANCH_UUID, MAIN_BRANCH, SPECIFIC_ANALYSIS.name(), null))
      .isInstanceOf(IllegalArgumentException.class)
      .hasMessageContaining("Invalid type 'SPECIFIC_ANALYSIS'. `newCodeDefinitionType` can only be set with types: [PREVIOUS_VERSION, NUMBER_OF_DAYS, REFERENCE_BRANCH]");
  }