use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class StoreAdminHandler method create.
@ApiOperation("Create a new store")
@ApiResponses({ @ApiResponse(code = 201, response = ArtifactStore.class, message = "The store was created"), @ApiResponse(code = 409, message = "A store with the specified type and name already exists") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@POST
@Consumes(ApplicationContent.application_json)
@Produces(ApplicationContent.application_json)
public Response create(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
final StoreType st = StoreType.get(type);
Response response = null;
String json = null;
try {
json = IOUtils.toString(request.getInputStream());
// logger.warn("=> JSON: " + json);
json = objectMapper.patchLegacyStoreJson(json);
} catch (final IOException e) {
final String message = "Failed to read " + st.getStoreClass().getSimpleName() + " from request body.";
logger.error(message, e);
response = responseHelper.formatResponse(e, message);
}
if (response != null) {
return response;
}
ArtifactStore store = null;
try {
store = objectMapper.readValue(json, st.getStoreClass());
} catch (final IOException e) {
final String message = "Failed to parse " + st.getStoreClass().getSimpleName() + " from request body.";
logger.error(message, e);
response = responseHelper.formatResponse(e, message);
}
if (response != null) {
return response;
}
logger.info("\n\nGot artifact store: {}\n\n", store);
try {
String user = securityManager.getUser(securityContext, request);
if (adminController.store(store, user, false)) {
final URI uri = uriInfo.getBaseUriBuilder().path("/api/admin/stores").path(store.getPackageType()).path(store.getType().singularEndpointName()).build(store.getName());
response = responseHelper.formatCreatedResponseWithJsonEntity(uri, store);
} else {
response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = responseHelper.formatResponse(e);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class StoreAdminHandler method revalidateArtifactStores.
@ApiOperation("Revalidation of Artifacts Stored on demand")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repositories was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/revalidate/all/")
@POST
public Response revalidateArtifactStores(@PathParam("packageType") String packageType, @PathParam("type") String type) {
ArtifactStoreValidateData result = null;
Map<String, ArtifactStoreValidateData> results = new HashMap<>();
Response response;
try {
StoreType storeType = StoreType.get(type);
List<ArtifactStore> allArtifactStores = adminController.getAllOfType(packageType, storeType);
for (ArtifactStore artifactStore : allArtifactStores) {
// Validate this Store
result = adminController.validateStore(artifactStore);
results.put(artifactStore.getKey().toString(), result);
}
response = responseHelper.formatOkResponseWithJsonEntity(results);
} catch (IndyDataException ide) {
logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
response = responseHelper.formatResponse(ide);
} catch (MalformedURLException mue) {
logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
response = responseHelper.formatResponse(mue);
} catch (IndyWorkflowException iwe) {
logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
response = responseHelper.formatResponse(iwe);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class StoreAdminHandler method delete.
@ApiOperation("Delete an artifact store")
@ApiResponses({ @ApiResponse(code = 204, response = ArtifactStore.class, message = "The store was deleted (or didn't exist in the first place)") })
@Path("/{name}")
@DELETE
public Response delete(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @QueryParam("deleteContent") final boolean deleteContent, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
final StoreType st = StoreType.get(type);
final StoreKey key = new StoreKey(packageType, st, name);
logger.info("Deleting: {}, deleteContent: {}", key, deleteContent);
Response response;
try {
String summary = null;
try {
summary = IOUtils.toString(request.getInputStream());
} catch (final IOException e) {
// no problem, try to get the summary from a header instead.
logger.info("store-deletion change summary not in request body, checking headers.");
}
if (isEmpty(summary)) {
summary = request.getHeader(METADATA_CHANGELOG);
}
if (isEmpty(summary)) {
summary = "Changelog not provided";
}
summary += (", deleteContent:" + deleteContent);
String user = securityManager.getUser(securityContext, request);
adminController.delete(key, user, summary, deleteContent);
response = noContent().build();
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = responseHelper.formatResponse(e);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class StoreAdminHandler method revalidateArtifactStore.
@ApiOperation("Revalidation of Artifact Stored on demand based on package, type and name")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "Revalidation for Remote Repository was successfull"), @ApiResponse(code = 404, message = "Revalidation is not successfull") })
@Path("/{name}/revalidate")
@POST
public Response revalidateArtifactStore(@PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
ArtifactStoreValidateData result = null;
Response response;
try {
final StoreType st = StoreType.get(type);
final StoreKey key = new StoreKey(packageType, st, name);
final ArtifactStore store = adminController.get(key);
logger.info("=> Returning repository: {}", store);
// Validate this Store
result = adminController.validateStore(store);
logger.warn("=> Result from Validating Store: " + result);
if (result == null) {
response = Response.status(Status.NOT_FOUND).build();
} else {
response = responseHelper.formatOkResponseWithJsonEntity(result);
}
} catch (IndyDataException ide) {
logger.warn("=> [IndyDataException] exception message: " + ide.getMessage());
response = responseHelper.formatResponse(ide);
} catch (MalformedURLException mue) {
logger.warn("=> [MalformedURLException] Invalid URL exception message: " + mue.getMessage());
response = responseHelper.formatResponse(mue);
} catch (IndyWorkflowException iwe) {
logger.warn("=> [IndyWorkflowException] exception message: " + iwe.getMessage());
response = responseHelper.formatResponse(iwe);
}
return response;
}
use of io.swagger.annotations.ApiResponse in project indy by Commonjava.
the class StatsHandler method getAllEndpoints.
@ApiOperation("Retrieve a listing of the artifact stores available on the system. This is especially useful for setting up a network of Indy instances that reference one another")
@ApiResponse(code = 200, response = EndpointViewListing.class, message = "The artifact store listing")
@Path("/all-endpoints")
@GET
@Produces(ApplicationContent.application_json)
public Response getAllEndpoints(@Context final UriInfo uriInfo) {
Response response;
try {
final String baseUri = uriInfo.getBaseUriBuilder().path(IndyDeployment.API_PREFIX).build().toString();
final EndpointViewListing listing = statsController.getEndpointsListing(baseUri, uriFormatter);
response = responseHelper.formatOkResponseWithJsonEntity(listing);
logger.info("\n\n\n\n\n\n{} Sent all-endpoints:\n\n{}\n\n\n\n\n\n\n", new Date(), listing);
} catch (final IndyWorkflowException e) {
logger.error(String.format("Failed to retrieve endpoint listing: %s", responseHelper.formatEntity(e)), e);
response = responseHelper.formatResponse(e);
}
return response;
}
Aggregations