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

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.regex.Pattern;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.osee.ats.AtsPlugin;
import org.eclipse.osee.ats.artifact.ActionArtifact;
import org.eclipse.osee.ats.artifact.TeamDefinitionArtifact;
import org.eclipse.osee.ats.util.LegacyPCRActions;
import org.eclipse.osee.framework.db.connection.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.IATSArtifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.artifact.editor.ArtifactEditor;
import org.eclipse.osee.framework.ui.skynet.util.OSEELog;
import org.eclipse.osee.framework.ui.skynet.widgets.dialog.EntryDialog;
import org.eclipse.swt.widgets.Display;

/**
 * @author Donald G. Dunne
 */
public class MultipleHridSearchItem extends WorldUISearchItem {
   private String enteredIds = "";
   Pattern numberPattern = Pattern.compile("^[0-9]+$");

   public MultipleHridSearchItem(String name) {
      super(name);
   }

   public MultipleHridSearchItem() {
      this("Search by ID(s)");
   }

   public MultipleHridSearchItem(MultipleHridSearchItem multipleHridSearchItem) {
      super(multipleHridSearchItem);
      this.enteredIds = multipleHridSearchItem.enteredIds;
   }

   @Override
   public Collection<Artifact> performSearch(SearchType searchType) throws OseeCoreException {
      List<String> ids = new ArrayList<String>();
      for (String str : enteredIds.split(",")) {
         str = str.replaceAll("^\\s+", "");
         str = str.replaceAll("\\s+$", "");
         if (!str.equals("")) {
            ids.add(str);
         }
      }

      if (isCancelled()) return EMPTY_SET;

      Set<Artifact> resultAtsArts = new HashSet<Artifact>();
      Set<Artifact> resultNonAtsArts = new HashSet<Artifact>();
      Set<Artifact> artifacts = new HashSet<Artifact>();

      Collection<ActionArtifact> actionArts =
            LegacyPCRActions.getTeamsActionArtifacts(ids, (Collection<TeamDefinitionArtifact>) null);
      if (actionArts.size() != 0) {
         for (ActionArtifact teamWf : actionArts) {
            resultAtsArts.add(teamWf);
         }
      }

      // This does artId search
      for (Artifact art : ArtifactQuery.getArtifactsFromIds(Lib.stringToIntegerList(enteredIds),
            BranchManager.getDefaultBranch(), false)) {
         artifacts.add(art);
      }
      // This does hrid/guid search
      for (Artifact art : ArtifactQuery.getArtifactsFromIds(ids, AtsPlugin.getAtsBranch())) {
         artifacts.add(art);
      }

      for (Artifact art : artifacts) {
         if (art instanceof IATSArtifact) {
            resultAtsArts.add(art);
         } else {
            resultNonAtsArts.add(art);
         }
      }

      if (isCancelled()) return EMPTY_SET;

      if (resultAtsArts.size() == 0 && resultNonAtsArts.size() == 0) {
         OSEELog.logException(AtsPlugin.class, "Invalid HRID/Guid/Legacy PCR Id(s): " + Lib.getCommaString(ids), null,
               true);
      }
      if (resultNonAtsArts.size() > 0) {
         ArtifactEditor.editArtifacts(resultNonAtsArts);
      }
      return resultAtsArts;
   }

   @Override
   public void performUI(SearchType searchType) throws OseeCoreException {
      super.performUI(searchType);
      EntryDialog ed =
            new EntryDialog(Display.getCurrent().getActiveShell(), getName(), null,
                  "Enter Legacy ID, Guid or HRID (comma separated)", MessageDialog.QUESTION, new String[] {"OK",
                        "Cancel"}, 0);
      int response = ed.open();
      if (response == 0) {
         enteredIds = ed.getEntry();
         if (enteredIds.equals("oseerocks")) {
            AWorkbench.popup("Confirmation", "Confirmed!  Osee Rocks!");
            cancelled = true;
            return;
         }
         return;
      } else
         enteredIds = null;
      cancelled = true;
   }

   /**
    * @return the enteredIds
    */
   public String getEnteredIds() {
      return enteredIds;
   }

   /* (non-Javadoc)
    * @see org.eclipse.osee.ats.world.search.WorldUISearchItem#copy()
    */
   @Override
   public WorldUISearchItem copy() {
      return new MultipleHridSearchItem(this);
   }

}

Back to the top