Search in sources :

Example 1 with ApiIgnore

use of springfox.documentation.annotations.ApiIgnore in project alien4cloud by alien4cloud.

the class SuggestionController method nodeTypeSuggest.

@ApiIgnore
@RequestMapping(value = "/nodetypes", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("isAuthenticated()")
public RestResponse<String[]> nodeTypeSuggest(@RequestParam("text") String searchText, @RequestParam(value = "isAbstract", required = false) Boolean isAbstract) {
    if (searchText == null || searchText.trim().isEmpty()) {
        return RestResponseBuilder.<String[]>builder().data(new String[0]).build();
    }
    searchText = StringUtils.lowerCase(searchText);
    QueryBuilder queryOnText = QueryBuilders.regexpQuery("elementId", ".*?" + searchText + ".*");
    // FIXME the way of getting the highest version of a component has changed
    // QueryBuilder queryOnHighest = QueryBuilders.termQuery("highestVersion", true);
    BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery().must(queryOnText);
    QueryBuilder query = boolQueryBuilder;
    if (isAbstract != null) {
        query = boolQueryBuilder.must(QueryBuilders.termQuery("abstract", isAbstract));
    }
    return RestResponseBuilder.<String[]>builder().data(dao.selectPath(dao.getIndexForType(NodeType.class), new String[] { MappingBuilder.indexTypeFromClass(NodeType.class) }, query, SortOrder.ASC, "elementId", 0, 10)).build();
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) NodeType(org.alien4cloud.tosca.model.types.NodeType) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ApiIgnore

use of springfox.documentation.annotations.ApiIgnore in project alien4cloud by alien4cloud.

the class EditorController method downloadTempFile.

/**
 * Download a temporary file which is not yet commited (uploaded or modified through an operation).
 *
 * @param topologyId The if of the topology.
 * @param artifactId The id of the temporary artifact.
 * @return The response entity with the input stream of the file.
 */
@ApiIgnore
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{topologyId:.+}/file/{artifactId:.+}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<InputStreamResource> downloadTempFile(@PathVariable String topologyId, @PathVariable String artifactId) {
    editorService.checkAuthorization(topologyId);
    HttpHeaders headers = new HttpHeaders();
    headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
    headers.add("Pragma", "no-cache");
    headers.add("Expires", "0");
    long length = artifactRepository.getFileLength(artifactId);
    return ResponseEntity.ok().headers(headers).contentLength(length).contentType(MediaType.parseMediaType("application/octet-stream")).body(new InputStreamResource(artifactRepository.getFile(artifactId)));
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) InputStreamResource(org.springframework.core.io.InputStreamResource) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with ApiIgnore

use of springfox.documentation.annotations.ApiIgnore in project alien4cloud by alien4cloud.

the class EditorController method upload.

/**
 * Method exposed to REST to upload a file in an archive under edition.
 *
 * @param topologyId The id of the topology/archive under edition.
 * @param lastOperationId The id of the user last known operation (for optimistic locking edition).
 * @param path The path in which to save/override the file in the archive.
 * @param file The file to save in the archive.
 */
@ApiIgnore
@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/{topologyId:.+}/upload", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public RestResponse<TopologyDTO> upload(@PathVariable String topologyId, @RequestParam("lastOperationId") String lastOperationId, @RequestParam("path") String path, @RequestParam(value = "file") MultipartFile file) throws IOException {
    if (lastOperationId != null && "null".equals(lastOperationId)) {
        lastOperationId = null;
    }
    try (InputStream artifactStream = file.getInputStream()) {
        UpdateFileOperation updateFileOperation = new UpdateFileOperation(path, artifactStream);
        updateFileOperation.setPreviousOperationId(lastOperationId);
        TopologyDTO topologyDTO = editorService.execute(topologyId, updateFileOperation);
        return RestResponseBuilder.<TopologyDTO>builder().data(topologyDTO).build();
    }
}
Also used : TopologyDTO(alien4cloud.topology.TopologyDTO) InputStream(java.io.InputStream) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ApiIgnore(springfox.documentation.annotations.ApiIgnore) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ApiIgnore

use of springfox.documentation.annotations.ApiIgnore 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)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiIgnore (springfox.documentation.annotations.ApiIgnore)4 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 Application (alien4cloud.model.application.Application)1 Tag (alien4cloud.model.common.Tag)1 TopologyDTO (alien4cloud.topology.TopologyDTO)1 InputStream (java.io.InputStream)1 UpdateFileOperation (org.alien4cloud.tosca.editor.operations.UpdateFileOperation)1 AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1 HttpHeaders (org.springframework.http.HttpHeaders)1