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

DataType page: App Id selector for data types #414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.khartec.waltz.data.IdSelectorFactory;
import com.khartec.waltz.data.capability.CapabilityIdSelectorFactory;
import com.khartec.waltz.data.data_type.DataTypeIdSelectorFactory;
import com.khartec.waltz.data.orgunit.OrganisationalUnitIdSelectorFactory;
import com.khartec.waltz.model.*;
import com.khartec.waltz.model.entiy_relationship.RelationshipKind;
import com.khartec.waltz.schema.tables.*;
import com.khartec.waltz.schema.tables.DataType;
import org.jooq.*;
import org.jooq.impl.DSL;
import org.slf4j.Logger;
Expand All @@ -18,6 +20,8 @@
import static com.khartec.waltz.schema.tables.AppCapability.APP_CAPABILITY;
import static com.khartec.waltz.schema.tables.Application.APPLICATION;
import static com.khartec.waltz.schema.tables.ApplicationGroupEntry.APPLICATION_GROUP_ENTRY;
import static com.khartec.waltz.schema.tables.DataType.DATA_TYPE;
import static com.khartec.waltz.schema.tables.DataTypeUsage.DATA_TYPE_USAGE;
import static com.khartec.waltz.schema.tables.Involvement.INVOLVEMENT;
import static com.khartec.waltz.schema.tables.Person.PERSON;
import static com.khartec.waltz.schema.tables.PersonHierarchy.PERSON_HIERARCHY;
Expand All @@ -29,12 +33,15 @@ public class ApplicationIdSelectorFactory implements IdSelectorFactory {
private static final Logger LOG = LoggerFactory.getLogger(ApplicationIdSelectorFactory.class);

private final DSLContext dsl;
private final OrganisationalUnitIdSelectorFactory orgUnitIdSelectorFactory;
private final CapabilityIdSelectorFactory capabilityIdSelectorFactory;
private final DataTypeIdSelectorFactory dataTypeIdSelectorFactory;
private final OrganisationalUnitIdSelectorFactory orgUnitIdSelectorFactory;

private final Application app = APPLICATION.as("app");
private final AppCapability appCapability = APP_CAPABILITY.as("appcap");
private final ApplicationGroupEntry appGroup = APPLICATION_GROUP_ENTRY.as("appgrp");
private final DataTypeUsage dataTypeUsage = DATA_TYPE_USAGE.as("dtu");
private final DataType dataType = DATA_TYPE.as("dt");
private final EntityRelationship relationship = EntityRelationship.ENTITY_RELATIONSHIP.as("relationship");
private final Involvement involvement = INVOLVEMENT.as("involvement");
private final Person person = PERSON.as("per");
Expand All @@ -44,13 +51,16 @@ public class ApplicationIdSelectorFactory implements IdSelectorFactory {
@Autowired
public ApplicationIdSelectorFactory(DSLContext dsl,
CapabilityIdSelectorFactory capabilityIdSelectorFactory,
DataTypeIdSelectorFactory dataTypeIdSelectorFactory,
OrganisationalUnitIdSelectorFactory orgUnitIdSelectorFactory) {
checkNotNull(dsl, "dsl cannot be null");
checkNotNull(capabilityIdSelectorFactory, "capabilityIdSelectorFactory cannot be null");
checkNotNull(dataTypeIdSelectorFactory, "dataTypeIdSelectorFactory cannot be null");
checkNotNull(orgUnitIdSelectorFactory, "orgUnitIdSelectorFactory cannot be null");

this.dsl = dsl;
this.capabilityIdSelectorFactory = capabilityIdSelectorFactory;
this.dataTypeIdSelectorFactory = dataTypeIdSelectorFactory;
this.orgUnitIdSelectorFactory = orgUnitIdSelectorFactory;
}

Expand All @@ -70,6 +80,8 @@ public Select<Record1<Long>> apply(IdSelectionOptions options) {
return mkForOrgUnit(ref, options.scope());
case PROCESS:
return mkForProcess(ref, options.scope());
case DATA_TYPE:
return mkForDataType(ref, options.scope());

default:
throw new IllegalArgumentException("Cannot create selector for entity kind: "+ref.kind());
Expand Down Expand Up @@ -205,4 +217,23 @@ private Select<Record1<Long>> mkForCapability(EntityReference ref, HierarchyQuer
.where(dsl.renderInlined(appCapability.CAPABILITY_ID.in(capabilitySelector)));
}


private Select<Record1<Long>> mkForDataType(EntityReference ref, HierarchyQueryScope scope) {
ImmutableIdSelectionOptions dtSelectorOptions = ImmutableIdSelectionOptions.builder()
.entityReference(ref)
.scope(scope)
.build();

Select<Record1<Long>> dtSelector = dataTypeIdSelectorFactory.apply(dtSelectorOptions);

Condition condition = dataTypeUsage.ENTITY_KIND.eq(EntityKind.APPLICATION.name())
.and(dataType.ID.in(dtSelector));

return dsl
.selectDistinct(dataTypeUsage.ENTITY_ID)
.from(dataTypeUsage)
.join(dataType).on(dataType.CODE.eq(dataTypeUsage.DATA_TYPE_CODE))
.where(dsl.renderInlined(condition));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.khartec.waltz.data.data_type;


import com.khartec.waltz.data.entity_hierarchy.AbstractIdSelectorFactory;
import com.khartec.waltz.model.EntityKind;
import com.khartec.waltz.model.IdSelectionOptions;
import org.jooq.DSLContext;
import org.jooq.Record1;
import org.jooq.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DataTypeIdSelectorFactory extends AbstractIdSelectorFactory {


@Autowired
public DataTypeIdSelectorFactory(DSLContext dsl) {
super(dsl, EntityKind.DATA_TYPE);
}

@Override
protected Select<Record1<Long>> mkForOptions(IdSelectionOptions options) {
throw new UnsupportedOperationException("Cannot create dataType selector from kind: " +
options.entityReference().kind());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.khartec.waltz.service.involvement.InvolvementService;
import org.jooq.DSLContext;
import org.jooq.Record1;
import org.jooq.Result;
import org.jooq.Select;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

Expand All @@ -30,8 +31,8 @@ public static void main(String[] args) {
IdSelectionOptions options = ImmutableIdSelectionOptions.builder()
.entityReference(ImmutableEntityReference
.builder()
.kind(EntityKind.ORG_UNIT)
.id(30)
.kind(EntityKind.DATA_TYPE)
.id(6000)
.build())
.scope(HierarchyQueryScope.CHILDREN)
.build();
Expand All @@ -40,6 +41,10 @@ public static void main(String[] args) {
Select<Record1<Long>> selector = factory.apply(options);

System.out.println(selector);

Result<Record1<Long>> fetch = dsl.fetch(selector);

fetch.forEach(r -> System.out.println(r.value1()));
}


Expand Down