Skip to content

Commit

Permalink
Merge pull request #543 from navikt/stoPickSkill
Browse files Browse the repository at this point in the history
Sto pick skill
  • Loading branch information
mamikals authored Jan 16, 2024
2 parents beac299 + 12d3f54 commit 0b696d1
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 19 deletions.
52 changes: 36 additions & 16 deletions force-app/main/default/classes/nksGetStoUtilityController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @description :
* @author : mamikals
* @group :
* @last modified on : 21-03-2023
* @last modified on : 11-01-2024
* @last modified by : mamikals
**/
public without sharing class nksGetStoUtilityController {
Expand All @@ -12,14 +12,20 @@ public without sharing class nksGetStoUtilityController {
public class NoCasesFoundException extends Exception {
}

private static List<Id> skillIdList = new List<Id>();
private static List<Id> userConfidentialitySkills = new List<Id>();
private static List<String> userOriginSkills = new List<String>();
private static final List<String> confidentialitySkills = new List<String>{
'Fortrolig_addresse',
'Skjermede_personer'
};
private static final List<String> originSkills = new List<String>{ 'BTO', 'STO' };
private static Id filteredSkillId;

private static GroupedSkills allUserSkills = new GroupedSkills();

@AuraEnabled
public static List<Record> getStoWithSkill(Id skillId) {
filteredSkillId = skillId;
return getSto();
}

@AuraEnabled
public static List<Record> getSto() {
Expand Down Expand Up @@ -51,7 +57,7 @@ public without sharing class nksGetStoUtilityController {
try {
Integer attempt = 0;
Id userId = UserInfo.getUserId();
getServiceResourceSkillIds(userId);
allUserSkills = getServiceResourceSkillIds();

do {
Id nextCaseId = getNextSTOCase();
Expand Down Expand Up @@ -88,9 +94,9 @@ public without sharing class nksGetStoUtilityController {
Map<String, Object> flowParams = new Map<String, Object>();
flowParams.put('CaseId', caseId);
if (Test.isRunningTest()) {
userOriginSkills.add('STO');
allUserSkills.userOriginMap.put('001xa000003DIlo', 'STO');
}
flowParams.put('UserOriginSkills', userOriginSkills);
flowParams.put('UserOriginSkills', allUserSkills.userOriginMap.values());

Flow.Interview.STO_Case_Set_Owner setOwnerFlow = new Flow.Interview.STO_Case_Set_Owner(flowParams);
setOwnerFlow.start();
Expand Down Expand Up @@ -163,8 +169,11 @@ public without sharing class nksGetStoUtilityController {
return records;
}

@TestVisible
private static void getServiceResourceSkillIds(Id userId) {
@AuraEnabled(cacheable=true)
public static GroupedSkills getServiceResourceSkillIds() {
Id userId = UserInfo.getUserId();
GroupedSkills retSkills = new GroupedSkills();

for (ServiceResourceSkill srs : [
SELECT SkillId, Skill.DeveloperName
FROM ServiceResourceSkill
Expand All @@ -177,13 +186,16 @@ public without sharing class nksGetStoUtilityController {
]) {
//Separating domain skills and person access skills
if (confidentialitySkills.contains(srs.Skill.DeveloperName)) {
userConfidentialitySkills.add(srs.SkillId);
retSkills.userConfidentialMap.put(srs.SkillId, srs.Skill.DeveloperName);
} else if (originSkills.contains(srs.Skill.DeveloperName)) {
userOriginSkills.add(srs.Skill.DeveloperName);
retSkills.userOriginMap.put(srs.SkillId, srs.Skill.DeveloperName);
} else {
skillIdList.add(srs.SkillId);
if (filteredSkillId == null || filteredSkillId == srs.SkillId) {
retSkills.skillMap.put(srs.SkillId, srs.Skill.DeveloperName);
}
}
}
return retSkills;
}

private static Id getNextSTOCase() {
Expand All @@ -207,19 +219,18 @@ public without sharing class nksGetStoUtilityController {
**/
private static List<PendingServiceRouting> getPendingServiceRouting() {
String userId = '%' + UserInfo.getUserID() + '%';

return [
SELECT Id, WorkItemId
FROM PendingServiceRouting
WHERE
Id IN (SELECT RelatedRecordId FROM SkillRequirement WHERE SkillId IN :skillIdList)
Id IN (SELECT RelatedRecordId FROM SkillRequirement WHERE SkillId IN :allUserSkills.skillMap.keySet())
AND ID NOT IN (
SELECT RelatedRecordId
FROM SkillRequirement
WHERE
(SkillId NOT IN :userConfidentialitySkills
(SkillId NOT IN :allUserSkills.userConfidentialMap.values()
AND Skill.DeveloperName IN :confidentialitySkills)
OR (Skill.DeveloperName NOT IN :userOriginSkills
OR (Skill.DeveloperName NOT IN :allUserSkills.userOriginMap.values()
AND Skill.DeveloperName IN :originSkills)
)
AND ServiceChannel.DeveloperName = 'Skriv_til_oss'
Expand All @@ -230,4 +241,13 @@ public without sharing class nksGetStoUtilityController {
LIMIT 1
];
}

public class GroupedSkills {
@AuraEnabled
public Map<Id, String> skillMap = new Map<Id, String>();
@AuraEnabled
public Map<Id, String> userConfidentialMap = new Map<Id, String>();
@AuraEnabled
public Map<Id, String> userOriginMap = new Map<Id, String>();
}
}
10 changes: 10 additions & 0 deletions force-app/main/default/lwc/nksGetStoUtility/nksGetStoUtility.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<template>
<div>
<div class="slds-m-horizontal_medium">
<lightning-select
name="queues"
label="Hvilken tjeneste vil du besvare?"
value={value}
options={options}
onchange={handleChange}
required
></lightning-select>
</div>
<lightning-layout class="slds-grid_align-center">
<lightning-layout-item class="slds-var-p-vertical_medium">
<lightning-button
Expand Down
39 changes: 36 additions & 3 deletions force-app/main/default/lwc/nksGetStoUtility/nksGetStoUtility.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { LightningElement, track } from 'lwc';
import { LightningElement, track, wire } from 'lwc';
import getList from '@salesforce/apex/nksGetStoUtilityController.getList';
import getSto from '@salesforce/apex/nksGetStoUtilityController.getSto';
import getStoWithSkill from '@salesforce/apex/nksGetStoUtilityController.getStoWithSkill';
import getServiceResourceSkillIds from '@salesforce/apex/nksGetStoUtilityController.getServiceResourceSkillIds';
import { NavigationMixin } from 'lightning/navigation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import hasStoBeta from '@salesforce/customPermission/STO_Beta';
Expand All @@ -18,6 +20,37 @@ export default class NksGetStoUtility extends NavigationMixin(LightningElement)

betaPermission = hasStoBeta;

skillMap;
value = 'All';

get options() {
const defaultLabel = [{ label: 'Alle tjenester jeg behandler', value: 'All' }];
if (this.skillMap != null) {
console.log(this.skillMap);
return defaultLabel.concat(
Object.keys(this.skillMap).map((id) => {
return { label: this.skillMap[id], value: id };
})
);
}
return defaultLabel;
}

handleChange(event) {
this.value = event.detail.value;
}

@wire(getServiceResourceSkillIds)
getSRSIds({ data, error }) {
if (data) {
this.skillMap = data.skillMap;
}
if (error) {
console.log('Could not get SRS');
console.log(error);
}
}

connectedCallback() {
publishToAmplitude('STO', { type: 'STO Utility opened' });
this.getUtilityId();
Expand Down Expand Up @@ -54,7 +87,7 @@ export default class NksGetStoUtility extends NavigationMixin(LightningElement)
getNewSTOHandler() {
publishToAmplitude('STO', { type: 'getNewSTOHandler' });
this.showSpinner = true;
getSto()
(this.value === 'All' ? getSto() : getStoWithSkill({ skillId: this.value }))
.then((records) => {
console.log(records);
records.forEach((record) => {
Expand Down Expand Up @@ -83,7 +116,7 @@ export default class NksGetStoUtility extends NavigationMixin(LightningElement)
this.dispatchEvent(
new ShowToastEvent({
title: 'Kunne ikke hente ny melding.',
message: 'Ingen flere meldinger på køer du behandler.',
message: 'Ingen flere meldinger på tjenester du behandler.',
variant: 'info'
})
);
Expand Down

0 comments on commit 0b696d1

Please sign in to comment.