use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class BuildFilterServiceIT method saveFilter_shared_after_account_one.
/**
* Checks that sharing a saved filter overrides the account specific one.
*/
@Test
public void saveFilter_shared_after_account_one() throws Exception {
// Branch
Branch branch = doCreateBranch();
// Account for the tests
Account account = doCreateAccount();
Account otherAccount = doCreateAccount();
// Creates a filter for this account
Ack ack = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
assertTrue("Account filter saved", ack.isSuccess());
// Makes sure we find this filter back when logged
Collection<BuildFilterResource<?>> filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
assertEquals(1, filters.size());
BuildFilterResource<?> filter = filters.iterator().next();
assertEquals("MyFilter", filter.getName());
assertFalse(filter.isShared());
// ... but it is not available for anybody else
assertTrue("Account filter not available for everybody else", asAccount(otherAccount).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()).isEmpty()));
// Now, shares a filter with the same name
ack = asAccount(account).with(branch.projectId(), ProjectView.class).with(branch.projectId(), BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Sharing
true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
assertTrue("Account filter shared", ack.isSuccess());
// Makes sure we find this filter back when logged
filters = asAccount(account).call(() -> buildFilterService.getBuildFilters(branch.getId()));
assertEquals(1, filters.size());
filter = filters.iterator().next();
assertEquals("MyFilter", filter.getName());
assertTrue(filter.isShared());
// ... and that it is available also for not logged users
filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
assertEquals("Account filter available for everybody else", 1, filters.size());
filter = filters.iterator().next();
assertEquals("MyFilter", filter.getName());
assertTrue(filter.isShared());
}
use of net.nemerosa.ontrack.model.structure.Branch 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.Branch in project ontrack by nemerosa.
the class ResourceHttpMessageConverterIT method branch.
@Test
public void branch() throws IOException {
// Objects
Project p = Project.of(new NameDescription("P", "Projet créé")).withId(ID.of(1)).withSignature(SIGNATURE);
Branch b = Branch.of(p, new NameDescription("B", "Branch")).withId(ID.of(1)).withSignature(SIGNATURE);
// Message
HttpOutputMessage message = mock(HttpOutputMessage.class);
ByteArrayOutputStream output = new ByteArrayOutputStream();
when(message.getBody()).thenReturn(output);
// Serialization
converter.writeInternal(b, message);
// Content
String json = new String(output.toByteArray(), "UTF-8");
// Parsing
JsonNode node = ObjectMapperFactory.create().readTree(json);
// Check
TestUtils.assertJsonEquals(object().with("id", 1).with("name", "B").with("description", "Branch").with("disabled", false).with("type", "CLASSIC").with("project", object().with("id", 1).with("name", "P").with("description", "Projet créé").with("disabled", false).with("signature", SIGNATURE_OBJECT).with("_self", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getProject:1").with("_branches", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchListForProject:1").with("_branchStatusViews", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getBranchStatusViews:1").with("_buildSearch", "urn:test:net.nemerosa.ontrack.boot.ui.BuildController#buildSearchForm:1").with("_buildDiffActions", "urn:test:net.nemerosa.ontrack.boot.ui.BuildController#buildDiffActions:1").with("_properties", "urn:test:net.nemerosa.ontrack.boot.ui.PropertyController#getProperties:PROJECT,1").with("_extra", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getInformation:PROJECT,1").with("_actions", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getActions:PROJECT,1").with("_decorations", "urn:test:net.nemerosa.ontrack.boot.ui.DecorationsController#getDecorations:PROJECT,1").with("_events", "urn:test:net.nemerosa.ontrack.boot.ui.EventController#getEvents:PROJECT,1,0,10").with("_page", "urn:test:#:entity:PROJECT:1").end()).with("signature", SIGNATURE_OBJECT).with("_self", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranch:1").with("_project", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectController#getProject:1").with("_promotionLevels", "urn:test:net.nemerosa.ontrack.boot.ui.PromotionLevelController#getPromotionLevelListForBranch:1").with("_validationStamps", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampController#getValidationStampListForBranch:1").with("_validationStampViews", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampController#getValidationStampViewListForBranch:1").with("_allValidationStampFilters", "urn:test:net.nemerosa.ontrack.boot.ui.ValidationStampFilterController#getAllBranchValidationStampFilters:1").with("_branches", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchListForProject:1").with("_properties", "urn:test:net.nemerosa.ontrack.boot.ui.PropertyController#getProperties:BRANCH,1").with("_actions", "urn:test:net.nemerosa.ontrack.boot.ui.ProjectEntityExtensionController#getActions:BRANCH,1").with("_status", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#getBranchStatusView:1").with("_view", "urn:test:net.nemerosa.ontrack.boot.ui.BranchController#buildView:1").with("_decorations", "urn:test:net.nemerosa.ontrack.boot.ui.DecorationsController#getDecorations:BRANCH,1").with("_buildFilterResources", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#buildFilters:1").with("_buildFilterForms", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#buildFilterForms:1").with("_buildFilterSave", "urn:test:net.nemerosa.ontrack.boot.ui.BuildFilterController#createFilter:1,").with("_events", "urn:test:net.nemerosa.ontrack.boot.ui.EventController#getEvents:BRANCH,1,0,10").with("_page", "urn:test:#:entity:BRANCH:1").end(), node);
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class ResourceHttpMessageConverterIT method branch_enable_granted_for_automation.
@Test
public void branch_enable_granted_for_automation() throws Exception {
// Objects
Project p = Project.of(new NameDescription("P", "Projet créé")).withId(ID.of(1)).withSignature(SIGNATURE);
Branch b = Branch.of(p, new NameDescription("B", "Branch")).withId(ID.of(1)).withDisabled(true).withSignature(SIGNATURE);
// Message
HttpOutputMessage message = mock(HttpOutputMessage.class);
ByteArrayOutputStream output = new ByteArrayOutputStream();
when(message.getBody()).thenReturn(output);
// Serialization
asGlobalRole("AUTOMATION").execute(() -> {
try {
converter.writeInternal(b, message);
} catch (IOException e) {
throw new RuntimeException(e);
}
});
// Content
String json = new String(output.toByteArray(), "UTF-8");
// Parsing
JsonNode node = ObjectMapperFactory.create().readTree(json);
// Enable link
assertEquals("urn:test:net.nemerosa.ontrack.boot.ui.BranchController#enableBranch:1", node.path("_enable").asText());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class ResourcesTest method resource_collection_with_filtering.
@Test
public void resource_collection_with_filtering() throws JsonProcessingException {
Project project = Project.of(new NameDescription("PRJ", "Project"));
List<Branch> branches = Arrays.asList(Branch.of(project, new NameDescription("B1", "Branch 1")).withSignature(SIGNATURE), Branch.of(project, new NameDescription("B2", "Branch 2")).withSignature(SIGNATURE));
Resources<Branch> resourceCollection = Resources.of(branches, URI.create("urn:branch"));
assertResourceJson(mapper, object().with("_self", "urn:branch").with("resources", array().with(object().with("id", 0).with("name", "B1").with("description", "Branch 1").with("disabled", false).with("type", "CLASSIC").with("signature", SIGNATURE_OBJECT).end()).with(object().with("id", 0).with("name", "B2").with("description", "Branch 2").with("disabled", false).with("type", "CLASSIC").with("signature", SIGNATURE_OBJECT).end()).end()).end(), resourceCollection, Resources.class);
}
Aggregations