use of org.commonjava.indy.promote.data.PromotionException 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 org.commonjava.indy.promote.data.PromotionException 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.promote.data.PromotionException 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;
}
use of org.commonjava.indy.promote.data.PromotionException in project indy by Commonjava.
the class PromoteResource method rollbackPaths.
@ApiOperation("Rollback promotion of any completed paths to a source repository from a target repository/group.")
@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/rollback")
@POST
@Consumes(ApplicationContent.application_json)
public Response rollbackPaths(@Context final HttpServletRequest request, @Context final UriInfo uriInfo) {
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.rollbackPathsPromote(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