Search in sources :

Example 1 with ResourceAction

use of com.liferay.ide.kaleo.core.model.ResourceAction in project liferay-ide by liferay.

the class KaleoModelUtil method changeTaskAssignments.

public static void changeTaskAssignments(Task task, AssignableOp op) {
    if ((task == null) || (op == null)) {
        return;
    }
    ElementHandle<User> user = task.getUser();
    user.clear();
    ElementHandle<Scriptable> scripteAssignment = task.getScriptedAssignment();
    scripteAssignment.clear();
    ElementList<ResourceAction> resourceAction = task.getResourceActions();
    resourceAction.clear();
    ElementList<Role> taskRole = task.getRoles();
    taskRole.clear();
    switch(op.getAssignmentType().content(true)) {
        case CREATOR:
            user.content(true);
            break;
        case USER:
            User content = user.content(true);
            content.copy(op.getImpliedUser());
            break;
        case ROLE:
            final Role newRole = taskRole.insert();
            newRole.copy(op.getImpliedRole());
            break;
        case ROLE_TYPE:
            for (Role role : op.getRoles()) {
                Role newRoleType = taskRole.insert();
                newRoleType.copy(role);
                Value<RoleType> roleType = role.getRoleType();
                newRoleType.setRoleType(roleType.content(true));
                Value<Boolean> autoCreate = role.getAutoCreate();
                if (autoCreate.content() != null) {
                    newRoleType.setAutoCreate(autoCreate.content());
                }
            }
            break;
        case SCRIPTED_ASSIGNMENT:
            Scriptable scriptable = scripteAssignment.content(true);
            Scriptable impliedScriptable = op.getImpliedScriptable();
            Value<ScriptLanguageType> scriptLanguageType = impliedScriptable.getScriptLanguage();
            scriptable.setScriptLanguage(scriptLanguageType.content(true));
            scriptable.setScript("/*specify script assignment */");
            break;
        case RESOURCE_ACTIONS:
            for (ResourceAction ra : op.getResourceActions()) {
                ResourceAction newResourceAction = resourceAction.insert();
                newResourceAction.copy(ra);
            }
            break;
    }
}
Also used : User(com.liferay.ide.kaleo.core.model.User) RoleType(com.liferay.ide.kaleo.core.model.RoleType) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) Role(com.liferay.ide.kaleo.core.model.Role) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Example 2 with ResourceAction

use of com.liferay.ide.kaleo.core.model.ResourceAction in project liferay-ide by liferay.

the class ChangeTaskAssignmentsActionHandler method run.

@Override
protected Object run(Presentation context) {
    Task task = _task(context);
    ChangeTaskAssignmentsOp op = ChangeTaskAssignmentsOp.TYPE.instantiate();
    for (WorkflowNode node : task.nearest(WorkflowDefinition.class).getDiagramNodes()) {
        Assignable assignable = node.nearest(Assignable.class);
        if (assignable != null) {
            for (Role role : assignable.getRoles()) {
                String name = role.getName().content(false);
                if (!isNullOrEmpty(name)) {
                    ElementList<RoleName> roleName = op.getRoleNames();
                    roleName.insert().setName(name);
                }
            }
        }
    }
    User existingUser = task.getUser().content(false);
    ElementList<Role> existingRoles = task.getRoles();
    ElementList<ResourceAction> existingActions = task.getResourceActions();
    Scriptable scriptedAssignment = task.getScriptedAssignment().content(false);
    if (existingUser != null) {
        op.getImpliedUser().copy(existingUser);
    } else if (ListUtil.isNotEmpty(existingRoles)) {
        op.getImpliedRole().copy(existingRoles.get(0));
        for (Role role : existingRoles) {
            Role newRole = op.getRoles().insert();
            newRole.copy(role);
            Boolean autoCreate = role.getAutoCreate().content(false);
            if (autoCreate != null) {
                newRole.setAutoCreate(role.getAutoCreate().content());
            }
        }
    } else if (ListUtil.isNotEmpty(existingActions)) {
        for (ResourceAction action : existingActions) {
            ElementList<ResourceAction> resourceActions = op.getResourceActions();
            ResourceAction resourceAction = resourceActions.insert();
            resourceAction.copy(action);
        }
    } else if (scriptedAssignment != null) {
        ElementHandle<Scriptable> scriptable = op.getScriptedAssignment();
        Scriptable content = scriptable.content(true);
        content.copy(scriptedAssignment);
    }
    DefinitionLoader loader = DefinitionLoader.context(NewWorkflowDefinitionWizard.class);
    DefinitionLoader loaderSdef = loader.sdef("WorkflowDefinitionWizards");
    SapphireWizard<ChangeTaskAssignmentsOp> wizard = new SapphireWizard<>(op, loaderSdef.wizard("changeTaskAssignmentsWizard"));
    int returnCode = new WizardDialog(((SwtPresentation) context).shell(), wizard).open();
    if (returnCode == IDialogConstants.OK_ID) {
        KaleoModelUtil.changeTaskAssignments(_task(context), op);
    }
    return null;
}
Also used : SapphireWizard(org.eclipse.sapphire.ui.forms.swt.SapphireWizard) Task(com.liferay.ide.kaleo.core.model.Task) User(com.liferay.ide.kaleo.core.model.User) WorkflowDefinition(com.liferay.ide.kaleo.core.model.WorkflowDefinition) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) WorkflowNode(com.liferay.ide.kaleo.core.model.WorkflowNode) Role(com.liferay.ide.kaleo.core.model.Role) RoleName(com.liferay.ide.kaleo.core.model.RoleName) DefinitionLoader(org.eclipse.sapphire.ui.def.DefinitionLoader) ElementHandle(org.eclipse.sapphire.ElementHandle) SwtPresentation(org.eclipse.sapphire.ui.forms.swt.SwtPresentation) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ChangeTaskAssignmentsOp(com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp) Assignable(com.liferay.ide.kaleo.core.model.Assignable) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Example 3 with ResourceAction

