Search in sources :

Example 1 with Assignments

use of org.whole.lang.workflows.model.Assignments in project whole by wholeplatform.

the class WorkflowsIDEInterpreterVisitor method visit.

@Override
public void visit(Task entity) {
    entity.getLabel().accept(this);
    String title = PrettyPrinterOperation.toPrettyPrintString(getResult());
    entity.getDescription().accept(this);
    String description = PrettyPrinterOperation.toPrettyPrintString(getResult());
    Assignments assignments = EntityUtils.clone(entity.getAssignments());
    Variable factoryVariable = entity.getFactory();
    ITaskDialogFactory factory;
    if (EntityUtils.isNotResolver(factoryVariable)) {
        factoryVariable.accept(this);
        factory = (ITaskDialogFactory) getResultValue();
    } else if (EntityUtils.isNotResolver(assignments)) {
        factory = AssignmentsDialogFactory.instance();
    } else
        factory = ConfirmationDialogFactory.instance();
    if (EntityUtils.isNotResolver(assignments)) {
        stagedVisit(assignments, 1);
        assignments = (Assignments) getResult();
    }
    if (!TaskDialogHelper.showTaskDialog(factory, title, description, assignments, getBindings()))
        throw new OperationCanceledException(new VisitException("task not completed: " + description));
    assignments.accept(this);
}
Also used : ITaskDialogFactory(org.whole.lang.workflows.ui.dialogs.ITaskDialogFactory) Variable(org.whole.lang.workflows.model.Variable) OperationCanceledException(org.whole.lang.operations.OperationCanceledException) VisitException(org.whole.lang.visitors.VisitException) Assignments(org.whole.lang.workflows.model.Assignments)

Example 2 with Assignments

use of org.whole.lang.workflows.model.Assignments in project whole by wholeplatform.

the class WorkflowsInterpreterVisitor method visit.

@Override
public void visit(CreateEntity entity) {
    try {
        entity.getEntityName().accept(this);
        String typeName = getResultString();
        EntityDescriptor<?> ed = CommonsDataTypePersistenceParser.parseEntityDescriptor(typeName);
        if (ed == null)
            throw new WholeIllegalArgumentException("The requested entity does not exist: " + typeName).withSourceEntity(entity).withBindings(getBindings());
        IEntityRegistryProvider provider = null;
        switch(entity.getRegistry().getValue().getOrdinal()) {
            case RegistryEnum.DEFAULT_ord:
                provider = RegistryConfigurations.DEFAULT;
                break;
            case RegistryEnum.RESOLVER_ord:
                provider = RegistryConfigurations.RESOLVER;
                break;
            case RegistryEnum.ADAPTER_ord:
                provider = RegistryConfigurations.ADAPTER;
                break;
            case RegistryEnum.STRICT_ord:
                provider = RegistryConfigurations.STRICT;
                break;
            case RegistryEnum.CUSTOM_ord:
                provider = RegistryConfigurations.CUSTOM;
                break;
        }
        IEntityFactory ef = GenericEntityFactory.instance(provider);
        IEntity model;
        Arguments arguments = entity.getArguments();
        if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Assignments, arguments)) {
            ITransactionScope resettableScope = BindingManagerFactory.instance.createTransactionScope();
            getBindings().wEnterScope(resettableScope);
            arguments.accept(this);
            for (int i = 0; i < arguments.wSize(); i++) {
                String name = ((Assignments) arguments).get(i).getName().getValue();
                FeatureDescriptor fd = ed.getFeatureDescriptorEnum().valueOf(name);
                if (fd != null)
                    getBindings().wDef(name, EntityUtils.convertCloneIfReparenting(getBindings().wGet(name), ed.getEntityFeatureDescriptor(fd)));
            }
            model = ef.create(ed, getBindings());
            resettableScope.rollback();
            getBindings().wExitScope();
        } else if (Matcher.matchImpl(WorkflowsEntityDescriptorEnum.Expressions, arguments)) {
            IEntity selfEntity = getBindings().wGet("self");
            if (ed.getEntityKind().isData()) {
                ((Expressions) arguments).get(0).accept(this);
                model = DataTypeUtils.convertCloneIfParented(getResult(), ed);
                resetSelfEntity(selfEntity);
            } else {
                IEntity[] values = new IEntity[arguments.wSize()];
                for (int i = 0; i < values.length; i++) {
                    ((Expressions) arguments).get(i).accept(this);
                    values[i] = EntityUtils.convertCloneIfReparenting(getResult(), ed.getEntityFeatureDescriptor(i));
                    resetSelfEntity(selfEntity);
                }
                model = ef.create(ed, values);
            }
        } else
            model = ef.create(ed);
        setResult(entity.getModel(), model);
    } catch (Exception e) {
        throw IWholeRuntimeException.asWholeException(e, entity, getBindings());
    }
}
Also used : ITransactionScope(org.whole.lang.bindings.ITransactionScope) IEntity(org.whole.lang.model.IEntity) IEntityFactory(org.whole.lang.factories.IEntityFactory) Arguments(org.whole.lang.workflows.model.Arguments) Assignments(org.whole.lang.workflows.model.Assignments) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) MissingVariableException(org.whole.lang.visitors.MissingVariableException) IOException(java.io.IOException) IWholeRuntimeException(org.whole.lang.exceptions.IWholeRuntimeException) VisitException(org.whole.lang.visitors.VisitException) ParseException(org.whole.lang.parsers.ParseException) WholeIllegalArgumentException(org.whole.lang.exceptions.WholeIllegalArgumentException) FeatureDescriptor(org.whole.lang.reflect.FeatureDescriptor) IEntityRegistryProvider(org.whole.lang.factories.IEntityRegistryProvider) Expressions(org.whole.lang.workflows.model.Expressions)

Aggregations

VisitException (org.whole.lang.visitors.VisitException)2 Assignments (org.whole.lang.workflows.model.Assignments)2 IOException (java.io.IOException)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 IWholeRuntimeException (org.whole.lang.exceptions.IWholeRuntimeException)1 WholeIllegalArgumentException (org.whole.lang.exceptions.WholeIllegalArgumentException)1 IEntityFactory (org.whole.lang.factories.IEntityFactory)1 IEntityRegistryProvider (org.whole.lang.factories.IEntityRegistryProvider)1 IEntity (org.whole.lang.model.IEntity)1 OperationCanceledException (org.whole.lang.operations.OperationCanceledException)1 ParseException (org.whole.lang.parsers.ParseException)1 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)1 MissingVariableException (org.whole.lang.visitors.MissingVariableException)1 Arguments (org.whole.lang.workflows.model.Arguments)1 Expressions (org.whole.lang.workflows.model.Expressions)1 Variable (org.whole.lang.workflows.model.Variable)1 ITaskDialogFactory (org.whole.lang.workflows.ui.dialogs.ITaskDialogFactory)1