-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(AChecker) fixes #28156: Expose the AChecker DWR class as a REST…
… Endpoint (#29879) ### Proposed Changes * Exposes the Accessibility Checker DWR class as a REST Endpoint for it to be used by the Angular layer.
- Loading branch information
1 parent
9ea466b
commit 70143ba
Showing
9 changed files
with
1,149 additions
and
56 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
dotCMS/src/enterprise/java/com/dotcms/enterprise/achecker/ACheckerAPI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.dotcms.enterprise.achecker; | ||
|
||
import com.dotcms.enterprise.achecker.model.GuideLineBean; | ||
import com.dotmarketing.business.DotValidationException; | ||
import com.dotmarketing.exception.DotDataException; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* This API provides the methods to interact with the Accessibility Checker service in dotCMS. Users | ||
* of this API can access the different Accessibility Guidelines available in the system, and | ||
* validate content against them. | ||
* | ||
* @author Jose Castro | ||
* @since Sep 5th, 2024 | ||
*/ | ||
public interface ACheckerAPI { | ||
|
||
String LANG = "lang"; | ||
String CONTENT = "content"; | ||
String GUIDELINES = "guidelines"; | ||
String FRAGMENT = "fragment"; | ||
|
||
/** | ||
* Returns the list of Accessibility Guidelines available in the system. | ||
* | ||
* @return The list of Accessibility Guidelines available in the system. | ||
* | ||
* @throws DotDataException If the guidelines can't be retrieved. | ||
*/ | ||
List<GuideLineBean> getAccessibilityGuidelineList() throws DotDataException; | ||
|
||
/** | ||
* Validates the given content against the specified Accessibility Guidelines. | ||
* | ||
* @param validationData Map containing the parameters to validate: | ||
* <ul> | ||
* <li>{@code lang}: the language of the content to validate (ISO | ||
* 639-1, 2 letters)</li> | ||
* <li>{@code content}: the content to validate</li> | ||
* <li>{@code guidelines}: the guidelines to validate against | ||
* (comma-separated list of guideline abbreviations)</li> | ||
* <li>{@code fragment}: whether the content is a fragment (does | ||
* not contain the required HTML tags)</li> | ||
* </ul> | ||
* | ||
* @return The result of the validation, as a JSON object. | ||
* | ||
* @throws DotValidationException If the validation fails. | ||
*/ | ||
ACheckerResponse validate(final Map<String, String> validationData) throws DotValidationException; | ||
|
||
} |
83 changes: 83 additions & 0 deletions
83
dotCMS/src/enterprise/java/com/dotcms/enterprise/achecker/impl/ACheckerAPIImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package com.dotcms.enterprise.achecker.impl; | ||
|
||
import com.dotcms.enterprise.achecker.ACheckerAPI; | ||
import com.dotcms.enterprise.achecker.ACheckerRequest; | ||
import com.dotcms.enterprise.achecker.ACheckerResponse; | ||
import com.dotcms.enterprise.achecker.dao.GuidelinesDAO; | ||
import com.dotcms.enterprise.achecker.model.GuideLineBean; | ||
import com.dotcms.enterprise.achecker.tinymce.DaoLocator; | ||
import com.dotcms.exception.ExceptionUtil; | ||
import com.dotcms.util.EnterpriseFeature; | ||
import com.dotmarketing.business.DotValidationException; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.util.UtilMethods; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Implements the {@link ACheckerAPI} interface. | ||
* | ||
* @author Jose Castro | ||
* @since Sep 5th, 2024 | ||
*/ | ||
public class ACheckerAPIImpl implements ACheckerAPI { | ||
|
||
private List<GuideLineBean> accessibilityGuidelineList = null; | ||
|
||
/** | ||
* Returns the list of Accessibility Guidelines available in the system. | ||
* | ||
* @return The list of Accessibility Guidelines available in the system. | ||
* | ||
* @throws Exception If the guidelines can't be retrieved. | ||
*/ | ||
@EnterpriseFeature | ||
public List<GuideLineBean> getAccessibilityGuidelineList() throws DotDataException { | ||
try { | ||
if (UtilMethods.isNotSet(this.accessibilityGuidelineList)) { | ||
GuidelinesDAO gLines = DaoLocator.getGuidelinesDAO(); | ||
this.accessibilityGuidelineList = gLines.getOpenGuidelines(); | ||
} | ||
return this.accessibilityGuidelineList; | ||
} catch (final Exception e) { | ||
throw new DotDataException(ExceptionUtil.getErrorMessage(e), e); | ||
} | ||
} | ||
|
||
/** | ||
* Validates the given content against the specified Accessibility Guidelines. | ||
* | ||
* @param validationData Map containing the parameters to validate: | ||
* <ul> | ||
* <li>{@code lang}: the language of the content to validate (ISO | ||
* 639-1, 2 letters)</li> | ||
* <li>{@code content}: the content to validate</li> | ||
* <li>{@code guidelines}: the guidelines to validate against | ||
* (comma-separated list of guideline abbreviations)</li> | ||
* <li>{@code fragment}: whether the content is a fragment (does | ||
* not contain the required HTML tags)</li> | ||
* </ul> | ||
* | ||
* @return The result of the validation, as a JSON object. | ||
* | ||
* @throws DotValidationException If the validation fails. | ||
*/ | ||
@EnterpriseFeature | ||
public ACheckerResponse validate(final Map<String, String> validationData) throws DotValidationException { | ||
final String lang = validationData.get(LANG); | ||
final String content = validationData.get(CONTENT); | ||
final String guidelines = validationData.get(GUIDELINES); | ||
final String fragment = validationData.get(FRAGMENT); | ||
try { | ||
if (UtilMethods.isSet(lang) && lang.trim().length() == 2) { | ||
DaoLocator.getLangCodesDAO().getLangCodeBy3LetterCode(lang); | ||
} | ||
final ACheckerRequest request = new ACheckerRequest(lang, content, guidelines, Boolean.parseBoolean(fragment)); | ||
return new ACheckerImpl().validate(request); | ||
} catch (final Exception e) { | ||
throw new DotValidationException(ExceptionUtil.getErrorMessage(e), e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.