Search in sources :

Example 6 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class SettingsController method updateSettings.

/**
 * Security
 */
@RequestMapping(value = "/{type:.*}", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.ACCEPTED)
public <T> Ack updateSettings(@PathVariable String type, @RequestBody JsonNode settingsNode) {
    securityService.checkGlobalFunction(GlobalSettings.class);
    // Gets the settings manager by type
    @SuppressWarnings("unchecked") SettingsManager<T> settingsManager = (SettingsManager<T>) settingsManagers.stream().filter(candidate -> StringUtils.equals(type, getSettingsManagerName(candidate))).findFirst().orElseThrow(() -> new SettingsManagerNotFoundException(type));
    // Parsing
    T settings;
    try {
        settings = objectMapper.treeToValue(settingsNode, settingsManager.getSettingsClass());
    } catch (JsonProcessingException e) {
        throw new SettingsValidationException(e);
    }
    // Saves the settings
    settingsManager.saveSettings(settings);
    // OK
    return Ack.OK;
}
Also used : Ack(net.nemerosa.ontrack.model.Ack) ObjectMapperFactory(net.nemerosa.ontrack.json.ObjectMapperFactory) AbstractResourceController(net.nemerosa.ontrack.ui.controller.AbstractResourceController) DescribedForm(net.nemerosa.ontrack.model.form.DescribedForm) MvcUriComponentsBuilder.on(org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.on) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GlobalSettings(net.nemerosa.ontrack.model.security.GlobalSettings) Autowired(org.springframework.beans.factory.annotation.Autowired) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SettingsManagerNotFoundException(net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException) Resource(net.nemerosa.ontrack.ui.resource.Resource) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) HttpStatus(org.springframework.http.HttpStatus) SecurityService(net.nemerosa.ontrack.model.security.SecurityService) List(java.util.List) Resources(net.nemerosa.ontrack.ui.resource.Resources) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) SettingsValidationException(net.nemerosa.ontrack.model.settings.SettingsValidationException) JsonNode(com.fasterxml.jackson.databind.JsonNode) SettingsManager(net.nemerosa.ontrack.model.settings.SettingsManager) SettingsManagerNotFoundException(net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException) SettingsManager(net.nemerosa.ontrack.model.settings.SettingsManager) SettingsValidationException(net.nemerosa.ontrack.model.settings.SettingsValidationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 7 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterServiceIT method saveFilter_predefined.

@Test
public void saveFilter_predefined() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a predefined filter for this account
    Ack filterCreated = asAccount(account).call(() -> buildFilterService.saveFilter(branch.getId(), false, "MyFilter", PromotionLevelBuildFilterProvider.class.getName(), JsonUtils.object().end()));
    assertFalse("A predefined filter cannot be saved", filterCreated.isSuccess());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Example 8 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterServiceIT method copyToBranch.

@Test
public void copyToBranch() throws Exception {
    // Source branch
    Branch sourceBranch = doCreateBranch();
    // Target branch
    Branch targetBranch = doCreateBranch();
    // Account for the tests
    Account account = doCreateAccount();
    // Creates a filter for this account
    Ack filterCreated = asAccount(account).call(() -> buildFilterService.saveFilter(sourceBranch.getId(), false, "MyFilter", StandardBuildFilterProvider.class.getName(), JsonUtils.object().with("count", 1).end()));
    assertTrue(filterCreated.isSuccess());
    // Checks the filter is created
    Collection<BuildFilterResource<?>> filters = asAccount(account).with(sourceBranch.projectId(), ProjectView.class).call(() -> buildFilterService.getBuildFilters(sourceBranch.getId()));
    assertEquals(1, filters.size());
    BuildFilterResource<?> filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
    // Copy of the branch
    asUser().with(sourceBranch.projectId(), ProjectView.class).with(targetBranch.projectId(), BranchEdit.class).call(() -> copyService.copy(targetBranch, new BranchCopyRequest(sourceBranch.getId(), Collections.emptyList())));
    // Gets the filter on the new branch
    filters = asAccount(account).withView(targetBranch).call(() -> buildFilterService.getBuildFilters(targetBranch.getId()));
    assertEquals(1, filters.size());
    filter = filters.iterator().next();
    assertEquals("MyFilter", filter.getName());
    assertEquals(StandardBuildFilterProvider.class.getName(), filter.getType());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) BranchCopyRequest(net.nemerosa.ontrack.model.structure.BranchCopyRequest) Ack(net.nemerosa.ontrack.model.Ack) ProjectView(net.nemerosa.ontrack.model.security.ProjectView) BranchEdit(net.nemerosa.ontrack.model.security.BranchEdit) Test(org.junit.Test)

Example 9 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class BuildFilterServiceIT method delete_unshared_filter.

@Test
public void delete_unshared_filter() throws Exception {
    // Branch
    Branch branch = doCreateBranch();
    // Account for the tests
    Account account = 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());
    // The filter is present
    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());
    // Deletes the filter
    asAccount(account).call(() -> buildFilterService.deleteFilter(branch.getId(), "MyFilter"));
    // The filter is no longer there
    filters = asAccount(account).withView(branch).call(() -> buildFilterService.getBuildFilters(branch.getId()));
    assertEquals(0, filters.size());
}
Also used : Account(net.nemerosa.ontrack.model.security.Account) Branch(net.nemerosa.ontrack.model.structure.Branch) BuildFilterResource(net.nemerosa.ontrack.model.buildfilter.BuildFilterResource) Ack(net.nemerosa.ontrack.model.Ack) Test(org.junit.Test)

