• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

common-workflow-language / cwlviewer / #1809

31 Mar 2025 07:07AM CUT coverage: 70.306%. Remained the same
#1809

Pull #695

github

kinow
Add missing license header
Pull Request #695: Add missing license header

1700 of 2418 relevant lines covered (70.31%)

0.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/main/java/org/commonwl/view/workflow/MultipleWorkflowsException.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.commonwl.view.workflow;
21

22
import java.util.Collection;
23
import java.util.Collections;
24
import java.util.HashSet;
25
import java.util.Set;
26
import org.commonwl.view.WebConfig.Format;
27
import org.springframework.http.HttpStatus;
28
import org.springframework.web.bind.annotation.ResponseStatus;
29

30
/** Exception thrown when multiple workflows exist for the request */
31
@ResponseStatus(value = HttpStatus.MULTIPLE_CHOICES)
32
public class MultipleWorkflowsException extends RuntimeException {
33

34
  private final Collection<Workflow> matches;
35

36
  public MultipleWorkflowsException(Workflow match) {
37
    this(Collections.singleton(match));
×
38
  }
×
39

40
  public MultipleWorkflowsException(Collection<Workflow> matches) {
×
41
    if (matches.isEmpty()) {
×
42
      throw new IllegalArgumentException("MultipleWorkflowsException, but empty list of workflows");
×
43
    }
44
    this.matches = matches;
×
45
  }
×
46

47
  // Always CRLF in text/uri-list
48
  private final String CRLF = "\r\n";
×
49

50
  public String getRawPermalink() {
51
    // all raw URIs should be the same without ?part=
52
    return matches.stream().findAny().get().getPermalink(Format.raw);
×
53
  }
54

55
  /**
56
   * Generate a text/uri-list of potential representations/redirects
57
   *
58
   * @see https://www.iana.org/assignments/media-types/text/uri-list
59
   */
60
  @Override
61
  public String toString() {
62
    StringBuffer sb = new StringBuffer();
×
63
    sb.append("## Multiple workflow representations found");
×
64
    sb.append(CRLF);
×
65
    sb.append("# ");
×
66
    sb.append(CRLF);
×
67

68
    sb.append("# ");
×
69
    sb.append(Format.raw.mediaType());
×
70
    sb.append(CRLF);
×
71
    sb.append(getRawPermalink());
×
72
    sb.append(CRLF);
×
73

74
    Set<String> seen = new HashSet<>();
×
75
    // For each workflow, link to each remaining format
76
    for (Workflow w : matches) {
×
77
      if (!seen.add(w.getIdentifier())) {
×
78
        // Skip permalink duplicates
79
        continue;
×
80
      }
81
      sb.append("#");
×
82
      sb.append(CRLF);
×
83
      sb.append("# ");
×
84
      sb.append(w.getIdentifier());
×
85
      sb.append(CRLF);
×
86
      for (Format f : Format.values()) {
×
87
        if (f == Format.raw) {
×
88
          // Already did that one above
89
          continue;
×
90
        }
91
        sb.append("#   ");
×
92
        sb.append(f.mediaType());
×
93
        sb.append(CRLF);
×
94
        sb.append(w.getPermalink(f));
×
95
        sb.append(CRLF);
×
96
      }
97
    }
×
98
    return sb.toString();
×
99
  }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc