Skip to content
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
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>com.adobe.granite.translation.connector</groupId>
<artifactId>lilt-connector</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>lilt-connector.core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,39 +281,58 @@ public TranslationStatus getTranslationJobStatus(String strTranslationJobID) thr
try {
int imported = 0;
int translated = 0;
int approved = 0;
int rejected = 0;
SourceFile[] files = liltApiClient.getFiles(strTranslationJobID);
// loop backwards through the list since the most recent files will be at the end.
for (SourceFile file : files) {
if (file.labels.contains("status=IMPORTED")) {
imported++;
}
if (file.labels.contains("status=TRANSLATED")) {
translated++;
}
if (file.labels.contains("approval=APPROVED")) {
approved++;
}
if (file.labels.contains("approval=REJECTED")) {
rejected++;
}
}
boolean hasImported = imported > 0;
boolean hasTranslated = translated > 0;
boolean hasRejected = rejected > 0;
if (hasImported && hasTranslated && approved >= imported) {
log.warn("lilt: job status for {} is APPROVED", strTranslationJobID);
return TranslationStatus.APPROVED;
}
if (hasImported && hasTranslated && hasRejected) {
log.info("lilt: job status for {} is TRANSLATION_IN_PROGRESS", strTranslationJobID);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to warn here instead of info?
You should probably log REJECTED status instead of TRANSLATION_IN_PROGRESS and return that too.

return TranslationStatus.TRANSLATION_IN_PROGRESS;
}
if (hasImported && hasTranslated) {
log.warn("lilt: job status for {} is TRANSLATED", strTranslationJobID);
return TranslationStatus.TRANSLATED;
}
if (hasImported) {
log.warn("lilt: job status for {} is TRANSLATION_IN_PROGRESS", strTranslationJobID);
return TranslationStatus.TRANSLATION_IN_PROGRESS;
}
} catch (Exception e) {
log.warn("error during getTranslationJobStatus {}", e);
}
log.warn("lilt: job status for {} is COMMITTED_FOR_TRANSLATION", strTranslationJobID);
return TranslationStatus.COMMITTED_FOR_TRANSLATION;
}

@Override
public CommentCollection<Comment> getTranslationJobCommentCollection(String strTranslationJobID) {
log.trace("BootstrapTranslationServiceImpl.getTranslationJobCommentCollection");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why warn instead of trace?

log.warn("BootstrapTranslationServiceImpl.getTranslationJobCommentCollection");
return null;
}

@Override
public void addTranslationJobComment(String strTranslationJobID, Comment comment) throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.addTranslationJobComment");
log.warn("BootstrapTranslationServiceImpl.addTranslationJobComment");

