use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class SecurityResource method getKeycloakJs.
@ApiOperation("Retrieve the keycloak Javascript adapter (for use by the UI)")
@ApiResponses({ @ApiResponse(code = 200, message = "Keycloak is disabled, return a Javascript comment to this effect."), @ApiResponse(code = 307, message = "Redirect to keycloak server to load Javascript adapter.") })
@Path("/keycloak.js")
@Produces("text/javascript")
@GET
public Response getKeycloakJs() {
logger.debug("Retrieving Keycloak Javascript adapter...");
Response response = null;
try {
final String url = controller.getKeycloakJs();
if (url == null) {
response = Response.ok("/* " + DISABLED_MESSAGE + "; loading of keycloak.js blocked. */").header(ApplicationHeader.cache_control.key(), NO_CACHE).build();
} else {
response = Response.temporaryRedirect(new URI(url)).build();
}
} catch (final IndyWorkflowException | URISyntaxException e) {
logger.error(String.format("Failed to load keycloak.js. Reason: %s", e.getMessage()), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class ValidationRequest method getSourcePaths.
public synchronized Set<String> getSourcePaths(boolean includeMetadata, boolean includeChecksums) throws PromotionValidationException {
if (requestPaths == null) {
Set<String> paths = null;
if (promoteRequest instanceof PathsPromoteRequest) {
paths = ((PathsPromoteRequest) promoteRequest).getPaths();
}
if (paths == null) {
ArtifactStore store = null;
try {
store = tools.getArtifactStore(promoteRequest.getSource());
} catch (IndyDataException e) {
throw new PromotionValidationException("Failed to retrieve source ArtifactStore: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
}
if (store != null) {
try {
paths = new HashSet<>();
listRecursively(store, "/", paths);
} catch (IndyWorkflowException e) {
throw new PromotionValidationException("Failed to list paths in source: {}. Reason: {}", e, promoteRequest.getSource(), e.getMessage());
}
}
}
requestPaths = paths;
}
if (!includeMetadata || !includeChecksums) {
Predicate<String> filter = (path) -> (includeMetadata || !path.matches(".+/maven-metadata\\.xml(\\.(md5|sha[0-9]+))?")) && (includeChecksums || !path.matches(".+\\.(md5|sha[0-9]+)"));
return requestPaths.stream().filter(filter).collect(Collectors.toSet());
}
return requestPaths;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class SetBackSettingsResource method get.
@ApiOperation("Return settings.xml that approximates the behavior of the specified Indy group/repository (CAUTION: Indy-hosted content will be unavailable!)")
@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 = 200, message = "Maven settings.xml content") })
@Path("/{type: (remote|group)}/{name}")
@GET
@Produces(ApplicationContent.application_xml)
public Response get(@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);
DataFile settingsXml = null;
try {
settingsXml = controller.getSetBackSettings(key);
} catch (final IndyWorkflowException e) {
response = ResponseUtils.formatResponse(e);
}
if (settingsXml != null && settingsXml.exists()) {
response = Response.ok(settingsXml).type(ApplicationContent.application_xml).build();
} else {
response = Response.status(Status.NOT_FOUND).build();
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class PromoteResource method promotePaths.
@ApiOperation("Promote paths from a source repository into a target repository/group (subject to validation).")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.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.PathsPromoteRequest")
@Path("/paths/promote")
@POST
@Consumes(ApplicationContent.application_json)
public Response promotePaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
PathsPromoteRequest req = null;
Response response = null;
try {
final String json = IOUtils.toString(request.getInputStream());
logger.info("Got promotion request:\n{}", json);
req = mapper.readValue(json, PathsPromoteRequest.class);
} catch (final IOException e) {
response = formatResponse(e, "Failed to read DTO from request body.");
}
if (response != null) {
return response;
}
try {
PackageTypeDescriptor packageTypeDescriptor = PackageTypes.getPackageTypeDescriptor(req.getSource().getPackageType());
final String baseUrl = uriInfo.getBaseUriBuilder().path(packageTypeDescriptor.getContentRestBasePath()).build(req.getSource().getType().singularEndpointName(), req.getSource().getName()).toString();
final PathsPromoteResult result = manager.promotePaths(req, baseUrl);
// TODO: Amend response status code based on presence of error? This would have consequences for client API...
response = formatOkResponseWithJsonEntity(result, mapper);
} catch (PromotionException | IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
use of org.commonjava.indy.IndyWorkflowException in project indy by Commonjava.
the class PromoteResource method resumePaths.
@ApiOperation("RESUME promotion of paths from a source repository into a target repository/group (subject to validation), presumably after a previous failure condition has been corrected.")
@ApiResponse(code = 200, message = "Promotion operation finished (consult response content for success/failure).", response = PathsPromoteResult.class)
@ApiImplicitParam(name = "body", paramType = "body", value = "JSON result from previous attempt, specifying source and target, with other configuration options", allowMultiple = false, required = true, dataType = "org.commonjava.indy.promote.model.PathsPromoteResult")
@Path("/paths/resume")
@POST
@Consumes(ApplicationContent.application_json)
public Response resumePaths(@Context final HttpServletRequest request) {
PathsPromoteResult result = null;
Response response = null;
try {
result = mapper.readValue(request.getInputStream(), PathsPromoteResult.class);
} catch (final IOException e) {
response = formatResponse(e, "Failed to read DTO from request body.");
}
if (response != null) {
return response;
}
try {
result = manager.resumePathsPromote(result);
// TODO: Amend response status code based on presence of error? This would have consequences for client API...
response = formatOkResponseWithJsonEntity(result, mapper);
} catch (PromotionException | IndyWorkflowException e) {
logger.error(e.getMessage(), e);
response = formatResponse(e);
}
return response;
}
Aggregations