use of org.commonjava.indy.model.core.StoreType 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());
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);
}
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);
}
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 = formatCreatedResponseWithJsonEntity(uri, store, objectMapper);
} else {
response = status(CONFLICT).entity("{\"error\": \"Store already exists.\"}").type(application_json).build();
}
} catch (final IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class NfcResource method clearStore.
@Path("/{packageType}/{type: (hosted|group|remote)}/{name}{path: (/.+)?}")
@ApiOperation("Clear all not-found cache entries for a particular store (or optionally, a subpath within a store)")
@DELETE
public Response clearStore(@ApiParam(name = "packageType", required = true, value = "The type of package (eg. maven, npm, generic-http)") @PathParam("packageType") final String packageType, @ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", required = true, value = "The name of the store") @PathParam("name") final String name, @ApiParam(name = "path", required = false, value = "The sub-path to clear") @PathParam("path") final String p) {
Response response;
final StoreType type = StoreType.get(t);
try {
final StoreKey key = new StoreKey(packageType, type, name);
if (isNotEmpty(p)) {
controller.clear(key);
} else {
controller.clear(key, p);
}
response = Response.ok().build();
} catch (final IndyWorkflowException e) {
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class NfcResource method deprecatedGetStore.
@Path("/{type: (hosted|group|remote)}/{name}")
@ApiOperation("[Deprecated] Retrieve all not-found cache entries currently tracked for a given store")
@ApiResponses({ @ApiResponse(code = 200, response = NotFoundCacheDTO.class, message = "The not-found cache for the specified artifact store") })
@GET
@Produces(ApplicationContent.application_json)
public Response deprecatedGetStore(@ApiParam(allowableValues = "hosted,group,remote", name = "type", required = true, value = "The type of store") @PathParam("type") final String t, @ApiParam(name = "name", value = "The name of the store") @PathParam("name") final String name) {
Response response;
final StoreType type = StoreType.get(t);
String altPath = Paths.get("/api/nfc", MAVEN_PKG_KEY, type.singularEndpointName(), name).toString();
final StoreKey key = new StoreKey(type, name);
try {
final NotFoundCacheDTO dto = controller.getMissing(key);
response = formatOkResponseWithJsonEntity(dto, serializer, rb -> markDeprecated(rb, altPath));
} catch (final IndyWorkflowException e) {
response = formatResponse(e, (rb) -> markDeprecated(rb, altPath));
}
return response;
}
use of org.commonjava.indy.model.core.StoreType in project indy by Commonjava.
the class DeprecatedStoreAdminHandler method getAll.
@ApiOperation("Retrieve the definitions of all artifact stores of a given type on the system")
@ApiResponses({ @ApiResponse(code = 200, response = StoreListingDTO.class, message = "The store definitions") })
@GET
@Produces(ApplicationContent.application_json)
public Response getAll(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String type) {
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;
try {
final List<ArtifactStore> stores = adminController.getAllOfType(st);
logger.info("Returning listing containing stores:\n\t{}", new JoinString("\n\t", stores));
final StoreListingDTO<ArtifactStore> dto = new StoreListingDTO<>(stores);
response = formatOkResponseWithJsonEntity(dto, 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 SetBackSettingsResource method delete.
@ApiOperation("DELETE the settings.xml simulation corresponding to the specified Indy group/repository")
@ApiResponses({ @ApiResponse(code = 400, message = "Requested repository is hosted on Indy and cannot be simulated via settings.xml"), @ApiResponse(code = 404, message = "No such repository or group, or the settings.xml has not been generated."), @ApiResponse(code = 204, message = "Deletion succeeded") })
@Path("/{type: (remote|group)}/{name}")
@DELETE
public Response delete(@ApiParam(allowableValues = "hosted,group,remote", required = true) @PathParam("type") final String t, @PathParam("name") final String n) {
final StoreType type = StoreType.get(t);
if (StoreType.hosted == type) {
return Response.status(Status.BAD_REQUEST).build();
}
Response response;
final StoreKey key = new StoreKey(type, n);
try {
final boolean found = controller.deleteSetBackSettings(key);
if (found) {
response = Response.status(Status.NO_CONTENT).build();
} else {
response = Response.status(Status.NOT_FOUND).build();
}
} catch (final IndyWorkflowException e) {
response = ResponseUtils.formatResponse(e);
}
return response;
}
Aggregations