Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Db contrib/waltz 6368 legal entities table page #6371

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.finos.waltz.data.legal_entity;

import org.finos.waltz.common.DateTimeUtilities;
import org.finos.waltz.model.EntityLifecycleStatus;
import org.finos.waltz.model.legal_entity.ImmutableLegalEntity;
import org.finos.waltz.model.legal_entity.LegalEntity;
import org.finos.waltz.model.logical_flow.LogicalFlow;
import org.finos.waltz.schema.tables.records.LegalEntityRecord;
import org.finos.waltz.schema.tables.records.LogicalFlowRecord;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.sql.Timestamp;
import java.util.Set;

import static org.finos.waltz.common.DateTimeUtilities.toLocalDateTime;
import static org.finos.waltz.schema.Tables.LEGAL_ENTITY;

@Repository
public class LegalEntityDao {

private final DSLContext dsl;

private static final RecordMapper<Record, LegalEntity> TO_DOMAIN_MAPPER = r -> {
LegalEntityRecord record = r.into(LEGAL_ENTITY);

return ImmutableLegalEntity.builder()
.id(record.getId())
.name(record.getName())
.description(record.getDescription())
.externalId(record.getExternalId())
.entityLifecycleStatus(EntityLifecycleStatus.valueOf(record.getEntityLifecycleStatus()))
.lastUpdatedAt(toLocalDateTime(record.getLastUpdatedAt()))
.lastUpdatedBy(record.getLastUpdatedBy())
.provenance(record.getProvenance())
.build();
};

@Autowired
public LegalEntityDao(DSLContext dsl) {
this.dsl = dsl;
}

public LegalEntity getById(long id) {
return dsl
.select(LEGAL_ENTITY.fields())
.from(LEGAL_ENTITY)
.where(LEGAL_ENTITY.ID.eq(id))
.fetchOne(TO_DOMAIN_MAPPER);
}


public Set<LegalEntity> findAll() {
return dsl
.select(LEGAL_ENTITY.fields())
.from(LEGAL_ENTITY)
.fetchSet(TO_DOMAIN_MAPPER);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.finos.waltz.data.legal_entity;

import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.EntityReference;
import org.finos.waltz.model.legal_entity.ImmutableLegalEntityRelationship;
import org.finos.waltz.model.legal_entity.LegalEntityRelationship;
import org.finos.waltz.schema.tables.records.LegalEntityRelationshipRecord;
import org.jooq.Condition;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Optional;
import java.util.Set;

import static org.finos.waltz.common.DateTimeUtilities.toLocalDateTime;
import static org.finos.waltz.model.EntityReference.mkRef;
import static org.finos.waltz.schema.Tables.LEGAL_ENTITY_RELATIONSHIP;
import static org.finos.waltz.schema.Tables.LEGAL_ENTITY_RELATIONSHIP_KIND;

@Repository
public class LegalEntityRelationshipDao {

private final DSLContext dsl;
private static final RecordMapper<Record, LegalEntityRelationship> TO_DOMAIN_MAPPER = r -> {
LegalEntityRelationshipRecord record = r.into(LEGAL_ENTITY_RELATIONSHIP);

EntityReference targetEntityReference = mkRef(EntityKind.valueOf(record.getTargetKind()), record.getTargetId());

return ImmutableLegalEntityRelationship.builder()
.id(record.getId())
.legalEntityId(record.getLegalEntityId())
.relationshipKindId(record.getRelationshipKindId())
.description(record.getDescription())
.targetEntityReference(targetEntityReference)
.externalId(Optional.ofNullable(record.getExternalId()))
.lastUpdatedAt(toLocalDateTime(record.getLastUpdatedAt()))
.lastUpdatedBy(record.getLastUpdatedBy())
.provenance(record.getProvenance())
.isReadOnly(record.getIsReadonly())
.build();
};

@Autowired
public LegalEntityRelationshipDao(DSLContext dsl) {
this.dsl = dsl;
}

public Set<LegalEntityRelationship> findByLegalEntityId(Long legalEntityId) {
Condition legalEntityCondition = LEGAL_ENTITY_RELATIONSHIP.LEGAL_ENTITY_ID.eq(legalEntityId);
return findByCondition(legalEntityCondition);
}

private Set<LegalEntityRelationship> findByCondition(Condition condition) {
return dsl
.select(LEGAL_ENTITY_RELATIONSHIP_KIND.fields())
.from(LEGAL_ENTITY_RELATIONSHIP_KIND)
.where(condition)
.fetchSet(TO_DOMAIN_MAPPER);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.finos.waltz.data.legal_entity;

import org.finos.waltz.model.Cardinality;
import org.finos.waltz.model.EntityKind;
import org.finos.waltz.model.legal_entity.ImmutableLegalEntityRelationshipKind;
import org.finos.waltz.model.legal_entity.LegalEntityRelationshipKind;
import org.finos.waltz.schema.tables.records.LegalEntityRelationshipKindRecord;
import org.jooq.DSLContext;
import org.jooq.Record;
import org.jooq.RecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Set;

import static org.finos.waltz.common.DateTimeUtilities.toLocalDateTime;
import static org.finos.waltz.schema.Tables.LEGAL_ENTITY_RELATIONSHIP_KIND;

@Repository
public class LegalEntityRelationshipKindDao {

private final DSLContext dsl;
private static final RecordMapper<Record, LegalEntityRelationshipKind> TO_DOMAIN_MAPPER = r -> {
LegalEntityRelationshipKindRecord record = r.into(LEGAL_ENTITY_RELATIONSHIP_KIND);

return ImmutableLegalEntityRelationshipKind.builder()
.id(record.getId())
.name(record.getName())
.description(record.getDescription())
.targetKind(EntityKind.valueOf(record.getTargetKind()))
.cardinality(Cardinality.valueOf(record.getCardinality()))
.requiredRole(record.getRequiredRole())
.externalId(record.getExternalId())
.lastUpdatedAt(toLocalDateTime(record.getLastUpdatedAt()))
.lastUpdatedBy(record.getLastUpdatedBy())
.provenance(record.getProvenance())
.build();
};

@Autowired
public LegalEntityRelationshipKindDao(DSLContext dsl) {
this.dsl = dsl;
}

public LegalEntityRelationshipKind getById(long id) {
return dsl
.select(LEGAL_ENTITY_RELATIONSHIP_KIND.fields())
.from(LEGAL_ENTITY_RELATIONSHIP_KIND)
.where(LEGAL_ENTITY_RELATIONSHIP_KIND.ID.eq(id))
.fetchOne(TO_DOMAIN_MAPPER);
}


public Set<LegalEntityRelationshipKind> findAll() {
return dsl
.select(LEGAL_ENTITY_RELATIONSHIP_KIND.fields())
.from(LEGAL_ENTITY_RELATIONSHIP_KIND)
.fetchSet(TO_DOMAIN_MAPPER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private SelectConditionStep<Record1<Long>> permissionGroupSelector(EntityReferen
case APPLICATION:
case ACTOR:
case CHANGE_INITIATIVE:
case LEGAL_ENTITY:
return DSL
.select(PERMISSION_GROUP_ENTRY.PERMISSION_GROUP_ID)
.from(PERMISSION_GROUP_ENTRY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void findAssessmentRatingPermissions() {
String differentRoleName = mkName(stem, "differentRoleName");

long schemeId = ratingSchemeHelper.createEmptyRatingScheme(mkName(stem, "assessment permission checker"));
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", 'R');
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", 'A');
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", 'G');
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", "R");
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", "A");
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", "G");
long defnId = assessmentHelper.createDefinition(schemeId, mkName(stem, "assessment permission checker"), adminRoleName, AssessmentVisibility.PRIMARY, null);

assertThrows(
Expand Down Expand Up @@ -168,9 +168,9 @@ public void findAssessmentRatingPermissionsNullGroupId() {
String adminRoleName = mkName(stem, "adminRoleName");

long schemeId = ratingSchemeHelper.createEmptyRatingScheme(mkName(stem, "assessment permission checker"));
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", 'R');
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", 'A');
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", 'G');
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", "R");
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", "A");
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", "G");
long defnId = assessmentHelper.createDefinition(schemeId, mkName(stem, "assessment permission checker"), adminRoleName, AssessmentVisibility.PRIMARY, null);

PermissionGroupRecord pg = permissionHelper.createGroup(stem);
Expand Down Expand Up @@ -201,9 +201,9 @@ public void findAssessmentRatingPermissionsNullPermittedRole() {
String adminRoleName = mkName(stem, "adminRoleName");

long schemeId = ratingSchemeHelper.createEmptyRatingScheme(mkName(stem, "assessment permission checker"));
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", 'R');
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", 'A');
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", 'G');
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", "R");
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", "A");
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", "G");
long defnId = assessmentHelper.createDefinition(schemeId, mkName(stem, "assessment permission checker"), null, AssessmentVisibility.PRIMARY, null);

AssessmentDefinitionRatingOperations nullPermittedRoleGivesAllPermissions = assessmentRatingPermissionChecker.getRatingPermissions(appA, defnId, u1);
Expand All @@ -223,9 +223,9 @@ public void findAssessmentRatingPermissionsReadOnlyDefinition() {
EntityReference appA = appHelper.createNewApp(mkName(stem, "appA"), ouIds.a);

long schemeId = ratingSchemeHelper.createEmptyRatingScheme(mkName(stem, "assessment permission checker"));
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", 'R');
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", 'A');
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", 'G');
ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", "R");
ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", "A");
ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", "G");
long defnId = assessmentHelper.createDefinition(schemeId, mkName(stem, "assessment permission checker"), null, AssessmentVisibility.PRIMARY, null);
assessmentHelper.updateDefinitionReadOnly(defnId);

Expand All @@ -246,9 +246,9 @@ public void findAssessmentRatingPermissionsReadOnlyRating() {
EntityReference appA = appHelper.createNewApp(mkName(stem, "appA"), ouIds.a);

long schemeId = ratingSchemeHelper.createEmptyRatingScheme(mkName(stem, "assessment permission checker"));
Long r1 = ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", 'R');
Long r2 = ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", 'A');
Long r3 = ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", 'G');
Long r1 = ratingSchemeHelper.saveRatingItem(schemeId, "Disinvest", 1, "red", "R");
Long r2 = ratingSchemeHelper.saveRatingItem(schemeId, "Maintain", 2, "amber", "A");
Long r3 = ratingSchemeHelper.saveRatingItem(schemeId, "Invest", 3, "green", "G");
long defnId = assessmentHelper.createDefinition(schemeId, mkName(stem, "assessment permission checker"), null, AssessmentVisibility.PRIMARY, null);
assessmentHelper.createAssessment(defnId, appA, r1);
assessmentHelper.updateRatingReadOnly(appA, defnId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ public static void main(String[] args) throws ParseException {

long schemeId = ratingSchemeHelper.createEmptyRatingScheme("Test Scheme");

Long y = ratingSchemeHelper.saveRatingItem(schemeId, "Yes", 10, "green", 'Y');
Long n = ratingSchemeHelper.saveRatingItem(schemeId, "No", 20, "red", 'N');
Long m = ratingSchemeHelper.saveRatingItem(schemeId, "Maybe", 30, "yellow", 'M');
Long y = ratingSchemeHelper.saveRatingItem(schemeId, "Yes", 10, "green", "Y");
Long n = ratingSchemeHelper.saveRatingItem(schemeId, "No", 20, "red", "N");
Long m = ratingSchemeHelper.saveRatingItem(schemeId, "Maybe", 30, "yellow", "M");

long defA = assessmentHelper.createDefinition(schemeId, "Test Definition A", null, AssessmentVisibility.PRIMARY, "Edit Favourites");
long defB = assessmentHelper.createDefinition(schemeId, "Test Definition B", null, AssessmentVisibility.SECONDARY, "Edit Favourites");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public enum EntityKind {
INVOLVEMENT("Involvement"),
INVOLVEMENT_KIND("Involvement kind"),
LICENCE("Licence"),
LEGAL_ENTITY("Legal Entity"),
LEGAL_ENTITY_RELATIONSHIP("Legal Entity Relationship"),
LEGAL_ENTITY_RELATIONSHIP_KIND("Legal Entity Relationship Kind"),
LOGICAL_DATA_ELEMENT("Logical data element"),
LOGICAL_DATA_FLOW("Logical flow"),
MEASURABLE("Measurable"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Waltz - Enterprise Architecture
* Copyright (C) 2016, 2017, 2018, 2019 Waltz open source project
* See README.md for more information
*
* 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
*
*/

package org.finos.waltz.model.legal_entity;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import org.finos.waltz.model.*;
import org.finos.waltz.model.logical_flow.ImmutableLogicalFlow;
import org.immutables.value.Value;


@Value.Immutable
@JsonSerialize(as = ImmutableLegalEntity.class)
@JsonDeserialize(as = ImmutableLegalEntity.class)
public abstract class LegalEntity implements
EntityLifecycleStatusProvider,
IdProvider,
ProvenanceProvider,
LastUpdatedProvider,
WaltzEntity,
EntityKindProvider {

public abstract String name();

public abstract String description();

public abstract String externalId();

@Override
public EntityReference entityReference() {
return EntityReference.mkRef(
EntityKind.LEGAL_ENTITY,
id().get());
}

@Value.Default
public EntityKind kind() {
return EntityKind.LEGAL_ENTITY;
}

}
Loading