Skip to content
This repository was archived by the owner on Mar 31, 2022. It is now read-only.

Commit

Permalink
chore: add DatabaseDataSourceView (#913)
Browse files Browse the repository at this point in the history
* chore: add DatabaseDataSourceView

* docs: update CHANGELOG.md
  • Loading branch information
ronjaquensel authored Feb 16, 2022
1 parent a911276 commit d93d2df
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.

## [x.x.x] - 2022-xx-xx

### Added
- Add custom view for `DatabaseDataSource` to display URL and driver class.

### Changed
- Update swagger-annotations version from 1.6.4 to 1.6.5.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.dataspaceconnector.controller.resource.view.util.SelfLinking;
import io.dataspaceconnector.controller.resource.view.util.SelfLinkHelper;
import io.dataspaceconnector.model.datasource.DataSource;
import io.dataspaceconnector.model.datasource.DatabaseDataSource;
import org.modelmapper.ModelMapper;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.server.RepresentationModelAssembler;
Expand All @@ -41,7 +42,13 @@ public final Link getSelfLink(final UUID entityId) {
@Override
public final DataSourceView toModel(final DataSource dataSource) {
final var modelMapper = new ModelMapper();
final var view = modelMapper.map(dataSource, DataSourceView.class);
DataSourceView view;
if (dataSource instanceof DatabaseDataSource) {
view = modelMapper.map(dataSource, DatabaseDataSourceView.class);
} else {
view = modelMapper.map(dataSource, DataSourceView.class);
}

view.add(getSelfLink(dataSource.getId()));

return view;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Fraunhofer Institute for Software and Systems Engineering
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.dataspaceconnector.controller.resource.view.datasource;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

/**
* A DTO for controlled exposing of database data source information in API responses.
*/
@Getter
@Setter
@EqualsAndHashCode(callSuper = true)
public class DatabaseDataSourceView extends DataSourceView {

/**
* JDBC URL of the database.
*/
private String url;

/**
* Name of the driver class to use for connecting to the database.
*/
private String driverClassName;

}

0 comments on commit d93d2df

Please sign in to comment.