Search in sources :

Example 1 with Tool

use of io.dockstore.webservice.core.Tool in project dockstore by dockstore.

the class AdvancedIndexingBenchmarkIT method addLabels.

private void addLabels(long id) {
    Response registerPutLabelResponse = client.target("http://localhost:" + SUPPORT.getLocalPort() + "/containers/" + id + "/labels").queryParam("labels", randomlyGeneratedQueryLabels()).request().header(HttpHeaders.AUTHORIZATION, "Bearer iamafakedockstoretoken").put(Entity.entity("asdf", MediaType.APPLICATION_JSON_TYPE));
    Tool registeredTool = registerPutLabelResponse.readEntity(Tool.class);
    assertEquals(id, registeredTool.getId());
}
Also used : Response(javax.ws.rs.core.Response) Tool(io.dockstore.webservice.core.Tool)

Example 2 with Tool

use of io.dockstore.webservice.core.Tool in project dockstore by dockstore.

the class LanguageHandlerInterface method getURLFromEntry.

/**
 * Given a docker entry (quay or dockerhub), return a URL to the given entry
 *
 * @param dockerEntry has the docker name
 * @return URL
 */
// TODO: Potentially add support for other registries and add message that the registry is unsupported
default String getURLFromEntry(String dockerEntry, ToolDAO toolDAO) {
    // For now ignore tag, later on it may be more useful
    String quayIOPath = "https://quay.io/repository/";
    // For type repo/subrepo:tag
    String dockerHubPathR = "https://hub.docker.com/r/";
    // For type repo:tag
    String dockerHubPathUnderscore = "https://hub.docker.com/_/";
    // Update to tools once UI is updated to use /tools instead of /containers
    String dockstorePath = "https://www.dockstore.org/containers/";
    String url;
    // Remove tag if exists
    Pattern p = Pattern.compile("([^:]+):?(\\S+)?");
    Matcher m = p.matcher(dockerEntry);
    if (m.matches()) {
        dockerEntry = m.group(1);
    }
    if (dockerEntry.isEmpty()) {
        return null;
    }
    // Regex for determining registry requires a tag; add a fake "0" tag
    Optional<Registry> registry = determineImageRegistry(dockerEntry + ":0");
    // TODO: How do we check that the URL is valid? If not then the entry is likely a local docker build
    if (registry.isPresent() && registry.get().equals(Registry.QUAY_IO)) {
        List<Tool> byPath = toolDAO.findAllByPath(dockerEntry, true);
        if (byPath == null || byPath.isEmpty()) {
            // when we cannot find a published tool on Dockstore, link to quay.io
            url = dockerEntry.replaceFirst("quay\\.io/", quayIOPath);
        } else {
            // when we found a published tool, link to the tool on Dockstore
            url = dockstorePath + dockerEntry;
        }
    } else if (registry.isEmpty() || !registry.get().equals(Registry.DOCKER_HUB)) {
        // if the registry is neither Quay nor Docker Hub, return the entry as the url
        url = "https://" + dockerEntry;
    } else {
        // DOCKER_HUB
        String[] parts = dockerEntry.split("/");
        if (parts.length == 2) {
            // if the path looks like pancancer/pcawg-oxog-tools
            List<Tool> publishedByPath = toolDAO.findAllByPath("registry.hub.docker.com/" + dockerEntry, true);
            if (publishedByPath == null || publishedByPath.isEmpty()) {
                // when we cannot find a published tool on Dockstore, link to docker hub
                url = dockerHubPathR + dockerEntry;
            } else {
                // when we found a published tool, link to the tool on Dockstore
                url = dockstorePath + "registry.hub.docker.com/" + dockerEntry;
            }
        } else {
            // if the path looks like debian:8 or debian
            url = dockerHubPathUnderscore + dockerEntry;
        }
    }
    return url;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) List(java.util.List) ArrayList(java.util.ArrayList) Registry(io.dockstore.common.Registry) AbstractImageRegistry(io.dockstore.webservice.helpers.AbstractImageRegistry) Tool(io.dockstore.webservice.core.Tool)

Example 3 with Tool

use of io.dockstore.webservice.core.Tool in project dockstore by dockstore.

the class CollectionResource method deleteEntryFromCollection.

