Class AutoTranslateMergeServiceImpl
- java.lang.Object
-
- com.composum.ai.aem.core.impl.autotranslate.AutoTranslateMergeServiceImpl
-
- All Implemented Interfaces:
AutoTranslateMergeService
public class AutoTranslateMergeServiceImpl extends Object implements AutoTranslateMergeService
Implementation of the AutoTranslateMergeService. Provides methods to retrieve properties for resources in the context of translations.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.composum.ai.aem.core.impl.autotranslate.AutoTranslateMergeService
AutoTranslateMergeService.AutoTranslateProperty, AutoTranslateMergeService.CancelOrReenable
-
-
Field Summary
Fields Modifier and Type Field Description protected static String[]COMPONENT_TITLE_PROPERTIESHeuristic set of properties that might give a recognizable title to the component.protected com.composum.ai.backend.slingbase.AIConfigurationServiceconfigurationService
-
Constructor Summary
Constructors Constructor Description AutoTranslateMergeServiceImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidapproveTranslation(org.apache.sling.api.resource.Resource resource, String propertyName)Approves a translation for the specified property of the given resource, marking it as accepted.voidchangeInheritance(org.apache.sling.api.resource.Resource resource, String propertyName, AutoTranslateMergeService.CancelOrReenable kind)Cancels a translation for the specified property of the given resource, marking it as cancelled.protected Stream<org.apache.sling.api.resource.Resource>descendantsStream(org.apache.sling.api.resource.Resource resource)protected StringgetComponentName(org.apache.sling.api.resource.Resource resource)Determines the jcr:title of the current component, as found by sling:resourceTypeprotected StringgetComponentTitle(org.apache.sling.api.resource.Resource resource)Determines the jcr:title , title, text etc. of the component by searching upwards for such a property.List<AutoTranslateMergeService.AutoTranslateProperty>getProperties(org.apache.sling.api.resource.Resource pageResource)Recursively finds all properties from the given resource and its children that have names starting withAITranslatePropertyWrapper.AI_NEW_TRANSLATED_SUFFIXand creates the AI Translate Property Wrapper for each.StringintelligentMerge(String language, org.apache.sling.api.resource.Resource resource, String originalSource, String newSource, String newTranslation, String currentText)booleanisAutomaticallyTranslated(org.apache.sling.api.resource.Resource resource)Checks whether this is an automatically translated resource.booleanisProcessingNeeded(org.apache.sling.api.resource.Resource pageResource)Checks whether there are any unmerged or unaccepted properties.Map<String,String>saveTranslation(org.apache.sling.api.resource.Resource resource, String propertyName, String content, boolean markAsMerged)Saves the new content to a property.
-
-
-
Field Detail
-
configurationService
protected com.composum.ai.backend.slingbase.AIConfigurationService configurationService
-
COMPONENT_TITLE_PROPERTIES
protected static final String[] COMPONENT_TITLE_PROPERTIES
Heuristic set of properties that might give a recognizable title to the component.
-
-
Method Detail
-
isProcessingNeeded
public boolean isProcessingNeeded(org.apache.sling.api.resource.Resource pageResource)
Description copied from interface:AutoTranslateMergeServiceChecks whether there are any unmerged or unaccepted properties.- Specified by:
isProcessingNeededin interfaceAutoTranslateMergeService
-
isAutomaticallyTranslated
public boolean isAutomaticallyTranslated(org.apache.sling.api.resource.Resource resource)
Description copied from interface:AutoTranslateMergeServiceChecks whether this is an automatically translated resource.- Specified by:
isAutomaticallyTranslatedin interfaceAutoTranslateMergeService
-
getProperties
@Nonnull public List<AutoTranslateMergeService.AutoTranslateProperty> getProperties(org.apache.sling.api.resource.Resource pageResource)
Description copied from interface:AutoTranslateMergeServiceRecursively finds all properties from the given resource and its children that have names starting withAITranslatePropertyWrapper.AI_NEW_TRANSLATED_SUFFIXand creates the AI Translate Property Wrapper for each.- Specified by:
getPropertiesin interfaceAutoTranslateMergeService- Parameters:
pageResource- the root resource to start property extraction from.- Returns:
- a list of AutoTranslateProperty instances with translation details.
-
saveTranslation
public Map<String,String> saveTranslation(@Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull String propertyName, @Nonnull String content, boolean markAsMerged) throws com.day.cq.wcm.api.WCMException
Description copied from interface:AutoTranslateMergeServiceSaves the new content to a property.- Specified by:
saveTranslationin interfaceAutoTranslateMergeService- Parameters:
resource- the resource to save the translation to.propertyName- the name of the property to save the translation to.content- the new content to save.markAsMerged- whether to mark the property as merged- Returns:
- a map containing "saved" and the text saved in the resource, to verify that it went OK, otherwise empty.
- Throws:
com.day.cq.wcm.api.WCMException
-
approveTranslation
public void approveTranslation(org.apache.sling.api.resource.Resource resource, String propertyName) throws com.day.cq.wcm.api.WCMExceptionDescription copied from interface:AutoTranslateMergeServiceApproves a translation for the specified property of the given resource, marking it as accepted.- Specified by:
approveTranslationin interfaceAutoTranslateMergeService- Parameters:
resource- the resource containing the property to approvepropertyName- the name of the property for which the translation is to be approved- Throws:
com.day.cq.wcm.api.WCMException
-
changeInheritance
public void changeInheritance(org.apache.sling.api.resource.Resource resource, String propertyName, AutoTranslateMergeService.CancelOrReenable kind) throws com.day.cq.wcm.api.WCMExceptionDescription copied from interface:AutoTranslateMergeServiceCancels a translation for the specified property of the given resource, marking it as cancelled.- Specified by:
changeInheritancein interfaceAutoTranslateMergeService- Parameters:
resource- the resource containing the property to cancelpropertyName- the name of the property for which the translation is to be cancelledkind- whether to cancel or reenable the property- Throws:
com.day.cq.wcm.api.WCMException
-
intelligentMerge
public String intelligentMerge(String language, @Nonnull org.apache.sling.api.resource.Resource resource, @Nonnull String originalSource, @Nonnull String newSource, @Nonnull String newTranslation, @Nonnull String currentText)
- Specified by:
intelligentMergein interfaceAutoTranslateMergeService
-
descendantsStream
protected Stream<org.apache.sling.api.resource.Resource> descendantsStream(org.apache.sling.api.resource.Resource resource)
-
getComponentName
protected String getComponentName(org.apache.sling.api.resource.Resource resource)
Determines the jcr:title of the current component, as found by sling:resourceType
-
-