Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aem650 #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.adobe.granite.translation.connector</groupId>
<artifactId>bootstrap-connector</artifactId>
<artifactId>lilt-connector</artifactId>
<version>2.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>bootstrap-connector.core</artifactId>
<artifactId>lilt-connector.core</artifactId>
<packaging>bundle</packaging>
<name>Bootstrap Translation Connector - Core</name>
<description>Core bundle for Bootstrap Translation Connector</description>
Expand Down Expand Up @@ -91,6 +91,14 @@
<version>1.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.adobe.granite.translation</groupId>
<artifactId>bootstrap-tms.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@

public interface BootstrapTranslationCloudConfig {

public static final String PROPERTY_DUMMY_SERVER_URL = "dummyserverurl";
public static final String PROPERTY_DUMMY_CONFIG_ID = "dummyconfigid";
public static final String PROPERTY_LILT_SERVER_URL = "liltserverurl";
public static final String PROPERTY_LILT_CONFIG_ID = "liltconfigid";
public static final String PROPERTY_PREVIEW_PATH = "previewPath";

public static final String RESOURCE_TYPE = "bootstrap-connector/components/bootstrap-connector-cloudconfig";
public static final String ROOT_PATH = "/etc/cloudservices/bootstrap-translation";
public static final String ROOT_PATH = "/etc/cloudservices/lilt-translation";

String getDummyServerUrl();
String getLiltServerUrl();

String getDummyConfigId();
String getLiltConfigId();

String getPreviewPath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public @interface BootstrapServiceConfiguration {

@AttributeDefinition(name = "Bootstrap Translation Factory Name", description = "The Unique ID associated with this Translation Factory Connector")
String getTranslationFactory() default "Bootstrap Connector";
String getTranslationFactory() default "Lilt Connector";

@AttributeDefinition(name = "Enable Preview", description="Preview Enabled for Translation Objects")
boolean isPreviewEnabled() default false;
Expand All @@ -22,4 +22,4 @@
@Option(label = "XLIFF 2.0", value = BootstrapConstants.EXPORT_FORMAT_XLIFF_2_0)})
String getExportFormat() default BootstrapConstants.EXPORT_FORMAT_XML;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Collections;

import org.osgi.framework.Constants;
import org.osgi.service.component.annotations.Activate;
Expand All @@ -35,7 +36,13 @@
import com.adobe.granite.translation.api.TranslationServiceFactory;
import com.adobe.granite.translation.bootstrap.tms.core.BootstrapTmsService;
import com.adobe.granite.translation.connector.bootstrap.core.BootstrapTranslationCloudConfig;
import com.adobe.granite.translation.connector.bootstrap.core.impl.config.BootstrapTranslationCloudConfigImpl;
import com.adobe.granite.translation.connector.bootstrap.core.impl.LiltApiClient;
import com.adobe.granite.translation.core.TranslationCloudConfigUtil;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.LoginException;

@Component(service = TranslationServiceFactory.class, immediate = true, configurationPid = "com.adobe.granite.translation.connector.bootstrap.core.impl.BootstrapTranslationServiceFactoryImpl", property = {
Constants.SERVICE_DESCRIPTION + "=Configurable settings for the Bootstrap Translation connector",
Expand All @@ -61,20 +68,21 @@ public class BootstrapTranslationServiceFactoryImpl implements TranslationServic
@Reference
CryptoSupport cryptoSupport;

@Reference
private ResourceResolverFactory resolverFactory;

@Reference
BootstrapTmsService bootstrapTmsService;

private List<TranslationMethod> supportedTranslationMethods;

private BootstrapServiceConfiguration config;


public BootstrapTranslationServiceFactoryImpl() {
log.trace("BootstrapTranslationServiceFactoryImpl.");

supportedTranslationMethods = new ArrayList<TranslationMethod>();
supportedTranslationMethods.add(TranslationMethod.HUMAN_TRANSLATION);
supportedTranslationMethods.add(TranslationMethod.MACHINE_TRANSLATION);
}

private static final Logger log = LoggerFactory.getLogger(BootstrapTranslationServiceFactoryImpl.class);
Expand All @@ -84,26 +92,41 @@ public TranslationService createTranslationService(TranslationMethod translation
throws TranslationException {
log.trace("BootstrapTranslationServiceFactoryImpl.createTranslationService");

BootstrapTranslationCloudConfig bootstrapCloudConfg = (BootstrapTranslationCloudConfig) cloudConfigUtil
.getCloudConfigObjectFromPath(BootstrapTranslationCloudConfig.class, cloudConfigPath);

String dummyConfigId = "";
String dummyServerUrl = "";
BootstrapTranslationCloudConfig bootstrapCloudConfg = null;
LiltApiClient liltApiClient = null;

String liltConfigId = "";
String liltServerUrl = "";
String previewPath = "";

try {
Map<String, Object> param = new HashMap<String, Object>();
param.put(ResourceResolverFactory.SUBSERVICE, "bootstrap-service");
ResourceResolver resourceResolver = resolverFactory.getServiceResourceResolver(param);
Resource res = resourceResolver.getResource(cloudConfigPath);
bootstrapCloudConfg = (BootstrapTranslationCloudConfig) cloudConfigUtil
.getCloudConfigObjectFromPath(res, BootstrapTranslationCloudConfig.class, cloudConfigPath);
if (res != null) {
bootstrapCloudConfg = new BootstrapTranslationCloudConfigImpl(res);
}
} catch (LoginException e) {
log.error("Error while resolving config resource {}", e);
}

if (bootstrapCloudConfg != null) {
dummyConfigId = bootstrapCloudConfg.getDummyConfigId();
dummyServerUrl = bootstrapCloudConfg.getDummyServerUrl();
liltConfigId = bootstrapCloudConfg.getLiltConfigId();
liltServerUrl = bootstrapCloudConfg.getLiltServerUrl();
previewPath = bootstrapCloudConfg.getPreviewPath();

liltApiClient = new LiltApiClient(liltServerUrl, liltConfigId);
}

if (cryptoSupport != null) {
try {
if (cryptoSupport.isProtected(dummyConfigId)) {
dummyConfigId = cryptoSupport.unprotect(dummyConfigId);
if (cryptoSupport.isProtected(liltConfigId)) {
liltConfigId = cryptoSupport.unprotect(liltConfigId);
} else {
log.trace("Dummy Config ID is not protected");
log.trace("Lilt Config ID is not protected");
}
} catch (CryptoException e) {
log.error("Error while decrypting the client secret {}", e);
Expand All @@ -113,8 +136,8 @@ public TranslationService createTranslationService(TranslationMethod translation
Map<String, String> availableLanguageMap = new HashMap<String, String>();
Map<String, String> availableCategoryMap = new HashMap<String, String>();
return new BootstrapTranslationServiceImpl(availableLanguageMap, availableCategoryMap, factoryName,
isPreviewEnabled, isPseudoLocalizationDisabled, exportFormat, dummyConfigId, dummyServerUrl,
previewPath, translationConfig, bootstrapTmsService);
isPreviewEnabled, isPseudoLocalizationDisabled, exportFormat, liltConfigId, liltServerUrl,
previewPath, translationConfig, liltApiClient, cloudConfigPath);
}

@Override
Expand Down
Loading