// Path: src/main/java/org/commonwl/view/WebConfig.java
// public static enum Format {
//     // Browser
//     html(MediaType.TEXT_HTML),
//     // API
//     json(MediaType.APPLICATION_JSON),
//     // RDF
//     turtle("text/turtle"), jsonld("application/ld+json"), rdfxml("application/rdf+xml"),
//     // Images
//     svg("image/svg+xml"), png(MediaType.IMAGE_PNG), dot("text/vnd+graphviz"),
//     // Archives
//     zip("application/zip"), ro("application/vnd.wf4ever.robundle+zip"),
//     // raw redirects
//     yaml("text/x-yaml"), raw(MediaType.APPLICATION_OCTET_STREAM);
// 
//     private final MediaType mediaType;
// 
//     Format(MediaType mediaType) {
//         this.mediaType = mediaType;
//     }
// 
//     Format(String mediaType) {
//         this.mediaType = parseMediaType(mediaType);
//     }
// 
//     public MediaType mediaType() {
//         return mediaType;
//     }
// }


import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.commonwl.view.WebConfig.Format;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.commonwl.view.workflow;



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

    private final Collection<Workflow> matches;

    public MultipleWorkflowsException(Workflow match) {
        this(Collections.singleton(match));
    }

    public MultipleWorkflowsException(Collection<Workflow> matches) {
        if (matches.isEmpty()) {
            throw new IllegalArgumentException("MultipleWorkflowsException, but empty list of workflows");
        }
        this.matches = matches;
    }

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

    public String getRawPermalink() {
        // all raw URIs should be the same without ?part=
// Path: src/main/java/org/commonwl/view/WebConfig.java
// public static enum Format {
//     // Browser
//     html(MediaType.TEXT_HTML),
//     // API
//     json(MediaType.APPLICATION_JSON),
//     // RDF
//     turtle("text/turtle"), jsonld("application/ld+json"), rdfxml("application/rdf+xml"),
//     // Images
//     svg("image/svg+xml"), png(MediaType.IMAGE_PNG), dot("text/vnd+graphviz"),
//     // Archives
//     zip("application/zip"), ro("application/vnd.wf4ever.robundle+zip"),
//     // raw redirects
//     yaml("text/x-yaml"), raw(MediaType.APPLICATION_OCTET_STREAM);
// 
//     private final MediaType mediaType;
// 
//     Format(MediaType mediaType) {
//         this.mediaType = mediaType;
//     }
// 
//     Format(String mediaType) {
//         this.mediaType = parseMediaType(mediaType);
//     }
// 
//     public MediaType mediaType() {
//         return mediaType;
//     }
// }


// Path: src/main/java/org/commonwl/view/workflow/MultipleWorkflowsException.java
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.commonwl.view.WebConfig.Format;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package org.commonwl.view.workflow;



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

    private final Collection<Workflow> matches;

    public MultipleWorkflowsException(Workflow match) {
        this(Collections.singleton(match));
    }

    public MultipleWorkflowsException(Collection<Workflow> matches) {
        if (matches.isEmpty()) {
            throw new IllegalArgumentException("MultipleWorkflowsException, but empty list of workflows");
        }
        this.matches = matches;
    }

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

    public String getRawPermalink() {
        // all raw URIs should be the same without ?part=
        return matches.stream().findAny().get().getPermalink(Format.raw);