Skip to main content
summaryrefslogtreecommitdiffstats
blob: 30b364bf736a8d968fd14086ba23540f7d498d95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
/*******************************************************************************
 * Copyright (c) 2013 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.disposition.rest.util;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.eclipse.osee.disposition.model.Discrepancy;
import org.eclipse.osee.disposition.model.DispoAnnotationData;
import org.eclipse.osee.disposition.model.DispoConfig;
import org.eclipse.osee.disposition.model.DispoConfigData;
import org.eclipse.osee.disposition.model.DispoItem;
import org.eclipse.osee.disposition.model.DispoItemData;
import org.eclipse.osee.disposition.model.DispoSet;
import org.eclipse.osee.disposition.model.DispoSetData;
import org.eclipse.osee.disposition.model.DispoStrings;
import org.eclipse.osee.disposition.model.DispoSummarySeverity;
import org.eclipse.osee.disposition.model.Note;
import org.eclipse.osee.disposition.model.OperationReport;
import org.eclipse.osee.disposition.model.OperationSummaryEntry;
import org.eclipse.osee.disposition.model.ResolutionMethod;
import org.eclipse.osee.disposition.rest.internal.LocationRangesCompressor;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author Angel Avila
 */
public final class DispoUtil {

   private static final Pattern pattern = Pattern.compile("^[,\\d-\\s]+$");
   private static final Pattern removeLastDot = Pattern.compile("[^\\.]([^.]*)$", Pattern.CASE_INSENSITIVE);

   private DispoUtil() {
      //
   }

