|
1 |
| -global without sharing class NetworkMapExtension { |
2 |
| - |
| 1 | +/** |
| 2 | + * @description extension class for NetworkMap LWC |
| 3 | + * @author M Rainboldt |
| 4 | + * @created AUG 2020 |
| 5 | + */ |
| 6 | +global with sharing class NetworkMapExtension { |
| 7 | + /** |
| 8 | + * @description get relationships based on the record id provided |
| 9 | + * @param recordId Id of the record in context |
| 10 | + * @return a json serialization of NetworkDataSet |
| 11 | + */ |
3 | 12 | @AuraEnabled(cacheable=true)
|
4 | 13 | public static String getRelationships(String recordId)
|
5 | 14 | {
|
6 | 15 | String sObjName = SObjectHelper.getObjectName(recordId);
|
7 | 16 | String dataSet;
|
8 | 17 | if(sObjName == 'Contact'){
|
9 | 18 | dataSet = getRelationshipsFromContact(recordId);
|
10 |
| - }else if(sObjName =='Investigative_Report__c') |
11 |
| - { |
12 |
| - dataSet = getRelationshipsFromReport(recordId); |
13 | 19 | }else if(sObjName == 'Account')
|
14 | 20 | {
|
15 | 21 |
|
16 | 22 | }
|
17 | 23 | return dataSet;
|
18 | 24 | }
|
19 | 25 |
|
20 |
| - @AuraEnabled |
21 |
| - public static Edge createEdge(String edgeJson, String recordId){ |
22 |
| - Edge newEdge = (Edge)JSON.deserialize(edgeJson, Edge.class); |
23 |
| - Entity_Link__c newLink = new Entity_Link__c(); |
24 |
| - newLink.Entity__c = newEdge.source; |
25 |
| - newLink.Related_Entity__c = newEdge.to; |
26 |
| - if(SObjectHelper.getObjectName(recordId) == 'Investigative_Report__c'){ |
27 |
| - newLink.Related_Report__c = recordId; |
28 |
| - } |
29 |
| - System.debug(newLink); |
30 |
| - Database.insert(newLink); |
31 |
| - |
32 |
| - newEdge.id = newLink.Id; |
33 |
| - |
34 |
| - return newEdge; |
35 |
| - } |
36 |
| - |
37 |
| - private static String getRelationshipsFromReport(String recordId){ |
38 |
| - NetworkDataSet dataSet = new NetworkDataSet(); |
39 |
| - Set<Id> nodeIds = new Set<Id>(); |
40 |
| - for(Entity_Link__c link: (List<Entity_Link__c>) Database.query( |
41 |
| - 'SELECT ' + SObjectHelper.generateQueryStringByObjectNameFullSOQL('Entity_Link__c', false, false) |
42 |
| - + ', Entity__r.Entity_Name__c' |
43 |
| - + ', Entity__r.Network_Icon__c' |
44 |
| - + ', Entity__r.Id' |
45 |
| - + ', Entity__r.Primary_Image_Id__c' |
46 |
| - + ', Entity__r.RecordType.DeveloperName' |
47 |
| - + ', Entity__r.RecordType.Name' |
48 |
| - + ', Related_Entity__r.Entity_Name__c' |
49 |
| - + ', Related_Entity__r.Network_Icon__c' |
50 |
| - + ', Related_Entity__r.Id' |
51 |
| - + ', Related_Entity__r.Primary_Image_Id__c' |
52 |
| - + ', Related_Entity__r.RecordType.DeveloperName' |
53 |
| - + ', Related_Entity__r.RecordType.Name' |
54 |
| - + ' FROM Entity_Link__c' |
55 |
| - + ' WHERE Related_Report__c = :recordId')) |
56 |
| - { |
57 |
| - if(!String.isBlank(link.Entity__c) |
58 |
| - && !nodeIds.contains(link.Entity__c)){ |
59 |
| - dataSet.nodes.add(getNodeFromEntity(link.Entity__r)); |
60 |
| - nodeIds.add(link.Entity__c); |
61 |
| - } |
62 |
| - if(!String.isBlank(link.Related_Entity__c) |
63 |
| - && !nodeIds.contains(link.Related_Entity__c)){ |
64 |
| - dataSet.nodes.add(getNodeFromEntity(link.Related_Entity__r)); |
65 |
| - nodeIds.add(link.Related_Entity__c); |
66 |
| - } |
67 |
| - |
68 |
| - if(String.isBlank(link.Entity__c) |
69 |
| - || String.isBlank(link.Related_Entity__c)) continue; |
70 |
| - |
71 |
| - Edge edge = new Edge(); |
72 |
| - edge.source = link.Entity__c; |
73 |
| - edge.to = link.Related_Entity__c; |
74 |
| - edge.id = link.Id; |
75 |
| - edge.label = link.Relationship__c; |
76 |
| - dataSet.Edges.add(edge); |
77 |
| - } |
78 |
| - return JSON.serialize(dataSet); |
79 |
| - } |
80 |
| - |
81 |
| - private static Node getNodeFromEntity(Entity__c entity) |
82 |
| - { |
83 |
| - Node node = new Node(); |
84 |
| - node.id = entity.Id; |
85 |
| - node.title = entity.Entity_Name__c; |
86 |
| - node.shape = 'circularImage'; |
87 |
| - node.groupId = entity.RecordType.DeveloperName; |
88 |
| - node.groupLabel = entity.RecordType.Name; |
89 |
| - if(String.isBlank(entity.Primary_Image_Id__c)){ |
90 |
| - node.imageName = entity.Network_Icon__c; |
91 |
| - node.isSlds = true; |
92 |
| - }else{ |
93 |
| - node.image = '/sfc/servlet.shepherd/version/download/' + entity.Primary_Image_Id__c; |
94 |
| - node.isSlds = false; |
95 |
| - } |
96 |
| - |
97 |
| - return node; |
98 |
| - } |
99 |
| - |
100 |
| - private static String getRelationshipsFromAccount(String recordId) |
101 |
| - { |
102 |
| - return ''; |
103 |
| - } |
104 |
| - |
105 |
| - |
106 |
| - |
| 26 | + /** |
| 27 | + * @description gets relationships for a contact record |
| 28 | + * including Contact, Account, Other Contacts related to Account, |
| 29 | + * NPSP Relationships, NPSP Affiliations |
| 30 | + * @param recordId id of the contact record |
| 31 | + * @return json serialization of NetworkDataSet |
| 32 | + */ |
107 | 33 | private static String getRelationshipsFromContact(String recordId)
|
108 | 34 | {
|
109 | 35 | NetworkDataSet dataSet = new NetworkDataSet();
|
@@ -168,7 +94,7 @@ global without sharing class NetworkMapExtension {
|
168 | 94 | edge.label = relationship.npe4__Type__c;
|
169 | 95 | dataSet.edges.add(edge);
|
170 | 96 | }
|
171 |
| - System.debug(LoggingLevel.INFO, dataSet.nodes.size()); |
| 97 | + |
172 | 98 | for(npe5__Affiliation__c affl: [SELECT Id
|
173 | 99 | , npe5__Organization__c
|
174 | 100 | , npe5__Organization__r.Name
|
@@ -197,7 +123,7 @@ global without sharing class NetworkMapExtension {
|
197 | 123 | edge.label = affl.npe5__Role__c;
|
198 | 124 | dataSet.edges.add(edge);
|
199 | 125 | }
|
200 |
| - System.debug(LoggingLevel.INFO, dataSet.nodes.size()); |
| 126 | + |
201 | 127 | for(Contact relContact: [SELECT Id
|
202 | 128 | , AccountId
|
203 | 129 | , Name
|
@@ -225,31 +151,6 @@ global without sharing class NetworkMapExtension {
|
225 | 151 | edge.id = relContact.Id + '' + relContact.AccountId;
|
226 | 152 | dataSet.edges.add(edge);
|
227 | 153 | }
|
228 |
| - System.debug(LoggingLevel.INFO, dataSet.nodes.size()); |
229 |
| - return JSON.serialize(dataSet); |
230 |
| - } |
231 |
| - |
232 |
| - @AuraEnabled(cacheable=true) |
233 |
| - public static String getNPSPRelationships(String recordId) |
234 |
| - { |
235 |
| - NetworkDataSet dataSet = new NetworkDataSet(); |
236 |
| - for(npe4__Relationship__c relationship: (List<npe4__Relationship__c>) |
237 |
| - Database.query(SObjectHelper.generateQueryStringByObjectName('npe4__Relationship__c', true) |
238 |
| - + ' WHERE npe4__Contact__c = :recordId')) |
239 |
| - { |
240 |
| - Node node = new Node(); |
241 |
| - node.id = relationship.npe4__RelatedContact__c; |
242 |
| - node.title = relationship.npe4__RelatedContact__r.Name; |
243 |
| - node.shape = 'circularImage'; |
244 |
| - node.imageName = 'action/user_60.png'; |
245 |
| - dataSet.nodes.add(node); |
246 |
| - |
247 |
| - Edge edge = new Edge(); |
248 |
| - edge.source = relationship.npe4__Contact__c; |
249 |
| - edge.to = relationship.npe4__RelatedContact__c; |
250 |
| - edge.id = relationship.Id; |
251 |
| - dataSet.edges.add(edge); |
252 |
| - } |
253 | 154 |
|
254 | 155 | return JSON.serialize(dataSet);
|
255 | 156 | }
|
|
0 commit comments