-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
24 changed files
with
845 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.crowdin.cli.client; | ||
|
||
import com.crowdin.client.tasks.model.AddTaskRequest; | ||
import com.crowdin.client.tasks.model.Status; | ||
import com.crowdin.client.tasks.model.Task; | ||
|
||
import java.util.List; | ||
|
||
public interface ClientTask extends Client { | ||
|
||
List<Task> listTask(Status status); | ||
|
||
Task addTask(AddTaskRequest request); | ||
|
||
} |
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
32 changes: 32 additions & 0 deletions
32
src/main/java/com/crowdin/cli/client/CrowdinClientTask.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,32 @@ | ||
package com.crowdin.cli.client; | ||
|
||
import com.crowdin.client.tasks.model.AddTaskRequest; | ||
import com.crowdin.client.tasks.model.Status; | ||
import com.crowdin.client.tasks.model.Task; | ||
|
||
import java.util.List; | ||
|
||
public class CrowdinClientTask extends CrowdinClientCore implements ClientTask { | ||
|
||
private final com.crowdin.client.Client client; | ||
private final String projectId; | ||
|
||
public CrowdinClientTask(com.crowdin.client.Client client, String projectId) { | ||
this.client = client; | ||
this.projectId = projectId; | ||
} | ||
|
||
@Override | ||
public List<Task> listTask(Status status) { | ||
return executeRequestFullList((limit, offset) -> this.client.getTasksApi() | ||
.listTasks(Long.valueOf(projectId), limit, offset, status)); | ||
} | ||
|
||
@Override | ||
public Task addTask(AddTaskRequest taskRequest) { | ||
return executeRequest(() -> this.client.getTasksApi() | ||
.addTask(Long.valueOf(projectId), taskRequest) | ||
.getData()); | ||
} | ||
|
||
} |
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
78 changes: 78 additions & 0 deletions
78
src/main/java/com/crowdin/cli/commands/actions/TaskAddAction.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,78 @@ | ||
package com.crowdin.cli.commands.actions; | ||
|
||
import com.crowdin.cli.client.ClientTask; | ||
import com.crowdin.cli.commands.NewAction; | ||
import com.crowdin.cli.commands.Outputter; | ||
|
||
import com.crowdin.cli.commands.functionality.PropertiesBeanUtils; | ||
import com.crowdin.cli.properties.ProjectProperties; | ||
|
||
import com.crowdin.client.tasks.model.AddTaskRequest; | ||
import com.crowdin.client.tasks.model.CrowdinTaskCreateFormRequest; | ||
import com.crowdin.client.tasks.model.EnterpriseTaskCreateFormRequest; | ||
import com.crowdin.client.tasks.model.Task; | ||
|
||
import lombok.AllArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; | ||
import static com.crowdin.cli.utils.console.ExecutionStatus.OK; | ||
|
||
@AllArgsConstructor | ||
class TaskAddAction implements NewAction<ProjectProperties, ClientTask> { | ||
|
||
private String title; | ||
|
||
private Integer type; | ||
|
||
private String language; | ||
|
||
private List<Long> fileId; | ||
|
||
private Long workflowStep; | ||
|
||
private String description; | ||
|
||
private boolean skipAssignedStrings; | ||
|
||
private boolean skipUntranslatedStrings; | ||
|
||
private List<Long> labels; | ||
|
||
@Override | ||
public void act(Outputter out, ProjectProperties pb, ClientTask client) { | ||
boolean isOrganization = PropertiesBeanUtils.isOrganization(pb.getBaseUrl()); | ||
Task task; | ||
AddTaskRequest addTaskRequest; | ||
if (isOrganization) { | ||
addTaskRequest = new EnterpriseTaskCreateFormRequest(); | ||
Optional.ofNullable(title).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setTitle(value)); | ||
Optional.ofNullable(language).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setLanguageId(value)); | ||
Optional.ofNullable(fileId).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setFileIds(value)); | ||
Optional.ofNullable(description).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setDescription(value)); | ||
Optional.ofNullable(skipAssignedStrings).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setSkipAssignedStrings(value)); | ||
Optional.ofNullable(labels).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setLabelIds(value)); | ||
Optional.ofNullable(workflowStep).ifPresent(value -> ((EnterpriseTaskCreateFormRequest) addTaskRequest).setWorkflowStepId(value)); | ||
} else { | ||
addTaskRequest = new CrowdinTaskCreateFormRequest(); | ||
Optional.ofNullable(title).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setTitle(value)); | ||
Optional.ofNullable(type).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setType(value)); | ||
Optional.ofNullable(language).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setLanguageId(value)); | ||
Optional.ofNullable(fileId).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setFileIds(value)); | ||
Optional.ofNullable(description).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setDescription(value)); | ||
Optional.ofNullable(skipAssignedStrings).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setSkipAssignedStrings(value)); | ||
Optional.ofNullable(skipUntranslatedStrings).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setSkipUntranslatedStrings(value)); | ||
Optional.ofNullable(labels).ifPresent(value -> ((CrowdinTaskCreateFormRequest) addTaskRequest).setLabelIds(value)); | ||
} | ||
|
||
try { | ||
task = client.addTask(addTaskRequest); | ||
} catch (Exception e) { | ||
throw new RuntimeException(String.format(RESOURCE_BUNDLE.getString("error.task_is_not_added"), addTaskRequest), e); | ||
} | ||
out.println(OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.task.added"), task.getTitle()))); | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/crowdin/cli/commands/actions/TaskListAction.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,58 @@ | ||
package com.crowdin.cli.commands.actions; | ||
|
||
import com.crowdin.cli.client.ClientTask; | ||
import com.crowdin.cli.commands.NewAction; | ||
import com.crowdin.cli.commands.Outputter; | ||
import com.crowdin.cli.properties.ProjectProperties; | ||
import com.crowdin.client.tasks.model.Status; | ||
import com.crowdin.client.tasks.model.Task; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; | ||
import static com.crowdin.cli.utils.console.ExecutionStatus.*; | ||
|
||
class TaskListAction implements NewAction<ProjectProperties, ClientTask> { | ||
|
||
private final boolean plainView; | ||
private final boolean isVerbose; | ||
|
||
private final String status; | ||
|
||
private final Long assigneeId; | ||
|
||
public TaskListAction(boolean plainView, boolean isVerbose, String status, Long assigneeId) { | ||
this.plainView = plainView; | ||
this.isVerbose = isVerbose; | ||
this.status = status; | ||
this.assigneeId = assigneeId; | ||
} | ||
|
||
@Override | ||
public void act(Outputter out, ProjectProperties pb, ClientTask client) { | ||
Status sts = status == null ? null : Status.valueOf(status.toUpperCase()); | ||
List<Task> tasks = client.listTask(sts); | ||
if (assigneeId != null) { | ||
tasks = tasks.stream() | ||
.filter(task -> task.getAssignees().stream() | ||
.anyMatch(assignee -> assignee.getId().equals(assigneeId))) | ||
.collect(Collectors.toList()); | ||
} | ||
for (Task task : tasks) { | ||
String okMessage = isVerbose ? "message.task.list.verbose" : "message.task.list"; | ||
String deadline = task.getDeadline() == null ? "NoDueDate" : task.getDeadline().toString(); | ||
if (!plainView) { | ||
out.println(LIST_ITEM.withIcon( | ||
String.format(RESOURCE_BUNDLE.getString(okMessage), task.getId(), task.getTargetLanguageId(), task.getTitle(), task.getStatus(), task.getWordsCount(), deadline))); | ||
} else { | ||
out.println(String.format(RESOURCE_BUNDLE.getString(okMessage), task.getId(), task.getTargetLanguageId(), task.getTitle(), task.getStatus(), task.getWordsCount(), deadline)); | ||
} | ||
} | ||
if (tasks.isEmpty()) { | ||
if (!plainView) { | ||
out.println(OK.withIcon(RESOURCE_BUNDLE.getString("message.task.list_empty"))); | ||
} | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/crowdin/cli/commands/picocli/ActCommandTask.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,28 @@ | ||
package com.crowdin.cli.commands.picocli; | ||
|
||
import com.crowdin.cli.client.ClientTask; | ||
import com.crowdin.cli.client.Clients; | ||
import com.crowdin.cli.commands.Outputter; | ||
import com.crowdin.cli.properties.ProjectParams; | ||
import com.crowdin.cli.properties.ProjectProperties; | ||
import com.crowdin.cli.properties.PropertiesBuilders; | ||
import picocli.CommandLine; | ||
|
||
public abstract class ActCommandTask extends GenericActCommand<ProjectProperties, ClientTask> { | ||
|
||
@CommandLine.Mixin | ||
private ConfigurationFilesProperties properties; | ||
|
||
@CommandLine.ArgGroup(exclusive = false, headingKey = "params.heading") | ||
private ProjectParams params; | ||
|
||
@Override | ||
protected ProjectProperties getProperties(PropertiesBuilders propertiesBuilders, Outputter out) { | ||
return propertiesBuilders.buildProjectProperties(out, properties.getConfigFile(), properties.getIdentityFile(), params); | ||
} | ||
|
||
@Override | ||
protected ClientTask getClient(ProjectProperties properties) { | ||
return Clients.getClientTask(properties.getApiToken(), properties.getBaseUrl(), properties.getProjectId()); | ||
} | ||
} |
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
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.