Skip to main content
summaryrefslogtreecommitdiffstats
blob: d972be35c728bec6c84490dc0a85c5be4d033b0a (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
/*******************************************************************************
 * Copyright (c) 2011 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.display.presenter;

import java.util.Arrays;
import java.util.List;

import org.eclipse.osee.display.api.search.ArtifactProvider;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.jdk.core.util.Collections.Filter;
import org.eclipse.osee.orcs.data.ArtifactReadable;

/**
 * @author John R. Misinco
 */
public class ArtifactFilter implements Filter<ArtifactReadable> {

   private static final IArtifactType[] notAllowedTypes = {CoreArtifactTypes.TestRun};

   private static final IArtifactType[] allowedTypes = {
      CoreArtifactTypes.SoftwareRequirement,
      CoreArtifactTypes.SubsystemRequirement,
      CoreArtifactTypes.SystemRequirement,
      CoreArtifactTypes.IndirectSoftwareRequirement,
      CoreArtifactTypes.TestUnit};

   private static final List<String> allowed = Arrays.asList("System Requirements", "Subsystem Requirements",
      "Software Requirements");

   private final ArtifactProvider provider;

   public ArtifactFilter(ArtifactProvider provider) {
      this.provider = provider;
   }

   public IArtifactType[] getAllowedTypes() {
      return allowedTypes;
   }

   @Override
   public boolean accept(ArtifactReadable item) throws Exception {
      boolean isAllowed = false;
      if (item != null) {
         if (item.isOfType(allowedTypes) || item.getBranch().equals(CoreBranches.COMMON)) {
            isAllowed = true;
         } else if (!item.isOfType(notAllowedTypes)) {
            ArtifactReadable current = item;
            while (current != null) {
               if (allowed.contains(current.getName())) {
                  isAllowed = true;
                  break;
               }
               current = provider.getParent(current);
            }
         }
      }
      return isAllowed;
   }
}

Back to the top