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

import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactPersistenceManager;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
 * @author Robert A. Fisher
 */
public class FromArtifactsSearch implements ISearchPrimitive {
   private static final String FROM_ARTIFACT_ELEMENT = "FromArtifact";

   private final List<ISearchPrimitive> criteria;
   private final boolean all;

   @Override
   public String getArtIdColName() {
      return "art_id";
   }

   public FromArtifactsSearch(List<ISearchPrimitive> criteria, boolean all) {
      this.criteria = criteria;
      this.all = all;
   }

   public FromArtifactsSearch(ISearchPrimitive primitive) {
      this.criteria = new ArrayList<ISearchPrimitive>(1);
      this.criteria.add(primitive);
      // all doesn't matter for just one primitive, so assume true
      this.all = true;
   }

   @Override
   public String getCriteriaSql(List<Object> dataList, IOseeBranch branch) throws OseeCoreException {
      return "art_id in (" + ArtifactPersistenceManager.getIdSql(criteria, all, dataList, branch) + ")";
   }

   @Override
   public String getTableSql(List<Object> dataList, IOseeBranch branch) {
      return "osee_artifact";
   }

   @Override
   public String toString() {
      StringBuilder sb = new StringBuilder();

      sb.append("(");

      for (ISearchPrimitive primitive : criteria) {
         sb.append(primitive);
      }

      sb.append(")");

      return sb.toString();
   }

   @Override
   public String getStorageString() {
      try {
         Document document = Jaxp.newDocumentNamespaceAware();

         Element root = document.createElement("FromArtifactAttribute");
         root.appendChild(getStorageElements(document));

         return Jaxp.getDocumentXml(document);
      } catch (Exception ex) {
         throw new IllegalStateException(ex);
      }
   }

   private Element getStorageElements(Document document) {
      Element rootElement = document.createElement(FROM_ARTIFACT_ELEMENT);
      rootElement.setAttribute("all", Boolean.toString(all));
      document.appendChild(rootElement);

      Element child;
      for (ISearchPrimitive primitive : criteria) {
         if (primitive instanceof FromArtifactsSearch) {
            child = ((FromArtifactsSearch) primitive).getStorageElements(document);
         } else {
            child = document.createElement("Simple");
            child.setAttribute("class", primitive.getClass().getCanonicalName());
            child.setAttribute("value", primitive.getStorageString());
         }
         rootElement.appendChild(child);
      }

      return rootElement;
   }
}

Back to the top