Skip to content

Commit

Permalink
Merge pull request #69 from hmcts/simplify
Browse files Browse the repository at this point in the history
Merge types library into config generator
  • Loading branch information
banderous authored Mar 5, 2021
2 parents 4669d48 + ba9af19 commit 9f2861e
Show file tree
Hide file tree
Showing 110 changed files with 332 additions and 279 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ subprojects {
}
}

def libraries = [project(":ccd-sdk-types"), project(":ccd-config-generator")]
def libraries = [project(":ccd-config-generator")]

configure(libraries) {

Expand Down
1 change: 0 additions & 1 deletion ccd-config-generator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ dependencies {
compile 'com.google.guava:guava:30.1-jre'

compile 'com.fasterxml.jackson.core:jackson-databind:2.12.2'
compile project(':ccd-sdk-types')
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand All @@ -11,7 +11,7 @@
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;

public class AuthorisationCaseEventGenerator {
class AuthorisationCaseEventGenerator {

public static void generate(File root,
Table<String, String, String> eventRolePermissions,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.base.Strings;
import com.google.common.collect.HashBasedTable;
Expand All @@ -19,23 +19,22 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.CRUDMerger;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.Field;
import uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.types.HasRole;
import uk.gov.hmcts.ccd.sdk.types.Search;
import uk.gov.hmcts.ccd.sdk.types.Search.SearchBuilder;
import uk.gov.hmcts.ccd.sdk.types.SearchField;
import uk.gov.hmcts.ccd.sdk.types.Tab;
import uk.gov.hmcts.ccd.sdk.types.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.types.TabField;
import uk.gov.hmcts.ccd.sdk.types.WorkBasket;
import uk.gov.hmcts.ccd.sdk.types.WorkBasket.WorkBasketBuilder;
import uk.gov.hmcts.ccd.sdk.types.WorkBasketField;

public class AuthorisationCaseFieldGenerator {
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.Field;
import uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.api.HasRole;
import uk.gov.hmcts.ccd.sdk.api.Search;
import uk.gov.hmcts.ccd.sdk.api.Search.SearchBuilder;
import uk.gov.hmcts.ccd.sdk.api.SearchField;
import uk.gov.hmcts.ccd.sdk.api.Tab;
import uk.gov.hmcts.ccd.sdk.api.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.api.TabField;
import uk.gov.hmcts.ccd.sdk.api.WorkBasket;
import uk.gov.hmcts.ccd.sdk.api.WorkBasket.WorkBasketBuilder;
import uk.gov.hmcts.ccd.sdk.api.WorkBasketField;

class AuthorisationCaseFieldGenerator {

public static void generate(File root, String caseType, List<Event> events,
Table<String, String, String> eventRolePermissions, List<TabBuilder> tabs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
Expand All @@ -16,11 +16,10 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.CRUDMerger;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.api.Event;

public class AuthorisationCaseStateGenerator {
class AuthorisationCaseStateGenerator {

public static void generate(File root, String caseType, List<Event> events,
Table<String, String, String> eventRolePermissions) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.collect.Lists;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.types.HasRole;
import uk.gov.hmcts.ccd.sdk.api.HasRole;

public class AuthorisationCaseTypeGenerator {
class AuthorisationCaseTypeGenerator {
public static void generate(File root, String caseType, Class roleEnum) {

List<Map<String, Object>> result = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableListMultimap;
Expand All @@ -11,12 +11,11 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.Webhook;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.Webhook;

public class CaseEventGenerator {
class CaseEventGenerator {

public static void writeEvents(File root, String caseType, List<Event> events) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.base.Strings;
import com.google.common.collect.ImmutableListMultimap;
Expand All @@ -10,13 +10,12 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.Field;
import uk.gov.hmcts.ccd.sdk.types.FieldCollection;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.Field;
import uk.gov.hmcts.ccd.sdk.api.FieldCollection;

public class CaseEventToComplexTypesGenerator {
class CaseEventToComplexTypesGenerator {

public static void writeEvents(File root, List<Event> events) {
for (Event event : events) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand All @@ -8,13 +8,12 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.Field;
import uk.gov.hmcts.ccd.sdk.types.FieldCollection;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.Field;
import uk.gov.hmcts.ccd.sdk.api.FieldCollection;

public class CaseEventToFieldsGenerator {
class CaseEventToFieldsGenerator {

public static void writeEvents(File root, List<Event> events, String caseType) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
Expand All @@ -18,17 +18,15 @@
import java.util.Set;
import net.jodah.typetools.TypeResolver;
import org.reflections.ReflectionUtils;
import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.OverwriteSpecific;
import uk.gov.hmcts.ccd.sdk.types.CCD;
import uk.gov.hmcts.ccd.sdk.types.ComplexType;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.types.FieldType;
import uk.gov.hmcts.ccd.sdk.types.Label;
import uk.gov.hmcts.ccd.sdk.api.CCD;
import uk.gov.hmcts.ccd.sdk.api.ComplexType;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.api.FieldType;
import uk.gov.hmcts.ccd.sdk.api.Label;

public class CaseFieldGenerator {
class CaseFieldGenerator {

// The field type set from code always takes precedence,
// so eg. if a field changes type it gets updated.
Expand Down Expand Up @@ -180,26 +178,26 @@ private static void inferFieldType(Class dataClass, Field field, Map<String, Obj

private static List<Map<String, Object>> getExplicitFields(String caseType, List<Event> events,
ConfigBuilderImpl builder) {
Map<String, uk.gov.hmcts.ccd.sdk.types.Field> explicitFields = Maps.newHashMap();
Map<String, uk.gov.hmcts.ccd.sdk.api.Field> explicitFields = Maps.newHashMap();
for (Event event : events) {
List<uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder> fc = event.getFields().build()
List<uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder> fc = event.getFields().build()
.getExplicitFields();

for (uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder fieldBuilder : fc) {
uk.gov.hmcts.ccd.sdk.types.Field field = fieldBuilder.build();
for (uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder fieldBuilder : fc) {
uk.gov.hmcts.ccd.sdk.api.Field field = fieldBuilder.build();
explicitFields.put(field.getId(), field);
}
}

List<uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder> fs = builder.explicitFields;
List<uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder> fs = builder.explicitFields;
for (FieldBuilder explicitField : fs) {
uk.gov.hmcts.ccd.sdk.types.Field field = explicitField.build();
uk.gov.hmcts.ccd.sdk.api.Field field = explicitField.build();
explicitFields.put(field.getId(), field);
}

List<Map<String, Object>> result = Lists.newArrayList();
for (String fieldId : explicitFields.keySet()) {
uk.gov.hmcts.ccd.sdk.types.Field field = explicitFields.get(fieldId);
uk.gov.hmcts.ccd.sdk.api.Field field = explicitFields.get(fieldId);
Map<String, Object> fieldData = getField(caseType, fieldId);
// Don't export inbuilt metadata fields.
if (fieldId.matches("\\[.+\\]")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand All @@ -7,15 +7,13 @@
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import uk.gov.hmcts.ccd.sdk.ConfigBuilderImpl;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;
import uk.gov.hmcts.ccd.sdk.types.HasRole;
import uk.gov.hmcts.ccd.sdk.types.Tab;
import uk.gov.hmcts.ccd.sdk.types.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.types.TabField;
import uk.gov.hmcts.ccd.sdk.api.HasRole;
import uk.gov.hmcts.ccd.sdk.api.Tab;
import uk.gov.hmcts.ccd.sdk.api.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.api.TabField;

public class CaseTypeTabGenerator {
class CaseTypeTabGenerator {

public static <T, R extends HasRole, S> void generate(File root, String caseType,
ConfigBuilderImpl<T, S, R> builder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package uk.gov.hmcts.ccd.sdk.generator;
package uk.gov.hmcts.ccd.sdk;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import uk.gov.hmcts.ccd.sdk.JsonUtils;
import uk.gov.hmcts.ccd.sdk.JsonUtils.AddMissing;
import uk.gov.hmcts.ccd.sdk.types.ComplexType;
import uk.gov.hmcts.ccd.sdk.api.ComplexType;

public class ComplexTypeGenerator {
class ComplexTypeGenerator {

public static void generate(File root, String caseType, Map<Class, Integer> types) {
File complexTypes = new File(root, "ComplexTypes");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import uk.gov.hmcts.ccd.sdk.types.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.types.Event;
import uk.gov.hmcts.ccd.sdk.types.EventTypeBuilder;
import uk.gov.hmcts.ccd.sdk.types.Field;
import uk.gov.hmcts.ccd.sdk.types.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.types.HasRole;
import uk.gov.hmcts.ccd.sdk.types.RoleBuilder;
import uk.gov.hmcts.ccd.sdk.types.Search.SearchBuilder;
import uk.gov.hmcts.ccd.sdk.types.Tab;
import uk.gov.hmcts.ccd.sdk.types.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.types.Webhook;
import uk.gov.hmcts.ccd.sdk.types.WebhookConvention;
import uk.gov.hmcts.ccd.sdk.types.WorkBasket.WorkBasketBuilder;

public class ConfigBuilderImpl<T, S, R extends HasRole> implements ConfigBuilder<T, S, R> {
import uk.gov.hmcts.ccd.sdk.api.ConfigBuilder;
import uk.gov.hmcts.ccd.sdk.api.Event;
import uk.gov.hmcts.ccd.sdk.api.EventTypeBuilder;
import uk.gov.hmcts.ccd.sdk.api.Field;
import uk.gov.hmcts.ccd.sdk.api.Field.FieldBuilder;
import uk.gov.hmcts.ccd.sdk.api.HasRole;
import uk.gov.hmcts.ccd.sdk.api.RoleBuilder;
import uk.gov.hmcts.ccd.sdk.api.Search.SearchBuilder;
import uk.gov.hmcts.ccd.sdk.api.Tab;
import uk.gov.hmcts.ccd.sdk.api.Tab.TabBuilder;
import uk.gov.hmcts.ccd.sdk.api.Webhook;
import uk.gov.hmcts.ccd.sdk.api.WebhookConvention;
import uk.gov.hmcts.ccd.sdk.api.WorkBasket.WorkBasketBuilder;

class ConfigBuilderImpl<T, S, R extends HasRole> implements ConfigBuilder<T, S, R> {

public String caseType = "";
public final Multimap<String, String> stateRoleHistoryAccess = ArrayListMultimap.create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.common.collect.Multimap;
import com.google.common.collect.Table;
import com.google.common.io.MoreFiles;
import com.google.common.io.RecursiveDeleteOption;
import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
Expand All @@ -26,24 +27,10 @@
import org.objenesis.ObjenesisStd;
import org.reflections.ReflectionUtils;
import org.reflections.Reflections;
import uk.gov.hmcts.ccd.sdk.generator.AuthorisationCaseEventGenerator;
import uk.gov.hmcts.ccd.sdk.generator.AuthorisationCaseFieldGenerator;
import uk.gov.hmcts.ccd.sdk.generator.AuthorisationCaseStateGenerator;
import uk.gov.hmcts.ccd.sdk.generator.AuthorisationCaseTypeGenerator;
import uk.gov.hmcts.ccd.sdk.generator.CaseEventGenerator;
import uk.gov.hmcts.ccd.sdk.generator.CaseEventToComplexTypesGenerator;
import uk.gov.hmcts.ccd.sdk.generator.CaseEventToFieldsGenerator;
import uk.gov.hmcts.ccd.sdk.generator.CaseFieldGenerator;
import uk.gov.hmcts.ccd.sdk.generator.CaseTypeTabGenerator;
import uk.gov.hmcts.ccd.sdk.generator.ComplexTypeGenerator;
import uk.gov.hmcts.ccd.sdk.generator.FixedListGenerator;
import uk.gov.hmcts.ccd.sdk.generator.SearchFieldAndResultGenerator;
import uk.gov.hmcts.ccd.sdk.generator.StateGenerator;
import uk.gov.hmcts.ccd.sdk.generator.WorkBasketGenerator;
import uk.gov.hmcts.ccd.sdk.types.CCDConfig;
import uk.gov.hmcts.ccd.sdk.types.Event;

public class ConfigGenerator {
import uk.gov.hmcts.ccd.sdk.api.CCDConfig;
import uk.gov.hmcts.ccd.sdk.api.Event;

class ConfigGenerator {

private final Reflections reflections;
private final String basePackage;
Expand Down Expand Up @@ -120,7 +107,7 @@ private void writeConfig(File outputfolder, ResolvedCCDConfig config) {
@SneakyThrows
private void initOutputDirectory(File outputfolder) {
if (outputfolder.exists() && outputfolder.isDirectory()) {
MoreFiles.deleteRecursively(outputfolder.toPath());
MoreFiles.deleteRecursively(outputfolder.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
}
outputfolder.mkdirs();
}
Expand Down
Loading

0 comments on commit 9f2861e

Please sign in to comment.