Package org.apache.sling.feature.extension.apiregions.api.artifacts

# Class VersionRule

java.lang.Object
org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
org.apache.sling.feature.extension.apiregions.api.artifacts.VersionRule

public class VersionRule extends AttributeableEntity
A rule to validate the version of an artifact. This class is not thread safe.

## Constructor Summary

Constructors
Constructor
Description
`VersionRule()`
Create a new rules object

## Method Summary

Modifier and Type
Method
Description
`void`
`clear()`
Clear the object and reset to defaults
`jakarta.json.JsonObjectBuilder`
`createJson()`
Convert this object into JSON
`void`
`fromJSONObject(jakarta.json.JsonObject jsonObj)`
Extract the metadata from the JSON object.
`org.osgi.framework.VersionRange[]`
`getAllowedVersionRanges()`
The allowed version ranges
`org.apache.sling.feature.ArtifactId`
`getArtifactId()`
Get the artifact id
`org.osgi.framework.VersionRange[]`
`getDeniedVersionRanges()`
Get the denied version ranges
`String`
`getEnforceOn()`
Get the optional enforce on information.
`Calendar`
`getEnforceOnDate()`
Return a date by which this rule is enforced
`String`
`getMessage()`
The validation message
`Mode`
`getMode()`
Get the validation mode.
`boolean`
`isAllowed(org.osgi.framework.Version artifactVersion)`
Check if a version is allowed according to the rules
`void`
`setAllowedVersionRanges(org.osgi.framework.VersionRange[] allowedVersions)`
Set the allowed version ranges
`void`
`setArtifactId(org.apache.sling.feature.ArtifactId artifactId)`
Set the artifact id
`void`
`setDeniedVersionRanges(org.osgi.framework.VersionRange[] deniedVersions)`
Set the denied version ranges
`void`
`setEnforceOn(String enforceOn)`
Set the enforce on information.
`void`
`setMessage(String message)`
Set the validation message
`void`
`setMode(Mode value)`
Set the validation mode

### Methods inherited from class org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity

`getAttributes, getBoolean, getInteger, getNumber, getString, getString, getStringArray, setDefaults, setString, setStringArray, toJSONObject`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### VersionRule

public VersionRule()
Create a new rules object

## Method Details

### clear

public void clear()
Clear the object and reset to defaults

Overrides:
  `clear` in class `AttributeableEntity`

### createJson

public jakarta.json.JsonObjectBuilder createJson() throws IOException
Convert this object into JSON

Overrides:
  `createJson` in class `AttributeableEntity`
Returns:
  The json object builder
Throws:
  `IOException` - If generating the JSON fails

### fromJSONObject

public void fromJSONObject(jakarta.json.JsonObject jsonObj) throws IOException
Extract the metadata from the JSON object. This method first calls `clear()`.

Overrides:
  `fromJSONObject` in class `AttributeableEntity`
Parameters:
  `jsonObj` - The JSON Object
Throws:
  `IOException` - If JSON parsing fails

### getMode

public Mode getMode()
Get the validation mode. The default is `Mode.STRICT`

Returns:
  The mode

### setMode

public void setMode(Mode value)
Set the validation mode

Parameters:
  `value` - The validation mode

### getArtifactId

public org.apache.sling.feature.ArtifactId getArtifactId()
Get the artifact id

Returns:
  the artifactId

### setArtifactId

public void setArtifactId(org.apache.sling.feature.ArtifactId artifactId)
Set the artifact id

Parameters:
  `artifactId` - the artifactId to set

### getMessage

public String getMessage()
The validation message

Returns:
  the message

### setMessage

public void setMessage(String message)
Set the validation message

Parameters:
  `message` - the message to set

### getAllowedVersionRanges

public org.osgi.framework.VersionRange[] getAllowedVersionRanges()
The allowed version ranges

Returns:
  the allowedVersions or `null`

### setAllowedVersionRanges

public void setAllowedVersionRanges(org.osgi.framework.VersionRange[] allowedVersions)
Set the allowed version ranges

Parameters:
  `allowedVersions` - the allowedVersions to set

### getDeniedVersionRanges

public org.osgi.framework.VersionRange[] getDeniedVersionRanges()
Get the denied version ranges

Returns:
  the deniedVersions or `null`

### setDeniedVersionRanges

public void setDeniedVersionRanges(org.osgi.framework.VersionRange[] deniedVersions)
Set the denied version ranges

Parameters:
  `deniedVersions` - the deniedVersions to set

### isAllowed

public boolean isAllowed(org.osgi.framework.Version artifactVersion)
Check if a version is allowed according to the rules

Parameters:
  `artifactVersion` - The version
Returns:
  `true` if it is allowed, `false` otherwise

### getEnforceOn

public String getEnforceOn()
Get the optional enforce on information. This must be a date in the format 'YYYY-MM-DD'.

Returns:
  The since information or `null`
Since:
  2.1.0

### setEnforceOn

public void setEnforceOn(String enforceOn)
Set the enforce on information. This must be a date in the format 'YYYY-MM-DD'.

Parameters:
  `enforceOn` - The new info or `null` to remove it
Throws:
  `IllegalArgumentException` - If the format is not correct
Since:
  2.1.0

### getEnforceOnDate

public Calendar getEnforceOnDate()
Return a date by which this rule is enforced

Returns:
  A calendar if the value from `getEnforceOn()` is set or yesterday
Since:
  2.1.0