text:
@interface ALCarouselViewModel ()

@property (strong, nonatomic) ALSdk* sdk;

@property (strong, nonatomic) NSArray*             nativeAds;
@property (strong, nonatomic) NSMutableDictionary* cardStates;

@end

@implementation ALCarouselViewModel
@dynamic nativeAdsCount;

static void* ALCarouselViewModelKVOContext = &ALCarouselViewModelKVOContext;
static NSString* kKeypathMuteState = @"muteState";

-(instancetype) initWithNativeAds: (NSArray *)ads
{
    self = [super init];
    if ( self )
    {
        self.nativeAds  = ads;
        self.cardStates = [NSMutableDictionary dictionary];
    }
    return self;
}

- (ALCarouselCardState *)cardStateAtNativeAdIndex:(NSUInteger)index
{
    if ( index >= [self nativeAdsCount])
    {
        ALLog(@"Requested card state at native ad index %lu is out-of-bounds", index);
        return nil;
    }
    else
    {
        ALCarouselCardState* cardState = self.cardStates[ @(index) ];
        if ( cardState )
        {
            ALLog(@"Requested card state at native ad index %lu", index);
            return cardState;
        }
        else
        {
            ALLog(@"Requested card state at native ad index %lu does not exist yet. Creating new card state", index);

            ALCarouselCardState* newState = [ALCarouselCardState cardStateForCarousel];
            [self beginObservingCardState: newState];
            [self.cardStates setObject: newState forKey: @(index)];

            return newState;
        }
    }
}

-(void) beginObservingCardState: (ALCarouselCardState*) cardState
{
    // Observe any properties which need to be synchronized among all card states.
    // E.g., propogate mute settings among cards while within a carousel view.
    // This allows us to add syncronization features on top of the card state without adding complexity for single card integrations.

    [cardState addObserver: self
                forKeyPath: kKeypathMuteState
                   options: NSKeyValueObservingOptionNew
                   context: ALCarouselViewModelKVOContext];
}

-(void) endObservingCardState: (ALCarouselCardState*) cardState
{
    // Observe any properties which need to be synchronized among all card states.
    // E.g., propogate mute settings among cards while within a carousel view.
    // This allows us to add syncronization features on top of the card state without adding complexity for single card integrations.

    @try {
        [cardState removeObserver: self
                       forKeyPath: kKeypathMuteState
                          context: ALCarouselViewModelKVOContext];
    }
    @catch (NSException* __unused ignore)
    {
    }
}

-(void) observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable id)object change:(nullable NSDictionary *)change context:(nullable void *)context
{
    if (context == ALCarouselViewModelKVOContext)
    {
        if ([keyPath isEqual: kKeypathMuteState])
        {
            NSNumber* newValue = change[NSKeyValueChangeNewKey];
            ALMuteState muteState = (ALMuteState) [newValue unsignedIntegerValue];

            if (muteState != ALMuteStateUnspecified)
            {
                [self updateMuteStates: muteState];
            }
        }
    }
    else
    {
        [super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
    }
}

-(void) updateMuteStates: (ALMuteState) newState
{
    [self.cardStates enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        ALCarouselCardState* cardState = (ALCarouselCardState*) obj;
        [self endObservingCardState: cardState];
        cardState.muteState = newState;
        [self beginObservingCardState: cardState];
    }];
}

- (ALCarouselCardState *)cardStateForNativeAd:(ALNativeAd *)ad
{
    NSUInteger index = [self.nativeAds indexOfObject: ad];
    if ( index != NSNotFound )
    {
        return [self cardStateAtNativeAdIndex: index];
    }
    else
    {
        return nil;
    }
}

- (ALNativeAd *)nativeAdAtIndex:(NSUInteger)index
{
    if ( index < self.nativeAds.count )
    {
        ALLog(@"Requested native ad index %lu", index);
        return [self.nativeAds objectAtIndex: index];
    }
    else
    {
        ALLog(@"Requested native ad index %lu is out of bounds", index);
        return nil;
    }
}

- (NSUInteger)nativeAdsCount
{
    return self.nativeAds.count;
}

-(void) removeAllObjects;
{
    self.nativeAds = nil;

    [self.cardStates enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
        ALCarouselCardState* cardState = (ALCarouselCardState*) obj;
        [self endObservingCardState: cardState];
    }];

    [self.cardStates removeAllObjects];
}

-(void) dealloc
{
    [self removeAllObjects];
}

@end


text:
package org.jbpm.runtime.manager.impl.migration;

import org.drools.core.command.SingleSessionCommandService;
import org.drools.core.command.impl.CommandBasedStatefulKnowledgeSession;
import org.drools.core.common.InternalKnowledgeRuntime;
import org.drools.persistence.api.SessionNotFoundException;
import org.drools.persistence.api.TransactionManager;
import org.drools.persistence.api.TransactionManagerFactory;
import org.jbpm.process.audit.JPAAuditLogService;
import org.jbpm.process.audit.ProcessInstanceLog;
import org.jbpm.runtime.manager.impl.jpa.EntityManagerFactoryManager;
import org.jbpm.runtime.manager.impl.migration.MigrationEntry.Type;
import org.jbpm.workflow.core.NodeContainer;
import org.jbpm.workflow.core.impl.NodeImpl;
import org.jbpm.workflow.core.node.HumanTaskNode;
import org.jbpm.workflow.instance.NodeInstanceContainer;
import org.jbpm.workflow.instance.impl.NodeInstanceImpl;
import org.jbpm.workflow.instance.impl.WorkflowProcessInstanceImpl;
import org.jbpm.workflow.instance.node.HumanTaskNodeInstance;
import org.kie.api.definition.process.Node;
import org.kie.api.definition.process.WorkflowProcess;
import org.kie.api.runtime.KieRuntime;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.process.NodeInstance;
import org.kie.api.runtime.process.ProcessInstance;
import org.kie.internal.persistence.jpa.JPAKnowledgeService;
import org.kie.internal.runtime.manager.InternalRuntimeManager;
import org.kie.internal.runtime.manager.RuntimeManagerRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Query;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * MigrationManager is responsible for updating all required components during process instance migration.
 * Each process instance should be have dedicated instance of the manager to allow simple execution model.
 * Each manager maintains MigrationReport that is constantly updated when migration is running.
 *
 * It comes with following migration entries (as part of the report)
 *

 *
INFO - written mostly for information about given migration step and its result

 *
WARN - not recommended operation performed though did not stop the migration

 *
ERROR - terminates the migration and restores to last state - before migration

 *

 * There could be at most single ERROR type of entry as first one that occurred terminates the migration.
 *
 * Migration is composed of two steps
 *

 *
validation - various checks to ensure migration can be performed to limit number of failed migrations

 *
migration - actual migration that changes state of the process instance and its index data - history logs

 *

 *
 * Migration can either be performed with or without node instance mapping. Node instance mapping allows to map nodes
 * only of the same type as it simply changes node reference of the node and does not replace the node instance
 * (by canceling current node and triggering new one).
 */
public class MigrationManager {

	private static final Logger logger = LoggerFactory.getLogger(MigrationManager.class);

	private MigrationReport report;
	private MigrationSpec migrationSpec;

	/**
	 * Creates new instance of MigrationManager with given migration specification.
	 * Migration specification will be validated upon call to {@link #migrate()} method
	 * @param migrationSpec definition of what needs to be migrated
	 */
	public MigrationManager(MigrationSpec migrationSpec) {
        this.report = new MigrationReport(migrationSpec);
        this.migrationSpec = migrationSpec;
    }

	/**
	 * Performs migration without node instance mapping
	 * @return returns migration report describing complete migration process.
	 */
	public MigrationReport migrate() {
	    return migrate(null);
	}