throw new TranslationException("This function is not implemented",
TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED);
Expand All @@ -323,13 +342,16 @@ public void addTranslationJobComment(String strTranslationJobID, Comment comment
public InputStream getTranslatedObject(String strTranslationJobID, TranslationObject translationObj)
throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.getTranslatedObject");
log.warn("lilt: strTranslationJobID: {}", strTranslationJobID);
String labels = String.format("%s,status=TRANSLATED", strTranslationJobID);
String objectPath = String.format("%s.%s", getObjectPath(translationObj), exportFormat);
log.warn("lilt: checking for objectPath {}", objectPath);
try {
SourceFile[] files = liltApiClient.getFiles(labels);
// loop backwards through the list since the most recent files will be at the end.
for (int i = files.length - 1; i >= 0; i--) {
SourceFile file = files[i];
log.warn("lilt: comparing {} to {}", file.name, objectPath);
if (Objects.equals(file.name, objectPath)) {
log.warn("Downloading the translated lilt file {}", file.id);
String translation = liltApiClient.downloadFile(file.id);
Expand Down Expand Up @@ -397,23 +419,53 @@ public String uploadTranslationObject(String strTranslationJobID, TranslationObj

@Override
public TranslationStatus updateTranslationObjectState(String strTranslationJobID,
TranslationObject translationObject, TranslationState state) throws TranslationException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Margin change.

log.trace("BootstrapTranslationServiceImpl.updateTranslationObjectState");
// bootstrapTmsService.setTmsProperty(strTranslationJobID+getObjectPath(translationObject), BootstrapTmsConstants.BOOTSTRAP_TMS_STATUS, state.getStatus().toString());
return TranslationStatus.TRANSLATED;
TranslationObject translationObject, TranslationState state) throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.updateTranslationObjectState");
log.warn("lilt: strTranslationJobID: {}", strTranslationJobID);
String labels = String.format("%s,status=TRANSLATED", strTranslationJobID);
String status = state.getStatus().toString();
String label = String.format("approval=%s", status);
String objectPath = String.format("%s.%s", getObjectPath(translationObject), exportFormat);
log.warn("lilt: checking for objectPath {}", objectPath);
try {
SourceFile[] files = liltApiClient.getFiles(labels);
// loop backwards through the list since the most recent files will be at the end.
for (int i = files.length - 1; i >= 0; i--) {
SourceFile file = files[i];
log.warn("lilt: comparing {} to {}", file.name, objectPath);
if (Objects.equals(file.name, objectPath)) {
log.warn("Adding label {} to file {}", label, file.id);
liltApiClient.addLabel(file.id, label);
return state.getStatus();
}
}
} catch (Exception e) {
log.warn("error during getTranslatedObject {}", e);
}
Comment comment = state.getComment();
if (comment != null) {
log.warn(comment.getMessage());
addTranslationObjectComment(strTranslationJobID, translationObject, comment);
}
return state.getStatus();
}

@Override
public TranslationStatus getTranslationObjectStatus(String strTranslationJobID, TranslationObject translationObject)
throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.getTranslationObjectStatus");
try {
String objectPath = String.format("%s.%s", getObjectPath(translationObject), exportFormat);
String path = getObjectPath(translationObject);
String objectPath = String.format("%s.%s", path, exportFormat);
log.warn("lilt: strTranslationJobID");
int imported = 0;
int translated = 0;
int approved = 0;
int rejected = 0;
int complete = 0;
SourceFile[] files = liltApiClient.getFiles(strTranslationJobID);
// loop backwards through the list since the most recent files will be at the end.
for (SourceFile file : files) {
log.warn("lilt: comparing {} to {}", file.name, objectPath);
if (!Objects.equals(file.name, objectPath)) {
continue;
}
Expand All @@ -423,20 +475,50 @@ public TranslationStatus getTranslationObjectStatus(String strTranslationJobID,
if (file.labels.contains("status=TRANSLATED")) {
translated++;
}
if (file.labels.contains("approval=APPROVED")) {
approved++;
}
if (file.labels.contains("approval=REJECTED")) {
rejected++;
}
if (file.labels.contains("approval=COMPLETE")) {
rejected++;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you mean complete?

}
}
boolean hasImported = imported > 0;
boolean hasTranslated = translated > 0;
boolean hasRejected = rejected > 0;
if (hasImported && hasTranslated && complete >= imported) {
log.warn("lilt: status for {} is COMPLETE", objectPath);
return TranslationStatus.COMPLETE;
}
if (hasImported && hasTranslated && approved >= imported) {
log.warn("lilt: status for {} is APPROVED", objectPath);
return TranslationStatus.APPROVED;
}
if (hasImported && hasTranslated && translated > rejected) {
log.warn("lilt: status for {} is APPROVED", objectPath);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the log message say "... TRANSLATED"?

Also, what's the difference between this check and the one few lines below: if (hasImported && hasTranslated)?

return TranslationStatus.TRANSLATED;
}
if (hasImported && hasTranslated && hasRejected) {
log.warn("lilt: status for {} is REJECTED", objectPath);
return TranslationStatus.REJECTED;
}
if (hasImported && hasTranslated) {
log.warn("lilt: status for {} is TRANSLATED", objectPath);
return TranslationStatus.TRANSLATED;
}
if (hasImported) {
log.warn("lilt: status for {} is TRANSLATION_IN_PROGRESS", objectPath);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't these types of log messages be info?

return TranslationStatus.TRANSLATION_IN_PROGRESS;
}
// if the object has an extension then it is an image or some sort of asset. we should consider those translated.
Optional<String> maybeExt = getFileExtension(objectPath);
// if the object has an extension then it is an image or some sort of asset. we should consider those complete.
Optional<String> maybeExt = getFileExtension(path);
if (maybeExt.isPresent()) {
return TranslationStatus.TRANSLATED;
}
log.warn("lilt: asset status for {} is APPROVED", path);
return TranslationStatus.APPROVED;
}
log.warn("lilt: status for {} is COMMITTED_FOR_TRANSLATION", objectPath);
} catch (Exception e) {
log.warn("error during getTranslationObjectStatus {}", e);
}
Expand Down Expand Up @@ -471,19 +553,29 @@ public TranslationStatus[] getTranslationObjectsStatus(String strTranslationJobI
@Override
public CommentCollection<Comment> getTranslationObjectCommentCollection(String strTranslationJobID,
TranslationObject translationObject) throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.getTranslationObjectCommentCollection");
log.warn("BootstrapTranslationServiceImpl.getTranslationObjectCommentCollection");

throw new TranslationException("This function is not implemented",
TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED);
}

@Override
public void addTranslationObjectComment(String strTranslationJobID, TranslationObject translationObject,
Comment comment) throws TranslationException {
log.trace("BootstrapTranslationServiceImpl.addTranslationObjectComment");

throw new TranslationException("This function is not implemented",
TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED);
Comment comment) throws TranslationException {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the margin change intentional?

log.warn("BootstrapTranslationServiceImpl.addTranslationObjectComment");
String annotation = comment.getAnnotationData();
String author = comment.getAuthorName();
String fileName = String.format("%s_%s.txt");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The specifiers are missing. Did you mean to pass annotation and author?

String objectPath = String.format("%s.%s", getObjectPath(translationObject), exportFormat);
String message = comment.getMessage();
String body = String.format("%s\n\n%s", objectPath, message);
InputStream inputStream = new ByteArrayInputStream(body.getBytes());
String labels = String.format("%s,comment", strTranslationJobID);
try {
liltApiClient.uploadFile(fileName, labels, inputStream);
} catch (Exception e) {
log.warn("error during addTranslationObjectComment {}", e);
}
}

@Override
Expand All @@ -495,9 +587,8 @@ public void updateTranslationJobMetadata(String strTranslationJobID, Translation
TranslationException.ErrorCode.SERVICE_NOT_IMPLEMENTED);
}


private String getObjectPath (TranslationObject translationObject){

if(translationObject.getTranslationObjectSourcePath()!= null && !translationObject.getTranslationObjectSourcePath().isEmpty()){
return translationObject.getTranslationObjectSourcePath();
}
Expand All @@ -506,19 +597,19 @@ else if(translationObject.getTitle().equals("TAGMETADATA")){
}
else if(translationObject.getTitle().equals("ASSETMETADATA")){
return ASSET_METADATA;
}
}
else if(translationObject.getTitle().equals("I18NCOMPONENTSTRINGDICT")){
return I18NCOMPONENTSTRINGDICT;
}
return null;
}
}

