001/* 002 * Copyright 2025 devteam@scivicslab.com 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, 011 * software distributed under the License is distributed on an 012 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the 014 * specific language governing permissions and limitations 015 * under the License. 016 */ 017 018package com.scivicslab.actoriac.report.sections.basic; 019 020import com.scivicslab.pojoactor.core.Action; 021import com.scivicslab.pojoactor.core.ActionResult; 022import com.scivicslab.pojoactor.workflow.IIActorRef; 023import com.scivicslab.pojoactor.workflow.IIActorSystem; 024 025/** 026 * IIAR wrapper for {@link WorkflowFileSection}. 027 * 028 * <p>Exposes the POJO's methods as actions via {@code @Action} annotations.</p> 029 * 030 * <h2>Usage in workflow YAML:</h2> 031 * <pre>{@code 032 * - actor: loader 033 * method: createChild 034 * arguments: ["reportBuilder", "wfFile", "...WorkflowFileSectionIIAR"] 035 * }</pre> 036 * 037 * @author devteam@scivicslab.com 038 * @since 2.16.0 039 */ 040public class WorkflowFileSectionIIAR extends IIActorRef<WorkflowFileSection> { 041 042 /** 043 * Constructs the IIAR with a new POJO instance. 044 * 045 * @param actorName the actor name 046 * @param system the actor system 047 */ 048 public WorkflowFileSectionIIAR(String actorName, IIActorSystem system) { 049 super(actorName, new WorkflowFileSection(), system); 050 initializeFromWorkflow(); 051 } 052 053 /** 054 * Initializes the POJO with workflow information from nodeGroup. 055 */ 056 private void initializeFromWorkflow() { 057 String workflowPath = getWorkflowPath(); 058 if (workflowPath != null) { 059 object.setWorkflowPath(workflowPath); 060 } 061 } 062 063 private String getWorkflowPath() { 064 if (actorSystem == null || !(actorSystem instanceof IIActorSystem)) return null; 065 IIActorSystem iiSystem = (IIActorSystem) actorSystem; 066 067 IIActorRef<?> nodeGroup = iiSystem.getIIActor("nodeGroup"); 068 if (nodeGroup == null) return null; 069 070 ActionResult result = nodeGroup.callByActionName("getWorkflowPath", ""); 071 return result.isSuccess() ? result.getResult() : null; 072 } 073 074 // ======================================================================== 075 // Actions - expose POJO methods 076 // ======================================================================== 077 078 @Action("generate") 079 public ActionResult generate(String args) { 080 String content = object.generate(); 081 return new ActionResult(true, content); 082 } 083 084 @Action("getTitle") 085 public ActionResult getTitle(String args) { 086 String title = object.getTitle(); 087 return new ActionResult(true, title != null ? title : ""); 088 } 089}