use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class TenantFilter method filter.
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
MultivaluedMap<String, String> headers = containerRequestContext.getHeaders();
MultivaluedMap<String, String> queryParameters = containerRequestContext.getUriInfo().getQueryParameters();
String tenantName = null;
if (headers.containsKey(WINERY_TENANT)) {
tenantName = headers.getFirst(WINERY_TENANT);
} else if (queryParameters.containsKey(WINERY_TENANT)) {
tenantName = queryParameters.getFirst(WINERY_TENANT);
}
if (tenantName != null) {
LOGGER.debug("Got new request for tenant: " + tenantName);
IRepository repo = RepositoryFactory.getRepository();
if (repo instanceof TenantRepository) {
((TenantRepository) repo).useTenant(tenantName);
}
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class APIResource method getAllArtifactTemplatesOfContainedDeploymentArtifacts.
@GET
@Path("getallartifacttemplatesofcontaineddeploymentartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedDeploymentArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
if (StringUtils.isEmpty(serviceTemplateQNameString)) {
return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
}
QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
final IRepository repository = RepositoryFactory.getRepository();
if (!repository.exists(serviceTemplateId)) {
return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
}
ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
Collection<QName> artifactTemplates = new ArrayList<>();
List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedDeploymentArtifacts(nodeTemplate, repository);
artifactTemplates.addAll(ats);
}
}
// convert QName list to select2 data
Select2DataWithOptGroups res = new Select2DataWithOptGroups();
for (QName qName : artifactTemplates) {
res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
}
return Response.ok().entity(res.asSortedSet()).build();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class APIResource method getAllArtifactTemplatesOfContainedImplementationArtifacts.
/**
* Implementation similar to
* getAllArtifactTemplatesOfContainedDeploymentArtifacts. Only difference is
* "getArtifactTemplatesOfReferencedImplementationArtifacts" instead of
* "getArtifactTemplatesOfReferencedDeploymentArtifacts".
*/
@GET
@Path("getallartifacttemplatesofcontainedimplementationartifacts")
@Produces(MediaType.APPLICATION_JSON)
public Response getAllArtifactTemplatesOfContainedImplementationArtifacts(@QueryParam("servicetemplate") String serviceTemplateQNameString, @QueryParam("nodetemplateid") String nodeTemplateId) {
if (StringUtils.isEmpty(serviceTemplateQNameString)) {
return Response.status(Status.BAD_REQUEST).entity("servicetemplate has be given as query parameter").build();
}
QName serviceTemplateQName = QName.valueOf(serviceTemplateQNameString);
ServiceTemplateId serviceTemplateId = new ServiceTemplateId(serviceTemplateQName);
final IRepository repository = RepositoryFactory.getRepository();
if (!repository.exists(serviceTemplateId)) {
return Response.status(Status.BAD_REQUEST).entity("service template does not exist").build();
}
ServiceTemplateResource serviceTemplateResource = new ServiceTemplateResource(serviceTemplateId);
Collection<QName> artifactTemplates = new ArrayList<>();
List<TNodeTemplate> allNestedNodeTemplates = BackendUtils.getAllNestedNodeTemplates(serviceTemplateResource.getServiceTemplate());
for (TNodeTemplate nodeTemplate : allNestedNodeTemplates) {
if (StringUtils.isEmpty(nodeTemplateId) || nodeTemplate.getId().equals(nodeTemplateId)) {
Collection<QName> ats = BackendUtils.getArtifactTemplatesOfReferencedImplementationArtifacts(nodeTemplate, repository);
artifactTemplates.addAll(ats);
}
}
// convert QName list to select2 data
Select2DataWithOptGroups res = new Select2DataWithOptGroups();
for (QName qName : artifactTemplates) {
res.add(qName.getNamespaceURI(), qName.toString(), qName.getLocalPart());
}
return Response.ok().entity(res.asSortedSet()).build();
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class AbstractComponentsResource method getListOfAllIds.
/**
* Used by org.eclipse.winery.repository.repository.client and by the artifactcreationdialog.tag. Especially the
* "name" field is used there at the UI
*
* @param grouped if given, the JSON output is grouped by namespace
* @return A list of all ids of all instances of this component type. Format: <code>[({"namespace": "[namespace]",
* "id": "[id]"},)* ]</code>.
* <p>
* If grouped is set, the list will be grouped by namespace.
* <code>[{"id": "[namsepace encoded]", "test": "[namespace decoded]", "children":[{"id": "[qName]", "text":
* "[id]"}]}]</code>
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Object getListOfAllIds(@QueryParam("grouped") String grouped, @QueryParam("includeVersions") String includeVersions, @QueryParam("full") @ApiParam("If set, the full information of the definition's child is returned. E.g., in the case of node types, the same result as a GET on {ns}/{id] is returned. Works only in the case of grouped.") String full) {
Class<? extends DefinitionsChildId> idClass = RestUtils.getComponentIdClassForComponentContainer(this.getClass());
final IRepository repository = RepositoryFactory.getRepository();
SortedSet<? extends DefinitionsChildId> allDefinitionsChildIds = repository.getAllDefinitionsChildIds(idClass);
if (Objects.nonNull(grouped)) {
return getGroupedListOfIds(allDefinitionsChildIds, full, includeVersions);
} else {
return RestUtils.getListOfIds(allDefinitionsChildIds, Objects.nonNull(full), Objects.nonNull(includeVersions));
}
}
use of org.eclipse.winery.repository.backend.IRepository in project winery by eclipse.
the class TenantRepositoryTest method testTenantRepository.
@Test
public void testTenantRepository() throws Exception {
Path repositoryRoot = Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot());
Environments.getInstance().getRepositoryConfig().setTenantRepository(true);
RepositoryFactory.reconfigure();
IRepository repository = RepositoryFactory.getRepository(repositoryRoot);
assertTrue(repository instanceof TenantRepository);
Files.createDirectory(repositoryRoot.resolve("tenant_1"));
Files.createDirectory(repositoryRoot.resolve("tenant_2"));
Files.createDirectory(repositoryRoot.resolve("tenant_3"));
((TenantRepository) repository).useTenant("tenant_1");
repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test1")), new TServiceTemplate.Builder("test1").build());
((TenantRepository) repository).useTenant("tenant_3");
repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test53")), new TServiceTemplate.Builder("test53").build());
repository.setElement(new ServiceTemplateId(QName.valueOf("{namespace}test3")), new TServiceTemplate.Builder("test3").build());
SortedSet<ServiceTemplateId>[] serviceTemplates = new SortedSet[3];
Thread tenant1Thread = new Thread(() -> {
((TenantRepository) repository).useTenant("tenant_1");
serviceTemplates[0] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
});
Thread tenant2Thread = new Thread(() -> {
((TenantRepository) repository).useTenant("tenant_2");
serviceTemplates[1] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
});
Thread tenant3Thread = new Thread(() -> {
((TenantRepository) repository).useTenant("tenant_3");
serviceTemplates[2] = repository.getAllDefinitionsChildIds(ServiceTemplateId.class);
});
tenant1Thread.start();
tenant2Thread.start();
tenant3Thread.start();
tenant1Thread.join();
tenant2Thread.join();
tenant3Thread.join();
assertEquals(1, serviceTemplates[0].size());
assertEquals(QName.valueOf("{namespace}test1"), serviceTemplates[0].first().getQName());
assertEquals(0, serviceTemplates[1].size());
assertEquals(2, serviceTemplates[2].size());
assertTrue(serviceTemplates[2].removeIf(serviceTemplateId -> serviceTemplateId.getQName().equals(QName.valueOf("{namespace}test53"))));
assertTrue(serviceTemplates[2].removeIf(serviceTemplateId -> serviceTemplateId.getQName().equals(QName.valueOf("{namespace}test3"))));
assertEquals(0, serviceTemplates[2].size());
}
Aggregations