-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Future updates will hook this into all the other models Relates to #140
- Loading branch information
Showing
8 changed files
with
375 additions
and
11 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
service/src/main/java/org/kiwiproject/champagne/dao/DeployableSystemDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.kiwiproject.champagne.dao; | ||
|
||
import org.jdbi.v3.sqlobject.config.RegisterRowMapper; | ||
import org.jdbi.v3.sqlobject.customizer.Bind; | ||
import org.jdbi.v3.sqlobject.customizer.BindBean; | ||
import org.jdbi.v3.sqlobject.statement.GetGeneratedKeys; | ||
import org.jdbi.v3.sqlobject.statement.SqlQuery; | ||
import org.jdbi.v3.sqlobject.statement.SqlUpdate; | ||
import org.kiwiproject.champagne.dao.mappers.DeployableSystemForUserMapper; | ||
import org.kiwiproject.champagne.dao.mappers.DeployableSystemMapper; | ||
import org.kiwiproject.champagne.model.DeployableSystem; | ||
|
||
import java.util.List; | ||
|
||
public interface DeployableSystemDao { | ||
|
||
@SqlUpdate("insert into deployable_systems (name) values (:name)") | ||
@GetGeneratedKeys | ||
long insertDeployableSystem(@BindBean DeployableSystem system); | ||
|
||
@SqlQuery("select s.*, us.system_admin from deployable_systems s join users_deployable_systems us on s.id = us.deployable_system_id where us.user_id = :userId") | ||
@RegisterRowMapper(DeployableSystemForUserMapper.class) | ||
List<DeployableSystem> findDeployableSystemsForUser(@Bind("userId") long userId); | ||
|
||
@SqlQuery("select * from deployable_systems order by created_at desc offset :offset limit :limit") | ||
@RegisterRowMapper(DeployableSystemMapper.class) | ||
List<DeployableSystem> findPagedDeployableSystems(@Bind("offset") int offset, @Bind("limit") int limit); | ||
|
||
@SqlQuery("select count(*) from deployable_systems") | ||
long countDeployableSystems(); | ||
|
||
@SqlUpdate("update deployable_systems set dev_environment_id = :envId where id = :id") | ||
int updateDevEnvironment(@Bind("id") long id, @Bind("envId") long envId); | ||
|
||
@SqlUpdate("update deployable_systems set environment_promotion_order = :envCsv where id = :id") | ||
int updateEnvironmentPromotionOrder(@Bind("id") long id, @Bind("envCsv") String envCsv); | ||
|
||
@SqlUpdate("delete from deployable_systems where id = :id") | ||
int deleteById(@Bind("id") long id); | ||
} |
16 changes: 16 additions & 0 deletions
16
...ce/src/main/java/org/kiwiproject/champagne/dao/mappers/DeployableSystemForUserMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.kiwiproject.champagne.dao.mappers; | ||
|
||
import org.jdbi.v3.core.statement.StatementContext; | ||
import org.kiwiproject.champagne.model.DeployableSystem; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class DeployableSystemForUserMapper extends DeployableSystemMapper { | ||
@Override | ||
public DeployableSystem map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
var deployableSystem = super.map(rs, ctx); | ||
|
||
return deployableSystem.withAdmin(rs.getBoolean("system_admin")); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
service/src/main/java/org/kiwiproject/champagne/dao/mappers/DeployableSystemMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.kiwiproject.champagne.dao.mappers; | ||
|
||
import static org.kiwiproject.jdbc.KiwiJdbc.instantFromTimestamp; | ||
import static org.kiwiproject.jdbc.KiwiJdbc.longValueOrNull; | ||
|
||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
import org.kiwiproject.champagne.model.DeployableSystem; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class DeployableSystemMapper implements RowMapper<DeployableSystem> { | ||
@Override | ||
public DeployableSystem map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
return DeployableSystem.builder() | ||
.id(rs.getLong("id")) | ||
.createdAt(instantFromTimestamp(rs, "created_at")) | ||
.updatedAt(instantFromTimestamp(rs, "updated_at")) | ||
.name(rs.getString("name")) | ||
.devEnvironmentId(longValueOrNull(rs, "dev_environment_id")) | ||
.environmentPromotionOrder(rs.getString("environment_promotion_order")) | ||
.build(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
service/src/main/java/org/kiwiproject/champagne/model/DeployableSystem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.kiwiproject.champagne.model; | ||
|
||
import lombok.Builder; | ||
import lombok.Value; | ||
import lombok.With; | ||
|
||
import java.time.Instant; | ||
|
||
@Builder | ||
@Value | ||
public class DeployableSystem { | ||
|
||
Long id; | ||
Instant createdAt; | ||
Instant updatedAt; | ||
|
||
String name; | ||
|
||
Long devEnvironmentId; | ||
String environmentPromotionOrder; | ||
|
||
/** | ||
* This is a transitive property populated through the users_system table and indicates if a specific user is | ||
* an admin in this system. Listing all systems will NOT populate this field. | ||
*/ | ||
@With | ||
boolean admin; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.