Search in sources :

Example 56 with Context

use of javax.ws.rs.core.Context in project Payara by payara.

the class GlassFishDomainResource method setBaseServiceLocator.

// called when jersey is injecting the habitat...
@Context
public void setBaseServiceLocator(LocatorBridge hab) {
    Dom dom1 = Dom.unwrap(hab.getRemoteLocator().<Domain>getService(Domain.class));
    childModel = dom1.document.getRoot().model;
    entity = dom1.document.getRoot();
}
Also used : Dom(org.jvnet.hk2.config.Dom) Domain(com.sun.enterprise.config.serverbeans.Domain) Context(javax.ws.rs.core.Context)

Example 57 with Context

use of javax.ws.rs.core.Context in project winery by eclipse.

the class NodeTemplateResource method createStateElement.

@POST
@Path("state")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response createStateElement(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail, @FormDataParam("file") FormDataBodyPart body, @Context UriInfo uriInfo) {
    LOGGER.debug("Received state artifact for Node Template {} with ID {}", this.nodeTemplate.getName(), this.nodeTemplate.getId());
    LOGGER.debug("Artifact file name is {} and is {} bytes big.", fileDetail.getFileName(), fileDetail.getSize());
    // ensure that the artifact type exists.
    IRepository repo = RepositoryFactory.getRepository();
    repo.getElement(new ArtifactTypeId(OpenToscaBaseTypes.stateArtifactType));
    // create DA
    Optional<TDeploymentArtifact> stateDeploymentArtifact = this.getDeploymentArtifacts().getDeploymentArtifacts().stream().filter(artifact -> artifact.getArtifactType() != null).filter(artifact -> artifact.getArtifactType().equals(OpenToscaBaseTypes.stateArtifactType)).findFirst();
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
    TDeploymentArtifact deploymentArtifact = new TDeploymentArtifact.Builder("state", OpenToscaBaseTypes.stateArtifactType).build();
    String componentVersion = dateFormat.format(new Date());
    ArtifactTemplateId newArtifactTemplateId = new ArtifactTemplateId("http://opentosca.org/artifacttemplates", this.getServiceTemplateResource().getServiceTemplate().getName() + "-" + this.nodeTemplate.getId() + "-State" + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + componentVersion + WineryVersion.WINERY_VERSION_SEPARATOR + WineryVersion.WINERY_VERSION_PREFIX + "1", false);
    LOGGER.debug("Created Artifact Template of Type \"State\" called {}", newArtifactTemplateId.getQName());
    // if there is already a state artifact, update the file
    if (stateDeploymentArtifact.isPresent()) {
        LOGGER.debug("Updating the state DA of the Node Template...");
        deploymentArtifact = stateDeploymentArtifact.get();
        // create new ArtifactTemplate version
        ArtifactTemplateId oldArtifactTemplateId = new ArtifactTemplateId(deploymentArtifact.getArtifactRef());
        List<WineryVersion> versions = WineryVersionUtils.getAllVersionsOfOneDefinition(oldArtifactTemplateId, repo);
        WineryVersion newWineryVersion = VersionUtils.getNewWineryVersion(versions);
        newWineryVersion.setWorkInProgressVersion(0);
        newWineryVersion.setComponentVersion(componentVersion);
        newArtifactTemplateId = (ArtifactTemplateId) VersionSupport.getDefinitionInTheGivenVersion(oldArtifactTemplateId, newWineryVersion);
    } else {
        LOGGER.debug("Creating the state DA of the Node Template...");
        List<TDeploymentArtifact> list = this.nodeTemplate.getDeploymentArtifacts();
        if (Objects.isNull(list)) {
            list = new ArrayList<>();
            this.nodeTemplate.setDeploymentArtifacts(list);
        }
        list.add(deploymentArtifact);
    }
    new ArtifactTemplatesResource().onJsonPost(new QNameWithTypeApiData(newArtifactTemplateId.getQName().getLocalPart(), newArtifactTemplateId.getQName().getNamespaceURI(), OpenToscaBaseTypes.stateArtifactType.toString()));
    LOGGER.debug("Attaching the new Artifact...");
    deploymentArtifact.setArtifactRef(newArtifactTemplateId.getQName());
    Response response = new ArtifactTemplateResource(newArtifactTemplateId).getFilesResource().onPost(uploadedInputStream, fileDetail, body, uriInfo, this.nodeTemplate.getId() + ".state");
    if (response.getStatus() != Response.Status.CREATED.getStatusCode()) {
        LOGGER.debug("Could not create artifact file! Response was {}", response);
        return response;
    }
    LOGGER.debug("Persisting now...");
    return RestUtils.persist(this.res);
}
Also used : Produces(javax.ws.rs.Produces) FormDataContentDisposition(org.glassfish.jersey.media.multipart.FormDataContentDisposition) Date(java.util.Date) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) Namespace(org.eclipse.winery.model.ids.Namespace) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) OpenToscaBaseTypes(org.eclipse.winery.model.tosca.constants.OpenToscaBaseTypes) WineryVersion(org.eclipse.winery.common.version.WineryVersion) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) IdNames(org.eclipse.winery.model.ids.IdNames) ServiceTemplateResource(org.eclipse.winery.repository.rest.resources.servicetemplates.ServiceTemplateResource) Namespaces(org.eclipse.winery.model.tosca.constants.Namespaces) VersionSupport(org.eclipse.winery.model.version.VersionSupport) IPersistable(org.eclipse.winery.repository.rest.resources._support.IPersistable) Map(java.util.Map) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) TEntityTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.TEntityTemplateResource) WineryVersionUtils(org.eclipse.winery.repository.backend.WineryVersionUtils) IIdDetermination(org.eclipse.winery.repository.rest.resources._support.collections.IIdDetermination) Context(javax.ws.rs.core.Context) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) RepositoryFactory(org.eclipse.winery.repository.backend.RepositoryFactory) DeploymentArtifactsResource(org.eclipse.winery.repository.rest.resources.artifacts.DeploymentArtifactsResource) Objects(java.util.Objects) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) List(java.util.List) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) Response(javax.ws.rs.core.Response) VersionUtils(org.eclipse.winery.common.version.VersionUtils) IRepository(org.eclipse.winery.repository.backend.IRepository) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) Optional(java.util.Optional) RestUtils(org.eclipse.winery.repository.rest.RestUtils) UriInfo(javax.ws.rs.core.UriInfo) QName(javax.xml.namespace.QName) GenericDirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.GenericDirectoryId) HEAD(javax.ws.rs.HEAD) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) DirectoryId(org.eclipse.winery.repository.datatypes.ids.elements.DirectoryId) GenericFileResource(org.eclipse.winery.repository.rest.resources._support.GenericFileResource) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) TNodeTemplate(org.eclipse.winery.model.tosca.TNodeTemplate) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) FormParam(javax.ws.rs.FormParam) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) INodeTemplateResourceOrNodeTypeImplementationResource(org.eclipse.winery.repository.rest.resources._support.INodeTemplateResourceOrNodeTypeImplementationResource) PUT(javax.ws.rs.PUT) InputStream(java.io.InputStream) ArtifactTypeId(org.eclipse.winery.model.ids.definitions.ArtifactTypeId) ArtifactTemplatesResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplatesResource) Date(java.util.Date) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) ArtifactTemplateResource(org.eclipse.winery.repository.rest.resources.entitytemplates.artifacttemplates.ArtifactTemplateResource) Response(javax.ws.rs.core.Response) QNameWithTypeApiData(org.eclipse.winery.repository.rest.resources.apiData.QNameWithTypeApiData) TDeploymentArtifact(org.eclipse.winery.model.tosca.TDeploymentArtifact) IRepository(org.eclipse.winery.repository.backend.IRepository) SimpleDateFormat(java.text.SimpleDateFormat) WineryVersion(org.eclipse.winery.common.version.WineryVersion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes)

