Skip to content

Commit

Permalink
Pull request finos#407: Bulk uploader for entity relationships
Browse files Browse the repository at this point in the history
Merge in WALTZ/waltz from WALTZ/waltz-sj:db-feature/CTCTOWALTZ-3403-bulk-uploader-for-entity-relationships to db-feature/waltz-7171-bulk-uploader-for-entity-relationships

* commit '0fd9aad736e2d47bc61f6fe133fd09ea33997c1e':
  remove comment
  cleanup
  add comment
  code cleanup
  code cleanup
  add / update - 6 totlal tests + minor indentaion change in ui component
  code cleanup
  indentation changes
  remove dummy response
  add: tests; change: indentation; wip: tests
  add: test items; update: test
  UI component for bulk relationships upload
  add: bulk upload relationship service and endpoint
  add: Item parser for relationship items
  add: models for bulk relationship upload
  add: get entity relationships by relationship kind / code
  add: get relationship kind by id
  • Loading branch information
jain-shreyans-db committed Oct 18, 2024
2 parents db98073 + 0fd9aad commit 55fefe4
Show file tree
Hide file tree
Showing 22 changed files with 1,517 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,32 @@ private Condition mkExactRefMatchCondition(EntityReference ref) {
return matchesA.or(matchesB);
}

public Collection<EntityRelationship> getEntityRelationshipsByKind(org.finos.waltz.model.rel.RelationshipKind relationshipKind) {
return dsl
.select(ENTITY_RELATIONSHIP.fields())
.from(ENTITY_RELATIONSHIP)
.where(ENTITY_RELATIONSHIP.RELATIONSHIP.eq(relationshipKind.code()))
.fetch(r -> {
EntityRelationshipRecord record = r.into(ENTITY_RELATIONSHIP);
return ImmutableEntityRelationship.builder()
.id(record.getId())
.a(ImmutableEntityReference.builder()
.kind(EntityKind.valueOf(record.getKindA()))
.id(record.getIdA())
.build())
.b(ImmutableEntityReference.builder()
.kind(EntityKind.valueOf(record.getKindB()))
.id(record.getIdB())
.build())
.provenance(record.getProvenance())
.relationship(record.getRelationship())
.description(record.getDescription())
.lastUpdatedBy(record.getLastUpdatedBy())
.lastUpdatedAt(toLocalDateTime(record.getLastUpdatedAt()))
.build();
});
}