	/**
	 * Performs migration with node mapping (if non null).
	 * @param nodeMapping node instance mapping that is composed of unique ids of source node mapped to target node
	 * @return returns migration report describing complete migration process.
	 */
	public MigrationReport migrate(Map<String, String> nodeMapping) {

	    validate();
	    KieSession current = null;
        KieSession tobe = null;
	    TransactionManager txm = null;
	    boolean transactionOwner = false;
	    try {
			InternalRuntimeManager currentManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getDeploymentId());
			InternalRuntimeManager toBeManager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId());
			// start transaction to secure consistency of the migration
			txm = TransactionManagerFactory.get().newTransactionManager(currentManager.getEnvironment().getEnvironment());
			transactionOwner = txm.begin();

			org.kie.api.definition.process.Process toBeProcess = toBeManager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId());

			String auditPu = currentManager.getDeploymentDescriptor().getAuditPersistenceUnit();

			EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(auditPu);
			EntityManager em = emf.createEntityManager();

			try {
    	         // update variable instance log information with new deployment id and process id
                Query varLogQuery = em.createQuery("update VariableInstanceLog set externalId = :depId, processId = :procId where processInstanceId = :procInstanceId");
                varLogQuery
                    .setParameter("depId", migrationSpec.getToDeploymentId())
                    .setParameter("procId", migrationSpec.getToProcessId())
                    .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                int varsUpdated = varLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Variable instances updated = " + varsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

    			// update node instance log information with new deployment id and process id
    			Query nodeLogQuery = em.createQuery("update NodeInstanceLog set externalId = :depId, processId = :procId where processInstanceId = :procInstanceId");
    			nodeLogQuery
    				.setParameter("depId", migrationSpec.getToDeploymentId())
    				.setParameter("procId", migrationSpec.getToProcessId())
    				.setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

    			int nodesUpdated = nodeLogQuery.executeUpdate();
    			report.addEntry(Type.INFO, "Node instances updated = " + nodesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

    			// update process instance log with new deployment and process id
    			Query pInstanceLogQuery = em.createQuery("update ProcessInstanceLog set externalId = :depId, processId = :procId, processName = :procName, processVersion= :procVersion where processInstanceId = :procInstanceId");
    			pInstanceLogQuery
    				.setParameter("depId", migrationSpec.getToDeploymentId())
    				.setParameter("procId", migrationSpec.getToProcessId())
    				.setParameter("procName", toBeProcess.getName())
    				.setParameter("procVersion", toBeProcess.getVersion())
    				.setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

    			int pInstancesUpdated = pInstanceLogQuery.executeUpdate();
    			report.addEntry(Type.INFO, "Process instances updated = " + pInstancesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

    			try {
        	         // update task audit instance log with new deployment and process id
                    Query taskVarLogQuery = em.createQuery("update TaskVariableImpl set processId = :procId where processInstanceId = :procInstanceId");
                    taskVarLogQuery
                        .setParameter("procId", migrationSpec.getToProcessId())
                        .setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

                    int taskVarUpdated = taskVarLogQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Task variables updated = " + taskVarUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
    			} catch (Throwable e) {
    			    logger.warn("Unexpected error during migration", e);
    			    report.addEntry(Type.WARN, "Cannot update task variables (added in version 6.3) due to " + e.getMessage());
                }

    			// update task audit instance log with new deployment and process id
    			Query auditTaskLogQuery = em.createQuery("update AuditTaskImpl set deploymentId = :depId, processId = :procId where processInstanceId = :procInstanceId");
    			auditTaskLogQuery
    				.setParameter("depId", migrationSpec.getToDeploymentId())
    				.setParameter("procId", migrationSpec.getToProcessId())
    				.setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

    			int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
    			report.addEntry(Type.INFO, "Task audit updated = " + auditTaskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

    			// update task  instance log with new deployment and process id
    			Query taskLogQuery = em.createQuery("update TaskImpl set deploymentId = :depId, processId = :procId where processInstanceId = :procInstanceId");
    			taskLogQuery
    				.setParameter("depId", migrationSpec.getToDeploymentId())
    				.setParameter("procId", migrationSpec.getToProcessId())
    				.setParameter("procInstanceId", migrationSpec.getProcessInstanceId());

    			int taskUpdated = taskLogQuery.executeUpdate();
    			report.addEntry(Type.INFO, "Tasks updated = " + taskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());

    			try {
    				// update context mapping info with new deployment
    				Query contextInfoQuery = em.createQuery("update ContextMappingInfo set ownerId = :depId where contextId = :procInstanceId");
    				contextInfoQuery
    					.setParameter("depId", migrationSpec.getToDeploymentId())
    					.setParameter("procInstanceId", migrationSpec.getProcessInstanceId().toString());

    				int contextInfoUpdated = contextInfoQuery.executeUpdate();
    				report.addEntry(Type.INFO, "Context info updated = " + contextInfoUpdated+ " for process instance id " + migrationSpec.getProcessInstanceId());
    			} catch (Throwable e) {
    			    logger.warn("Unexpected error during migration", e);
    			    report.addEntry(Type.WARN, "Cannot update context mapping owner (added in version 6.2) due to " + e.getMessage());
    			}

    			current = JPAKnowledgeService.newStatefulKnowledgeSession(currentManager.getEnvironment().getKieBase(), null, currentManager.getEnvironment().getEnvironment());
    			tobe = JPAKnowledgeService.newStatefulKnowledgeSession(toBeManager.getEnvironment().getKieBase(), null, toBeManager.getEnvironment().getEnvironment());

    			upgradeProcessInstance(current, tobe, migrationSpec.getProcessInstanceId(), migrationSpec.getToProcessId(), nodeMapping, em, toBeManager.getIdentifier());

    			em.flush();
			} finally {
    			em.clear();
    			em.close();
			}

			txm.commit(transactionOwner);
			report.addEntry(Type.INFO, "Migration of process instance (" + migrationSpec.getProcessInstanceId() + ") completed successfully to process " + migrationSpec.getToProcessId());
			report.setSuccessful(true);
			report.setEndDate(new Date());
		} catch (Throwable e) {
		    txm.rollback(transactionOwner);
		    logger.error("Unexpected error during migration", e);
		    report.addEntry(Type.ERROR, "Migration of process instance (" + migrationSpec.getProcessInstanceId() + ") failed due to " + e.getMessage());
		} finally {
            if (current != null) {
                try {
                    current.destroy();
                } catch (SessionNotFoundException e) {
                    // in case of rollback session might not exist
                }
            }

            if (tobe != null) {

                try {
                    tobe.destroy();
                } catch (SessionNotFoundException e) {
                    // in case of rollback session might not exist
                }
            }
		}

		return report;
	}

    private void validate() {
        if (migrationSpec == null) {
            report.addEntry(Type.ERROR, "no process data given for migration");
            return;
        }
        // source (active) process instance information
        if (isEmpty(migrationSpec.getDeploymentId())) {
            report.addEntry(Type.ERROR, "No deployment id set");
        }
        if (migrationSpec.getProcessInstanceId() == null) {
            report.addEntry(Type.ERROR, "No process instance id set");
        }
        // target process information
        if (isEmpty(migrationSpec.getToDeploymentId())) {
            report.addEntry(Type.ERROR, "No target deployment id set");
        }
        if (isEmpty(migrationSpec.getToProcessId())) {
            report.addEntry(Type.ERROR, "No target process id set");
        }

        // verify if given runtime manager exists - registered under source deployment id
        if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getDeploymentId())) {
            report.addEntry(Type.ERROR, "No deployment found for " + migrationSpec.getDeploymentId());
        }
        // verify if given runtime manager exists - registered under target deployment id
        if (!RuntimeManagerRegistry.get().isRegistered(migrationSpec.getToDeploymentId())) {
            report.addEntry(Type.ERROR, "No target deployment found for " + migrationSpec.getToDeploymentId());
        }

        // verify if given target process id exists in target runtime manager
        InternalRuntimeManager manager = (InternalRuntimeManager) RuntimeManagerRegistry.get().getManager(migrationSpec.getToDeploymentId());
        if (manager.getEnvironment().getKieBase().getProcess(migrationSpec.getToProcessId()) == null) {
            report.addEntry(Type.ERROR, "No process found for " + migrationSpec.getToProcessId() + " in deployment " + migrationSpec.getToDeploymentId());
        }

        String auditPu = manager.getDeploymentDescriptor().getAuditPersistenceUnit();

        EntityManagerFactory emf = EntityManagerFactoryManager.get().getOrCreate(auditPu);

        JPAAuditLogService auditService = new JPAAuditLogService(emf);
        try {
            ProcessInstanceLog log = auditService.findProcessInstance(migrationSpec.getProcessInstanceId());
            if (log == null || log.getStatus() != ProcessInstance.STATE_ACTIVE) {
                 report.addEntry(Type.ERROR, "No process instance found or it is not active (id " + migrationSpec.getProcessInstanceId() + " in status " + (log == null?"-1":log.getStatus()));
            }
        } finally {
            auditService.dispose();
        }
    }

    private void upgradeProcessInstance(KieRuntime oldkruntime,
    		KieRuntime kruntime,
    		long processInstanceId,
    		String processId,
    		Map<String, String> nodeMapping, EntityManager em, String deploymentId) {
    	if (nodeMapping == null) {
    		nodeMapping = new HashMap<String, String>();
    	}
        WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) oldkruntime.getProcessInstance(processInstanceId);
        if (processInstance == null) {
            report.addEntry(Type.ERROR, "Could not find process instance " + processInstanceId);
        }
        if (processId == null) {
            report.addEntry(Type.ERROR, "Null process id");
        }
        WorkflowProcess process = (WorkflowProcess) kruntime.getKieBase().getProcess(processId);
        if (process == null) {
            report.addEntry(Type.ERROR, "Could not find process " + processId);
        }
        if (processInstance.getProcessId().equals(processId)) {
            report.addEntry(Type.WARN, "Source and target process id is exactly the same (" + processId + ") it's recommended to use unique process ids");
        }
        synchronized (processInstance) {
        	org.kie.api.definition.process.Process oldProcess = processInstance.getProcess();
	        processInstance.disconnect();
	        processInstance.setProcess(oldProcess);
	        updateNodeInstances(processInstance, nodeMapping, (NodeContainer) process, em);
	        processInstance.setKnowledgeRuntime((InternalKnowledgeRuntime) extractIfNeeded(kruntime));
	        processInstance.setDeploymentId(deploymentId);
	        processInstance.setProcess(process);
	        processInstance.reconnect();
		}
    }

    @SuppressWarnings("unchecked")
    private void updateNodeInstances(NodeInstanceContainer nodeInstanceContainer, Map<String, String> nodeMapping, NodeContainer nodeContainer, EntityManager em) {

        for (NodeInstance nodeInstance: nodeInstanceContainer.getNodeInstances()) {
            Long upgradedNodeId = null;
            String oldNodeId = (String) ((NodeImpl) ((org.jbpm.workflow.instance.NodeInstance) nodeInstance).getNode()).getMetaData().get("UniqueId");
            String newNodeId = nodeMapping.get(oldNodeId);
            if (newNodeId == null) {
                newNodeId = oldNodeId;
            }
            Node upgradedNode = findNodeByUniqueId(newNodeId, nodeContainer);
            if (upgradedNode == null) {
            	try {
            		upgradedNodeId = Long.parseLong(newNodeId);
            	} catch (NumberFormatException e) {
            		continue;
            	}
            } else {
                upgradedNodeId = upgradedNode.getId();
            }

            ((NodeInstanceImpl) nodeInstance).setNodeId(upgradedNodeId);

            if (upgradedNode != null) {
                // update log information for new node information
                Query nodeInstanceIdQuery = em.createQuery("select nodeInstanceId from NodeInstanceLog nil" +
                        " where nil.nodeId = :oldNodeId and processInstanceId = :processInstanceId " +
                        " GROUP BY nil.nodeInstanceId" +
                        " HAVING sum(nil.type) = 0");
                nodeInstanceIdQuery
                    .setParameter("oldNodeId", oldNodeId)
                    .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());

                List<Long> nodeInstanceIds = nodeInstanceIdQuery.getResultList();
                report.addEntry(Type.INFO, "Mapping: Node instance logs to be updated  = " + nodeInstanceIds);

                Query nodeLogQuery = em.createQuery("update NodeInstanceLog set nodeId = :nodeId, nodeName = :nodeName, nodeType = :nodeType "
                        + "where nodeInstanceId in (:ids) and processInstanceId = :processInstanceId");
                nodeLogQuery
                    .setParameter("nodeId", (String) upgradedNode.getMetaData().get("UniqueId"))
                    .setParameter("nodeName", upgradedNode.getName())
                    .setParameter("nodeType", upgradedNode.getClass().getSimpleName())
                    .setParameter("ids", nodeInstanceIds)
                    .setParameter("processInstanceId", nodeInstance.getProcessInstance().getId());

                int nodesUpdated = nodeLogQuery.executeUpdate();
                report.addEntry(Type.INFO, "Mapping: Node instance logs updated = " + nodesUpdated + " for node instance id " + nodeInstance.getId());

                if (upgradedNode instanceof HumanTaskNode && nodeInstance instanceof HumanTaskNodeInstance) {

                    Long taskId = (Long) em.createQuery("select id from TaskImpl where workItemId = :workItemId")
                                                        .setParameter("workItemId", ((HumanTaskNodeInstance) nodeInstance).getWorkItemId())
                                                        .getSingleResult();
                    String name = ((HumanTaskNode) upgradedNode).getName();
                    String description = (String)((HumanTaskNode) upgradedNode).getWork().getParameter("Description");

                    // update task audit instance log with new deployment and process id
                    Query auditTaskLogQuery = em.createQuery("update AuditTaskImpl set name = :name, description = :description where taskId = :taskId");
                    auditTaskLogQuery
                        .setParameter("name", name)
                        .setParameter("description", description)
                        .setParameter("taskId", taskId);

                    int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Mapping: Task audit updated = " + auditTaskUpdated + " for task id " + taskId);

                    // update task  instance log with new deployment and process id
                    Query taskLogQuery = em.createQuery("update TaskImpl set name = :name, description = :description where id = :taskId");
                    taskLogQuery
                    .setParameter("name", name)
                    .setParameter("description", description)
                    .setParameter("taskId", taskId);

                    int taskUpdated = taskLogQuery.executeUpdate();
                    report.addEntry(Type.INFO, "Mapping: Task updated = " + taskUpdated + " for task id " + taskId);

                }
            }

            if (nodeInstance instanceof NodeInstanceContainer) {
            	updateNodeInstances((NodeInstanceContainer) nodeInstance, nodeMapping, nodeContainer, em);
            }
        }

    }

    private Node findNodeByUniqueId(String uniqueId, NodeContainer nodeContainer) {
    	Node result = null;

    	for (Node node : nodeContainer.getNodes()) {
    		if (uniqueId.equals(node.getMetaData().get("UniqueId"))) {
    			return node;
    		}
    		if (node instanceof NodeContainer) {
    			result = findNodeByUniqueId(uniqueId, (NodeContainer) node);
    			if (result != null) {
    				return result;
    			}
    		}
    	}

    	return result;
    }

    private  KieRuntime extractIfNeeded(KieRuntime ksession) {
    	if (ksession instanceof CommandBasedStatefulKnowledgeSession) {
    		return ((SingleSessionCommandService)((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession();
    	}

    	return ksession;
    }

	private boolean isEmpty(String value) {
		if (value == null || value.isEmpty()) {
			return true;
		}

		return false;
	}
}

redpajama_set_name: RedPajamaGithub


text:
QUERY_CHOOSER_MODAL_ONLOAD_HANDLERS = {
  chooser: function (modal, jsonData) {
    function ajaxifyLinks(context) {
      $('.listing a.choose-query', context).on('click', chooseQuery);

      $('.pagination a', context).on('click', function () {
        var page = this.getAttribute('data-page');
        setPage(page);
        return false;
      });
    }

    var searchUrl = $('form.query-search', modal.body).attr('action');
    var request;

    function search() {
      request = $.ajax({
        url: searchUrl,
        data: { q: $('#id_q').val() },
        success: function (data, status) {
          request = null;
          $('#query-results').html(data);
          ajaxifyLinks($('#query-results'));
        },
        error: function () {
          request = null;
        },
      });
      return false;
    }
    function setPage(page) {
      var dataObj;

      if ($('#id_q').val().length) {
        dataObj = { q: $('#id_q').val(), p: page };
      } else {
        dataObj = { p: page };
      }

      request = $.ajax({
        url: searchUrl,
        data: dataObj,
        success: function (data, status) {
          request = null;
          $('#query-results').html(data);
          ajaxifyLinks($('#query-results'));
        },
        error: function () {
          request = null;
        },
      });
      return false;
    }
    function chooseQuery() {
      modal.respond('queryChosen', $(this).data());
      modal.close();

      return false;
    }

    ajaxifyLinks(modal.body);

    $('form.query-search', modal.body).on('submit', search);

    $('#id_q').on('input', function () {
      if (request) {
        request.abort();
      }
      clearTimeout($.data(this, 'timer'));
      var wait = setTimeout(search, 200);
      $(this).data('timer', wait);
    });
  },
};


text:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { intlShape } from 'react-intl';
import { Field, reduxForm } from 'redux-form';
import { TextField } from 'redux-form-material-ui';
import { AvatarImageField } from '../ReduxFormFields';
import ReactList from 'react-list';
import {List} from 'material-ui/List';
import Toggle from 'material-ui/Toggle';
import Subheader from 'material-ui/Subheader';

class UserForm extends Component {

  render() {
    const {
      handleSubmit,
      intl,
      initialized,
      uid,
      renderRoleItem,
      roles,
      handleAdminChange,
      isAdmin
    } = this.props;

    return (
      <form onSubmit={handleSubmit} style={{
        height: '100%',
        alignItems: 'strech',
        display: 'flex',
        flexWrap: 'wrap',
        justifyContent: 'flex-start'
      }}>
      <button type="submit" style={{display: 'none'}} />

        <AvatarImageField
          disabled={true}
          uid={uid}
          change={this.props.change}
          initialized={initialized}
          intl={intl}
          path={'users'}
        />

          <Field
            name="displayName"
            disabled={true}
            component={TextField}
            hintText={intl.formatMessage({id: 'name_hint'})}
            floatingLabelText={intl.formatMessage({id: 'name_label'})}
            ref="displayName"
            withRef
          />

          <Field
            name="email"
            disabled={true}
            component={TextField}
            hintText={intl.formatMessage({id: 'email_hint'})}
            floatingLabelText={intl.formatMessage({id: 'email_label'})}
            ref="email"
            withRef
          />

          <Toggle
            label={intl.formatMessage({id: 'is_admin_label'})}
            toggled={isAdmin}
            onToggle={handleAdminChange}
          />

        <Subheader>{intl.formatMessage({id: 'roles'})}</Subheader>
        <List style={{height: '100%'}} ref={(field) => { this.roles = field; }}>
          <ReactList
            itemRenderer={renderRoleItem}
            length={roles?roles.length:0}
            type='simple'
          />
        </List>

    </form>
  );
}
}

UserForm.propTypes = {
  handleSubmit: PropTypes.func.isRequired,
  renderRoleItem: PropTypes.func.isRequired,
  renderTerminalNotifierItem: PropTypes.func.isRequired,
  handleAdminChange: PropTypes.func.isRequired,
  isAdmin: PropTypes.bool.isRequired,
  intl: intlShape.isRequired,
  initialized: PropTypes.bool.isRequired,
  setDialogIsOpen: PropTypes.any.isRequired,
  uid: PropTypes.string.isRequired,
};

export default reduxForm({form: 'user'})(UserForm);


text:
*"Lasciate ogni speranza, voi ch'entrate."*

# easiOS
easiOS is an in-development operating system for x86.

![Screenshot of 0.3.12](https://raw.githubusercontent.com/easiOS/docs/master/art/screenshot.png)

## Features
* Multi-user
* Cooperative software multitasking
* Keyboard oriented window manager with design inspired by the AESTHETICS of Windows 2000
* Lua 5.1 bytecode as executable
* Multiboot2 compliant

## How to build
### Requirements:
* GCC cross-compiler for i686 ELF (i686-elf-gcc)
* Netwide Assembler (nasm)
* Python 3
* GRUB2 (optional, for building ISO)

1. Download source code (git clone, tarball, etc.)
2. Make a build directory somewhere
3. Generate project files using CMake into the build directory
4. Build the project
5. (Optional) Run biso.py to generate ISO file

## How to run
### Requirements:
* Multiboot2 compatible bootloader (syslinux, grub2, etc.)
* x86 PC: CPU with SSE or better (Pentium 3 or better recommended), 256MB memory or more

### In a virtual Machine
1. Build easiOS like described above
2. Mount the ISO (found in the root directory of the source) in the VM
3. Run the VM

### On a real machine
1. Build easiOS like described above
2. Copy easios.bin from root directory of the source to your boot directory
3. Add an entry for easiOS in your bootloader's config files (sample for GRUB2 included in /iso/boot/grub/grub.cfg)

## What works
* Single-user mode
* Cooperative software multitasking
* Window manager (needs optimization)
* PS/2 Keyboard & Mouse
* Serial port communication
* PIT
* Memory management
* Graphical mode and drawing
* File I/O on FAT32 partitions (MBR, GPT supported), running Lua bytecode from disk
* Network stack (ARP works, can reply to ping)

## Supported devices

### Functioning
* PS/2 Keyboard
* Serial ports
* PIT
* Virtualbox Graphics Adapter (modesetting works)
* IDE disks
* Intel Ethernet i217 (e1000) and every compatible ethernet card

### Non-functioning
* PS/2 Mouse (actually, works but glitchy af)
* ATI RV100 gfx card (PCI)
* NE2000 ethernet card (PCI)
* PCNET32 ethernet card (PCI)
* VirtIO Network Device (PCI)
* USB Enhanced Host Controller Interface (PCI)

## How multitasking works
Every window has (as of v0.3.3) 5 callbacks: load, unload, update, event, draw. Load is called after the window is
spawned, unload is called before the window is destroyed. The window manager calls event and update for every window in
the main loop. The event callback handles keyboard and mouse events. In update, the program does things like calculations.
In draw, the window should not do anything other than drawing, as draw is only called for the current active window.


text:
'use strict';
/**
 * @ngdoc function
 * @name sbAdminApp.controller:MainCtrl
 * @description
 * # MainCtrl
 * Controller of the sbAdminApp

angular.module('sbAdminApp')
  .controller('MainCtrl', ['$scope', '$position', 'Autenticacao', function($scope,$position,Autenticacao) {

	function MainCtrls($scope, Autenticacao) {

	  	var vm.this;

		vm.logout = logout;

		function logout() {
			Autenticacao.logout();
		}

  }]);
*/

angular
		.module('sbAdminApp')
		.controller('MainCtrl', MainCtrl);

	MainCtrl.$inject = ['$scope', '$position', 'Autenticacao'];

	function MainCtrl($scope, $position, Autenticacao) {

		var vm = this;

		vm.logout = logout;

		function logout() {
			Autenticacao.logout();
		}
	}


text:
package org.popper.fw.webdriver.elements;

import org.popper.fw.element.IFileupload;

/**
 * Interfaces describing the function a fileupload must provide
 * @author Michael
 *
 */
public interface IWebFileupload extends IWebInput, IFileupload {
}