class AppcOrchestratorPreProcessor {

    public void addVmInfoToAppcTaskRequest(BuildingBlockExecution execution) {
        try {
            ApplicationControllerTaskRequest appcTaskRequest =
                    (ApplicationControllerTaskRequest) execution.getVariable("appcOrchestratorRequest");
            ArrayList<String> vmIdList = execution.getVariable("vmIdList");
            ArrayList<String> vserverIdList = execution.getVariable("vserverIdList");
            Integer vmIndex = (Integer) execution.getVariable("vmIndex");

            if (vmIdList != null && !vmIdList.isEmpty() && vserverIdList != null && !vserverIdList.isEmpty()) {
                execution.setVariable("vmIdListSize", vmIdList.size());
                if (vmIndex < vmIdList.size()) {
                    ApplicationControllerVm applicationControllerVm = new ApplicationControllerVm();
                    applicationControllerVm.setVmId(vmIdList.get(vmIndex));
                    applicationControllerVm.setVserverId(vserverIdList.get(vmIndex));
                    if (appcTaskRequest.getApplicationControllerVnf() == null) {
                        ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
                        appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf);
                    }
                    appcTaskRequest.getApplicationControllerVnf().setApplicationControllerVm(applicationControllerVm);
                    execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
                    vmIndex++;
                    execution.setVariable("vmIndex", vmIndex);
                }
            }
        } catch (Exception e) {
            logger.error("Error adding VM info to ApplicationControllerTaskRequest Object", e);
            exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
        }
    }

}