Package SDK를 사용하여 공유 세션 구성

Package SDK는 SDK 사용자가 공유 세션을 만들고 사용할 수 있도록 구성을 제공합니다. 세션은 서로 다른 Bot 간에 원활하게 공유되어 리소스를 공유합니다. 따라서 한 세션이 생성된 경우 다른 Task Bot이 세션을 읽고 업데이트할 수 있으며, 그 반대의 경우도 마찬가지입니다.

상위 및 하위 간의 세션 공유

다음 섹션에서는 공유 세션 생성에 대해 설명합니다. 상위 GlobalSessionDemoUpperCaseParent세션 값을 글로벌 세션에 반환하고 하위 Bot GlobalSessionDemoUpperCaseChild에 의해 사용됩니다.
주: 아래의 세 가지 클래스를 다음 위치에 배치합니다. <PackageSDK>\src\main\java\com\automationanywhere\botcommand\samples\commands\basic
  1. CloseableSessionObject를 구현하는 POJO 클래스 DemoForSession을 만듭니다.

    package com.automationanywhere.botcommand.samples.commands.basic.GlobalSessionSampleProject;
    
    import com.automationanywhere.toolchain.runtime.session.CloseableSessionObject;
    
    import java.io.IOException;
    
    public class DemoForSession implements CloseableSessionObject
    {
        public void setClose(boolean close) {
            this.close = close;
        }
    
        boolean close=false;
        public String getDemo() {
            return demo;
        }
    
        public void setDemo(String demo) {
            this.demo = demo;
        }
        public DemoForSession(String demo){
            this.demo=demo;
        }
        String demo;
    
        @Override
        public boolean isClosed() {
            return close;
        }
    
        @Override
        public void close() throws IOException {
    
        }
    }
    
  2. @BotCommand 주석을 추가하여 클래스를 Control Room의 작업으로 만듭니다. 주석에 대한 자세한 정보는 라벨의 내용을 참조하십시오.
    @BotCommand
  3. @CommandPkg 주석을 추가하여 모든 UI 관련 컴포넌트(labels, description , icon, return_type, name)를 정의합니다. @CommandPkg에 속하는 return_label, return_settings, return_typereturn_required 요소는 세션이 상위 Bot에서 반환되도록 합니다.
    @CommandPkg(
    		//Unique name inside a package and label to display.
    		name = "GlobalSession", label = "Global session uppercase parent",
    		node_label = "Shared session parent node label", description = "Shared session parent description", icon = "pkg.svg",
    		
    		//Return type information. return_type ensures only the right kind of variable is provided on the UI. 
    		return_label = "Return the parent session",
    		return_settings = {ReturnSettingsType.SESSION_TARGET},
    		return_type = SESSION,
    		return_required = true)
  4. GlobalSessionDemoUpperCaseParent 객체를 만듭니다. GlobalSessionDemoUpperCaseParent는 작업 입력에서 소문자 문자열 입력을 가져오고, 이를 대문자 문자열로 변환한 다음 결과를 SessionValue에 저장합니다.

    • 컴파일 도중 메서드를 실행하려면 메서드에 @Execute 주석을 추가합니다.

      package com.automationanywhere.botcommand.samples.commands.basic.GlobalSessionSampleProject;
      
      import com.automationanywhere.botcommand.data.impl.SessionValue;
      import com.automationanywhere.commandsdk.annotations.*;
      import com.automationanywhere.commandsdk.annotations.rules.NotEmpty;
      import com.automationanywhere.commandsdk.model.ReturnSettingsType;
      import org.apache.logging.log4j.LogManager;
      import org.apache.logging.log4j.Logger;
      
      import java.util.Map;
      
      import static com.automationanywhere.commandsdk.model.AttributeType.TEXT;
      import static com.automationanywhere.commandsdk.model.DataType.SESSION;
      
      
      //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 = "GlobalSession", label = "Global session uppercase parent",
      		node_label = "Shared session parent node label", description = "Shared session parent description", icon = "pkg.svg",
      		
      		//Return type information. return_type ensures only the right kind of variable is provided on the UI. 
      		return_label = "Return the parent session",
      		return_settings = {ReturnSettingsType.SESSION_TARGET},
      		return_type = SESSION,
      		return_required = true)
      public class GlobalSessionDemoForStringUpperCaseParent {
      	private static Logger logger = LogManager.getLogger(GlobalSessionDemoForStringUpperCaseParent.class);
      
      	//Identify the entry point for the action. Returns a SessionValue because the return_type is SESSION. 
      	@Execute
      	public SessionValue action(
      			//Idx 1 would be displayed first, with a text box for entering the value.
      			@Idx(index = "1", type = TEXT) 
      			//UI labels.
      			@Pkg(label = "Enter string in lower case")
      			//Ensure that a validation error is thrown when the value is null.
      			@NotEmpty 
      			String firstString) {
      		String result = firstString.toUpperCase();
      		DemoForSession demoForSession= new DemoForSession(result);
      		return SessionValue
      				.builder()
      				.withSessionObject(demoForSession)
      				.build();
      	}
      }
  5. GlobalSessionDemoUpperCaseChild 객체를 만듭니다. GlobalSessionDemoUpperCaseChild는 작업 입력에서 소문자 문자열 입력을 가져오고, 이를 대문자로 변환한 다음 이를 상위 Bot에서 받은 SessionValue와 연결합니다.

    package com.automationanywhere.botcommand.samples.commands.basic.GlobalSessionSampleProject;
    
    import com.automationanywhere.botcommand.data.Value;
    import com.automationanywhere.botcommand.data.impl.StringValue;
    import com.automationanywhere.botcommand.samples.commands.basic.Uppercase;
    import com.automationanywhere.commandsdk.annotations.*;
    import com.automationanywhere.commandsdk.annotations.rules.NotEmpty;
    import com.automationanywhere.commandsdk.annotations.rules.SessionObject;
    import com.automationanywhere.commandsdk.model.AttributeType;
    import com.automationanywhere.commandsdk.model.DataType;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    
    import static com.automationanywhere.commandsdk.model.AttributeType.TEXT;
    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 = "GlobalSessionChild", label = "Global session upper case child",
    		node_label = "Global session child node label",
    		description = "Global session child description", icon = "pkg.svg",
    		
    		//Return type information. return_type ensures only the right kind of variable is provided on the UI. 
    		return_label = "Return the concatenated string to", return_type = STRING, return_required = true)
    public class GlobalSessionDemoUpperCaseChild {
    	private static Logger logger = LogManager.getLogger(Uppercase.class);
    	
    	@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 = "Enter a sting in lower case to concatenate")
    			//Ensure that a validation error is thrown when the value is null.
    			@NotEmpty 
    			String sourceString,
    			@Idx(index = "2", type = AttributeType.SESSION)
    			@Pkg(label = "sharedSession", description = "sharedSession",
    					default_value = "Default", default_value_type = DataType.SESSION)
    			//Using the sessionObject annotation here as its a consumer class
    					@SessionObject
    					DemoForSession session) {
    
    		//Business logic
    		String result = sourceString.toUpperCase();
    		logger.info("session: {}",session);
    		return new StringValue(result+session.getDemo().toUpperCase());
    	}
    }
  6. 사용자 지정 패키지를 빌드하고 Control Room에 업로드합니다. 패키지 업로드에 대한 자세한 정보는 Package SDK 사용 안내의 내용을 참조하십시오.
  7. Global session uppercase parent 작업을 사용하여 Bot을 생성합니다.
    1. 소문자 문자열을 입력합니다(예: parentbot string).
    2. 세션의 고유한 이름을 입력합니다. 상위 Bot은 글로벌 세션에 값을 반환합니다(예: Global)
  8. Global session upper case child 작업을 사용하여 Task Bot을 생성합니다. 소문자 문자열을 입력하고 공유 상위 세션에서 문자열을 가져올 수도 있습니다. 상위 문자열과 하위 문자열을 연결합니다.
  9. 메시지 상자를 사용하여 출력을 표시합니다.

    Variable SDK 데모를 보여주는 이미지

  10. 이제 Global session upper case child를 상위에 호출합니다. Variable SDK 데모를 보여주는 이미지
  11. 상위 Bot을 실행하면 공유 글로벌 세션을 사용하여 파생된 하위 Bot의 값을 보여주는 메시지 상자가 표시됩니다.