Skip to content

Commit

Permalink
concord-server: order ui_process_card by a new order_id field (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
oalfonso-o authored Feb 12, 2025
1 parent 972d7e2 commit be408d7
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 12 deletions.
2 changes: 2 additions & 0 deletions sdk/src/main/java/com/walmartlabs/concord/sdk/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,8 @@ public static class Multipart {
public static final String SYNC = "sync";

public static final String META = "meta";

public static final String ORDER_ID = "orderId";
}

public static class Headers {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,6 @@
<include file="v2.12.0.xml" relativeToChangelogFile="true"/>
<include file="v2.14.0.xml" relativeToChangelogFile="true"/>
<include file="v2.21.0.xml" relativeToChangelogFile="true"/>
<include file="v2.22.0.xml" relativeToChangelogFile="true"/>

</databaseChangeLog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.3.xsd">

<changeSet id="2220000" author="oalfonso@gmail.com">
<addColumn tableName="UI_PROCESS_CARDS">
<column name="ORDER_ID" type="int">
<constraints nullable="true"/>
</column>
</addColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@ public static UUID assertUuid(MultipartInput input, String key) {
throw new ConcordApplicationException(key + " not specified", Response.Status.BAD_REQUEST);
}

public static Integer getInt(MultipartInput input, String key) {
String s = getString(input, key);
if (s == null) {
return null;
}
return Integer.parseInt(s);
}

public static InputStream getStream(MultipartInput input, String key) {
try {
for (InputPart p : input.getParts()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public interface ProcessCardEntry extends Serializable {

boolean isCustomForm();

@Nullable
Integer orderId();

static ImmutableProcessCardEntry.Builder builder() {
return ImmutableProcessCardEntry.builder();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public List<ProcessCardEntry> listUserCards(UUID userId) {
return dao.listCards(userId);
}

public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID repoId, String name, Optional<String> entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data) {
public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID repoId, String name, Optional<String> entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data, Integer orderId) {
boolean exists;
if (id == null) {
if (projectId == null) {
Expand All @@ -110,12 +110,12 @@ public ProcessCardOperationResponse createOrUpdate(UUID id, UUID projectId, UUID
}

if (!exists) {
UUID resultId = dao.insert(id, projectId, repoId, name, entryPoint.orElse(Constants.Request.DEFAULT_ENTRY_POINT_NAME), description, icon, form, data);
UUID resultId = dao.insert(id, projectId, repoId, name, entryPoint.orElse(Constants.Request.DEFAULT_ENTRY_POINT_NAME), description, icon, form, data, orderId);
return new ProcessCardOperationResponse(resultId, OperationResult.CREATED);
} else {
assertAccess(id);

dao.update(id, projectId, repoId, name, entryPoint.orElse(null), description, icon, form, data);
dao.update(id, projectId, repoId, name, entryPoint.orElse(null), description, icon, form, data, orderId);
return new ProcessCardOperationResponse(id, OperationResult.UPDATED);
}
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public Optional<UUID> getIdByName(UUID projectId, String name) {
.fetchOptional(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID);
}

public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data) {
public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String entryPoint, String description, InputStream icon, InputStream form, Map<String, Object> data, Integer orderId) {
return txResult(tx -> {
String sql = tx.insertInto(UI_PROCESS_CARDS)
.columns(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID,
Expand All @@ -173,8 +173,9 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String
UI_PROCESS_CARDS.ICON,
UI_PROCESS_CARDS.FORM,
UI_PROCESS_CARDS.DATA,
UI_PROCESS_CARDS.OWNER_ID)
.values((UUID) null, null, null, null, null, null, null, null, null, null)
UI_PROCESS_CARDS.OWNER_ID,
UI_PROCESS_CARDS.ORDER_ID)
.values((UUID) null, null, null, null, null, null, null, null, null, null, null)
.returning(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.getSQL();

Expand All @@ -190,6 +191,7 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String
ps.setBinaryStream(8, form);
ps.setObject(9, data != null ? objectMapper.toJSONB(data).data() : null);
ps.setObject(10, UserPrincipal.assertCurrent().getId());
ps.setObject(11, orderId);

try (ResultSet rs = ps.executeQuery()) {
if (!rs.next()) {
Expand All @@ -205,7 +207,7 @@ public UUID insert(UUID cardId, UUID projectId, UUID repoId, String name, String

public void update(UUID cardId, UUID projectId, UUID repoId, String name,
String entryPoint, String description, InputStream icon, InputStream form,
Map<String, Object> data) {
Map<String, Object> data, Integer orderId) {
tx(tx -> {
List<Object> params = new ArrayList<>();
UpdateSetStep<UiProcessCardsRecord> q = tx.update(UI_PROCESS_CARDS);
Expand Down Expand Up @@ -254,6 +256,11 @@ public void update(UUID cardId, UUID projectId, UUID repoId, String name,
return;
}

if (orderId != null) {
q.set(UI_PROCESS_CARDS.ORDER_ID, (Integer) null);
params.add(orderId);
}

String sql = q.set(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID, cardId)
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.eq(cardId))
.getSQL();
Expand Down Expand Up @@ -358,7 +365,7 @@ private List<ProcessCardEntry> listCards(DSLContext tx, UUID userId) {
.where(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID.in(userCardsFilter));

return query
.orderBy(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.orderBy(UI_PROCESS_CARDS.ORDER_ID, UI_PROCESS_CARDS.UI_PROCESS_CARD_ID)
.fetch(this::toEntry);
}

Expand Down Expand Up @@ -404,7 +411,7 @@ private static <T> Optional<T> getInputStream(DSLContext tx, String sql, UUID ca
});
}

private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean>> buildSelect(DSLContext tx) {
private static SelectOnConditionStep<Record13<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean, Integer>> buildSelect(DSLContext tx) {
Field<Boolean> isCustomForm = when(field(UI_PROCESS_CARDS.FORM).isNotNull(), true).otherwise(false);

return tx.select(
Expand All @@ -419,14 +426,15 @@ private static SelectOnConditionStep<Record12<UUID, UUID, String, UUID, String,
UI_PROCESS_CARDS.ENTRY_POINT,
UI_PROCESS_CARDS.DESCRIPTION,
UI_PROCESS_CARDS.ICON,
isCustomForm.as("isCustomForm"))
isCustomForm.as("isCustomForm"),
UI_PROCESS_CARDS.ORDER_ID)
.from(UI_PROCESS_CARDS)
.leftJoin(REPOSITORIES).on(REPOSITORIES.REPO_ID.eq(UI_PROCESS_CARDS.REPO_ID))
.leftJoin(PROJECTS).on(PROJECTS.PROJECT_ID.eq(UI_PROCESS_CARDS.PROJECT_ID))
.leftJoin(ORGANIZATIONS).on(ORGANIZATIONS.ORG_ID.eq(PROJECTS.ORG_ID));
}

private ProcessCardEntry toEntry(Record12<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean> r) {
private ProcessCardEntry toEntry(Record13<UUID, UUID, String, UUID, String, UUID, String, String, String, String, byte[], Boolean, Integer> r) {
return ProcessCardEntry.builder()
.id(r.get(UI_PROCESS_CARDS.UI_PROCESS_CARD_ID))
.orgName(r.get(ORGANIZATIONS.ORG_NAME))
Expand All @@ -437,6 +445,7 @@ private ProcessCardEntry toEntry(Record12<UUID, UUID, String, UUID, String, UUID
.description(r.get(UI_PROCESS_CARDS.DESCRIPTION))
.icon(encodeBase64(r.get(UI_PROCESS_CARDS.ICON)))
.isCustomForm(r.get("isCustomForm", Boolean.class))
.orderId(r.get(UI_PROCESS_CARDS.ORDER_ID))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public String getEntryPoint() {
return MultipartUtils.getString(input, Constants.Multipart.ENTRY_POINT);
}

@Schema(name = Constants.Multipart.ORDER_ID)
public Integer getOrderId() {
return MultipartUtils.getInt(input, Constants.Multipart.ORDER_ID);
}

@Schema(name = "name")
public String getName() {
return MultipartUtils.getString(input, "name");
Expand Down Expand Up @@ -105,4 +110,5 @@ public InputStream getIcon() {
public InputStream getForm() {
return MultipartUtils.getStream(input, "form");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,11 @@ public ProcessCardOperationResponse createOrUpdate(
String description = r.getDescription();
Map<String, Object> data = r.getData();
UUID id = r.getId();
Integer orderId = r.getOrderId();

try (InputStream icon = r.getIcon();
InputStream form = r.getForm()) {
return processCardManager.createOrUpdate(id, projectId, repoId, name, entryPoint, description, icon, form, data);
return processCardManager.createOrUpdate(id, projectId, repoId, name, entryPoint, description, icon, form, data, orderId);
}
}

Expand Down

0 comments on commit be408d7

Please sign in to comment.