Example 58 with Context

use of javax.ws.rs.core.Context in project iaf by ibissource.

the class ApiTestBase method checkContextFields.

// This has to happen before it's proxied by Mockito (spy method)
public void checkContextFields(M resource) {
    for (Field field : resource.getClass().getDeclaredFields()) {
        // Injected JAX-WS Resources
        Context context = AnnotationUtils.findAnnotation(field, Context.class);
        if (context != null) {
            field.setAccessible(true);
            if (field.getType().isAssignableFrom(Request.class)) {
                Request request = new MockHttpRequest();
                try {
                    field.set(resource, request);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                    fail("unable to inject Request");
                }
            } else if (field.getType().isAssignableFrom(SecurityContext.class)) {
                try {
                    field.set(resource, securityContext);
                } catch (IllegalArgumentException | IllegalAccessException e) {
                    e.printStackTrace();
                    fail("unable to inject Request");
                }
            }
        }
    }
}
Also used : SecurityContext(javax.ws.rs.core.SecurityContext) IbisContext(nl.nn.adapterframework.configuration.IbisContext) MockServletContext(org.springframework.mock.web.MockServletContext) Context(javax.ws.rs.core.Context) Field(java.lang.reflect.Field) Request(javax.ws.rs.core.Request) SecurityContext(javax.ws.rs.core.SecurityContext)

Example 59 with Context

use of javax.ws.rs.core.Context in project mica2 by obiba.

the class StudyStatesResource method listCollectionStudyStates.

