Crie uma classe Java
Baixar como PDF
Compartilhar
- Última atualização2022/05/19
Use o IntelliJ para criar uma nova classe java e um novo diretório, e configure outros arquivos de build.
Pré-requisitos
Complete as etapas listadas nas seguintes tarefas: Como configurar arquivos de build.
Procedimento
- 
            Crie uma nova classe Java, clique com o botão direito do mouse no pacote com.automationanywhere.botcommand e selecione Nova > Classe Java. Digite o nome para a nova classe GetFileDetails.
            - 
                  Copie o @BotCommandde Concatenate. java e cole-o no novo arquivo GetFileDetails.java.import static com.automationanywhere.commandsdk.model.DataType.STRING; //BotCommand makes a class eligible for being considered as an action. @BotCommand //CommandPks adds required information to be dispalable on GUI. @CommandPkg( //Unique name inside a package and label to display. name = "concatenate", label = "[[Concatenate.label]]", node_label = "[[Concatenate.node_label]]", description = "[[Concatenate.description]]", icon = "pkg.svg", //Return type information. return_type ensures only the right kind of variable is provided on the UI. return_label = "[[Concatenate.return_label]]", return_type = STRING, return_required = true) public class Concatenate { //Messages read from full qualified property file name and provide i18n capability. private static final Messages MESSAGES = MessagesFactory .getMessages("com.automationanywhere.botcommand.samples.messages"); //Identify the entry point for the action. Returns a Value<String> because the return type is String. @Execute public Value<String> action( //Idx 1 would be displayed first, with a text box for entering the value. @Idx(index = "1", type = TEXT) //UI labels. @Pkg(label = "[[Concatenate.firstString.label]]") //Ensure that a validation error is thrown when the value is null. @NotEmpty String firstString, @Idx(index = "2", type = TEXT) @Pkg(label = "[[Concatenate.secondString.label]]") @NotEmpty String secondString) { //Internal validation, to disallow empty strings. No null check needed as we have NotEmpty on firstString. if ("".equals(firstString.trim())) throw new BotCommandException(MESSAGES.getString("emptyInputString", "firstString")); if ("".equals(secondString.trim())) throw new BotCommandException(MESSAGES.getString("emptyInputString", "secondString")); //Business logic String result = firstString + secondString; //Return StringValue. return new StringValue(result);
- 
                  Atualize os parâmetros @CommandPkg como: name,label,node_label,descriptioneicon.
- 
                  Atualize o return_labele oreturn_type.
- 
                  Adicione a ação NumberValue, validação interna, lógica comercial e o valor de retorno.
- Exclua o arquivo Concatenated. java, o diretório samples.commands. basic e o diretório sample.commands.
 
- 
                  Copie o 
- 
            Configure o arquivo en_US.json: acesse src > main > resources > locales > en_US.json, adicione os seguintes campos após os valores de rótulo e descrição e exclua outros parâmetros do arquivo.
            { "label": "File Details", "description": "Returns basic file details", "GetFileDetails.label": "File Size", "GetFileDetails.description": "Return the size of the selected file in bytes", "GetFileDetails.node_label": "File Size in Bytes", "GetFileDetails.return_label": "File Size", "GetFileDetails.return_label_description": "Return in bytes", "GetFileDetails.filePath.label": "Select a File for analysis" }
- Exclua os pacotes: acesse src > main > java > com.automationanyhwere.botcommand, exclua o samples.commands e exclua os pacotes samples.
- 
            Importe novos ícones do Github e atualize a anotação CommandPkg.
            - Baixe quaisquer ícones que você queira usar em seu fluxo de bots e salve-os como arquivos .svg.
- Copie ambos os arquivos na pasta src > main > resources > icons.
 
- 
            Crie um novo diretório: vá para srcclique com o botão direito, e selecione Novo > Diretório.
            - 
                  No campo Nome, digite test\java. Como alternativa, selecione o test\javae digite o nome TestFileSize.
- Configure anotações de teste na classe java TestFileSize.
- 
                  Crie uma classe pública @test, crie um objetoGetFileDetailse inicie a ação.
- Opcional: Execute o TestGetFileDetails no IntelliJ para testá-lo.
 
- 
                  No campo Nome, digite test\java. Como alternativa, selecione o 
- 
            Configure o arquivo TestFileSize, abra TestFileSize e copie e cole o seguinte código:
            { @Test public void TestGetFileDetails() { String filePath = "src\\main\\resources\\icons\\sample.svg"; //Create GetFileDetails Object GetFileDetails getFileDetails = new GetFileDetails(); //invoke action NumberValue output = getFileDetails.action(filePath); Assert.assertEquals(output.getAsDouble(), 5027.0); }
- Salve o projeto: Arquivo > Salvar tudo.
- Clique em Recarregar todos os projetos Gradlee depois clique em Executar tarefa Gradle e assegure que o projeto A2019FileDetails esteja selecionado.
- 
            Na janela Executar qualquer coisa, digite gradle clean build shadowJar.
            Após a execução, é exibida a seguinte mensagem: BUILD BEM SUCEDIDO em 8s <número de segundos>