Search in sources :

Example 1 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class ContentPackService method checkConstraintsV1.

private Set<ConstraintCheckResult> checkConstraintsV1(ContentPackV1 contentPackV1) {
    Set<Constraint> requiredConstraints = contentPackV1.constraints();
    final Set<ConstraintCheckResult> fulfilledConstraints = new HashSet<>();
    for (ConstraintChecker constraintChecker : constraintCheckers) {
        fulfilledConstraints.addAll(constraintChecker.checkConstraints(requiredConstraints));
    }
    return fulfilledConstraints;
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) ConstraintChecker(org.graylog2.contentpacks.constraints.ConstraintChecker) HashSet(java.util.HashSet)

Example 2 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class PluginVersionConstraintChecker method checkConstraints.

@Override
public Set<ConstraintCheckResult> checkConstraints(Collection<Constraint> requestedConstraints) {
    final ImmutableSet.Builder<ConstraintCheckResult> fulfilledConstraints = ImmutableSet.builder();
    for (Constraint constraint : requestedConstraints) {
        if (constraint instanceof PluginVersionConstraint) {
            final PluginVersionConstraint versionConstraint = (PluginVersionConstraint) constraint;
            final Requirement requiredVersion = versionConstraint.version();
            boolean result = false;
            for (Semver pluginVersion : pluginVersions) {
                if (requiredVersion.isSatisfiedBy(pluginVersion)) {
                    result = true;
                }
            }
            ConstraintCheckResult constraintCheckResult = ConstraintCheckResult.create(versionConstraint, result);
            fulfilledConstraints.add(constraintCheckResult);
        }
    }
    return fulfilledConstraints.build();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) Requirement(com.vdurmont.semver4j.Requirement) ImmutableSet(com.google.common.collect.ImmutableSet) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Semver(com.vdurmont.semver4j.Semver)

Example 3 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class ContentPackResource method getContentPackRevisions.

@GET
@Path("{contentPackId}/{revision}")
@Timed
@ApiOperation(value = "Get a revision of a content pack")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Error loading content packs") })
@JsonView(ContentPackView.HttpView.class)
public ContentPackResponse getContentPackRevisions(@ApiParam(name = "contentPackId", value = "Content pack ID", required = true) @PathParam("contentPackId") ModelId id, @ApiParam(name = "revision", value = "Content pack revision", required = true) @PathParam("revision") int revision) {
    checkPermission(RestPermissions.CONTENT_PACK_READ);
    ContentPack contentPack = contentPackPersistenceService.findByIdAndRevision(id, revision).orElseThrow(() -> new NotFoundException("Content pack " + id + " with revision " + revision + " not found!"));
    Set<ConstraintCheckResult> constraints = contentPackService.checkConstraints(contentPack);
    return ContentPackResponse.create(contentPack, constraints);
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) ContentPack(org.graylog2.contentpacks.model.ContentPack) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) JsonView(com.fasterxml.jackson.annotation.JsonView) ApiResponses(io.swagger.annotations.ApiResponses)

Example 4 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class GraylogVersionConstraintCheckerTest method checkConstraints.

@Test
public void checkConstraints() {
    final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^1.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
    assertThat(result.stream().allMatch(c -> c.fulfilled())).isTrue();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Example 5 with ConstraintCheckResult

use of org.graylog2.contentpacks.model.constraints.ConstraintCheckResult in project graylog2-server by Graylog2.

the class GraylogVersionConstraintCheckerTest method checkConstraintsFails.

@Test
public void checkConstraintsFails() {
    final GraylogVersionConstraintChecker constraintChecker = new GraylogVersionConstraintChecker("1.0.0");
    final GraylogVersionConstraint graylogVersionConstraint = GraylogVersionConstraint.builder().version("^2.0.0").build();
    final PluginVersionConstraint pluginVersionConstraint = PluginVersionConstraint.builder().pluginId("unique-id").version("^1.0.0").build();
    final ImmutableSet<Constraint> requiredConstraints = ImmutableSet.of(graylogVersionConstraint, pluginVersionConstraint);
    final Set<ConstraintCheckResult> result = constraintChecker.checkConstraints(requiredConstraints);
    assertThat(result.stream().allMatch(c -> !c.fulfilled())).isTrue();
}
Also used : ConstraintCheckResult(org.graylog2.contentpacks.model.constraints.ConstraintCheckResult) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) PluginVersionConstraint(org.graylog2.contentpacks.model.constraints.PluginVersionConstraint) Constraint(org.graylog2.contentpacks.model.constraints.Constraint) GraylogVersionConstraint(org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint) Test(org.junit.Test)

Aggregations

ConstraintCheckResult (org.graylog2.contentpacks.model.constraints.ConstraintCheckResult)7 Constraint (org.graylog2.contentpacks.model.constraints.Constraint)5 GraylogVersionConstraint (org.graylog2.contentpacks.model.constraints.GraylogVersionConstraint)3 PluginVersionConstraint (org.graylog2.contentpacks.model.constraints.PluginVersionConstraint)3 Test (org.junit.Test)3 ImmutableSet (com.google.common.collect.ImmutableSet)2 Requirement (com.vdurmont.semver4j.Requirement)2 ContentPack (org.graylog2.contentpacks.model.ContentPack)2 Timed (com.codahale.metrics.annotation.Timed)1 JsonView (com.fasterxml.jackson.annotation.JsonView)1 Semver (com.vdurmont.semver4j.Semver)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 Path (javax.ws.rs.Path)1 ConstraintChecker (org.graylog2.contentpacks.constraints.ConstraintChecker)1 ModelId (org.graylog2.contentpacks.model.ModelId)1