Class VersionRule
java.lang.Object
org.apache.sling.feature.extension.apiregions.api.config.AttributeableEntity
org.apache.sling.feature.extension.apiregions.api.artifacts.VersionRule
A rule to validate the version of an artifact.
This class is not thread safe.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear the object and reset to defaultsjakarta.json.JsonObjectBuilderConvert this object into JSONvoidfromJSONObject(jakarta.json.JsonObject jsonObj) Extract the metadata from the JSON object.org.osgi.framework.VersionRange[]The allowed version rangesorg.apache.sling.feature.ArtifactIdGet the artifact idorg.osgi.framework.VersionRange[]Get the denied version rangesGet the optional enforce on information.Return a date by which this rule is enforcedThe validation messagegetMode()Get the validation mode.booleanisAllowed(org.osgi.framework.Version artifactVersion) Check if a version is allowed according to the rulesvoidsetAllowedVersionRanges(org.osgi.framework.VersionRange[] allowedVersions) Set the allowed version rangesvoidsetArtifactId(org.apache.sling.feature.ArtifactId artifactId) Set the artifact idvoidsetDeniedVersionRanges(org.osgi.framework.VersionRange[] deniedVersions) Set the denied version rangesvoidsetEnforceOn(String enforceOn) Set the enforce on information.voidsetMessage(String message) Set the validation messagevoidSet the validation modeMethods inherited from class AttributeableEntity
getAttributes, getBoolean, getInteger, getNumber, getString, getString, getStringArray, setDefaults, setString, setStringArray, toJSONObject
-
Constructor Details
-
VersionRule
public VersionRule()Create a new rules object
-
-
Method Details
-
clear
public void clear()Clear the object and reset to defaults- Overrides:
clearin classAttributeableEntity
-
createJson
Convert this object into JSON- Overrides:
createJsonin classAttributeableEntity- Returns:
- The json object builder
- Throws:
IOException- If generating the JSON fails
-
fromJSONObject
Extract the metadata from the JSON object. This method first callsclear().- Overrides:
fromJSONObjectin classAttributeableEntity- Parameters:
jsonObj- The JSON Object- Throws:
IOException- If JSON parsing fails
-
getMode
-
setMode
-
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
-
setMessage
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:
trueif it is allowed,falseotherwise
-
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
Set the enforce on information. This must be a date in the format 'YYYY-MM-DD'.- Parameters:
enforceOn- The new info ornullto remove it- Throws:
IllegalArgumentException- If the format is not correct- Since:
- 2.1.0
-
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
-