Skip to main content
summaryrefslogtreecommitdiffstats
blob: 95899d47b971427d29bd3ee66e799f6facaf5908 (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
/*******************************************************************************
 * 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.framework.skynet.core.importing.operations;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.osee.framework.core.data.IArtifactType;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.operation.AbstractOperation;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.attribute.AttributeTypeManager;
import org.eclipse.osee.framework.skynet.core.importing.RoughArtifact;
import org.eclipse.osee.framework.skynet.core.internal.Activator;

/**
 * Usually used as part of the import process to filter items found by the {@link RoughArtifactCollector}
 * {@link #collector}. Result fills the {@link #selectedArtifactTypes}.
 *
 * @author Roberto E. Escobar
 */
public class FilterArtifactTypesByAttributeTypes extends AbstractOperation {

   private final IOseeBranch branch;
   private final Collection<IArtifactType> selectedArtifactTypes;
   private final RoughArtifactCollector collector;

   /**
    * @param branch
    * @param collector
    * @param selectedArtifactTypes ----> <b>MUTABLE</b> list of items {{@link #doWork(IProgressMonitor)} will operate
    * on.
    */
   public FilterArtifactTypesByAttributeTypes(IOseeBranch branch, RoughArtifactCollector collector, Collection<IArtifactType> selectedArtifactTypes) {
      super("Filter Artifact Types", Activator.PLUGIN_ID);
      this.branch = branch;
      this.selectedArtifactTypes = selectedArtifactTypes;
      this.collector = collector;
   }

   @Override
   protected void doWork(IProgressMonitor monitor) throws Exception {
      Set<String> names = new HashSet<>();
      for (RoughArtifact artifact : collector.getRoughArtifacts()) {
         names.addAll(artifact.getAttributeTypeNames());
      }
      selectedArtifactTypes.clear();
      Set<IAttributeType> requiredTypes = new HashSet<>();
      for (String name : names) {
         requiredTypes.add(AttributeTypeManager.getType(name));
      }
      Branch resolvedBranch = BranchManager.getBranch(branch);
      for (ArtifactType artifactType : ArtifactTypeManager.getConcreteArtifactTypes(resolvedBranch)) {
         Collection<IAttributeType> attributeTypes = artifactType.getAttributeTypes(resolvedBranch);
         if (Collections.setComplement(requiredTypes, attributeTypes).isEmpty()) {
            selectedArtifactTypes.add(artifactType);
         }
      }
   }
}

Back to the top