public void updateDueDate(String strTranslationJobID, Date date)
throws TranslationException {
log.debug("NEW DUE DATE:{}",date);
// bootstrapTmsService.setTmsJobDuedate(strTranslationJobID, date);
}

private static void unzipFileFromStream(ZipInputStream zipInputStream, String targetPath) throws IOException {
File dirFile = new File(targetPath + File.separator);
if (!dirFile.exists()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

import com.google.gson.Gson;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
Expand Down Expand Up @@ -100,4 +103,24 @@ public String downloadFile(Integer fileId) throws IOException, URISyntaxExceptio
.collect(Collectors.joining("\n"));
}
}

public void addLabel(Integer fileId, String label) throws IOException, URISyntaxException {
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
log.warn("addLabel fileId {}", fileId);
String baseUrl = String.format("%s/files/labels", apiUrl);
URIBuilder req = new URIBuilder(baseUrl);
req.setParameter("id", Integer.toString(fileId));
req.setParameter("key", apiKey);
HttpPost httppost = new HttpPost(req.build());
HashMap<String, String> reqBody = new HashMap<>();
reqBody.put("name", label);
Gson gson = new Gson();
String jsonBody = gson.toJson(reqBody);
log.warn("addLabel body {}", jsonBody);
HttpEntity body = new StringEntity(jsonBody, ContentType.APPLICATION_JSON);
httppost.setEntity(body);
log.warn("Executing request {}", httppost.getRequestLine());
httpclient.execute(httppost);
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<artifactId>lilt-connector</artifactId>
<name>Lilt Translation Connector</name>
<packaging>pom</packaging>
<version>2.0-SNAPSHOT</version>
<version>2.2</version>
<description>Lilt Translation Connector</description>

<modules>
Expand Down
2 changes: 1 addition & 1 deletion ui.apps/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>com.adobe.granite.translation.connector</groupId>
<artifactId>lilt-connector</artifactId>
<version>2.0-SNAPSHOT</version>
<version>2.2</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down