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"));
}
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());
}
}
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();
}
};
}
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);
}
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);
}
Aggregations