Search in sources :

Example 1 with ProjectNotFoundException

use of net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException in project ontrack by nemerosa.

the class GQLRootQueryBuilds method buildFetcher.

private DataFetcher buildFetcher() {
    return environment -> {
        Integer id = environment.getArgument("id");
        Optional<String> oProject = GraphqlUtils.getStringArgument(environment, PROJECT_ARGUMENT);
        Optional<String> oBranch = GraphqlUtils.getStringArgument(environment, BRANCH_ARGUMENT);
        Object branchFilter = environment.getArgument(BUILD_BRANCH_FILTER_ARGUMENT);
        Object projectFilter = environment.getArgument(BUILD_PROJECT_FILTER_ARGUMENT);
        // Per ID
        if (id != null) {
            checkArgList(environment, "id");
            return Collections.singletonList(structureService.getBuild(ID.of(id)));
        } else // Per project
        if (oProject.isPresent()) {
            // ... and branch
            if (oBranch.isPresent()) {
                // Gets the branch
                Branch branch = structureService.findBranchByName(oProject.get(), oBranch.get()).orElseThrow(() -> new BranchNotFoundException(oProject.get(), oBranch.get()));
                // Configurable branch filter
                BuildFilterProviderData<?> filter = inputBuildStandardFilter.convert(branchFilter);
                // Runs the filter
                return filter.filterBranchBuilds(branch);
            } else // Project only
            {
                // Gets the project
                Project project = structureService.findProjectByName(oProject.get()).orElseThrow(() -> new ProjectNotFoundException(oProject.get()));
                // Build search form as argument
                BuildSearchForm form = inputBuildSearchForm.convert(projectFilter);
                return structureService.buildSearch(project.getId(), form);
            }
        } else // Branch filter only - not accepted
        if (branchFilter != null) {
            throw new IllegalStateException(String.format("%s must be used together with %s", BUILD_BRANCH_FILTER_ARGUMENT, BRANCH_ARGUMENT));
        } else // Project filter only - not accepted
        if (projectFilter != null) {
            throw new IllegalStateException(String.format("%s must be used together with %s", BUILD_PROJECT_FILTER_ARGUMENT, PROJECT_ARGUMENT));
        } else // None
        {
            return Collections.emptyList();
        }
    };
}
Also used : GraphQLString(graphql.Scalars.GraphQLString) ProjectNotFoundException(net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) BuildFilterProviderData(net.nemerosa.ontrack.model.buildfilter.BuildFilterProviderData) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphQLArgument.newArgument(graphql.schema.GraphQLArgument.newArgument) GraphqlUtils.stdList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.stdList) GraphQLFieldDefinition.newFieldDefinition(graphql.schema.GraphQLFieldDefinition.newFieldDefinition) GraphqlUtils.checkArgList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.checkArgList) Component(org.springframework.stereotype.Component) net.nemerosa.ontrack.model.structure(net.nemerosa.ontrack.model.structure) DataFetcher(graphql.schema.DataFetcher) Optional(java.util.Optional) GraphQLInt(graphql.Scalars.GraphQLInt) Collections(java.util.Collections) GraphqlUtils(net.nemerosa.ontrack.graphql.support.GraphqlUtils) BranchNotFoundException(net.nemerosa.ontrack.model.exceptions.BranchNotFoundException) ProjectNotFoundException(net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException) Optional(java.util.Optional) BranchNotFoundException(net.nemerosa.ontrack.model.exceptions.BranchNotFoundException)

Example 2 with ProjectNotFoundException

use of net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException in project ontrack by nemerosa.

the class GitHubEngineConfigurationMigrationActionIT method migration.

/**
 * Test of the migration.
 * <p>
 * An old GitHub configuration is created with name "OntrackTest"
 * (see {@link TestGitHubEngineConfigurationMigrationPreparationAction})
 * <p>
 * A project P is created, using this configuration.
 * <p>
 * The test must check that the old configuration has been migrated and that the project
 * is now using a configuration including the repository, the indexation interval.
 */
@Test
public void migration() throws Exception {
    // Gets the project
    Project project = asUser().with(ProjectList.class).call(() -> structureService.findProjectByName("GitHubEngineConfigurationMigrationAction")).orElseThrow(() -> new ProjectNotFoundException("GitHubEngineConfigurationMigrationAction"));
    // Gets the migrated configuration
    GitHubEngineConfiguration gitHubEngineConfiguration = configurationRepository.find(GitHubEngineConfiguration.class, "OntrackTest").orElseThrow(() -> new RuntimeException("Cannot find \"OntrackTest\" configuration"));
    assertEquals("OntrackTest", gitHubEngineConfiguration.getName());
    assertEquals("https://github.com", gitHubEngineConfiguration.getUrl());
    assertEquals("user", gitHubEngineConfiguration.getUser());
    assertEquals("password", encryptionService.decrypt(gitHubEngineConfiguration.getPassword()));
    assertEquals("token", gitHubEngineConfiguration.getOauth2Token());
    // Gets the GitHub project property
    GitHubProjectConfigurationProperty configurationProperty = asUser().withView(project).call(() -> propertyService.getProperty(project, GitHubProjectConfigurationPropertyType.class).option()).orElseThrow(() -> new RuntimeException("Missing GitHub property on project"));
    assertEquals("OntrackTest", configurationProperty.getConfiguration().getName());
    assertEquals("nemerosa/ontrack", configurationProperty.getRepository());
    assertEquals(30, configurationProperty.getIndexationInterval());
}
Also used : Project(net.nemerosa.ontrack.model.structure.Project) ProjectNotFoundException(net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException) GitHubProjectConfigurationProperty(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationProperty) GitHubProjectConfigurationPropertyType(net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationPropertyType) GitHubEngineConfiguration(net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration) Test(org.junit.Test)

Aggregations

ProjectNotFoundException (net.nemerosa.ontrack.model.exceptions.ProjectNotFoundException)2 GraphQLInt (graphql.Scalars.GraphQLInt)1 GraphQLString (graphql.Scalars.GraphQLString)1 DataFetcher (graphql.schema.DataFetcher)1 GraphQLArgument.newArgument (graphql.schema.GraphQLArgument.newArgument)1 GraphQLFieldDefinition (graphql.schema.GraphQLFieldDefinition)1 GraphQLFieldDefinition.newFieldDefinition (graphql.schema.GraphQLFieldDefinition.newFieldDefinition)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 GitHubEngineConfiguration (net.nemerosa.ontrack.extension.github.model.GitHubEngineConfiguration)1 GitHubProjectConfigurationProperty (net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationProperty)1 GitHubProjectConfigurationPropertyType (net.nemerosa.ontrack.extension.github.property.GitHubProjectConfigurationPropertyType)1 GraphqlUtils (net.nemerosa.ontrack.graphql.support.GraphqlUtils)1 GraphqlUtils.checkArgList (net.nemerosa.ontrack.graphql.support.GraphqlUtils.checkArgList)1 GraphqlUtils.stdList (net.nemerosa.ontrack.graphql.support.GraphqlUtils.stdList)1 BuildFilterProviderData (net.nemerosa.ontrack.model.buildfilter.BuildFilterProviderData)1 BranchNotFoundException (net.nemerosa.ontrack.model.exceptions.BranchNotFoundException)1 net.nemerosa.ontrack.model.structure (net.nemerosa.ontrack.model.structure)1 Project (net.nemerosa.ontrack.model.structure.Project)1 Test (org.junit.Test)1