Skip to content

Commit af551c5

Browse files
authored
Merge pull request #64 from HHS/update-util-to-4.2.0
Update util to 4.2.0
2 parents efba2d7 + 87e4506 commit af551c5

26 files changed

+367
-153
lines changed

.github/workflows/dev_build.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ name: Taskit Development Build
1111
on:
1212
push:
1313
branches: [ "dev" ]
14-
pull_request:
15-
branches-ignore: ["main"]
1614

1715
jobs:
1816
dev-build:

.github/workflows/dev_pr_build.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3+
4+
# This workflow uses actions that are not certified by GitHub.
5+
# They are provided by a third-party and are governed by
6+
# separate terms of service, privacy policy, and support
7+
# documentation.
8+
9+
name: Taskit Development PR Build
10+
11+
on:
12+
pull_request:
13+
branches-ignore: ["main"]
14+
15+
jobs:
16+
dev-build:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout Taskit
20+
uses: actions/checkout@v4
21+
22+
- name: Set up JDK 17
23+
uses: actions/setup-java@v4
24+
with:
25+
java-version: '17'
26+
distribution: 'temurin'
27+
cache: maven
28+
29+
- name: Get Util Version
30+
run: |
31+
echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV"
32+
33+
- name: Checkout Util
34+
if: ${{ endsWith(env.util_version, 'SNAPSHOT') }}
35+
uses: actions/checkout@v4
36+
with:
37+
repository: HHS/ASPR-ms-util
38+
path: util
39+
ref: dev
40+
41+
- name: Build Util
42+
if: ${{ endsWith(env.util_version, 'SNAPSHOT') }}
43+
run: mvn clean install -DskipTests --file util/pom.xml
44+
45+
- name: Build Taskit
46+
run: mvn clean install --file pom.xml
47+
48+
# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
49+
# - name: Update dependency graph
50+
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6

.github/workflows/release_pr_build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- name: Version Is Snapshot
3535
if: ${{ endsWith(env.version, 'SNAPSHOT') }}
3636
run: |
37-
echo "::error Version is a SNAPSHOT. Update version to proper version."
37+
echo "Version is a SNAPSHOT version. Update version to proper version."
3838
exit 1
3939
4040
- name: Build Taskit

