Skip to content

Commit

Permalink
Merge pull request #265 from davidwatkins73/master
Browse files Browse the repository at this point in the history
Data type usage & Updated LnF
  • Loading branch information
davidwatkins73 authored Jul 8, 2016
2 parents 07677e3 + 51466f0 commit 579e9e0
Show file tree
Hide file tree
Showing 67 changed files with 2,220 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,16 @@ public static <X, Y> Collection<Y> map(Collection<X> xs, Function<X, Y> fn) {
checkNotNull(fn, "transformation fn cannot be null");

return xs.stream()
.map(x -> fn.apply(x))
.map(fn)
.collect(Collectors.toList());
}

public static <X> Collection<X> filter(Collection<X> xs, Predicate<X> pred) {
checkNotNull(xs, "collection must not be null");
checkNotNull(pred, "predicate fn cannot be null");

return xs.stream()
.filter(pred)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@

package com.khartec.waltz.common;

import java.util.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collector;
import java.util.stream.Collectors;

import static com.khartec.waltz.common.Checks.checkNotNull;


public class SetUtilities {

Expand All @@ -31,6 +35,12 @@ public static <T> Set<T> fromArray(T... ts) {
return new HashSet<>(Arrays.asList(ts));
}

public static <T> Set<T> fromCollection(Collection<T> ts) {
if (ts == null || ts.isEmpty()) return new HashSet<>();

return new HashSet<>(ts);
}

public static <X, Y> Set<Y> map(Collection<X> xs, Function<X, Y> fn) {
if (xs == null || xs.isEmpty()) return new HashSet<>();
return xs.stream()
Expand All @@ -45,4 +55,23 @@ public static <T> Set<T> union(Collection<T>... xss) {
}
return result;
}

public static <T> Set<T> minus(Set<T> xs, Set<T> ys) {
checkNotNull(xs, "xs cannot be null");
checkNotNull(ys, "ys cannot be null");

Set<T> working = new HashSet<>(xs);
working.removeAll(ys);
return working;
}

public static <T> Set<T> intersection(Set<T> xs, Set<T> ys) {
checkNotNull(xs, "xs cannot be null");
checkNotNull(ys, "ys cannot be null");

Set<T> working = new HashSet<>(xs);
working.retainAll(ys);
return working;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,11 @@ public static String mkSafe(String str) {
? ""
: str;
}


public static String limit(String str, int maxLength) {
if (str == null) return null;
int howMuch = Math.min(maxLength, str.length());
return str.substring(0, howMuch);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* This file is part of Waltz.
*
* Waltz is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Waltz is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Waltz. If not, see <http://www.gnu.org/licenses/>.
*/

package com.khartec.waltz.common;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class StringUtilities_limit {

@Test
public void limitingNullGivesNull() {
String result = StringUtilities.limit(null, 10);
assertNull(result);
}

@Test
public void limitingLongStringReturnsInitialPortion() {
String result = StringUtilities.limit("hello world", 5);
assertEquals("hello", result);
}

@Test
public void limitingShortStringReturnsFullString() {
String result = StringUtilities.limit("hello", 10);
assertEquals("hello", result);
}


}
84 changes: 84 additions & 0 deletions waltz-data/src/main/ddl/liquibase/db.changelog-1.0.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2049,4 +2049,88 @@
</createIndex>
</changeSet>


<!-- 253 Record usage of data types by applications -->
<changeSet author="dwatkins"
id="20160629-253-1">
<createTable tableName="data_type_usage">
<column name="entity_kind"
type="VARCHAR(128)">
<constraints nullable="false"/>
</column>
<column name="entity_id"
type="${long.type}">
<constraints nullable="false"/>
</column>
<column name="data_type_code"
type="VARCHAR(128)">
<constraints nullable="false"/>
</column>
<column name="usage_kind"
type="VARCHAR(128)">
<constraints nullable="false"/>
</column>
<column name="description"
type="VARCHAR(2048)"
defaultValue="">
<constraints nullable="false"/>
</column>
<column name="provenance"
type="varchar(64)"
defaultValue="waltz">
<constraints nullable="false"/>
</column>
</createTable>
</changeSet>


<changeSet author="dwatkins"
id="20160629-253-2">
<addPrimaryKey columnNames="entity_kind, entity_id, data_type_code, usage_kind"
constraintName="data_type_usage_pkey"
tableName="data_type_usage"/>
</changeSet>



<changeSet author="dwatkins"
id="20160629-253-3">
<sql>
INSERT INTO data_type_usage (entity_id, entity_kind, data_type_code, usage_kind)
SELECT DISTINCT df.source_entity_id as entity_id, df.source_entity_kind as entity_kind, df.data_type as data_type_code, 'DISTRIBUTOR' as usage_kind
FROM data_flow df
WHERE data_type != 'UNKNOWN'
UNION ALL
SELECT DISTINCT df.target_entity_id as entity_id, df.target_entity_kind as entity_kind, df.data_type as data_type_code, 'CONSUMER' as 'usage_kind'
FROM data_flow df
WHERE data_type != 'UNKNOWN'
UNION ALL
SELECT DISTINCT df.source_entity_id as entity_id, df.source_entity_kind as entity_kind, df.data_type as data_type_code, 'ORIGINATOR' as 'usage_kind'
FROM data_flow df
WHERE data_type != 'UNKNOWN'
AND NOT EXISTS(
SELECT *
FROM data_flow
WHERE target_entity_kind = df.source_entity_kind
AND target_entity_id = df.source_entity_id
AND data_type = df.data_type)
</sql>
</changeSet>


<changeSet author="dwatkins"
id="20160629-253-4">
<addColumn tableName="data_type_usage">
<column name="is_selected" type="boolean"/>
</addColumn>
</changeSet>

<changeSet author="dwatkins"
id="20160629-253-5">
<sql>
UPDATE data_type_usage SET is_selected = 1
</sql>
</changeSet>


</databaseChangeLog>
Loading

0 comments on commit 579e9e0

Please sign in to comment.