Skip to main content
summaryrefslogtreecommitdiffstats
blob: f66bcb29f20c25e587b917bec660f613bb11f4f2 (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
/*******************************************************************************
 * 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.internal;

import static org.eclipse.osee.disposition.rest.DispoConstants.DISPO_ARTIFACT;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.UriGeneralStringData;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.eclipse.osee.disposition.model.DispoConfig;
import org.eclipse.osee.disposition.model.DispoItem;
import org.eclipse.osee.disposition.model.DispoProgram;
import org.eclipse.osee.disposition.model.DispoSet;
import org.eclipse.osee.disposition.model.OperationReport;
import org.eclipse.osee.disposition.rest.DispoConstants;
import org.eclipse.osee.disposition.rest.internal.importer.coverage.CoverageUtil;
import org.eclipse.osee.disposition.rest.util.DispoUtil;
import org.eclipse.osee.framework.core.data.ArtifactId;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.TokenFactory;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.CoreRelationTypes;
import org.eclipse.osee.framework.core.enums.QueryOption;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.framework.jdk.core.type.Identifiable;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.ResultSet;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.resource.management.IResource;
import org.eclipse.osee.logger.Log;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.OrcsBranch;
import org.eclipse.osee.orcs.data.ArtifactReadable;
import org.eclipse.osee.orcs.data.AttributeReadable;
import org.eclipse.osee.orcs.data.BranchReadable;
import org.eclipse.osee.orcs.data.TransactionReadable;
import org.eclipse.osee.orcs.search.QueryFactory;
import org.eclipse.osee.orcs.transaction.TransactionBuilder;
import org.eclipse.osee.orcs.transaction.TransactionFactory;
import org.json.JSONArray;
import org.json.JSONObject;

/**
 * @author Angel Avila
 */
public class OrcsStorageImpl implements Storage {
   private final Log logger;
   private final OrcsApi orcsApi;

   public OrcsStorageImpl(Log logger, OrcsApi orcsApi) {
      this.logger = logger;
      this.orcsApi = orcsApi;
   }

   private IOseeBranch getAdminBranch() {
      return CoreBranches.COMMON;
   }

   @SuppressWarnings("unchecked")
   private ArtifactReadable getDispoUser() throws OseeCoreException {
      return getQuery().fromBranch(getAdminBranch()).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
   }

   private QueryFactory getQuery() {
      return orcsApi.getQueryFactory();
   }

   private TransactionFactory getTxFactory() {
      return orcsApi.getTransactionFactory();
   }

   private OrcsBranch getBranchFactory() {
      return orcsApi.getBranchOps();
   }

   private void reloadTypes() {
      orcsApi.getOrcsTypes().invalidateAll();
   }

   private ResultSet<ArtifactReadable> getDispoTypesArtifact() throws OseeCoreException {
      return getQuery().fromBranch(getAdminBranch()).andUuid(DISPO_ARTIFACT.getUuid()).andTypeEquals(
         DISPO_ARTIFACT.getArtifactType()).getResults();
   }

   @Override
   public boolean typesExist() {
      boolean result = false;
      try {
         result = !getDispoTypesArtifact().isEmpty();
      } catch (OseeCoreException ex) {
         logger.warn(ex, "Error checking for Dispo Types");
      }
      return result;
   }

   @Override
   public void storeTypes(IResource resource) {
      TransactionBuilder tx =
         getTxFactory().createTransaction(getAdminBranch(), getDispoUser(), "Initialize Dispo Types");
      ArtifactId artifactId = tx.createArtifact(DISPO_ARTIFACT);
      InputStream stream = null;
      try {
         stream = resource.getContent();
         tx.setSoleAttributeFromStream(artifactId, UriGeneralStringData, stream);
      } finally {
         Lib.close(stream);
      }
      tx.commit();
      reloadTypes();
   }

   @SuppressWarnings("unchecked")
   @Override
   public ArtifactReadable findUser() {
      return getQuery().fromBranch(getAdminBranch()).andIds(SystemUser.OseeSystem).getResults().getExactlyOne();
   }

   @Override
   public ArtifactReadable findUser(String userId) {
      return getQuery().fromBranch(getAdminBranch()).andGuid(userId).getResults().getExactlyOne();
   }

   @Override
   public ArtifactReadable findUnassignedUser() {
      return getQuery().fromBranch(getAdminBranch()).andNameEquals("UnAssigned").andTypeEquals(
         CoreArtifactTypes.User).getResults().getExactlyOne();
   }

   @Override
   public boolean isUniqueProgramName(String name) {
      ResultSet<BranchReadable> results = getQuery().branchQuery().andNameEquals(name).getResults();

      return results.isEmpty();
   }

   @Override
   public boolean isUniqueSetName(DispoProgram program, String name) {
      ResultSet<ArtifactReadable> results = getQuery()//
      .fromBranch(program.getUuid())//
      .andTypeEquals(DispoConstants.DispoSet)//
      .andNameEquals(name)//
      .getResults();

      return results.isEmpty();
   }

   @Override
   public boolean isUniqueItemName(DispoProgram program, String setId, String name) {
      ArtifactReadable setArt = findDispoArtifact(program, setId, DispoConstants.DispoSet);
      ResultSet<ArtifactReadable> results = getQuery()//
      .fromBranch(program.getUuid())//
      .andRelatedTo(CoreRelationTypes.Default_Hierarchical__Parent, setArt)//
      .andTypeEquals(DispoConstants.DispoItem)//
      .andNameEquals(name)//
      .getResults();

      return results.isEmpty();
   }

   @Override
   public List<DispoSet> findDispoSets(DispoProgram program) {
      ResultSet<ArtifactReadable> results = getQuery()//
      .fromBranch(program.getUuid())//
      .andTypeEquals(DispoConstants.DispoSet)//
      .getResults();

      List<DispoSet> toReturn = new ArrayList<>();
      for (ArtifactReadable art : results) {
         toReturn.add(new DispoSetArtifact(art));
      }
      return toReturn;
   }

   @Override
   public DispoSet findDispoSetsById(DispoProgram program, String setId) {
      ArtifactReadable result = findDispoArtifact(program, setId, DispoConstants.DispoSet);
      return new DispoSetArtifact(result);
   }

   private ArtifactReadable findDispoArtifact(DispoProgram program, String setId, IArtifactType type) {
      return getQuery()//
      .fromBranch(program.getUuid())//
      .andGuid(setId)//
      .getResults().getOneOrNull();
   }

   @Override
   public List<DispoItem> findDipoItems(DispoProgram program, String setId) {
      ArtifactReadable setArt = findDispoArtifact(program, setId, DispoConstants.DispoSet);
      ResultSet<ArtifactReadable> results = setArt.getChildren();

      List<DispoItem> toReturn = new ArrayList<>();
      for (ArtifactReadable art : results) {
         DispoItemArtifact dispoItemArtifact = new DispoItemArtifact(art);
         dispoItemArtifact.getAborted();
         toReturn.add(dispoItemArtifact);
      }
      return toReturn;
   }

   @Override
   public Long createDispoProgram(ArtifactReadable author, String name) {
      String normalizedName = "(DISPO)" + name;
      BranchReadable dispoBranch = getQuery().branchQuery().andNameEquals("Dispo Parent").getResults().getExactlyOne();
      IOseeBranch branch = TokenFactory.createBranch(normalizedName);

      try {
         getBranchFactory().createWorkingBranch(branch, author, dispoBranch, null).call();
      } catch (Exception ex) {
         throw OseeCoreException.wrap(ex);
      }

      return branch.getGuid();
   }

   @Override
   public Identifiable<String> createDispoSet(ArtifactReadable author, DispoProgram program, DispoSet descriptor) {
      TransactionBuilder tx = getTxFactory().createTransaction(program.getUuid(), author, "Create Dispo Set");
      ArtifactId creatdArtId = tx.createArtifact(DispoConstants.DispoSet, descriptor.getName());
      tx.setSoleAttributeFromString(creatdArtId, DispoConstants.ImportPath, descriptor.getImportPath());
      tx.setSoleAttributeFromString(creatdArtId, DispoConstants.ImportState, descriptor.getImportState());
      tx.setSoleAttributeFromString(creatdArtId, DispoConstants.DispoType, descriptor.getDispoType());
      tx.setSoleAttributeFromString(creatdArtId, DispoConstants.DispoNotesJson, descriptor.getNotesList().toString());
      tx.commit();
      return creatdArtId;
   }

   @Override
   public boolean deleteDispoItem(ArtifactReadable author, DispoProgram program, String itemId) {
      return deleteDispoEntityArtifact(author, program, itemId, DispoConstants.DispoItem);
   }

   @Override
   public boolean deleteDispoSet(ArtifactReadable author, DispoProgram program, String setId) {
      return deleteDispoEntityArtifact(author, program, setId, DispoConstants.DispoSet);
   }

   private boolean deleteDispoEntityArtifact(ArtifactReadable author, DispoProgram program, String entityId, IArtifactType type) {
      boolean toReturn = false;
      ArtifactReadable dispoArtifact = findDispoArtifact(program, entityId, type);
      if (dispoArtifact != null) {
         TransactionBuilder tx = getTxFactory().createTransaction(program.getUuid(), author, "Delete Dispo Artifact");
         tx.deleteArtifact(dispoArtifact);
         tx.commit();
         toReturn = true;
      }

      return toReturn;
   }

   @Override
   public void updateDispoSet(ArtifactReadable author, DispoProgram program, String setId, DispoSet newData) {
      ArtifactReadable dispoSet = findDispoArtifact(program, setId, DispoConstants.DispoSet);
      DispoSetArtifact origSetAs = new DispoSetArtifact(dispoSet);

      String name = newData.getName();
      String importPath = newData.getImportPath();
      JSONArray notesList = newData.getNotesList();

      TransactionBuilder tx = getTxFactory().createTransaction(program.getUuid(), author, "Update Dispo Set");
      if (name != null && !name.equals(origSetAs.getName())) {
         tx.setName(dispoSet, name);
      }
      if (importPath != null && !importPath.equals(origSetAs.getImportPath())) {
         tx.setSoleAttributeFromString(dispoSet, DispoConstants.ImportPath, importPath);
      }
      if (notesList != null && !notesList.toString().equals(origSetAs.getNotesList().toString())) {
         tx.setSoleAttributeFromString(dispoSet, DispoConstants.DispoNotesJson, notesList.toString());
      }
      tx.commit();
   }

   @Override
   public void createDispoItems(ArtifactReadable author, DispoProgram program, DispoSet parentSet, List<DispoItem> data, String assignee) {
      ArtifactReadable parentSetArt = findDispoArtifact(program, parentSet.getGuid(), DispoConstants.DispoSet);
      TransactionBuilder tx = getTxFactory().createTransaction(program.getUuid(), author, "Create Dispoable Item");

      for (DispoItem item : data) {
         ArtifactId createdItem = tx.createArtifact(DispoConstants.DispoItem, item.getName());

         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoDateCreated, item.getCreationDate());
         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoLastUpdated, item.getLastUpdate());
         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoItemStatus, item.getStatus());
         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoItemTotalPoints, item.getTotalPoints());
         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoItemNeedsRerun, item.getNeedsRerun());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoDiscrepanciesJson,
            item.getDiscrepanciesList().toString());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoAnnotationsJson,
            item.getAnnotationsList().toString());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemVersion, item.getVersion());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemAssignee, assignee);
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemMachine, item.getMachine());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemCategory, item.getCategory());
         tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemElapsedTime, item.getElapsedTime());
         tx.setSoleAttributeValue(createdItem, DispoConstants.DispoItemAborted, item.getAborted());

         if (Strings.isValid(item.getFileNumber())) {
            tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemFileNumber, item.getFileNumber());
         }
         if (Strings.isValid(item.getMethodNumber())) {
            tx.setSoleAttributeFromString(createdItem, DispoConstants.DispoItemMethodNumber, item.getMethodNumber());
         }
         tx.relate(parentSetArt, CoreRelationTypes.Default_Hierarchical__Child, createdItem);
      }
      tx.commit();
   }

   private void updateSingleItem(ArtifactReadable author, DispoProgram program, ArtifactReadable currentItemArt, DispoItem newItemData, TransactionBuilder tx, boolean resetRerunFlag) {
      Date lastUpdate = newItemData.getLastUpdate();
      String name = newItemData.getName();
      JSONObject discrepanciesList = newItemData.getDiscrepanciesList();
      JSONArray annotationsList = newItemData.getAnnotationsList();
      String status = newItemData.getStatus();
      String assignee = newItemData.getAssignee();
      String totalPoints = newItemData.getTotalPoints();
      String machine = newItemData.getMachine();
      String category = newItemData.getCategory();
      String elapsedTime = newItemData.getElapsedTime();
      Boolean aborted = newItemData.getAborted();
      String itemNotes = newItemData.getItemNotes();
      String fileNumber = newItemData.getFileNumber();
      String methodNumber = newItemData.getMethodNumber();

      Boolean needsRerun;
      if (resetRerunFlag) {
         needsRerun = false;
      } else {
         needsRerun = newItemData.getNeedsRerun();
      }

      DispoItemArtifact origItem = new DispoItemArtifact(currentItemArt);

      if (name != null && !name.equals(origItem.getName())) {
         tx.setName(currentItemArt, name);
      }
      if (discrepanciesList != null && !discrepanciesList.equals(origItem.getDiscrepanciesList())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoDiscrepanciesJson,
            discrepanciesList.toString());
      }
      if (annotationsList != null && !annotationsList.equals(origItem.getAnnotationsList())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoAnnotationsJson, annotationsList.toString());
      }
      if (assignee != null && !assignee.equals(origItem.getAssignee())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemAssignee, assignee);
      }
      if (status != null && !status.equals(origItem.getStatus())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemStatus, status);
      }
      if (lastUpdate != null && !lastUpdate.equals(origItem.getLastUpdate())) {
         tx.setSoleAttributeValue(currentItemArt, DispoConstants.DispoLastUpdated, lastUpdate);
      }
      if (needsRerun != null && !needsRerun.equals(origItem.getNeedsRerun())) {
         tx.setSoleAttributeValue(currentItemArt, DispoConstants.DispoItemNeedsRerun, needsRerun.booleanValue());
      }
      if (totalPoints != null && !totalPoints.equals(origItem.getTotalPoints())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemTotalPoints, totalPoints);
      }
      if (machine != null && !machine.equals(origItem.getMachine())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemMachine, machine);
      }
      if (category != null && !category.equals(origItem.getCategory())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemCategory, category);
      }
      if (elapsedTime != null && !elapsedTime.equals(origItem.getElapsedTime())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemElapsedTime, elapsedTime);
      }
      if (aborted != null && !aborted.equals(origItem.getAborted())) {
         tx.setSoleAttributeValue(currentItemArt, DispoConstants.DispoItemAborted, aborted);
      }
      if (itemNotes != null && !itemNotes.equals(origItem.getItemNotes())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemItemNotes, itemNotes);
      }
      if (fileNumber != null && !fileNumber.equals(origItem.getFileNumber())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemFileNumber, fileNumber);
      }
      if (methodNumber != null && !methodNumber.equals(origItem.getMethodNumber())) {
         tx.setSoleAttributeFromString(currentItemArt, DispoConstants.DispoItemMethodNumber, methodNumber);
      }

   }

   @Override
   public void updateDispoItem(ArtifactReadable author, DispoProgram program, String dispoItemId, DispoItem data) {
      IOseeBranch branch = TokenFactory.createBranch(program.getUuid());
      TransactionBuilder tx = getTxFactory().createTransaction(branch, author, "Update Dispo Item");
      ArtifactReadable dispoItemArt = findDispoArtifact(program, dispoItemId, DispoConstants.DispoItem);
      updateSingleItem(author, program, dispoItemArt, data, tx, false);
      tx.commit();
   }

   @Override
   public void updateDispoItems(ArtifactReadable author, DispoProgram program, Collection<DispoItem> data, boolean resetRerunFlag, String operation) {
      TransactionBuilder tx = getTxFactory().createTransaction(program.getUuid(), author, operation);

      for (DispoItem newItem : data) {
         ArtifactReadable dispoItemArt = findDispoArtifact(program, newItem.getGuid(), DispoConstants.DispoItem);
         updateSingleItem(author, program, dispoItemArt, newItem, tx, resetRerunFlag);
      }

      tx.commit();
   }

   @Override
   public List<IOseeBranch> getDispoBranches() {
      List<IOseeBranch> dispoBranchesNormalized = new ArrayList<>();
      BranchReadable dispoBranch = getQuery().branchQuery().andNameEquals("Dispo Parent").getResults().getExactlyOne();

      ResultSet<BranchReadable> dispoBranches =
         getQuery().branchQuery().andIsOfType(BranchType.WORKING).andIsChildOf(dispoBranch).getResults();

      for (BranchReadable branch : dispoBranches) {
         IOseeBranch newName =
            TokenFactory.createBranch(branch.getUuid(), branch.getName().replaceFirst("\\(DISPO\\)", ""));

         dispoBranchesNormalized.add(newName);
      }

      return dispoBranchesNormalized;
   }

   @Override
   public Collection<DispoItem> findDispoItemByAnnoationText(DispoProgram program, String setId, String keyword) {
      ArtifactReadable dispoSetArt = findDispoArtifact(program, setId, DispoConstants.DispoSet);

      Set<DispoItem> toReturn = new HashSet<>();
      ResultSet<ArtifactReadable> dispoArtifacts = getQuery()//
      .fromBranch(program.getUuid())//
      .andTypeEquals(DispoConstants.DispoItem)//
      .andRelatedTo(CoreRelationTypes.Default_Hierarchical__Parent, dispoSetArt).and(
         DispoConstants.DispoAnnotationsJson, keyword, //
         QueryOption.CONTAINS_MATCH_OPTIONS)//
         .getResults();

      for (ArtifactReadable art : dispoArtifacts) {
         toReturn.add(new DispoItemArtifact(art));
      }

      return toReturn;
   }

   @Override
   public DispoItem findDispoItemById(DispoProgram program, String itemId) {
      DispoItem toReturn = null;
      ArtifactReadable dispoArtifact = findDispoArtifact(program, itemId, DispoConstants.DispoItem);
      if (dispoArtifact != null) {
         toReturn = new DispoItemArtifact(dispoArtifact);
      }

      return toReturn;
   }

   @Override
   public DispoConfig findDispoConfig(DispoProgram program) {
      ArtifactReadable config =
         getQuery().fromBranch(program.getUuid()).andNameEquals("Program Config").getResults().getOneOrNull();

      if (config == null) {
         return DispoUtil.getDefaultConfig();
      }
      return DispoUtil.configArtToConfigData(new DispoConfigArtifact(config));
   }

   @Override
   public String createDispoReport(DispoProgram program, ArtifactReadable author, String contents, String operationTitle) {
      String toReturn = "";

      TransactionBuilder tx =
         getTxFactory().createTransaction(program.getUuid(), author, "Update Report: " + operationTitle);

      ArtifactReadable reportArt =
         getQuery().fromBranch(program.getUuid()).andNameEquals("Dispo_Report").getResults().getOneOrNull();

      if (reportArt == null) {
         TransactionBuilder txToCreate =
            getTxFactory().createTransaction(program.getUuid(), author, "Add Operation Report Art");
         txToCreate.createArtifact(CoreArtifactTypes.GeneralData, "Dispo_Report");
         txToCreate.commit();
         reportArt =
            getQuery().fromBranch(program.getUuid()).andNameEquals("Dispo_Report").getResults().getExactlyOne();
      }

      tx.setSoleAttributeFromString(reportArt, CoreAttributeTypes.GeneralStringData, contents);
      TransactionReadable commit = tx.commit();
      if (commit != null) {

         ArtifactReadable newRerpotArt =
            getQuery().fromBranch(program.getUuid()).fromTransaction(commit.getCommit()).andGuid(
               reportArt.getGuid()).getResults().getExactlyOne();

         AttributeReadable<Object> contentsAsAttribute =
            newRerpotArt.getAttributes(CoreAttributeTypes.GeneralStringData).getExactlyOne();

         toReturn = String.format("/orcs/branch/%s/artifact/%s/attribute/%s/version/%s", program.getUuid(),
            newRerpotArt.getGuid(), contentsAsAttribute.getLocalId(), commit.getGuid());
      }
      return toReturn;

   }

   @Override
   public Map<String, ArtifactReadable> getCoverageUnits(long branchUuid, String artifactUuid) {
      ArtifactReadable coveragePackage =
         getQuery().fromBranch(branchUuid).andGuid(artifactUuid).getResults().getOneOrNull();

      List<ArtifactReadable> descendants = coveragePackage.getDescendants();
      return getChildrenRecurse(descendants);
   }

   private Map<String, ArtifactReadable> getChildrenRecurse(List<ArtifactReadable> descendants) {
      Map<String, ArtifactReadable> toReturn = new HashMap<>();

      for (ArtifactReadable descendant : descendants) {
         if (!descendant.getAttributeValues(CoverageUtil.Item).isEmpty()) {
            ArtifactReadable parent = descendant.getParent();
            String fullName = String.format("%s.%s", parent.getName(), descendant.getName());
            toReturn.put(fullName, descendant);
         }
      }

      return toReturn;
   }

   @Override
   public void updateOperationSummary(ArtifactReadable author, DispoProgram program, DispoSet set, OperationReport summary) {
      ArtifactReadable dispoSet = findDispoArtifact(program, set.getGuid(), DispoConstants.DispoSet);
      TransactionBuilder tx =
         getTxFactory().createTransaction(program.getUuid(), author, "Update Dispo Operation Report");

      tx.setSoleAttributeFromString(dispoSet, DispoConstants.ImportState, summary.getStatus().getName());
      tx.setSoleAttributeFromString(dispoSet, DispoConstants.OperationSummary,
         DispoUtil.operationReportToString(summary));
      tx.commit();
   }
}

Back to the top