1 /*******************************************************************************
2 * Copyright (c) 2012-2013 University of Stuttgart.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * and the Apache License 2.0 which both accompany this distribution,
6 * and are available at http://www.eclipse.org/legal/epl-v10.html
7 * and http://www.apache.org/licenses/LICENSE-2.0
10 * Oliver Kopp - initial API and implementation
11 *******************************************************************************/
12 package org.eclipse.winery.repository.resources.entitytypes.artifacttypes;
14 import java.util.SortedSet;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.Produces;
18 import javax.ws.rs.QueryParam;
19 import javax.ws.rs.core.MediaType;
20 import javax.ws.rs.core.Response;
21 import javax.ws.rs.core.Response.Status;
23 import org.eclipse.winery.common.ids.definitions.ArtifactTypeId;
24 import org.eclipse.winery.repository.backend.Repository;
25 import org.eclipse.winery.repository.resources.AbstractComponentsResource;
27 public class ArtifactTypesResource extends AbstractComponentsResource<ArtifactTypeResource> {
29 // This cannot be used as the INSTANCE is per startup of the whole
31 // We could do some checking for the number of ArtifactTypeResources or
34 // private final HashMap<String, ArtifactTypeResource> fileExtensionMapping
35 // = new ArtifactTypesResource().getFileExtensionMapping();
38 * @return a mapping from file extension to artifact type resources
40 // public HashMap<String, ArtifactTypeResource> getFileExtensionMapping() {
41 // HashMap<String, ArtifactTypeResource> res = new HashMap<String,
42 // ArtifactTypeResource>();
43 // for (ArtifactTypeResource at : this.getArtifactTypeResources()) {
44 // if (at.getAssociatedFileExtension() != null) {
45 // res.put(at.getAssociatedFileExtension(), at);
52 // should be "QName", but that MIME type is not available. XLink is too
53 // complicated for our setup
54 @Produces(MediaType.TEXT_PLAIN)
55 public Response getArtifactTypeQNameForExtension(@QueryParam("extension") String extension) {
56 if (extension == null) {
57 return Response.status(Status.NOT_ACCEPTABLE).build();
59 ArtifactTypeResource artifactType = this.getArtifactTypeForExtension(extension);
61 if (artifactType == null) {
62 res = Response.status(Status.NOT_FOUND).build();
64 res = Response.ok().entity(artifactType.getId().getQName().toString()).build();
70 * Returns the first matching ArtifactTypeResource for the given file
71 * extension. Returns null if no such ArtifactType can be found
73 * The case of the extension is ignored.
75 * This is more a DAO method
77 public ArtifactTypeResource getArtifactTypeForExtension(String extension) {
78 SortedSet<ArtifactTypeId> allArtifactTypeIds = Repository.INSTANCE.getAllTOSCAComponentIds(ArtifactTypeId.class);
79 ArtifactTypeResource res = null;
80 for (ArtifactTypeId id : allArtifactTypeIds) {
81 ArtifactTypeResource r = new ArtifactTypeResource(id);
82 if (extension.equalsIgnoreCase(r.getAssociatedFileExtension())) {