Search in sources :

Example 1 with ID

use of net.nemerosa.ontrack.model.structure.ID in project ontrack by nemerosa.

the class PropertyJdbcRepository method toProperty.

private TProperty toProperty(ResultSet rs) throws SQLException {
    int id = rs.getInt("id");
    String searchKey = rs.getString("searchKey");
    String typeName = rs.getString("type");
    // Detects the entity
    ProjectEntityType entityType = null;
    ID entityId = null;
    for (ProjectEntityType candidate : ProjectEntityType.values()) {
        Integer candidateId = rs.getInt(candidate.name());
        if (!rs.wasNull()) {
            entityType = candidate;
            entityId = ID.of(candidateId);
        }
    }
    // Sanity check
    if (entityType == null || !ID.isDefined(entityId)) {
        throw new IllegalStateException(String.format("Could not find any entity for property %s with key %s (id = %d)", typeName, searchKey, id));
    }
    // OK
    return new TProperty(typeName, entityType, entityId, searchKey, readJson(rs, "json"));
}
Also used : ProjectEntityType(net.nemerosa.ontrack.model.structure.ProjectEntityType) ID(net.nemerosa.ontrack.model.structure.ID)

Example 2 with ID

use of net.nemerosa.ontrack.model.structure.ID in project ontrack by nemerosa.

the class BuildFilterServiceImpl method getBuildFilters.

@Override
public Collection<BuildFilterResource<?>> getBuildFilters(ID branchId) {
    Branch branch = structureService.getBranch(branchId);
    // Are we logged?
    Account account = securityService.getCurrentAccount();
    if (account != null) {
        // Gets the filters for this account and the branch
        return buildFilterRepository.findForBranch(OptionalInt.of(account.id()), branchId.getValue()).stream().map(t -> loadBuildFilterResource(branch, t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    } else // Not logged, no filter
    {
        // Gets the filters for the branch
        return buildFilterRepository.findForBranch(OptionalInt.empty(), branchId.get()).stream().map(t -> loadBuildFilterResource(branch, t)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
    }
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) BuildFilterNotFoundException(net.nemerosa.ontrack.model.exceptions.BuildFilterNotFoundException) BranchFilterMgt(net.nemerosa.ontrack.model.security.BranchFilterMgt) StandardBuildFilterData(net.nemerosa.ontrack.model.structure.StandardBuildFilterData) StructureService(net.nemerosa.ontrack.model.structure.StructureService) BuildFilterRepository(net.nemerosa.ontrack.repository.BuildFilterRepository) Collection(java.util.Collection) Account(net.nemerosa.ontrack.model.security.Account) Autowired(org.springframework.beans.factory.annotation.Autowired) TBuildFilter(net.nemerosa.ontrack.repository.TBuildFilter) BuildFilterNotLoggedException(net.nemerosa.ontrack.model.exceptions.BuildFilterNotLoggedException) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) Service(org.springframework.stereotype.Service) LocalDate(java.time.LocalDate) Map(java.util.Map) Optional(java.util.Optional) JsonNode(com.fasterxml.jackson.databind.JsonNode) net.nemerosa.ontrack.model.buildfilter(net.nemerosa.ontrack.model.buildfilter) ID(net.nemerosa.ontrack.model.structure.ID) Branch(net.nemerosa.ontrack.model.structure.Branch) Transactional(org.springframework.transaction.annotation.Transactional) Account(net.nemerosa.ontrack.model.security.Account) Optional(java.util.Optional) Branch(net.nemerosa.ontrack.model.structure.Branch)

Example 3 with ID

use of net.nemerosa.ontrack.model.structure.ID in project ontrack by nemerosa.

the class GQLRootQueryBranches method branchFetcher.

private DataFetcher branchFetcher() {
    return environment -> {
        Integer id = environment.getArgument("id");
        String projectName = environment.getArgument("project");
        String name = environment.getArgument("name");
        Object propertyFilterArg = environment.getArgument(GQLInputPropertyFilter.ARGUMENT_NAME);
        // Per ID
        if (id != null) {
            checkArgList(environment, "id");
            return Collections.singletonList(structureService.getBranch(ID.of(id)));
        } else // Per project name, name or property filter
        if (isNotBlank(projectName) || isNotBlank(name) || propertyFilterArg != null) {
            // Project filter
            Predicate<Project> projectFilter = p -> true;
            if (isNotBlank(projectName)) {
                projectFilter = projectFilter.and(project -> StringUtils.equals(projectName, project.getName()));
            }
            // Branch filter
            Predicate<Branch> branchFilter = b -> true;
            if (isNotBlank(name)) {
                Pattern pattern = Pattern.compile(name);
                branchFilter = branchFilter.and(b -> pattern.matcher(b.getName()).matches());
            }
            // Property filter?
            if (propertyFilterArg != null) {
                PropertyFilter filterObject = propertyFilter.convert(propertyFilterArg);
                if (filterObject != null && StringUtils.isNotBlank(filterObject.getType())) {
                    branchFilter = branchFilter.and(propertyFilter.getFilter(filterObject));
                }
            }
            // Gets the list of authorised projects
            return structureService.getProjectList().stream().filter(projectFilter).flatMap(project -> structureService.getBranchesForProject(project.getId()).stream()).filter(branchFilter).collect(Collectors.toList());
        } else // No result to return
        {
            return Collections.emptyList();
        }
    };
}
Also used : GraphQLString(graphql.Scalars.GraphQLString) StructureService(net.nemerosa.ontrack.model.structure.StructureService) Predicate(java.util.function.Predicate) GraphQLFieldDefinition(graphql.schema.GraphQLFieldDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) GraphQLArgument.newArgument(graphql.schema.GraphQLArgument.newArgument) GraphqlUtils.stdList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.stdList) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) GraphQLFieldDefinition.newFieldDefinition(graphql.schema.GraphQLFieldDefinition.newFieldDefinition) GraphqlUtils.checkArgList(net.nemerosa.ontrack.graphql.support.GraphqlUtils.checkArgList) Component(org.springframework.stereotype.Component) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) DataFetcher(graphql.schema.DataFetcher) GraphQLInt(graphql.Scalars.GraphQLInt) Pattern(java.util.regex.Pattern) Project(net.nemerosa.ontrack.model.structure.Project) Collections(java.util.Collections) ID(net.nemerosa.ontrack.model.structure.ID) Branch(net.nemerosa.ontrack.model.structure.Branch) Project(net.nemerosa.ontrack.model.structure.Project) Pattern(java.util.regex.Pattern) Branch(net.nemerosa.ontrack.model.structure.Branch) GraphQLString(graphql.Scalars.GraphQLString)

