Skip to main content
summaryrefslogtreecommitdiffstats
blob: 1a8849fcb09666c33db66a4b9f282c65ad5cbd1c (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
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.ats.core.client.config;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.api.data.AtsAttributeTypes;
import org.eclipse.osee.ats.core.config.AtsConfigCache;
import org.eclipse.osee.ats.core.util.AtsObjects;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.util.Result;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

/**
 * @author Donald G. Dunne
 */
public class ActionableItemManager {

   private final Artifact artifact;

   public ActionableItemManager(Artifact artifact) {
      this.artifact = artifact;
   }

   public Set<IAtsActionableItem> getActionableItems() throws OseeCoreException {
      Set<IAtsActionableItem> ais = new HashSet<IAtsActionableItem>();
      for (String guid : getActionableItemGuids()) {
         IAtsActionableItem aia = AtsConfigCache.instance.getSoleByGuid(guid, IAtsActionableItem.class);
         ais.add(aia);
      }
      return ais;
   }

   public String getActionableItemsStr() throws OseeCoreException {
      return AtsObjects.toString("; ", getActionableItems());
   }

   public List<String> getActionableItemGuids() throws OseeCoreException {
      return artifact.getAttributesToStringList(AtsAttributeTypes.ActionableItem);
   }

   public void addActionableItem(IAtsActionableItem aia) throws OseeCoreException {
      if (!getActionableItemGuids().contains(aia.getGuid())) {
         artifact.addAttribute(AtsAttributeTypes.ActionableItem, aia.getGuid());
      }
   }

   public void removeActionableItem(IAtsActionableItem aia) throws OseeCoreException {
      artifact.deleteAttribute(AtsAttributeTypes.ActionableItem, aia.getGuid());
   }

   public Result setActionableItems(Collection<IAtsActionableItem> newItems) throws OseeCoreException {
      Set<IAtsActionableItem> existingAias = getActionableItems();

      // Remove non-selected items
      for (IAtsActionableItem existingAia : existingAias) {
         if (!newItems.contains(existingAia)) {
            removeActionableItem(existingAia);
         }
      }

      // Add newly-selected items
      for (IAtsActionableItem newItem : newItems) {
         if (!existingAias.contains(newItem)) {
            addActionableItem(newItem);
         }
      }

      return Result.TrueResult;
   }

}

Back to the top