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();
}
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);
}
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");
}
}
}
}
}
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());
}
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();
}
Aggregations