   public static JSONObject asJSONObject(String value) {
      try {
         return new JSONObject(value);
      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
   }

   public static boolean isDefaultAnotation(DispoAnnotationData annotation) {
      return annotation.getResolutionType().equalsIgnoreCase(
         DispoStrings.Test_Unit_Resolution) || annotation.getResolutionType().equalsIgnoreCase(
            DispoStrings.Exception_Handling_Resolution);
   }

   public static boolean isNumericLocations(String str) {
      Matcher matcher = pattern.matcher(str.trim());
      return matcher.matches();
   }

   public static String operationReportToString(OperationReport report) {
      JSONObject reportAsJson = new JSONObject(report);
      return reportAsJson.toString();
   }

   public static OperationReport cleanOperationReport(OperationReport origReport) {
      OperationReport newRerport = new OperationReport();
      if (origReport.getStatus().isFailed()) {
         List<OperationSummaryEntry> entries = origReport.getEntries();
         for (OperationSummaryEntry entry : entries) {
            if (DispoSummarySeverity.ERROR.equals(entry.getSeverity())) {
               newRerport.addEntry(entry.getName(), entry.getMessage(), entry.getSeverity());
            }
         }
         return newRerport;
      } else {
         return origReport;
      }
   }

   public static DispoAnnotationData getById(List<DispoAnnotationData> list, String id) {
      for (DispoAnnotationData annotation : list) {
         if (annotation.getId().equals(id)) {
            return annotation;
         }
      }

      return null;
   }

   public static JSONArray asJSONArray(String value) {
      try {
         return new JSONArray(value);
      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
   }

   public static DispoItemData itemArtToItemData(DispoItem dispoItemArt, boolean isIncludeDiscrepancies) {
      return itemArtToItemData(dispoItemArt, isIncludeDiscrepancies, false);
   }

   public static DispoItemData itemArtToItemData(DispoItem dispoItemArt, boolean isIncludeDiscrepancies, boolean isIncludeAnnotations) {
      DispoItemData dispoItemData = new DispoItemData();
      dispoItemData.setName(dispoItemArt.getName());
      dispoItemData.setGuid(dispoItemArt.getGuid());
      dispoItemData.setCreationDate(dispoItemArt.getCreationDate());
      dispoItemData.setAssignee(dispoItemArt.getAssignee());
      dispoItemData.setVersion(dispoItemArt.getVersion());
      dispoItemData.setLastUpdate(dispoItemArt.getLastUpdate());
      dispoItemData.setStatus(dispoItemArt.getStatus());
      dispoItemData.setTotalPoints(dispoItemArt.getTotalPoints());
      dispoItemData.setNeedsRerun(dispoItemArt.getNeedsRerun());
      dispoItemData.setCategory(dispoItemArt.getCategory());
      dispoItemData.setMachine(dispoItemArt.getMachine());
      dispoItemData.setAborted(dispoItemArt.getAborted());
      dispoItemData.setElapsedTime(dispoItemArt.getElapsedTime());
      dispoItemData.setItemNotes(dispoItemArt.getItemNotes());
      dispoItemData.setFileNumber(dispoItemArt.getFileNumber());
      dispoItemData.setMethodNumber(dispoItemArt.getMethodNumber());
      dispoItemData.setTeam(dispoItemArt.getTeam());
      if (isIncludeDiscrepancies) {
         Map<String, Discrepancy> discrepanciesList = dispoItemArt.getDiscrepanciesList();
         dispoItemData.setDiscrepanciesList(discrepanciesList);
         dispoItemData.setDiscrepanciesAsRanges(discrepanciesToString(discrepanciesList));
         dispoItemData.setFailureCount(discrepanciesList.size());
      }
      if (isIncludeAnnotations) {
         dispoItemData.setAnnotationsList(dispoItemArt.getAnnotationsList());
      }
      return dispoItemData;
   }

   public static String discrepanciesToString(Map<String, Discrepancy> discrepanciesList) {
      String toReturn;
      boolean isAllNumeric = true;
      List<Integer> discrepancyLocationAsInts = new ArrayList<>();
      List<String> discrepancyLocationsAsString = new ArrayList<>();
      for (String key : discrepanciesList.keySet()) {
         Discrepancy disrepancy = discrepanciesList.get(key);
         String location = disrepancy.getLocation();
         if (isAllNumeric && isNumericLocations(location)) {
            discrepancyLocationAsInts.add(Integer.valueOf(location));
         } else {
            isAllNumeric = false;
            discrepancyLocationsAsString.add(location);
         }
      }

      if (isAllNumeric) {
         toReturn = LocationRangesCompressor.compress(discrepancyLocationAsInts);
      } else {
         toReturn = listToString(discrepancyLocationsAsString);
      }
      return toReturn;
   }

   public static String listToString(List<String> locations) {
      StringBuilder sb = new StringBuilder();
      boolean isFirst = true;
      for (String location : locations) {
         if (isFirst) {
            sb.append(location);
            isFirst = false;
         } else {
            sb.append(", ");
            sb.append(location);
         }
      }
      return sb.toString();
   }

   public static DispoItemData jsonObjToDispoItem(JSONObject jsonObject) {
      DispoItemData dispoItem = new DispoItemData();
      try {
         if (jsonObject.has("name")) {
            dispoItem.setName(jsonObject.getString("name"));
         }
         if (jsonObject.has("guid")) {
            dispoItem.setGuid(jsonObject.getString("guid"));
         }
         if (jsonObject.has("status")) {
            dispoItem.setStatus(jsonObject.getString("status"));
         }
         if (jsonObject.has("totalPoints")) {
            dispoItem.setTotalPoints(jsonObject.getString("totalPoints"));
         }
         if (jsonObject.has("needsRerun")) {
            dispoItem.setNeedsRerun(jsonObject.getBoolean("needsRerun"));
         }
         if (jsonObject.has("version")) {
            dispoItem.setVersion(jsonObject.getString("version"));
         }
         if (jsonObject.has("assignee")) {
            dispoItem.setAssignee(jsonObject.getString("assignee"));
         }
         if (jsonObject.has("category")) {
            dispoItem.setCategory(jsonObject.getString("category"));
         }
         if (jsonObject.has("machine")) {
            dispoItem.setMachine(jsonObject.getString("machine"));
         }
         if (jsonObject.has("elapsedTime")) {
            dispoItem.setElapsedTime(jsonObject.getString("elapsedTime"));
         }
         if (jsonObject.has("aborted")) {
            dispoItem.setAborted(jsonObject.getBoolean("aborted"));
         }
         if (jsonObject.has("itemNotes")) {
            dispoItem.setItemNotes(jsonObject.getString("itemNotes"));
         }
         if (jsonObject.has("fileNumber")) {
            dispoItem.setFileNumber(jsonObject.getString("fileNumber"));
         }
         if (jsonObject.has("methodNumber")) {
            dispoItem.setMethodNumber(jsonObject.getString("methodNumber"));
         }
         if (jsonObject.has("team")) {
            dispoItem.setTeam(jsonObject.getString("team"));
         }
      } catch (JSONException ex) {
         throw new OseeCoreException("Error deserializing a Dispositionable Item.", ex);
      }

      return dispoItem;
   }

   public static DispoSetData jsonObjToDispoSet(JSONObject jsonObject) {
      DispoSetData dispoSet = new DispoSetData();
      try {
         if (jsonObject.has("importPath")) {
            dispoSet.setImportPath(jsonObject.getString("importPath"));
         }
         if (jsonObject.has("name")) {
            dispoSet.setName(jsonObject.getString("name"));
         }
         if (jsonObject.has("operation")) {
            dispoSet.setOperation(jsonObject.getString("operation"));
         }
         if (jsonObject.has("notesList")) {
            JSONArray jArray = jsonObject.getJSONArray("notesList");
            List<Note> notesList = new ArrayList<Note>();
            for (int i = 0; i < jArray.length(); i++) {
               notesList.add(jsonObjToNote(jArray.getJSONObject(i)));
            }
            dispoSet.setNotesList(notesList);
         }
         if (jsonObject.has("ciSet")) {
            dispoSet.setCiSet(jsonObject.getString("ciSet"));
         }
      } catch (JSONException ex) {
         throw new OseeCoreException("Error deserializing a Dispositionable Item.", ex);
      }
      return dispoSet;
   }

   public static JSONObject dispoItemToJsonObj(DispoItem dispoItem, boolean isDetailed) {
      JSONObject jsonObject = new JSONObject();
      try {
         jsonObject.put("discrepanciesAsRanges", discrepanciesToString(dispoItem.getDiscrepanciesList()));
         if (isDetailed) {
            jsonObject.put("discrepancies", dispoItem.getDiscrepanciesList());
         }
         jsonObject.put("failureCount", dispoItem.getDiscrepanciesList().size());
         jsonObject.put("name", dispoItem.getName());
         jsonObject.put("status", dispoItem.getStatus());
         jsonObject.put("totalPoints", dispoItem.getTotalPoints());
         jsonObject.put("assignee", dispoItem.getAssignee());
         jsonObject.put("needsRerun", dispoItem.getNeedsRerun());
         jsonObject.put("guid", dispoItem.getGuid());
         jsonObject.put("category", dispoItem.getCategory());
         jsonObject.put("machine", dispoItem.getMachine());
         jsonObject.put("elapsedTime", dispoItem.getElapsedTime());
         jsonObject.put("aborted", dispoItem.getAborted());
         jsonObject.put("lastUpdated", dispoItem.getLastUpdate());
         jsonObject.put("creationDate", dispoItem.getCreationDate());
         jsonObject.put("itemNotes", dispoItem.getItemNotes());
         jsonObject.put("version", dispoItem.getVersion());
         jsonObject.put("fileNumber", dispoItem.getFileNumber());
         jsonObject.put("methodNumber", dispoItem.getMethodNumber());
         jsonObject.put("team", dispoItem.getTeam());
      } catch (JSONException ex) {
         throw new OseeCoreException("Error deserializing a Dispositionable Item.", ex);
      }

      return jsonObject;
   }

   public static JSONArray noteListToJsonObj(List<Note> notes) {
      JSONArray jArray = new JSONArray();
      for (Note note : notes) {
         jArray.put(new JSONObject(note));
      }

      return jArray;
   }

   public static JSONObject discrepancyToJsonObj(Discrepancy discrepancy) {
      JSONObject toReturn = new JSONObject(discrepancy);
      return toReturn;
   }

   public static OperationSummaryEntry jsonObjToOperationSummaryEntry(JSONObject jObj) throws JSONException {
      OperationSummaryEntry entry = new OperationSummaryEntry();
      if (jObj.has("message")) {
         entry.setMessage(jObj.getString("message"));
      }
      if (jObj.has("name")) {
         entry.setName(jObj.getString("name"));
      }
      if (jObj.has("severity")) {
         String severity = jObj.getJSONObject("severity").getString("name").toUpperCase();
         DispoSummarySeverity dispoSummarySeverity = DispoSummarySeverity.valueOf(severity);
         entry.setSeverity(dispoSummarySeverity);
      }
      return entry;
   }

   public static OperationReport jsonObjToOperationSummary(JSONObject jObj) {
      OperationReport summary = new OperationReport();
      List<OperationSummaryEntry> entries = new ArrayList<>();

      try {
         if (jObj.has("entries")) {
            JSONArray entriesJson = jObj.getJSONArray("entries");
            for (int i = 0; i < entriesJson.length(); i++) {
               JSONObject entryAsJson = entriesJson.getJSONObject(i);
               OperationSummaryEntry entry = jsonObjToOperationSummaryEntry(entryAsJson);
               entries.add(entry);
            }
            summary.setEntries(entries);
         }
      } catch (JSONException ex) {
         //
      }
      return summary;
   }

   public static JSONObject dispoSetToJsonObj(DispoSet dispoSet) {
      JSONObject jsonObject = new JSONObject(dispoSet, true);
      JSONObject operationSummaryJObj = new JSONObject();
      JSONArray jArray = new JSONArray();
      try {
         for (OperationSummaryEntry entry : dispoSet.getOperationSummary().getEntries()) {
            JSONObject entryJson = new JSONObject(entry);
            jArray.put(entryJson);
         }
         operationSummaryJObj.put("entries", jArray);
         jsonObject.put("operationSummary", operationSummaryJObj);
      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }

      return jsonObject;
   }

   public static JSONObject annotationToJsonObj(DispoAnnotationData annotation) {
      JSONObject toReturn = new JSONObject(annotation);
      try {
         toReturn.put("idsOfCoveredDiscrepancies", annotation.getIdsOfCoveredDiscrepancies());
      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
      return toReturn;
   }

   public static DispoAnnotationData jsonObjToDispoAnnotationData(JSONObject object) {
      DispoAnnotationData dispoAnnotation = new DispoAnnotationData();
      try {
         if (object.has("id")) {
            dispoAnnotation.setId(object.getString("id"));
         }
         if (object.has("index")) {
            dispoAnnotation.setIndex(object.getInt("index"));
         }
         if (object.has("locationRefs")) {
            dispoAnnotation.setLocationRefs(object.getString("locationRefs"));
         }
         if (object.has("idsOfCoveredDiscrepancies")) {
            List<String> idsOfCoveredDiscrepanciesList = new ArrayList<String>();
            JSONArray jArray = object.getJSONArray("idsOfCoveredDiscrepancies");
            for (int i = 0; i < jArray.length(); i++) {
               idsOfCoveredDiscrepanciesList.add(jArray.getString(i));
            }
            dispoAnnotation.setIdsOfCoveredDiscrepancies(idsOfCoveredDiscrepanciesList);
         }
         if (object.has("isValid")) {
            dispoAnnotation.setIsConnected(object.getBoolean("isValid"));
         }
         if (object.has("developerNotes")) {
            dispoAnnotation.setDeveloperNotes(object.getString("developerNotes"));
         }
         if (object.has("customerNotes")) {
            dispoAnnotation.setCustomerNotes(object.getString("customerNotes"));
         }
         if (object.has("resolution")) {
            dispoAnnotation.setResolution(object.getString("resolution"));
         }
         if (object.has("isConnected")) {
            dispoAnnotation.setIsConnected(object.getBoolean("isConnected"));
         }
         if (object.has("isDefault")) {
            dispoAnnotation.setIsDefault(object.getBoolean("isDefault"));
         }
         if (object.has("isResolutionValid")) {
            dispoAnnotation.setIsResolutionValid(object.getBoolean("isResolutionValid"));
         }
         if (object.has("resolutionType")) {
            dispoAnnotation.setResolutionType(object.getString("resolutionType"));
         }
      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
      return dispoAnnotation;
   }

   public static JSONObject disrepanciesMapToJson(Map<String, Discrepancy> discrepancies) {
      JSONObject jObject = null;
      try {
         jObject = new JSONObject();
         for (String key : discrepancies.keySet()) {
            jObject.put(key, DispoUtil.discrepancyToJsonObj(discrepancies.get(key)));
         }

      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
      return jObject;

   }

   public static JSONArray annotationsListToJson(List<DispoAnnotationData> annotations) {
      JSONArray jArray = null;
      try {
         jArray = new JSONArray();
         for (DispoAnnotationData annotation : annotations) {
            jArray.put(annotation.getIndex(), DispoUtil.annotationToJsonObj(annotation));
         }

      } catch (JSONException ex) {
         throw new OseeCoreException(ex);
      }
      return jArray;
   }

   public static Discrepancy jsonObjToDiscrepancy(JSONObject object) throws JSONException {
      Discrepancy discrepancy = new Discrepancy();
      discrepancy.setLocation(object.getString("location"));
      discrepancy.setText(object.getString("text"));
      discrepancy.setId(object.getString("id"));
      return discrepancy;
   }

   public static Note jsonObjToNote(JSONObject object) throws JSONException {
      Note note = new Note();
      note.setContent(object.getString("content"));
      note.setDateString(object.getString("dateString"));
      note.setType(object.getString("type"));
      return note;
   }

   public static ResolutionMethod jsonObjToResolutionMethod(JSONObject object) throws JSONException {
      ResolutionMethod method = new ResolutionMethod();
      method.setText(object.getString("text"));
      method.setValue(object.getString("value"));
      method.setIsDefault(object.getBoolean("isDefault"));
      return method;
   }

   public static DispoConfigData configArtToConfigData(DispoConfig config) {
      DispoConfigData configData = new DispoConfigData();
      configData.setValidResolutions(config.getValidResolutions());

      return configData;
   }

   public static DispoConfig getDefaultConfig() {
      DispoConfigData configData = new DispoConfigData();
      ResolutionMethod defaultMethod = new ResolutionMethod();
      defaultMethod.setText("METHODS HAVEN'T BEEN SET");
      defaultMethod.setValue("INVALID");
      defaultMethod.setIsDefault(true);
      configData.setValidResolutions(Collections.singletonList(defaultMethod));

      return configData;
   }

   public static List<DispoAnnotationData> asAnnotationsList(JSONArray annotations) {
      List<DispoAnnotationData> toReturn = new ArrayList<>();
      for (int i = 0; i < annotations.length(); i++) {
         try {
            toReturn.add(jsonObjToDispoAnnotationData(annotations.getJSONObject(i)));
         } catch (JSONException ex) {
            throw new OseeCoreException(ex);
         }
      }

      return toReturn;
   }

   public static JSONArray listAsJsonArray(List<DispoAnnotationData> annotations) {
      JSONArray toReturn = new JSONArray();
      for (DispoAnnotationData annotation : annotations) {
         try {
            toReturn.put(annotation.getIndex(), annotationToJsonObj(annotation));
         } catch (JSONException ex) {
            throw new OseeCoreException(ex);
         }
      }

      return toReturn;
   }

   public static Date getTimestampOfFile(String fullPathFileName) {
      Date date = new Date(0);
      File f = new File(fullPathFileName);
      if (f.exists()) {
         long lastModified = f.lastModified();
         date = new Date(lastModified);
      }
      return date;
   }

   public static HashMap<String, String> splitTestScriptNameAndPath(List<DispoAnnotationData> annotations) {
      HashMap<String, String> testScriptNameToPath = new HashMap<>();
      for (DispoAnnotationData data : annotations) {
         String name = "", path = "", comment = "";
         String resolution = data.getResolution();
         if (!resolution.isEmpty()) {
            String[] split = resolution.split("___");
            if (split.length > 1) {
               path = split[0];
               comment = split[1];
            } else {
               path = split.toString();
            }
            path = path.replaceFirst("results", "");
            Matcher matcher = removeLastDot.matcher(path);
            while (matcher.find()) {
               name = matcher.group() + ".java";
            }
            path = path.replaceAll("\\.", "/");
         }
         testScriptNameToPath.put(name, path);
      }
      return testScriptNameToPath;
   }

   public static DispoItem findDispoItem(List<DispoItem> items, String itemName) {
      for (DispoItem dItem : items) {
         if (dItem.getName().equals(itemName)) {
            return dItem;
         }
      }
      return null;
   }

   public static List<Integer> splitDiscrepancyLocations(String locations) {
      String[] locationString = locations.split(",");
      List<Integer> range = new ArrayList<>();
      if (locations != null && !locations.isEmpty()) {
         for (String location : locationString) {
            String[] loc = location.split("-");
            if (loc.length > 1) {
               range.addAll(
                  IntStream.range(Integer.valueOf(loc[0].trim()), Integer.valueOf(loc[1].trim()) + 1).boxed().collect(
                     Collectors.toList()));
            } else {
               range.add(Integer.valueOf(loc[0].trim()));
            }
         }
      }
      return range;
   }

   public static List<String> findDiscrepancyLocsToRemove(List<Integer> ranges, DispoItem item) {
      List<String> removeDiscrepancies = new ArrayList<>();
      if (ranges != null && !ranges.isEmpty()) {
         for (Integer locRef : ranges) {
            for (Entry<String, Discrepancy> discrepancy : item.getDiscrepanciesList().entrySet()) {
               Discrepancy value = discrepancy.getValue();
               String location = value.getLocation();
               if (Strings.isValid(location) && locRef == Integer.valueOf(location)) {
                  removeDiscrepancies.add(discrepancy.getKey());
               }
            }
         }
      }
      return removeDiscrepancies;
   }

   public static List<String> findMissingDiscrepancyLocs(List<Integer> ranges, DispoItem item) {
      List<String> missingDiscrepanciesLoc = new ArrayList<>();
      if (ranges != null && !ranges.isEmpty()) {
         for (Integer locRef : ranges) {
            boolean found = false;
            for (Entry<String, Discrepancy> discrepancy : item.getDiscrepanciesList().entrySet()) {
               Discrepancy value = discrepancy.getValue();
               String location = value.getLocation();
               if (Strings.isValid(location) && locRef == Integer.valueOf(location)) {
                  found = true;
                  break;
               }
            }
            if (!found) {
               missingDiscrepanciesLoc.add(String.valueOf(locRef));
            }
         }
      }
      return missingDiscrepanciesLoc;
   }

}

Back to the top