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