use of com.thinkbiganalytics.metadata.api.catalog.DataSourceAlreadyExistsException in project kylo by Teradata.
the class DataSourceController method createDataSource.
@POST
@ApiOperation("Create a new data source")
@ApiResponses({ @ApiResponse(code = 200, message = "Data source created", response = DataSource.class), @ApiResponse(code = 400, message = "Invalid connector", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "Internal server error", response = RestResponseStatus.class) })
@Consumes(MediaType.APPLICATION_JSON)
public Response createDataSource(@Nonnull final CreateDataSourceEntity source) {
log.entry(source);
final DataSource dataSource;
try {
// TODO: Remove this check for the ID and force updates to use the PUT to updateDataSource() for a more typical REST API
if (StringUtils.isNotEmpty(source.getId())) {
return updateDataSource(source);
} else {
try {
dataSource = dataSourceService.createDataSource(source, source.isDetectSimilarNiFiControllerServices());
} catch (final CatalogException e) {
if (log.isDebugEnabled()) {
log.debug("Cannot create data source from request: " + source, e);
}
throw new BadRequestException(getMessage(e));
}
}
} catch (PotentialControllerServiceConflictException e) {
throw new WebApplicationException(Response.status(Status.CONFLICT).entity(e.getControllerServiceConflictEntity()).build());
} catch (DataSourceAlreadyExistsException e) {
throw new BadRequestException(e.getMessage());
}
return Response.ok(log.exit(dataSource)).build();
}
Aggregations