Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6da461831f70d5fe9ff0d4b5e5654c3a5b4bb47e (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
/*********************************************************************
 * Copyright (c) 2010 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

package org.eclipse.osee.framework.core.dsl.ui.integration.internal;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.ArtifactTypeId;
import org.eclipse.osee.framework.core.data.ArtifactTypeToken;
import org.eclipse.osee.framework.core.data.AttributeTypeId;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.data.RelationTypeToken;
import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider;
import org.eclipse.osee.framework.jdk.core.type.Id;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

/**
 * @author Roberto E. Escobar
 */
public final class ArtifactDataProviderImpl implements ArtifactDataProvider {

   @Override
   public boolean isApplicable(Object object) {
      boolean result = false;
      try {
         result = asCastedObject(object) != null;
      } catch (OseeCoreException ex) {
         OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE, ex);
      }
      return result;
   }

   @Override
   public ArtifactProxy asCastedObject(Object object) {
      XArtifactProxy proxy = null;
      if (object instanceof Artifact) {
         final Artifact artifact = (Artifact) object;
         proxy = new XArtifactProxy(artifact);
      } else if (object instanceof BranchId) {
         BranchId branch = (BranchId) object;
         final Artifact artifact = OseeSystemArtifacts.getDefaultHierarchyRootArtifact(branch);
         proxy = new XArtifactProxy(artifact);
      }
      return proxy;
   }

   private final class XArtifactProxy implements ArtifactProxy {
      private final Artifact self;

      public XArtifactProxy(Artifact self) {
         this.self = self;
      }

      @Override
      public String getGuid() {
         return self.getGuid();
      }

      @Override
      public ArtifactTypeToken getArtifactType() {
         return self.getArtifactType();
      }

      @Override
      public boolean isOfType(ArtifactTypeId... artifactTypes) {
         return self.isOfType(artifactTypes);
      }

      @Override
      public boolean isAttributeTypeValid(AttributeTypeId attributeType) {
         return self.isAttributeTypeValid(attributeType);
      }

      @Override
      public Collection<RelationTypeToken> getValidRelationTypes() {
         return org.eclipse.osee.framework.jdk.core.util.Collections.cast(self.getValidRelationTypes());
      }

      @Override
      public Collection<ArtifactProxy> getHierarchy() {
         Collection<ArtifactProxy> hierarchy = new HashSet<>();
         try {
            Artifact artifactPtr = self.getParent();
            while (artifactPtr != null) {
               if (!hierarchy.add(new XArtifactProxy(artifactPtr))) {
                  OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE,
                     String.format("Cycle detected with artifact: %s", artifactPtr));
                  return Collections.emptyList();
               }
               artifactPtr = artifactPtr.getParent();
            }
         } catch (OseeCoreException ex) {
            OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE, ex);
         }
         return hierarchy;
      }

      @Override
      public boolean matches(Id... identities) {
         return self.matches(identities);
      }

      @Override
      public BranchId getBranch() {
         return self.getBranch();
      }

      @Override
      public IOseeBranch getBranchToken() {
         return self.getBranchToken();
      }

      @Override
      public String getName() {
         return self.getName();
      }

      @Override
      public int hashCode() {
         return self.hashCode();
      }

      @Override
      public boolean equals(Object obj) {
         return self.equals(obj);
      }

      @Override
      public String toString() {
         return self.toString();
      }

      @Override
      public Long getId() {
         return self.getId();
      }
   }
}

Back to the top