private Condition mkExactKeyMatchCondition(EntityRelationshipKey key) {
return ENTITY_RELATIONSHIP.ID_A.eq(key.a().id())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public Set<RelationshipKind> findAll() {
.fetchSet(TO_DOMAIN_MAPPER);
}

public RelationshipKind getById(long id) {
return dsl
.select()
.from(RELATIONSHIP_KIND)
.where(RELATIONSHIP_KIND.ID.eq(id))
.fetchOne(TO_DOMAIN_MAPPER);
}


public Set<RelationshipKind> findRelationshipKindsBetweenEntites(EntityReference parent, EntityReference target){

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableBulkUploadRelationshipApplyResult.class)
public interface BulkUploadRelationshipApplyResult {

Long recordsAdded();

Long recordsUpdated();

Long skippedRows();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

import com.fasterxml.jackson.annotation.JsonAlias;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import org.finos.waltz.model.Nullable;
import org.immutables.value.Value;

@Value.Immutable
@JsonDeserialize(as = ImmutableBulkUploadRelationshipItem.class)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonFormat(with = JsonFormat.Feature.ACCEPT_CASE_INSENSITIVE_PROPERTIES)
public interface BulkUploadRelationshipItem {

@JsonAlias({"source_external_id", "source_id"})
String sourceExternalId();

@JsonAlias({"target_external_id", "target_id"})
String targetExternalId();

@Nullable
String description();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.Nullable;
import org.immutables.value.Value;

import java.util.List;

@Value.Immutable
@JsonSerialize(as = ImmutableBulkUploadRelationshipParsedResult.class)
public interface BulkUploadRelationshipParsedResult {

@Value.Immutable
interface BulkUploadRelationshipParseError {
String message();

@Nullable
Integer line();

@Nullable
Integer column();
}

String input();

List<BulkUploadRelationshipItem> parsedItems();

@Nullable
BulkUploadRelationshipParseError error();

static BulkUploadRelationshipParsedResult mkResult(List<BulkUploadRelationshipItem> items,
String input) {
if(items.isEmpty()) {
return ImmutableBulkUploadRelationshipParsedResult
.builder()
.input(input)
.error(ImmutableBulkUploadRelationshipParseError
.builder()
.message("Cannot parse input.")
.build())
.build();
}

return ImmutableBulkUploadRelationshipParsedResult
.builder()
.parsedItems(items)
.input(input)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.Nullable;
import org.immutables.value.Value;

import java.util.Set;

@Value.Immutable
@JsonSerialize(as = ImmutableBulkUploadRelationshipValidatedItem.class)
public interface BulkUploadRelationshipValidatedItem {
BulkUploadRelationshipItem parsedItem();

@Nullable
EntityReference sourceEntityRef();

@Nullable
EntityReference targetEntityRef();

@Nullable
String description();

@Nullable
Set<ValidationError> error();

UploadOperation uploadOperation();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.Nullable;
import org.immutables.value.Value;

import java.util.List;

@Value.Immutable
@JsonSerialize(as = ImmutableBulkUploadRelationshipValidationResult.class)
public interface BulkUploadRelationshipValidationResult {
List<BulkUploadRelationshipValidatedItem> validatedItems();

@Nullable
BulkUploadRelationshipParsedResult.BulkUploadRelationshipParseError parseError();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

public enum UploadOperation {
ADD,
UPDATE,
NONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.finos.waltz.model.bulk_upload.entity_relationship;

public enum ValidationError {
SOURCE_INVALID,
SOURCE_NOT_FOUND,
TARGET_INVALID,
TARGET_NOT_FOUND

}
19 changes: 18 additions & 1 deletion waltz-ng/client/svelte-stores/entity-relationship-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,29 @@ export function mkEntityRelationshipStore() {

};

const bulkUploadRelationshipsPreview = (relationshipKindId, data) => remote
.execute(
"POST",
`api/entity-relationship/bulk/preview/${relationshipKindId}`,
data
);

const bulkUploadRelationshipsApply = (relationshipKindId, data) => remote
.execute(
"POST",
`api/entity-relationship/bulk/apply/${relationshipKindId}`,
data
);


return {
getById,
findBetweenEntities,
findForEntity,
remove,
create
create,
bulkUploadRelationshipsPreview,
bulkUploadRelationshipsApply
};
}

Expand Down
10 changes: 10 additions & 0 deletions waltz-ng/client/system/relationship-kinds-view.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ <h4 ng-bind="$ctrl.selectedRelationshipKind.name"></h4>
class="clickable">
Remove
</a>
|
<a ng-click="$ctrl.bulkUploadRelationships()"
class="clickable">
Bulk Upload Relationships
</a>
</span>
</div>
</div>
Expand All @@ -175,6 +180,11 @@ <h4 ng-bind="$ctrl.selectedRelationshipKind.name"></h4>

<hr>

<div ng-if="$ctrl.visibility.bulk" class="col-sm-12">
<waltz-svelte-component component="$ctrl.BulkRelationshipUpload" selected-relationship-kind="$ctrl.selectedRelationshipKind">
</waltz-svelte-component>
</div>

<div ng-if="$ctrl.visibility.update" class="col-sm-12">
<hr>
<h4> Update relationship kind: </h4>
Expand Down
17 changes: 14 additions & 3 deletions waltz-ng/client/system/relationship-kinds-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import * as _ from "lodash";
import {displayError} from "../common/error-utils";
import {entity} from "../common/services/enums/entity";
import toasts from "../svelte-stores/toast-store";
import BulkRelationshipUpload from "./svelte/bulk-relationships/BulkRelationshipUpload.svelte";

const initialState = {
relationshipKinds: [],
Expand All @@ -40,8 +41,10 @@ const initialState = {
},
visibility: {
create: false,
edit: false
}
update: false,
bulk: false
},
BulkRelationshipUpload
};


Expand All @@ -51,7 +54,7 @@ const columnDefs = [
displayName: "Name",
width: "25%",
},{
field: "name",
field: "reverseName",
displayName: "Reverse Name",
width: "25%",
}, {
Expand Down Expand Up @@ -127,12 +130,14 @@ function controller(serviceBroker, $q) {
vm.form.position = vm.selectedRelationshipKind.position;

vm.visibility.update = true;
vm.visibility.bulk = false;
};

vm.createRelationshipKind = () => {
vm.resetForm();
vm.visibility.create = true;
vm.visibility.update = false;
vm.visibility.bulk = false;
vm.selectedRelationshipKind = null;
};

Expand Down Expand Up @@ -171,6 +176,7 @@ function controller(serviceBroker, $q) {
vm.onDismiss = () => {
vm.visibility.create = false;
vm.visibility.update = false;
vm.visibility.bulk = false;
vm.resetForm();
};

Expand Down Expand Up @@ -225,6 +231,11 @@ function controller(serviceBroker, $q) {
});
}
}

vm.bulkUploadRelationships = () => {
vm.visibility.bulk = true;
vm.visibility.update = false;
}
}

controller.$inject = [
Expand Down
Loading

0 comments on commit 55fefe4

Please sign in to comment.