Skip to content

Commit

Permalink
IVYPORTAL-17212 Portal LTS breadcrumb error
Browse files Browse the repository at this point in the history
- Use optional chaining operator to bypass error
  • Loading branch information
chnam-axonivy committed Oct 14, 2024
1 parent c847845 commit 27fa9bf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,105 +1,54 @@
package ch.ivy.addon.portalkit.test.util;

import java.util.ArrayList;
import java.util.List;

import ch.ivyteam.ivy.environment.Ivy;
import ch.ivyteam.ivy.persistence.IQueryResult;
import ch.ivyteam.ivy.security.exec.Sudo;
import ch.ivyteam.ivy.workflow.CaseProperty;
import ch.ivyteam.ivy.workflow.CaseState;
import ch.ivyteam.ivy.workflow.ICase;
import ch.ivyteam.ivy.workflow.IPropertyFilter;
import ch.ivyteam.ivy.workflow.ITask;
import ch.ivyteam.ivy.workflow.TaskProperty;
import ch.ivyteam.ivy.workflow.TaskState;
import ch.ivyteam.ivy.workflow.query.CaseQuery;
import ch.ivyteam.ivy.workflow.query.TaskQuery;

public class TaskUtils {

public static List<ICase> destroyAllCase() {
try {
return Sudo.call(() -> {
try {
IPropertyFilter<CaseProperty> noFilter = null;
IQueryResult<ICase> qr = Ivy.wf().findCases(noFilter, null, 0, -1, true);
List<ICase> names = new ArrayList<ICase>();
for (ICase ivyCase : qr.getResultList()) {
try {
if (ivyCase.getState().intValue() != TaskState.DESTROYED.intValue()
&& ivyCase.getState().intValue() != TaskState.DONE.intValue()) {
ivyCase.destroy();
}
} catch (Exception e1) {
Ivy.log().error(e1);
}
}
return names;
} catch (Exception e2) {
Ivy.log().error(e2);
return null;
}
});
} catch (Exception e) {
Ivy.log().error(e);
public static void destroyAllCase() throws Exception {
Sudo.call(() -> {
List<ICase> result = Ivy.wf().getCaseQueryExecutor()
.getResults(CaseQuery.create().where().state().isNotIn(CaseState.DESTROYED, CaseState.DONE));
for (ICase iCaze : result) {
iCaze.destroy();
}
return null;
}
}

public static boolean resumeFirstTask() {
try {
Sudo.call(() -> {
try {
IPropertyFilter<TaskProperty> filter = null;
IQueryResult<ITask> result = Ivy.wf().findTasks(filter, null, 0, -1, true);
List<ITask> tasks = result.getResultList();
for (ITask task : tasks) {
if (TaskState.SUSPENDED == task.getState()) {
Ivy.session().resumeTask(task.getId());
break;
}
}
return true;
} catch (Exception e) {
return false;
}
});
} catch (Exception e) {
return false;
}
return false;
});
}

public static void deleteCompletedCases() throws Exception {
Sudo.call(() -> {
IPropertyFilter<CaseProperty> noFilter = null;
IQueryResult<ICase> qr = Ivy.wf().findCases(noFilter, null, 0, -1, true);
for (ICase ivyCase : qr.getResultList()) {
if (ivyCase.getState() == CaseState.DESTROYED || ivyCase.getState() == CaseState.DONE) {
Ivy.wf().deleteCompletedCase(ivyCase);
}
List<ICase> result = Ivy.wf().getCaseQueryExecutor()
.getResults(CaseQuery.create().where().state().isIn(CaseState.DESTROYED, CaseState.DONE));
for (ICase iCaze : result) {
Ivy.wf().deleteCompletedCase(iCaze);
}
return null;
});
}

public static void deleteDestroyedCases() throws Exception {
Sudo.call(() -> {
IPropertyFilter<CaseProperty> noFilter = null;
IQueryResult<ICase> qr = Ivy.wf().findCases(noFilter, null, 0, -1, true);
for (ICase ivyCase : qr.getResultList()) {
if (ivyCase.getState() == CaseState.DESTROYED) {
Ivy.wf().deleteCompletedCase(ivyCase);
}
List<ICase> result = Ivy.wf().getCaseQueryExecutor()
.getResults(CaseQuery.create().where().state().isEqual(CaseState.DESTROYED));
for (ICase iCaze : result) {
Ivy.wf().deleteCompletedCase(iCaze);
}
return null;
});
}

public static void destroyTaskByCustomField(String customFieldName) throws Exception {
Sudo.call(() -> {
ITask selectedTask = TaskQuery.create().where().customField()
.stringField(customFieldName).isNotNull().executor().firstResult();
ITask selectedTask =
TaskQuery.create().where().customField().stringField(customFieldName).isNotNull().executor().firstResult();
if (selectedTask != null) {
selectedTask.destroy();
selectedTask.customFields().stringField(customFieldName).delete();
Expand Down
12 changes: 6 additions & 6 deletions AxonIvyPortal/portal/webContent/resources/js/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ var MainMenu = {
}
this.removeActiveMenu(activeMenuItemList);
$currentPageMenu.parent().addClass('active-menuitem');
PF('main-menu').addMenuitem($currentPageMenu.parent().attr('id'));
PF('main-menu')?.addMenuitem($currentPageMenu.parent().attr('id'));
}
},

Expand Down Expand Up @@ -274,10 +274,10 @@ function handleError(xhr, renderDetail, isShowErrorLog){
$("[id$='ajax-indicator:form-data']").text(decodeURIComponent(xhr.pfSettings.data));
$("[id$='ajax-indicator:response-text']").text(xhr.responseText);
$("[id$='ajax-indicator:xhr']").text(JSON.stringify(xhr));
PF('detail-error-dialog').show();
PF('detail-error-dialog')?.show();
});
}
PF('error-ajax-dialog').show();
PF('error-ajax-dialog')?.show();
if(isShowErrorLog){
var settingsSourceId = "PfSettings.source.id:\n";
console.log("Status code:\n" + xhr.status);
Expand Down Expand Up @@ -327,7 +327,7 @@ function executeStoreMenuRemoteCommand(menuItem, isWorkingOnATask, isOpenOnNewTa
function fireEventClickOnMenuItem(menuItem, prevMenuItemId) {
PF('main-menu').addMenuitem(menuItem);
if (prevMenuItemId !== menuItem) {
PF('main-menu').removeMenuitem(prevMenuItemId);
PF('main-menu')?.removeMenuitem(prevMenuItemId);
}
}

Expand All @@ -354,15 +354,15 @@ function highlightDashboardItem(menuId) {
}

function activeMenuItemOnLeftMenu(menuId) {
PF('main-menu').addMenuitem(menuId);
PF('main-menu')?.addMenuitem(menuId);
let $selectedMenu = $("[id$='" + menuId + "']");
if (!$selectedMenu.hasClass('active-menuitem')) {
$selectedMenu.addClass('active-menuitem');
}
}

function deactivateMenuItemOnLeftMenu(menuId) {
PF('main-menu').removeMenuitem(menuId);
PF('main-menu')?.removeMenuitem(menuId);
let $removedMenu = $("[id$='" + menuId + "']");
if ($removedMenu.hasClass('active-menuitem')) {
$removedMenu.removeClass('active-menuitem');
Expand Down

0 comments on commit 27fa9bf

Please sign in to comment.