@DELETE
@Timed
@UnitOfWork
@Path("{organizationId}/collections/{collectionId}/entry")
@ApiOperation(value = "Delete an entry from a collection.", authorizations = { @Authorization(value = JWT_SECURITY_DEFINITION_NAME) }, response = Collection.class)
@Operation(operationId = "deleteEntryFromCollection", summary = "Delete an entry to a collection.", description = "Delete an entry to a collection.", security = @SecurityRequirement(name = "bearer"))
public Collection deleteEntryFromCollection(@ApiParam(hidden = true) @Parameter(hidden = true, name = "user") @Auth User user, @ApiParam(value = "Organization ID.", required = true) @Parameter(description = "Organization ID.", name = "organizationId", in = ParameterIn.PATH, required = true) @PathParam("organizationId") Long organizationId, @ApiParam(value = "Collection ID.", required = true) @Parameter(description = "Collection ID.", name = "collectionId", in = ParameterIn.PATH, required = true) @PathParam("collectionId") Long collectionId, @ApiParam(value = "Entry ID", required = true) @Parameter(description = "Entry ID.", name = "entryId", in = ParameterIn.QUERY, required = true) @QueryParam("entryId") Long entryId, @ApiParam(value = "Version ID", required = false) @Parameter(description = "Version ID.", name = "versionId", in = ParameterIn.QUERY, required = false) @QueryParam("versionName") String versionName) {
    // Call common code to check if entry and collection exist and return them
    ImmutablePair<Entry, Collection> entryAndCollection = commonModifyCollection(organizationId, entryId, collectionId, user);
    Long versionId = null;
    if (versionName != null) {
        Set<Version> workflowVersions = entryAndCollection.getLeft().getWorkflowVersions();
        Optional<Version> first = workflowVersions.stream().filter(version -> version.getName().equals(versionName)).findFirst();
        if (first.isPresent()) {
            versionId = first.get().getId();
        } else {
            throw new CustomWebApplicationException("Version not found", HttpStatus.SC_NOT_FOUND);
        }
    }
    // Remove the entry from the organization,
    // This silently fails if the user somehow manages to give a non-existent entryId and versionId pair
    entryAndCollection.getRight().removeEntry(entryAndCollection.getLeft().getId(), versionId);
    // Event for deletion
    Organization organization = organizationDAO.findById(organizationId);
    Event.Builder eventBuild = new Event.Builder().withOrganization(organization).withCollection(entryAndCollection.getRight()).withInitiatorUser(user).withType(Event.EventType.REMOVE_FROM_COLLECTION);
    if (entryAndCollection.getLeft() instanceof BioWorkflow) {
        eventBuild = eventBuild.withBioWorkflow((BioWorkflow) entryAndCollection.getLeft());
    } else if (entryAndCollection.getLeft() instanceof Service) {
        eventBuild = eventBuild.withService((Service) entryAndCollection.getLeft());
    } else if (entryAndCollection.getLeft() instanceof Tool) {
        eventBuild = eventBuild.withTool((Tool) entryAndCollection.getLeft());
    }
    Event removeFromCollectionEvent = eventBuild.build();
    eventDAO.create(removeFromCollectionEvent);
    return collectionDAO.findById(collectionId);
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) WorkflowDAO(io.dockstore.webservice.jdbi.WorkflowDAO) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) ApiParam(io.swagger.annotations.ApiParam) HttpStatus(org.apache.http.HttpStatus) OrganizationUser(io.dockstore.webservice.core.OrganizationUser) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) CollectionEntry(io.dockstore.webservice.core.CollectionEntry) OPENAPI_JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.resources.ResourceConstants.OPENAPI_JWT_SECURITY_DEFINITION_NAME) User(io.dockstore.webservice.core.User) DELETE(javax.ws.rs.DELETE) SecurityRequirement(io.swagger.v3.oas.annotations.security.SecurityRequirement) Schema(io.swagger.v3.oas.annotations.media.Schema) Service(io.dockstore.webservice.core.Service) Collection(io.dockstore.webservice.core.Collection) SessionFactory(org.hibernate.SessionFactory) Set(java.util.Set) Tool(io.dockstore.webservice.core.Tool) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Parameter(io.swagger.v3.oas.annotations.Parameter) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Event(io.dockstore.webservice.core.Event) CollectionDAO(io.dockstore.webservice.jdbi.CollectionDAO) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Tag(io.swagger.v3.oas.annotations.tags.Tag) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) Optional(java.util.Optional) SecuritySchemeType(io.swagger.v3.oas.annotations.enums.SecuritySchemeType) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Auth(io.dropwizard.auth.Auth) Session(org.hibernate.Session) JWT_SECURITY_DEFINITION_NAME(io.dockstore.webservice.Constants.JWT_SECURITY_DEFINITION_NAME) SecurityScheme(io.swagger.v3.oas.annotations.security.SecurityScheme) PublicStateManager(io.dockstore.webservice.helpers.PublicStateManager) ParameterIn(io.swagger.v3.oas.annotations.enums.ParameterIn) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Label(io.dockstore.webservice.core.Label) Content(io.swagger.v3.oas.annotations.media.Content) Operation(io.swagger.v3.oas.annotations.Operation) OrganizationDAO(io.dockstore.webservice.jdbi.OrganizationDAO) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) EventDAO(io.dockstore.webservice.jdbi.EventDAO) Api(io.swagger.annotations.Api) UserDAO(io.dockstore.webservice.jdbi.UserDAO) SecuritySchemes(io.swagger.v3.oas.annotations.security.SecuritySchemes) ToolDAO(io.dockstore.webservice.jdbi.ToolDAO) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) VersionDAO(io.dockstore.webservice.jdbi.VersionDAO) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Organization(io.dockstore.webservice.core.Organization) Version(io.dockstore.webservice.core.Version) Entry(io.dockstore.webservice.core.Entry) PUT(javax.ws.rs.PUT) Authorization(io.swagger.annotations.Authorization) Hibernate(org.hibernate.Hibernate) Organization(io.dockstore.webservice.core.Organization) Service(io.dockstore.webservice.core.Service) CustomWebApplicationException(io.dockstore.webservice.CustomWebApplicationException) BioWorkflow(io.dockstore.webservice.core.BioWorkflow) CollectionEntry(io.dockstore.webservice.core.CollectionEntry) Entry(io.dockstore.webservice.core.Entry) Version(io.dockstore.webservice.core.Version) Collection(io.dockstore.webservice.core.Collection) Event(io.dockstore.webservice.core.Event) Tool(io.dockstore.webservice.core.Tool) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ApiOperation(io.swagger.annotations.ApiOperation) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 4 with Tool

