use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method audit.
@Test
public void audit() throws JsonProcessingException {
// Entity
Branch branch = do_create_branch();
// Adds some data
String name = uid("T");
EntityDataStoreRecord record = store.add(branch, CATEGORY, name, Signature.of(TEST_USER), null, new IntNode(15));
// Gets the audit
List<EntityDataStoreRecordAudit> audit = store.getRecordAudit(record.getId());
assertEquals(1, audit.size());
assertEquals(EntityDataStoreRecordAuditType.CREATED, audit.get(0).getType());
assertEquals(TEST_USER, audit.get(0).getSignature().getUser().getName());
// Updates the same name
store.replaceOrAdd(branch, CATEGORY, name, Signature.of("other"), null, new IntNode(16));
// Checks
audit = store.getRecordAudit(record.getId());
assertEquals(2, audit.size());
assertEquals(EntityDataStoreRecordAuditType.UPDATED, audit.get(0).getType());
assertEquals("other", audit.get(0).getSignature().getUser().getName());
assertEquals(EntityDataStoreRecordAuditType.CREATED, audit.get(1).getType());
assertEquals(TEST_USER, audit.get(1).getSignature().getUser().getName());
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class EntityDataStoreIT method getByFilter.
@Test
public void getByFilter() {
// Entities
Branch branch1 = do_create_branch();
Branch branch2 = do_create_branch();
// Adds some data
store.deleteAll();
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 1);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 2);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 3);
store.addObject(branch1, "C1", "N1", Signature.of(TEST_USER), null, 4);
store.addObject(branch1, "C1", "N2", Signature.of(TEST_USER), null, 5);
store.addObject(branch1, "C2", "N3", Signature.of(TEST_USER), null, 6);
store.addObject(branch2, "C1", "N1", Signature.of(TEST_USER), null, 7);
store.addObject(branch2, "C1", "N2", Signature.of(TEST_USER), null, 8);
store.addObject(branch2, "C2", "N3", Signature.of(TEST_USER), null, 9);
// Checks
assertEquals(6, store.getByFilter(new EntityDataStoreFilter(branch1)).size());
assertEquals(5, store.getByFilter(new EntityDataStoreFilter(branch1).withCategory("C1")).size());
assertEquals(4, store.getByFilter(new EntityDataStoreFilter(branch1).withCategory("C1").withName("N1")).size());
}
use of net.nemerosa.ontrack.model.structure.Branch 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.Branch in project ontrack by nemerosa.
the class BuildFilterServiceImpl method saveFilter.
@Override
public Ack saveFilter(ID branchId, boolean shared, String name, String type, JsonNode parameters) {
// Checks the account
if (shared) {
Account account = securityService.getCurrentAccount();
// Gets the branch
Branch branch = structureService.getBranch(branchId);
// Checks access rights
securityService.checkProjectFunction(branch, BranchFilterMgt.class);
// Deletes any previous filter
int currentAccountId = account.id();
buildFilterRepository.findByBranchAndName(currentAccountId, branchId.get(), name).ifPresent((filter) -> buildFilterRepository.delete(currentAccountId, branchId.get(), name, true));
// No account to be used
return doSaveFilter(OptionalInt.empty(), branchId, name, type, parameters);
} else {
Account account = securityService.getCurrentAccount();
if (account == null) {
return Ack.NOK;
} else {
// Saves it for this account
return doSaveFilter(OptionalInt.of(account.id()), branchId, name, type, parameters);
}
}
}
use of net.nemerosa.ontrack.model.structure.Branch in project ontrack by nemerosa.
the class BuildFilterServiceIT method delete_shared_filter.
@Test
public void delete_shared_filter() throws Exception {
// Branch
Branch branch = doCreateBranch();
// Account for the tests
Account account = doCreateAccount();
// Creates a shared filter for this account
Ack ack = asAccount(account).with(branch, BranchFilterMgt.class).call(() -> buildFilterService.saveFilter(branch.getId(), // Shared
true, "MyFilter", NamedBuildFilterProvider.class.getName(), objectMapper.valueToTree(NamedBuildFilterData.of("1"))));
assertTrue("Account filter saved", ack.isSuccess());
// The filter is present for this account
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());
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());
// Deletes the filter
asAccount(account).call(() -> buildFilterService.deleteFilter(branch.getId(), "MyFilter"));
// The filter is no longer there for the account
filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
assertEquals(0, filters.size());
// ... not for unlogged users
filters = asUser().withId(10).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
assertEquals("Account filter not available for everybody else", 0, filters.size());
}
Aggregations