core/src/main/java/gov/hhs/aspr/ms/taskit/core/CoreTranslationError.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public enum CoreTranslationError implements ContractError {
1919
NO_TRANSLATION_ENGINES("There are no translation engines added to this controller."),
2020
NULL_CLASS_REF("Null Class Ref"),
2121
NULL_DEPENDENCY("Null dependency"),
22-
NULL_INIT_CONSUMER("Null Initilizer Consumer"),
22+
NULL_INIT_CONSUMER("Null Initializer Consumer"),
2323
NULL_OBJECT_FOR_TRANSLATION("The object to be translated was null"),
2424
NULL_PATH("Null Path"),
2525
NULL_TRANSLATION_ENGINE("Null Translation Engine"),
@@ -34,7 +34,7 @@ public enum CoreTranslationError implements ContractError {
3434
"Translators were added to the builder but were not initialized. Make sure to call super.initTranslators() during your custom engine build method"),
3535
UNKNOWN_CLASSREF("No object has been read in with the specified classRef"),
3636
UNKNOWN_OBJECT("Object is not Translatable by this TranslationSpec"),
37-
UNKNWON_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"),
37+
UNKNOWN_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"),
3838
UNKNOWN_TRANSLATION_SPEC("No translation spec was provided for the given class"),
3939
UNSUPPORTED_VERSION("The given version is not supported");
4040

core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationController.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import gov.hhs.aspr.ms.util.errors.ContractException;
1616

1717
/**
18-
* The TranslatorController serves as the master of cerimonies for translating
18+
* The TranslatorController serves as the master of ceremonies for translating
1919
* between two types of objects. Additionally, it has the ability to distribute
2020
* Input/Output files for reading and writing.
2121
*/
@@ -137,7 +137,7 @@ public Builder addInputFilePath(Path filePath, Class<?> classRef, TranslationEng
137137
}
138138

139139
/**
140-
* Adds the given classRef markerInterace mapping.
140+
* Adds the given classRef markerInterface mapping.
141141
* <p>
142142
* explicitly used when calling {@link TranslationController#writeOutput} with a
143143
* class for which a classRef ScenarioId pair does not exist and/or the need to
@@ -196,7 +196,7 @@ public Builder addTranslationEngine(TranslationEngine translationEngine) {
196196

197197
this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef);
198198
}
199-
199+
200200
return this;
201201
}
202202
}
@@ -404,18 +404,27 @@ <M extends U, U> void writeOutput(Path path, M object, Optional<Class<U>> superC
404404
* Searches the list of read in objects and returns the first Object found of
405405
* the given classRef
406406
*
407-
* @param <T> the type of the obect to get
407+
* @param <T> the type of the object to get
408408
* @throws ContractException
409409
* <ul>
410410
* <li>{@linkplain CoreTranslationError#UNKNOWN_CLASSREF}
411411
* if no object with the specified class is found</li>
412412
* </ul>
413413
*/
414414
public <T> T getFirstObject(Class<T> classRef) {
415-
for (Object object : this.objects) {
415+
int index = -1;
416+
for (int i = 0; i < this.objects.size(); i++) {
417+
Object object = this.objects.get(i);
418+
416419
if (classRef.isAssignableFrom(object.getClass())) {
417-
return classRef.cast(object);
420+
index = i;
421+
break;
418422
}
423+
424+
}
425+
426+
if (index > -1) {
427+
return classRef.cast(this.objects.remove(index));
419428
}
420429

421430
throw new ContractException(CoreTranslationError.UNKNOWN_CLASSREF);
@@ -425,24 +434,38 @@ public <T> T getFirstObject(Class<T> classRef) {
425434
* Searches the list of read in objects and returns all Objects found with the
426435
* given classRef
427436
*
428-
* @param <T> the type of the obect to get
437+
* @param <T> the type of the object to get
429438
*/
430439
public <T> List<T> getObjects(Class<T> classRef) {
431440
List<T> objects = new ArrayList<>();
432-
for (Object object : this.objects) {
441+
for (int i = 0; i < this.objects.size(); i++) {
442+
Object object = this.objects.get(i);
443+
433444
if (classRef.isAssignableFrom(object.getClass())) {
434445
objects.add(classRef.cast(object));
435446
}
447+
436448
}
437449

450+
this.objects.removeAll(objects);
451+
438452
return objects;
439453
}
440454

441455
/**
442456
* Returns the entire list of read in objects
443457
*/
444458
public List<Object> getObjects() {
445-
return this.objects;
459+
List<Object> objects = new ArrayList<>(this.objects);
460+
461+
this.objects.clear();
462+
463+
return objects;
464+
}
465+
466+
// package access for testing
467+
int getNumObjects() {
468+
return this.objects.size();
446469
}
447470

448471
}

core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationEngine.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ protected final <I, A> void _addTranslationSpec(TranslationSpec<I, A> translatio
180180
* <li>{@linkplain CoreTranslationError#NULL_TRANSLATOR}
181181
* if translator is null</li>
182182
* <li>{@linkplain CoreTranslationError#DUPLICATE_TRANSLATOR}
183-
* if translator has alaready been added</li>
183+
* if translator has already been added</li>
184184
* </ul>
185185
*/
186186
public abstract Builder addTranslator(Translator translator);
@@ -196,7 +196,7 @@ protected final void _addTranslator(Translator translator) {
196196
}
197197

198198
/**
199-
* Adds the given classRef markerInterace mapping.
199+
* Adds the given classRef markerInterface mapping.
200200
* <p>
201201
* explicitly used when calling {@link TranslationController#writeOutput} with a
202202
* class for which a classRef ScenarioId pair does not exist and/or the need to
@@ -380,7 +380,7 @@ void checkForCyclicGraph(MutableGraph<TranslatorId, Object> mutableGraph) {
380380

381381
private void validateTranslationEngineType() {
382382
if (this.data.translationEngineType == TranslationEngineType.UNKNOWN) {
383-
throw new ContractException(CoreTranslationError.UNKNWON_TRANSLATION_ENGINE_TYPE);
383+
throw new ContractException(CoreTranslationError.UNKNOWN_TRANSLATION_ENGINE_TYPE);
384384
}
385385
}
386386

@@ -401,7 +401,7 @@ Map<Class<?>, Class<?>> getChildParentClassMap() {
401401
/**
402402
* returns the {@link TranslationEngineType} of this TranslationEngine
403403
*
404-
* guarenteed to NOT be {@link TranslationEngineType#UNKNOWN}
404+
* guaranteed to NOT be {@link TranslationEngineType#UNKNOWN}
405405
*/
406406
public TranslationEngineType getTranslationEngineType() {
407407
return this.data.translationEngineType;

core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslationSpec.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ public boolean isInitialized() {
3737
* Input Class and if so, calls the related method
3838
* </p>
3939
* <p>
40-
* It then checks if the the object class is assinable from either the App or
40+
* It then checks if the the object class is assignable from either the App or
4141
* Input Class and if so, calls the related method
4242
* </p>
4343
* <p>
4444
* If no match can be found, an exception is thrown
4545
* </p>
4646
*
47-
* @param <T> the expected return type after translation/coversion
47+
* @param <T> the expected return type after translation/conversion
4848
* @throws ContractException {@linkplain CoreTranslationError#UNKNOWN_OBJECT} if
4949
* no match can be found between the passed in object
5050
* and the given appClass and InputClass
@@ -102,7 +102,7 @@ public boolean equals(Object obj) {
102102
return false;
103103
}
104104

105-
// if different intput class, not equal
105+
// if different input class, not equal
106106
if (getInputObjectClass() != other.getInputObjectClass()) {
107107
return false;
108108
}

core/src/main/java/gov/hhs/aspr/ms/taskit/core/Translator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ public Builder setInitializer(Consumer<TranslatorContext> initConsumer) {
120120
* @throws ContractException
121121
* <ul>
122122
* <li>{@linkplain CoreTranslationError#NULL_DEPENDENCY}
123-
* if the dependecy is null</li>
123+
* if the dependency is null</li>
124124
* <li>{@linkplain CoreTranslationError#DUPLICATE_DEPENDENCY}
125-
* if the dependecy has already been added</li>
125+
* if the dependency has already been added</li>
126126
* </ul>
127127
*/
128128
public Builder addDependency(TranslatorId dependency) {

core/src/main/java/gov/hhs/aspr/ms/taskit/core/TranslatorId.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
public interface TranslatorId {
77
/**
8-
* Implementationn consistent with equals()
8+
* Implementation consistent with equals()
99
*/
1010
@Override
1111
public int hashCode();
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package gov.hhs.aspr.ms.taskit.core.testsupport;
2+
3+
import java.io.File;
4+
import java.nio.file.Path;
5+
import java.util.ArrayList;
6+
import java.util.LinkedHashSet;
7+
import java.util.List;
8+
import java.util.Set;
9+
10+
import gov.hhs.aspr.ms.taskit.core.TranslationSpec;
11+
import gov.hhs.aspr.ms.util.resourcehelper.ResourceHelper;
12+
13+
public class TranslationSpecSupport {
14+
15+
private TranslationSpecSupport() {}
16+
/*
17+
* This method is to ensure that every translationSpec that is supposed to be
18+
* tied to a Translator is defined in its list of translationSpecs. If a
19+
* translationSpec is added and not subsequently added to the list in the
20+
* Translator, then this test will fail and provide the name of the missing
21+
* TranslationSpec
22+
*/
23+
public static <T> Set<String> testGetTranslationSpecs(Class<T> translatorClassRef,
24+
List<TranslationSpec<?, ?>> translationSpecs) throws ClassNotFoundException {
25+
Set<String> missingTranslationSpecs = new LinkedHashSet<>();
26+
List<Class<?>> translationSpecClasses = new ArrayList<>();
27+
28+
// create a list with the translation spec class names
29+
for (TranslationSpec<?, ?> translationSpec : translationSpecs) {
30+
translationSpecClasses.add(translationSpec.getClass());
31+
}
32+
33+
// get the package of the translator class to get its translationSpecs package
34+
// path
35+
String packageName = translatorClassRef.getPackageName() + ".translationSpecs";
36+
String packagePath = packageName.replaceAll("[.]", "/");
37+
38+
ClassLoader classLoader = ClassLoader.getSystemClassLoader();
39+
40+
Path path = ResourceHelper.getResourceDir(translatorClassRef)
41+
.getParent()
42+
.resolve("classes")
43+
.resolve(packagePath);
44+
45+
// the path from above will be referencing the test-classes compile folder. We
46+
// want the classes folder, else it will fail because the test classes for
47+
// translationSpecs are prefixed with AT_
48+
File[] files = path.toFile().listFiles();
49+
50+
// loop over all the files in the directory, for every file that ends in .class,
51+
// construct the full qualified class name. use the classLoader to load the
52+
// class and assert that the provided list of translationSpecs contains that
53+
// class
54+
for (File file : files) {
55+
String className = file.getName();
56+
if (className.endsWith(".class")) {
57+
// note the substring here is to eliminate the .class suffix of the filename
58+
className = packageName + "." + className.substring(0, className.length() - 6);
59+
Class<?> classRef = classLoader.loadClass(className);
60+
61+
if(!translationSpecClasses.contains(classRef)) {
62+
missingTranslationSpecs.add(classRef.getSimpleName());
63+
}
64+
}
65+
}
66+
67+
return missingTranslationSpecs;
68+
}
69+
}

0 commit comments

Comments
 (0)