Search in sources :

Example 1 with CatalogVersionResult

use of org.alien4cloud.tosca.catalog.CatalogVersionResult in project alien4cloud by alien4cloud.

the class ComponentController method getComponentVersions.

/**
 * Get all versions of a given component.
 *
 * @param elementId unique id of the component for which to get all other versions.
 * @return A {@link RestResponse} that contains an {@link AbstractToscaType} .
 */
@ApiOperation(value = "Get details for a component (tosca type).")
@RequestMapping(value = "/element/{elementId:.+}/versions", method = RequestMethod.GET)
@PreAuthorize("hasAnyAuthority('ADMIN', 'COMPONENTS_MANAGER', 'COMPONENTS_BROWSER')")
public RestResponse<CatalogVersionResult[]> getComponentVersions(@PathVariable String elementId, @RequestParam(required = false) QueryComponentType toscaType) {
    Class<? extends AbstractToscaType> queryClass = toscaType == null ? AbstractToscaType.class : toscaType.getIndexedToscaElementClass();
    Object array = toscaTypeSearchService.findAll(queryClass, elementId);
    if (array != null) {
        int length = Array.getLength(array);
        CatalogVersionResult[] versions = new CatalogVersionResult[length];
        for (int i = 0; i < length; i++) {
            AbstractToscaType element = ((AbstractToscaType) Array.get(array, i));
            versions[i] = new CatalogVersionResult(element.getId(), element.getArchiveVersion());
        }
        return RestResponseBuilder.<CatalogVersionResult[]>builder().data(versions).build();
    }
    return RestResponseBuilder.<CatalogVersionResult[]>builder().data(new CatalogVersionResult[0]).build();
}
Also used : CatalogVersionResult(org.alien4cloud.tosca.catalog.CatalogVersionResult) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with CatalogVersionResult

use of org.alien4cloud.tosca.catalog.CatalogVersionResult in project alien4cloud by alien4cloud.

the class MixingComponentVersionsDefinitionsSteps method getComponentVersions.

private Set<String> getComponentVersions(String elementId) throws Throwable {
    Set<String> versions = Sets.newHashSet();
    String responseString = Context.getRestClientInstance().get("/rest/v1/components/element/" + elementId + "/versions");
    RestResponse<?> response = JsonUtil.read(responseString);
    List<CatalogVersionResult> versionResults = JsonUtil.toList(JsonUtil.toString(response.getData()), CatalogVersionResult.class);
    for (CatalogVersionResult versionResult : versionResults) {
        versions.add(versionResult.getVersion());
    }
    return versions;
}
Also used : CatalogVersionResult(org.alien4cloud.tosca.catalog.CatalogVersionResult)

Example 3 with CatalogVersionResult

use of org.alien4cloud.tosca.catalog.CatalogVersionResult in project alien4cloud by alien4cloud.

the class TopologyTemplateStepDefinitions method i_Should_Be_Able_To_Retrieve_A_Topology_With_Name_And_Store_It_As_A_SPEL_Context.

@And("^I should be able to retrieve a topology with name \"([^\"]*)\" and store it as a SPEL context$")
public void i_Should_Be_Able_To_Retrieve_A_Topology_With_Name_And_Store_It_As_A_SPEL_Context(String name) throws Throwable {
    CatalogVersionResult version = getOneTopologyVersion(name);
    assertNotNull(version);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/catalog/topologies/" + version.getId()));
    commonStepDefinitions.I_should_receive_a_RestResponse_with_no_error();
    // register the retrieved topology as SPEL context
    Topology topology = JsonUtil.read(Context.getInstance().getRestResponse(), Topology.class, Context.getJsonMapper()).getData();
    Context.getInstance().registerTopologyId(topology.getId());
    Context.getInstance().buildEvaluationContext(topology);
}
Also used : CatalogVersionResult(org.alien4cloud.tosca.catalog.CatalogVersionResult) Topology(org.alien4cloud.tosca.model.templates.Topology) And(cucumber.api.java.en.And)

Aggregations

CatalogVersionResult (org.alien4cloud.tosca.catalog.CatalogVersionResult)3 And (cucumber.api.java.en.And)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1 AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1