Example 4 with ID

use of net.nemerosa.ontrack.model.structure.ID in project ontrack by nemerosa.

the class PredefinedPromotionLevelServiceImpl method newPredefinedPromotionLevel.

@Override
public PredefinedPromotionLevel newPredefinedPromotionLevel(PredefinedPromotionLevel stamp) {
    securityService.checkGlobalFunction(GlobalSettings.class);
    ID id = predefinedPromotionLevelRepository.newPredefinedPromotionLevel(stamp);
    return getPredefinedPromotionLevel(id);
}
Also used : ID(net.nemerosa.ontrack.model.structure.ID)

Example 5 with ID

use of net.nemerosa.ontrack.model.structure.ID in project ontrack by nemerosa.

the class PredefinedValidationStampServiceImpl method newPredefinedValidationStamp.

@Override
public PredefinedValidationStamp newPredefinedValidationStamp(PredefinedValidationStamp stamp) {
    securityService.checkGlobalFunction(GlobalSettings.class);
    ID id = predefinedValidationStampRepository.newPredefinedValidationStamp(stamp);
    return getPredefinedValidationStamp(id);
}
Also used : ID(net.nemerosa.ontrack.model.structure.ID)

Aggregations

ID (net.nemerosa.ontrack.model.structure.ID)7 Collectors (java.util.stream.Collectors)3 StructureService (net.nemerosa.ontrack.model.structure.StructureService)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Optional (java.util.Optional)2 Branch (net.nemerosa.ontrack.model.structure.Branch)2 Project (net.nemerosa.ontrack.model.structure.Project)2 ProjectEntityType (net.nemerosa.ontrack.model.structure.ProjectEntityType)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 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 LocalDate (java.time.LocalDate)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1