use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler 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(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type, name).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
final StoreKey key = new StoreKey(st, name);
logger.info("Deleting: {}", key);
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";
}
String user = securityManager.getUser(securityContext, request);
adminController.delete(key, user, summary);
response = markDeprecated(noContent(), altPath).build();
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler 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(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @Context final UriInfo uriInfo, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
Response response = null;
String json = null;
try {
json = IOUtils.toString(request.getInputStream());
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 = formatResponse(e, message, modifier);
}
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 = formatResponse(e, message, modifier);
}
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(getClass()).path(store.getName()).build(store.getKey().getType().singularEndpointName());
response = formatCreatedResponseWithJsonEntity(uri, store, objectMapper, modifier);
} else {
response = markDeprecated(status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json), altPath).build();
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method get.
@ApiOperation("Retrieve the definition of a specific artifact store")
@ApiResponses({ @ApiResponse(code = 200, response = ArtifactStore.class, message = "The store definition"), @ApiResponse(code = 404, message = "The store doesn't exist") })
@Path("/{name}")
@GET
@Produces(ApplicationContent.application_json)
public Response get(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type, name).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
final StoreKey key = new StoreKey(st, name);
Response response;
try {
final ArtifactStore store = adminController.get(key);
logger.info("Returning repository: {}", store);
if (store == null) {
response = markDeprecated(Response.status(Status.NOT_FOUND), altPath).build();
} else {
response = formatOkResponseWithJsonEntity(store, objectMapper, modifier);
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method store.
/*
* (non-Javadoc)
* @see org.commonjava.indy.core.rest.admin.DeployPointAdminResource#store(java.lang.String)
*/
@ApiOperation("Update an existing store")
@ApiResponses({ @ApiResponse(code = 200, message = "The store was updated"), @ApiResponse(code = 400, message = "The store specified in the body JSON didn't match the URL parameters") })
@ApiImplicitParams({ @ApiImplicitParam(allowMultiple = false, paramType = "body", name = "body", required = true, dataType = "org.commonjava.indy.model.core.ArtifactStore", value = "The artifact store definition JSON") })
@Path("/{name}")
@PUT
@Consumes(ApplicationContent.application_json)
public Response store(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name, @Context final HttpServletRequest request, @Context final SecurityContext securityContext) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type, name).toString();
Consumer<Response.ResponseBuilder> modifier = (rb) -> markDeprecated(rb, altPath);
final StoreType st = StoreType.get(type);
Response response = null;
String json = null;
try {
json = IOUtils.toString(request.getInputStream());
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 = formatResponse(e, message, modifier);
}
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 = formatResponse(e, message, modifier);
}
if (response != null) {
return response;
}
if (!name.equals(store.getName())) {
response = markDeprecated(Response.status(Status.BAD_REQUEST).entity(String.format("Store in URL path is: '%s' but in JSON it is: '%s'", name, store.getName())), altPath).build();
}
try {
String user = securityManager.getUser(securityContext, request);
logger.info("Storing: {}", store);
if (adminController.store(store, user, false)) {
response = markDeprecated(ok(), altPath).build();
} else {
logger.warn("{} NOT modified!", store);
response = markDeprecated(notModified(), altPath).build();
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e, modifier);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method exists.
// @Context
// private UriInfo uriInfo;
//
// @Context
// private HttpServletRequest request;
@ApiOperation("Check if a given store exists")
@ApiResponses({ @ApiResponse(code = 200, message = "The store exists"), @ApiResponse(code = 404, message = "The store doesn't exist") })
@Path("/{name}")
@HEAD
public Response exists(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type, @ApiParam(required = true) @PathParam("name") final String name) {
String altPath = Paths.get(MavenPackageTypeDescriptor.MAVEN_ADMIN_REST_BASE_PATH, type, name).toString();
Response response;
final StoreType st = StoreType.get(type);
logger.info("Checking for existence of: {}:{}", st, name);
if (adminController.exists(new StoreKey(st, name))) {
logger.info("returning OK");
response = markDeprecated(Response.ok(), altPath).build();
} else {
logger.info("Returning NOT FOUND");
response = markDeprecated(Response.status(Status.NOT_FOUND), altPath).build();
}
return response;
}
Aggregations