use of io.swagger.annotations.ApiResponse in project graylog2-server by Graylog2.
the class IndexSetsResource method list.
@GET
@Timed
@ApiOperation(value = "Get a list of all index sets")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized") })
public IndexSetResponse list(@ApiParam(name = "skip", value = "The number of elements to skip (offset).", required = true) @QueryParam("skip") @DefaultValue("0") int skip, @ApiParam(name = "limit", value = "The maximum number of elements to return.", required = true) @QueryParam("limit") @DefaultValue("0") int limit, @ApiParam(name = "stats", value = "Include index set stats.") @QueryParam("stats") @DefaultValue("false") boolean computeStats) {
final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
List<IndexSetSummary> indexSets;
int count;
if (limit > 0) {
// First collect all index set ids the user is allowed to see.
final Set<String> allowedIds = indexSetService.findAll().stream().filter(indexSet -> isPermitted(RestPermissions.INDEXSETS_READ, indexSet.id())).map(IndexSetConfig::id).collect(Collectors.toSet());
indexSets = indexSetService.findPaginated(allowedIds, limit, skip).stream().map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = allowedIds.size();
} else {
indexSets = indexSetService.findAll().stream().filter(indexSetConfig -> isPermitted(RestPermissions.INDEXSETS_READ, indexSetConfig.id())).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).collect(Collectors.toList());
count = indexSets.size();
}
final Map<String, IndexSetStats> stats;
if (computeStats) {
stats = indexSetRegistry.getAll().stream().collect(Collectors.toMap(indexSet -> indexSet.getConfig().id(), indexSetStatsCreator::getForIndexSet));
} else {
stats = Collections.emptyMap();
}
return IndexSetResponse.create(count, indexSets, stats);
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class AutoProxCalculatorResource method eval.
@ApiOperation(value = "Calculate the effects of referencing a store with the given type and name to determine what AutoProx will auto-create", response = AutoProxCalculation.class)
@ApiResponse(code = 200, message = "Result of calculation")
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response eval(@PathParam("packageType") final String packageType, @PathParam("type") final String type, @PathParam("name") final String remoteName) {
Response response = checkEnabled();
if (response != null) {
return response;
}
try {
StoreKey key = new StoreKey(packageType, StoreType.get(type), remoteName);
final AutoProxCalculation calc = controller.eval(key);
response = formatOkResponseWithJsonEntity(serializer.writeValueAsString(calc == null ? Collections.singletonMap("error", "Nothing was created") : calc));
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
response = formatResponse(e);
} catch (final JsonProcessingException e) {
logger.error(String.format("Failed to create demo RemoteRepository for: '%s'. Reason: %s", remoteName, e.getMessage()), e);
response = formatResponse(e);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class PromoteResource method promoteToGroup.
@ApiOperation("Promote a source repository into the membership of a target group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = GroupPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON request specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.GroupPromoteRequest")
@Path("/groups/promote")
@POST
@Consumes(ApplicationContent.application_json)
public GroupPromoteResult promoteToGroup(final GroupPromoteRequest request, @Context final HttpServletRequest servletRequest, @Context final SecurityContext securityContext, @Context final UriInfo uriInfo) {
Response response = null;
try {
PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(request.getSource().getPackageType());
String user = securityManager.getUser(securityContext, servletRequest);
final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(request.getSource().getType().singularEndpointName(), request.getSource().getName()).toString();
return manager.promoteToGroup(request, user, baseUrl);
} catch (PromotionException e) {
logger.error(e.getMessage(), e);
throwError(e);
}
return null;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class MaintenanceHandler method deprecatedRescan.
@ApiOperation("[Deprecated] Rescan all content in the specified repository to re-initialize metadata, capture missing index keys, etc.")
@ApiResponse(code = 200, message = "Rescan was started successfully. (NOTE: There currently is no way to determine when rescanning is complete.)")
@Path("/rescan/{type: (hosted|group|remote)}/{name}")
@GET
@Deprecated
public Response deprecatedRescan(@ApiParam(value = "The type of store / repository", allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam("The name of the store / repository") @PathParam("name") final String name) {
final StoreType storeType = StoreType.get(type);
String altPath = Paths.get("/api/admin/maint", MAVEN_PKG_KEY, type, name).toString();
final StoreKey key = new StoreKey(storeType, name);
Response response;
try {
contentController.rescan(key);
response = markDeprecated(Response.ok(), altPath).build();
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to rescan: %s. Reason: %s", key, e.getMessage()), e);
response = formatResponse(e, rb -> markDeprecated(rb, altPath));
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class MaintenanceHandler method rescan.
@ApiOperation("Rescan all content in the specified repository to re-initialize metadata, capture missing index keys, etc.")
@ApiResponse(code = 200, message = "Rescan was started successfully. (NOTE: There currently is no way to determine when rescanning is complete.)")
@Path("/rescan/{packageType}/{type: (hosted|group|remote)}/{name}")
@GET
public Response rescan(@ApiParam(value = "The package type (eg. maven, npm, generic-http)", required = true) @PathParam("packageType") final String packageType, @ApiParam(value = "The type of store / repository", allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam("The name of the store / repository") @PathParam("name") final String name) {
final StoreKey key = new StoreKey(packageType, StoreType.get(type), name);
Response response;
try {
contentController.rescan(key);
response = Response.ok().build();
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to rescan: %s. Reason: %s", key, e.getMessage()), e);
response = formatResponse(e);
}
return response;
}
Aggregations