Example 10 with Ack

use of net.nemerosa.ontrack.model.Ack in project ontrack by nemerosa.

the class PropertyServiceImpl method deleteProperty.

private <T> Ack deleteProperty(ProjectEntity entity, PropertyType<T> propertyType) {
    // Checks for edition
    if (!propertyType.canEdit(entity, securityService)) {
        throw new AccessDeniedException("Property is not opened for viewing.");
    }
    // Gets the existing value
    T value = getPropertyValue(propertyType, entity);
    // If existing, deletes it
    if (value != null) {
        Ack ack = propertyRepository.deleteProperty(propertyType.getClass().getName(), entity.getProjectEntityType(), entity.getId());
        if (ack.isSuccess()) {
            // Property deletion event
            eventPostService.post(eventFactory.propertyDelete(entity, propertyType));
            // Listener
            propertyType.onPropertyDeleted(entity, value);
        }
        // OK
        return ack;
    } else {
        return Ack.NOK;
    }
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) Ack(net.nemerosa.ontrack.model.Ack)

Aggregations

Ack (net.nemerosa.ontrack.model.Ack)10 Test (org.junit.Test)8 Account (net.nemerosa.ontrack.model.security.Account)5 Branch (net.nemerosa.ontrack.model.structure.Branch)5 BuildFilterResource (net.nemerosa.ontrack.model.buildfilter.BuildFilterResource)4 ProjectView (net.nemerosa.ontrack.model.security.ProjectView)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 ObjectMapperFactory (net.nemerosa.ontrack.json.ObjectMapperFactory)1 DescribedForm (net.nemerosa.ontrack.model.form.DescribedForm)1 BranchEdit (net.nemerosa.ontrack.model.security.BranchEdit)1 BranchFilterMgt (net.nemerosa.ontrack.model.security.BranchFilterMgt)1 GlobalSettings (net.nemerosa.ontrack.model.security.GlobalSettings)1 SecurityService (net.nemerosa.ontrack.model.security.SecurityService)1 SettingsManager (net.nemerosa.ontrack.model.settings.SettingsManager)1 SettingsManagerNotFoundException (net.nemerosa.ontrack.model.settings.SettingsManagerNotFoundException)1