Skip to main content
summaryrefslogtreecommitdiffstats
blob: f9867b54d3894d74b9a96809623a913bee36db2a (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
/*******************************************************************************
 * Copyright (c) 2013 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.orcs.core.internal.relation.impl;

import java.util.Collection;
import org.eclipse.osee.framework.core.enums.LoadLevel;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.orcs.OrcsSession;
import org.eclipse.osee.orcs.core.ds.DataLoader;
import org.eclipse.osee.orcs.core.ds.DataLoaderFactory;
import org.eclipse.osee.orcs.core.internal.graph.GraphBuilder;
import org.eclipse.osee.orcs.core.internal.graph.GraphBuilderFactory;
import org.eclipse.osee.orcs.core.internal.graph.GraphData;
import org.eclipse.osee.orcs.core.internal.relation.RelationNode;
import org.eclipse.osee.orcs.core.internal.relation.RelationNodeLoader;

/**
 * @author Roberto E. Escobar
 */
public class RelationNodeLoaderImpl implements RelationNodeLoader {

   private final DataLoaderFactory dataLoaderFactory;
   private final GraphBuilderFactory graphBuilderFactory;

   public RelationNodeLoaderImpl(DataLoaderFactory dataLoaderFactory, GraphBuilderFactory graphBuilderFactory) {
      super();
      this.dataLoaderFactory = dataLoaderFactory;
      this.graphBuilderFactory = graphBuilderFactory;
   }

   @Override
   public <T extends RelationNode> Iterable<T> loadNodes(OrcsSession session, final GraphData graph, Collection<Integer> ids, LoadLevel level) throws OseeCoreException {
      GraphBuilder builder = graphBuilderFactory.createBuilderForGraph(graph);

      DataLoader loader = dataLoaderFactory.fromBranchAndArtifactIds(session, graph.getBranch(), ids);
      loader.setLoadLevel(level);
      loader.fromTransaction(graph.getTransaction());
      loader.load(null, builder);

      return getResults(builder);
   }

   @SuppressWarnings("unchecked")
   private static <T> Iterable<T> getResults(GraphBuilder builder) {
      return (Iterable<T>) builder.getArtifacts();
   }

}

Back to the top