@GET
@Path("/study-states")
@Timed
public List<Mica.StudySummaryDto> listCollectionStudyStates(@QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("type") String type, @QueryParam("exclude") List<String> excludes, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    Stream<? extends EntityState> result;
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = Strings.isNullOrEmpty(type) ? studyService.getIdsByStateFilter(entityStateFilter) : getStudyServiceByType(type).getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(getPermissionResources(type)).ids(filteredIds).build();
    String ids = excludes.stream().map(s -> "id:" + s).collect(Collectors.joining(" "));
    if (!Strings.isNullOrEmpty(ids)) {
        if (Strings.isNullOrEmpty(query))
            query = String.format("NOT(%s)", ids);
        else
            query += String.format(" AND NOT(%s)", ids);
    }
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<Study> studyDocuments = draftStudyService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
    totalCount = studyDocuments.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return studyDocuments.getList().stream().map(study -> dtos.asDto(study, studyService.getEntityState(study.getId()))).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) EntityState(org.obiba.mica.core.domain.EntityState) QueryParam(javax.ws.rs.QueryParam) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) Dtos(org.obiba.mica.web.model.Dtos) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Context(javax.ws.rs.core.Context) Searcher(org.obiba.mica.spi.search.Searcher) HarmonizationStudyService(org.obiba.mica.study.service.HarmonizationStudyService) BaseStudy(org.obiba.mica.study.domain.BaseStudy) HttpServletResponse(javax.servlet.http.HttpServletResponse) StudyService(org.obiba.mica.study.service.StudyService) NotNull(javax.validation.constraints.NotNull) AbstractStudyService(org.obiba.mica.study.service.AbstractStudyService) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) Timed(com.codahale.metrics.annotation.Timed) IndividualStudyService(org.obiba.mica.study.service.IndividualStudyService) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Study(org.obiba.mica.study.domain.Study) Stream(java.util.stream.Stream) DocumentService(org.obiba.mica.core.service.DocumentService) DraftStudyService(org.obiba.mica.study.service.DraftStudyService) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) BaseStudy(org.obiba.mica.study.domain.BaseStudy) Study(org.obiba.mica.study.domain.Study) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 60 with Context

use of javax.ws.rs.core.Context in project mica2 by obiba.

the class DraftProjectsResource method list.

@GET
@Path("/projects")
@Timed
public Mica.ProjectsDto list(@QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = projectService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/project")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<Project> projectDocuments = draftProjectService.find(from, limit, sort, order, null, query, null, null, accessibleIdFilter);
    long totalCount = projectDocuments.getTotal();
    List<Mica.ProjectDto> result = projectDocuments.getList().stream().map(n -> dtos.asDto(n, true)).collect(toList());
    Mica.ProjectsDto.Builder builder = Mica.ProjectsDto.newBuilder();
    builder.setFrom(from).setLimit(limit).setTotal(Long.valueOf(totalCount).intValue());
    builder.addAllProjects(result);
    if (subjectAclService.isPermitted("/draft/project", "ADD")) {
        builder.addActions("ADD");
    }
    return builder.build();
}
Also used : PathParam(javax.ws.rs.PathParam) Project(org.obiba.mica.project.domain.Project) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) ProjectService(org.obiba.mica.project.service.ProjectService) AbstractGitPersistable(org.obiba.mica.core.domain.AbstractGitPersistable) DraftProjectService(org.obiba.mica.project.service.DraftProjectService) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) EventBus(com.google.common.eventbus.EventBus) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Searcher(org.obiba.mica.spi.search.Searcher) HttpServletResponse(javax.servlet.http.HttpServletResponse) ApplicationContext(org.springframework.context.ApplicationContext) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) DocumentService(org.obiba.mica.core.service.DocumentService) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) IndexProjectsEvent(org.obiba.mica.project.event.IndexProjectsEvent) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Project(org.obiba.mica.project.domain.Project) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

Context (javax.ws.rs.core.Context)73 Response (javax.ws.rs.core.Response)54 Path (javax.ws.rs.Path)49 PathParam (javax.ws.rs.PathParam)42 GET (javax.ws.rs.GET)40 List (java.util.List)39 MediaType (javax.ws.rs.core.MediaType)36 POST (javax.ws.rs.POST)35 Produces (javax.ws.rs.Produces)32 UriInfo (javax.ws.rs.core.UriInfo)32 Inject (javax.inject.Inject)29 PUT (javax.ws.rs.PUT)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 QueryParam (javax.ws.rs.QueryParam)27 Collectors (java.util.stream.Collectors)26 Map (java.util.Map)25 Api (io.swagger.annotations.Api)24 ApiOperation (io.swagger.annotations.ApiOperation)24 IOException (java.io.IOException)24 URI (java.net.URI)24