@Test(expected = InvalidEntitySettingsException.class) public void shouldSignalInvalidHistoryTrackingSettings() { fixDataModel(); List<EntityDto> entities = getDataModel(); entities.get(0).setRecordHistory(false); EntitySorter.sortByHasARelation(entities, schemaHolder); }
public static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder) { List<EntityDto> sorted = new ArrayList<>(allEntities); MultiValueMap<String, String> unresolvedRelations = new LinkedMultiValueMap<>(); for (int i = 0; i < sorted.size(); ++i) { EntityDto entity = sorted.get(i); List<FieldDto> fields = (List<FieldDto>) CollectionUtils.select( schemaHolder.getFields(entity), new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof FieldDto && ((FieldDto) object).getType().isRelationship(); } }); if (CollectionUtils.isNotEmpty(fields)) { int max = i; for (FieldDto field : fields) { final RelationshipHolder holder = new RelationshipHolder(field); unresolvedRelations = validateRelationship(unresolvedRelations, entity, holder); assertRelationshipIsHistoryCompatible(entity, holder, allEntities); EntityDto relation = (EntityDto) CollectionUtils.find(sorted, new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof EntityDto && ((EntityDto) object).getClassName().equalsIgnoreCase(holder.getRelatedClass()); } }); boolean biDirectional = field.getMetadata(RELATED_FIELD) != null; max = Math.max(max, biDirectional ? -1 : sorted.indexOf(relation)); } if (max != i) { sorted.remove(i); --i; if (max < sorted.size()) { sorted.add(max, entity); } else { sorted.add(entity); } } } } return sorted; }
EntitySorter { public static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder) { List<EntityDto> sorted = new ArrayList<>(allEntities); MultiValueMap<String, String> unresolvedRelations = new LinkedMultiValueMap<>(); for (int i = 0; i < sorted.size(); ++i) { EntityDto entity = sorted.get(i); List<FieldDto> fields = (List<FieldDto>) CollectionUtils.select( schemaHolder.getFields(entity), new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof FieldDto && ((FieldDto) object).getType().isRelationship(); } }); if (CollectionUtils.isNotEmpty(fields)) { int max = i; for (FieldDto field : fields) { final RelationshipHolder holder = new RelationshipHolder(field); unresolvedRelations = validateRelationship(unresolvedRelations, entity, holder); assertRelationshipIsHistoryCompatible(entity, holder, allEntities); EntityDto relation = (EntityDto) CollectionUtils.find(sorted, new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof EntityDto && ((EntityDto) object).getClassName().equalsIgnoreCase(holder.getRelatedClass()); } }); boolean biDirectional = field.getMetadata(RELATED_FIELD) != null; max = Math.max(max, biDirectional ? -1 : sorted.indexOf(relation)); } if (max != i) { sorted.remove(i); --i; if (max < sorted.size()) { sorted.add(max, entity); } else { sorted.add(entity); } } } } return sorted; } }
EntitySorter { public static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder) { List<EntityDto> sorted = new ArrayList<>(allEntities); MultiValueMap<String, String> unresolvedRelations = new LinkedMultiValueMap<>(); for (int i = 0; i < sorted.size(); ++i) { EntityDto entity = sorted.get(i); List<FieldDto> fields = (List<FieldDto>) CollectionUtils.select( schemaHolder.getFields(entity), new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof FieldDto && ((FieldDto) object).getType().isRelationship(); } }); if (CollectionUtils.isNotEmpty(fields)) { int max = i; for (FieldDto field : fields) { final RelationshipHolder holder = new RelationshipHolder(field); unresolvedRelations = validateRelationship(unresolvedRelations, entity, holder); assertRelationshipIsHistoryCompatible(entity, holder, allEntities); EntityDto relation = (EntityDto) CollectionUtils.find(sorted, new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof EntityDto && ((EntityDto) object).getClassName().equalsIgnoreCase(holder.getRelatedClass()); } }); boolean biDirectional = field.getMetadata(RELATED_FIELD) != null; max = Math.max(max, biDirectional ? -1 : sorted.indexOf(relation)); } if (max != i) { sorted.remove(i); --i; if (max < sorted.size()) { sorted.add(max, entity); } else { sorted.add(entity); } } } } return sorted; } private  EntitySorter(); }
EntitySorter { public static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder) { List<EntityDto> sorted = new ArrayList<>(allEntities); MultiValueMap<String, String> unresolvedRelations = new LinkedMultiValueMap<>(); for (int i = 0; i < sorted.size(); ++i) { EntityDto entity = sorted.get(i); List<FieldDto> fields = (List<FieldDto>) CollectionUtils.select( schemaHolder.getFields(entity), new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof FieldDto && ((FieldDto) object).getType().isRelationship(); } }); if (CollectionUtils.isNotEmpty(fields)) { int max = i; for (FieldDto field : fields) { final RelationshipHolder holder = new RelationshipHolder(field); unresolvedRelations = validateRelationship(unresolvedRelations, entity, holder); assertRelationshipIsHistoryCompatible(entity, holder, allEntities); EntityDto relation = (EntityDto) CollectionUtils.find(sorted, new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof EntityDto && ((EntityDto) object).getClassName().equalsIgnoreCase(holder.getRelatedClass()); } }); boolean biDirectional = field.getMetadata(RELATED_FIELD) != null; max = Math.max(max, biDirectional ? -1 : sorted.indexOf(relation)); } if (max != i) { sorted.remove(i); --i; if (max < sorted.size()) { sorted.add(max, entity); } else { sorted.add(entity); } } } } return sorted; } private  EntitySorter(); static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder); static List<EntityDto> sortByInheritance(List<EntityDto> list); }
EntitySorter { public static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder) { List<EntityDto> sorted = new ArrayList<>(allEntities); MultiValueMap<String, String> unresolvedRelations = new LinkedMultiValueMap<>(); for (int i = 0; i < sorted.size(); ++i) { EntityDto entity = sorted.get(i); List<FieldDto> fields = (List<FieldDto>) CollectionUtils.select( schemaHolder.getFields(entity), new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof FieldDto && ((FieldDto) object).getType().isRelationship(); } }); if (CollectionUtils.isNotEmpty(fields)) { int max = i; for (FieldDto field : fields) { final RelationshipHolder holder = new RelationshipHolder(field); unresolvedRelations = validateRelationship(unresolvedRelations, entity, holder); assertRelationshipIsHistoryCompatible(entity, holder, allEntities); EntityDto relation = (EntityDto) CollectionUtils.find(sorted, new Predicate() { @Override public boolean evaluate(Object object) { return object instanceof EntityDto && ((EntityDto) object).getClassName().equalsIgnoreCase(holder.getRelatedClass()); } }); boolean biDirectional = field.getMetadata(RELATED_FIELD) != null; max = Math.max(max, biDirectional ? -1 : sorted.indexOf(relation)); } if (max != i) { sorted.remove(i); --i; if (max < sorted.size()) { sorted.add(max, entity); } else { sorted.add(entity); } } } } return sorted; } private  EntitySorter(); static List<EntityDto> sortByHasARelation(List<EntityDto> allEntities, SchemaHolder schemaHolder); static List<EntityDto> sortByInheritance(List<EntityDto> list);  }