use of com.liferay.ide.kaleo.core.model.ResourceAction in project liferay-ide by liferay.

the class CurrentAssignmentsDerviedValueService method compute.

@Override
protected String compute() {
    StringBuilder data = new StringBuilder();
    Assignable assignable = context(Assignable.class);
    ElementHandle<User> assignableUser = assignable.getUser();
    User user = assignableUser.content(false);
    ElementList<Role> roles = assignable.getRoles();
    ElementHandle<Scriptable> scripteAssignment = assignable.getScriptedAssignment();
    Scriptable scriptable = scripteAssignment.content(false);
    ElementList<ResourceAction> resourceActions = assignable.getResourceActions();
    if (user != null) {
        Value<Integer> userId = user.getUserId();
        Value<String> userScreenName = user.getScreenName();
        Value<String> userEmailAddress = user.getEmailAddress();
        if (userId.content() != null) {
            data.append(userId.content() + ", ");
        } else if (userScreenName.content() != null) {
            data.append(userScreenName.content() + ", ");
        } else if (userEmailAddress.content() != null) {
            data.append(userEmailAddress.content() + ", ");
        } else {
            data.append("User: Asset Creator");
        }
    }
    if (ListUtil.isNotEmpty(roles)) {
        data.append("Roles: ");
        for (Role role : roles) {
            Value<Integer> roleId = role.getRoleId();
            Value<String> roleName = role.getName();
            if (roleId.content() != null) {
                data.append(roleId.content() + ", ");
            } else {
                data.append(roleName.text() + ", ");
            }
        }
    }
    if (scriptable != null) {
        Value<String> script = scriptable.getScript();
        Value<ScriptLanguageType> scriptLanguageType = scriptable.getScriptLanguage();
        if (script.content() != null) {
            data.append("Script language: " + scriptLanguageType.content());
        }
    }
    if (ListUtil.isNotEmpty(resourceActions)) {
        data.append("Resource actions: ");
        for (ResourceAction resourceAction : resourceActions) {
            Value<String> reAction = resourceAction.getResourceAction();
            if (reAction.content() != null) {
                data.append(reAction.content() + ", ");
            }
        }
    }
    String dataInfo = data.toString();
    return dataInfo.replaceAll(", $", "");
}
Also used : User(com.liferay.ide.kaleo.core.model.User) ScriptLanguageType(com.liferay.ide.kaleo.core.model.ScriptLanguageType) Scriptable(com.liferay.ide.kaleo.core.model.Scriptable) Role(com.liferay.ide.kaleo.core.model.Role) Assignable(com.liferay.ide.kaleo.core.model.Assignable) ResourceAction(com.liferay.ide.kaleo.core.model.ResourceAction)

Aggregations

ResourceAction (com.liferay.ide.kaleo.core.model.ResourceAction)3 Role (com.liferay.ide.kaleo.core.model.Role)3 Scriptable (com.liferay.ide.kaleo.core.model.Scriptable)3 User (com.liferay.ide.kaleo.core.model.User)3 Assignable (com.liferay.ide.kaleo.core.model.Assignable)2 ScriptLanguageType (com.liferay.ide.kaleo.core.model.ScriptLanguageType)2 RoleName (com.liferay.ide.kaleo.core.model.RoleName)1 RoleType (com.liferay.ide.kaleo.core.model.RoleType)1 Task (com.liferay.ide.kaleo.core.model.Task)1 WorkflowDefinition (com.liferay.ide.kaleo.core.model.WorkflowDefinition)1 WorkflowNode (com.liferay.ide.kaleo.core.model.WorkflowNode)1 ChangeTaskAssignmentsOp (com.liferay.ide.kaleo.core.op.ChangeTaskAssignmentsOp)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 ElementHandle (org.eclipse.sapphire.ElementHandle)1 DefinitionLoader (org.eclipse.sapphire.ui.def.DefinitionLoader)1 SapphireWizard (org.eclipse.sapphire.ui.forms.swt.SapphireWizard)1 SwtPresentation (org.eclipse.sapphire.ui.forms.swt.SwtPresentation)1