use of io.dockstore.webservice.core.Tool in project dockstore by dockstore.

the class DockerRepoResource method getStarredUsers.

@GET
@Path("/{containerId}/starredUsers")
@Timed
@UnitOfWork(readOnly = true)
@Operation(operationId = "getStarredUsers", description = "Returns list of users who starred a tool.")
@ApiOperation(value = "Returns list of users who starred a tool.", response = User.class, responseContainer = "List")
public Set<User> getStarredUsers(@ApiParam(value = "Tool to grab starred users for.", required = true) @PathParam("containerId") Long containerId) {
    Tool tool = toolDAO.findById(containerId);
    checkEntry(tool);
    return tool.getStarredUsers();
}
Also used : Tool(io.dockstore.webservice.core.Tool) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiOperation(io.swagger.annotations.ApiOperation) Operation(io.swagger.v3.oas.annotations.Operation)

Example 5 with Tool

use of io.dockstore.webservice.core.Tool in project dockstore by dockstore.

the class DockerRepoResource method getPublishedContainer.

@GET
@Timed
@UnitOfWork(readOnly = true)
@Path("/published/{containerId}")
@ApiOperation(value = "Get a published tool.", notes = "NO authentication", response = Tool.class)
public Tool getPublishedContainer(@ApiParam(value = "Tool ID", required = true) @PathParam("containerId") Long containerId, @ApiParam(value = "Comma-delimited list of fields to include: validations") @QueryParam("include") String include) {
    Tool tool = toolDAO.findPublishedById(containerId);
    checkEntry(tool);
    if (checkIncludes(include, "validations")) {
        tool.getWorkflowVersions().forEach(tag -> Hibernate.initialize(tag.getValidations()));
    }
    Hibernate.initialize(tool.getAliases());
    return filterContainersForHiddenTags(tool);
}
Also used : Tool(io.dockstore.webservice.core.Tool) Path(javax.ws.rs.Path) UnitOfWork(io.dropwizard.hibernate.UnitOfWork) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

Tool (io.dockstore.webservice.core.Tool)75 CustomWebApplicationException (io.dockstore.webservice.CustomWebApplicationException)34 ApiOperation (io.swagger.annotations.ApiOperation)33 Operation (io.swagger.v3.oas.annotations.Operation)32 Timed (com.codahale.metrics.annotation.Timed)31 UnitOfWork (io.dropwizard.hibernate.UnitOfWork)31 Path (javax.ws.rs.Path)31 Tag (io.dockstore.webservice.core.Tag)26 ArrayList (java.util.ArrayList)23 SourceFile (io.dockstore.webservice.core.SourceFile)19 Entry (io.dockstore.webservice.core.Entry)18 User (io.dockstore.webservice.core.User)18 List (java.util.List)18 GET (javax.ws.rs.GET)17 Workflow (io.dockstore.webservice.core.Workflow)16 HttpStatus (org.apache.http.HttpStatus)16 Map (java.util.Map)15 Optional (java.util.Optional)15 Set (java.util.Set)15 Logger (org.slf4j.Logger)15