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;
}
}
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;
}
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(", $", "");
}
Aggregations