Skip to main content
summaryrefslogtreecommitdiffstats
blob: 61f7ccfae1019278fa8b913fc2fd6c1dd38ab165 (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
/*******************************************************************************
 * 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.manager.servlet.ats;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Collections;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.resource.management.IResource;
import org.w3c.dom.Node;

/**
 * @author Roberto E. Escobar
 */
public class AtsXmlSearch {

   public AtsXmlSearch() {
   }

   public Collection<Node> findPrograms(IResource resource) throws OseeCoreException {
      return XmlUtil.findInResource(resource, "//program");
   }

   public Collection<Node> findBuildsByProgramId(IResource resource, String programId) throws OseeCoreException {
      return XmlUtil.findInResource(resource, "//build[buildProgramId=\"" + programId + "\"]");
   }

   public Collection<Node> findWorkflowsByProgramAndBuild(IResource resource, String programId, String buildId) throws OseeCoreException {
      return XmlUtil.findInResource(resource,
         "//workflow[workflowProgramId=\"" + programId + "\" and workflowBuildId=\"" + buildId + "\"]");
   }

   public Collection<Node> findWorkflowsById(IResource resource, String id) throws OseeCoreException {
      Collection<Node> toReturn = null;
      String predicate = multiIdsToXPath(id);
      if (Strings.isValid(predicate)) {
         StringBuilder builder = new StringBuilder();
         builder.append("//workflow[");
         builder.append(predicate);
         builder.append("]");
         toReturn = XmlUtil.findInResource(resource, builder.toString());
      } else {
         toReturn = java.util.Collections.emptyList();
      }
      return toReturn;
   }

   public String multiIdsToXPath(String idsWithCommas) throws OseeCoreException {
      List<String> predicates = new ArrayList<String>();
      if (Strings.isValid(idsWithCommas)) {
         String[] ids = idsWithCommas.split("[\\s,]+");
         for (String id : ids) {
            predicates.add(idToXPath(id));
         }
      }
      return Collections.toString(" or ", predicates);
   }

   public String idToXPath(String id) throws OseeCoreException {
      StringBuilder builder = new StringBuilder();
      if (IdUtils.isValidLegacyId(id)) {
         builder.append("workflowPcrId=");
      } else if (IdUtils.isValidGUID(id)) {
         builder.append("workflowId=");
      } else if (IdUtils.isValidHRID(id)) {
         builder.append("workflowHrid=");
      } else {
         throw new OseeCoreException(String.format("Invalid id [%s]", id));
      }
      if (builder.length() > 0) {
         builder.append("\"" + id + "\"");
      }
      return builder.toString();
   }
}

Back to the top