Search in sources :

Example 11 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType in project alien4cloud by alien4cloud.

the class ComponentController method getComponent.

/**
 * Get details for a component based on it's name and version.
 *
 * @param elementId unique id of the component for which to get details.
 * @param version unique id of the component for which to get details.
 * @return A {@link RestResponse} that contains an {@link AbstractToscaType} .
 */
@ApiOperation(value = "Get details for a component (tosca type) from it's id (including archive hash).")
@RequestMapping(value = "/element/{elementId:.+}/version/{version:.+}", method = RequestMethod.GET)
@PreAuthorize("hasAnyAuthority('ADMIN', 'COMPONENTS_MANAGER', 'COMPONENTS_BROWSER')")
public RestResponse<AbstractToscaType> getComponent(@PathVariable String elementId, @PathVariable String version, @RequestParam(required = false) QueryComponentType toscaType) {
    Class<? extends AbstractToscaType> queryClass = toscaType == null ? AbstractToscaType.class : toscaType.getIndexedToscaElementClass();
    AbstractToscaType component = toscaTypeSearchService.find(queryClass, elementId, version);
    return RestResponseBuilder.<AbstractToscaType>builder().data(component).build();
}
Also used : 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 12 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType in project alien4cloud by alien4cloud.

the class ToscaContextualAspect method findDependencies.

private Set<CSARDependency> findDependencies(Object[] args) {
    for (Object arg : args) {
        if (arg instanceof Topology) {
            return ((Topology) arg).getDependencies();
        }
        if (arg instanceof Set) {
            Set set = (Set) arg;
            if (set.size() > 0 && set.iterator().next() instanceof CSARDependency) {
                return (Set<CSARDependency>) arg;
            }
        }
        if (arg instanceof AbstractToscaType) {
            AbstractToscaType type = ((AbstractToscaType) arg);
            Csar csar = csarRepositorySearchService.getArchive(type.getArchiveName(), type.getArchiveVersion());
            if (csar == null) {
                throw new NotFoundException("Unable to find dependencies from type as it's archive cannot be found in the repository.");
            }
            Set<CSARDependency> dependencies = csar.getDependencies() == null ? Sets.newHashSet() : csar.getDependencies();
            dependencies.add(new CSARDependency(type.getArchiveName(), type.getArchiveVersion()));
            return dependencies;
        }
    }
    return Sets.<CSARDependency>newHashSet();
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NotFoundException(alien4cloud.exception.NotFoundException) Topology(org.alien4cloud.tosca.model.templates.Topology) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 13 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType in project alien4cloud by alien4cloud.

the class SuggestionController method tagSuggest.

/**
 * Get suggestion for tags based on current tags defined on the components.
 *
 * @param tagName The name of the tag for which to get suggestion.
 * @param searchPrefix The current prefix for the tag suggestion.
 * @return A {@link RestResponse} that contains a list of suggestions for the tag key.
 */
@ApiIgnore
@RequestMapping(value = "/tag/{tagName}/{searchPrefix}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String[]> tagSuggest(@PathVariable String tagName, @PathVariable String searchPrefix) {
    String suggestFieldPath = TAG_FIELD.concat(".").concat(tagName);
    GetMultipleDataResult searchResult = dao.suggestSearch(INDEXES, CLASSES, suggestFieldPath, searchPrefix, FetchContext.TAG_SUGGESTION, 0, SUGGESTION_COUNT);
    String[] types = searchResult.getTypes();
    Set<String> tagsSuggestions = Sets.newHashSet();
    for (int i = 0; i < types.length; i++) {
        List<Tag> tags;
        if (types[i].equals(MappingBuilder.indexTypeFromClass(Application.class))) {
            Application app = (Application) searchResult.getData()[i];
            tags = app.getTags();
        } else {
            AbstractToscaType indexedToscaElement = (AbstractToscaType) searchResult.getData()[i];
            tags = indexedToscaElement.getTags();
        }
        addSuggestedTag(tags, tagName, searchPrefix, tagsSuggestions);
    }
    return RestResponseBuilder.<String[]>builder().data(tagsSuggestions.toArray(new String[tagsSuggestions.size()])).build();
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) Tag(alien4cloud.model.common.Tag) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Application(alien4cloud.model.application.Application) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType in project alien4cloud by alien4cloud.

the class TopologyStepDefinitions method There_are_properties_for_element_and_archive_version.

@Given("^There are properties for \"([^\"]*)\" element \"([^\"]*)\" and archive version \"([^\"]*)\"$")
public void There_are_properties_for_element_and_archive_version(String elementType, String elementId, String archiveVersion, DataTable properties) throws Throwable {
    String componentId = getFullId(elementId, archiveVersion);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/components/" + componentId));
    AbstractToscaType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), WORDS_TO_CLASSES.get(elementType), Context.getJsonMapper()).getData();
    assertNotNull(idnt);
    assertEquals(componentId, idnt.getId());
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) Given(cucumber.api.java.en.Given)

Example 15 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType in project alien4cloud by alien4cloud.

the class TopologyStepDefinitions method There_is_a_with_element_name_and_archive_version.

@Given("^There is a \"([^\"]*)\" with element name \"([^\"]*)\" and archive version \"([^\"]*)\"$")
public void There_is_a_with_element_name_and_archive_version(String elementType, String elementId, String archiveVersion) throws Throwable {
    String componentId = getFullId(elementId, archiveVersion);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/components/" + componentId));
    AbstractToscaType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), WORDS_TO_CLASSES.get(elementType), Context.getJsonMapper()).getData();
    assertNotNull(idnt);
    assertEquals(componentId, idnt.getId());
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) Given(cucumber.api.java.en.Given)

Aggregations

AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiOperation (io.swagger.annotations.ApiOperation)3 NodeType (org.alien4cloud.tosca.model.types.NodeType)3 Tag (alien4cloud.model.common.Tag)2 Given (cucumber.api.java.en.Given)2 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Application (alien4cloud.model.application.Application)1 And (cucumber.api.java.en.And)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 SneakyThrows (lombok.SneakyThrows)1 CatalogVersionResult (org.alien4cloud.tosca.catalog.CatalogVersionResult)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1 Csar (org.alien4cloud.tosca.model.Csar)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1