Skip to content

Commit

Permalink
Merge pull request #64 from HHS/update-util-to-4.2.0
Browse files Browse the repository at this point in the history
Update util to 4.2.0
  • Loading branch information
bischoffz authored Jun 14, 2024
2 parents efba2d7 + 87e4506 commit af551c5
Show file tree
Hide file tree
Showing 26 changed files with 367 additions and 153 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/dev_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ name: Taskit Development Build
on:
push:
branches: [ "dev" ]
pull_request:
branches-ignore: ["main"]

jobs:
dev-build:
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/dev_pr_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Taskit Development PR Build

on:
pull_request:
branches-ignore: ["main"]

jobs:
dev-build:
runs-on: ubuntu-latest
steps:
- name: Checkout Taskit
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Get Util Version
run: |
echo "util_version=v$(mvn help:evaluate -Dexpression=util.version -q -DforceStdout --file pom.xml)" >> "$GITHUB_ENV"
- name: Checkout Util
if: ${{ endsWith(env.util_version, 'SNAPSHOT') }}
uses: actions/checkout@v4
with:
repository: HHS/ASPR-ms-util
path: util
ref: dev

- name: Build Util
if: ${{ endsWith(env.util_version, 'SNAPSHOT') }}
run: mvn clean install -DskipTests --file util/pom.xml

- name: Build Taskit
run: mvn clean install --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
2 changes: 1 addition & 1 deletion .github/workflows/release_pr_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Version Is Snapshot
if: ${{ endsWith(env.version, 'SNAPSHOT') }}
run: |
echo "::error Version is a SNAPSHOT. Update version to proper version."
echo "Version is a SNAPSHOT version. Update version to proper version."
exit 1
- name: Build Taskit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum CoreTranslationError implements ContractError {
NO_TRANSLATION_ENGINES("There are no translation engines added to this controller."),
NULL_CLASS_REF("Null Class Ref"),
NULL_DEPENDENCY("Null dependency"),
NULL_INIT_CONSUMER("Null Initilizer Consumer"),
NULL_INIT_CONSUMER("Null Initializer Consumer"),
NULL_OBJECT_FOR_TRANSLATION("The object to be translated was null"),
NULL_PATH("Null Path"),
NULL_TRANSLATION_ENGINE("Null Translation Engine"),
Expand All @@ -34,7 +34,7 @@ public enum CoreTranslationError implements ContractError {
"Translators were added to the builder but were not initialized. Make sure to call super.initTranslators() during your custom engine build method"),
UNKNOWN_CLASSREF("No object has been read in with the specified classRef"),
UNKNOWN_OBJECT("Object is not Translatable by this TranslationSpec"),
UNKNWON_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"),
UNKNOWN_TRANSLATION_ENGINE_TYPE("Translation Engine Type was not set"),
UNKNOWN_TRANSLATION_SPEC("No translation spec was provided for the given class"),
UNSUPPORTED_VERSION("The given version is not supported");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import gov.hhs.aspr.ms.util.errors.ContractException;

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

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

this.data.parentChildClassRelationshipMap.put(childClassRef, parentClassRef);
}

return this;
}
}
Expand Down Expand Up @@ -404,18 +404,27 @@ <M extends U, U> void writeOutput(Path path, M object, Optional<Class<U>> superC
* Searches the list of read in objects and returns the first Object found of
* the given classRef
*
* @param <T> the type of the obect to get
* @param <T> the type of the object to get
* @throws ContractException
* <ul>
* <li>{@linkplain CoreTranslationError#UNKNOWN_CLASSREF}
* if no object with the specified class is found</li>
* </ul>
*/
public <T> T getFirstObject(Class<T> classRef) {
for (Object object : this.objects) {
int index = -1;
for (int i = 0; i < this.objects.size(); i++) {
Object object = this.objects.get(i);

if (classRef.isAssignableFrom(object.getClass())) {
return classRef.cast(object);
index = i;
break;
}

}

if (index > -1) {
return classRef.cast(this.objects.remove(index));
}

throw new ContractException(CoreTranslationError.UNKNOWN_CLASSREF);
Expand All @@ -425,24 +434,38 @@ public <T> T getFirstObject(Class<T> classRef) {
* Searches the list of read in objects and returns all Objects found with the
* given classRef
*
* @param <T> the type of the obect to get
* @param <T> the type of the object to get
*/
public <T> List<T> getObjects(Class<T> classRef) {
List<T> objects = new ArrayList<>();
for (Object object : this.objects) {
for (int i = 0; i < this.objects.size(); i++) {
Object object = this.objects.get(i);

if (classRef.isAssignableFrom(object.getClass())) {
objects.add(classRef.cast(object));
}

}

this.objects.removeAll(objects);

return objects;
}

/**
* Returns the entire list of read in objects
*/
public List<Object> getObjects() {
return this.objects;
List<Object> objects = new ArrayList<>(this.objects);

this.objects.clear();

return objects;
}

// package access for testing
int getNumObjects() {
return this.objects.size();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected final <I, A> void _addTranslationSpec(TranslationSpec<I, A> translatio
* <li>{@linkplain CoreTranslationError#NULL_TRANSLATOR}
* if translator is null</li>
* <li>{@linkplain CoreTranslationError#DUPLICATE_TRANSLATOR}
* if translator has alaready been added</li>
* if translator has already been added</li>
* </ul>
*/
public abstract Builder addTranslator(Translator translator);
Expand All @@ -196,7 +196,7 @@ protected final void _addTranslator(Translator translator) {
}

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

private void validateTranslationEngineType() {
if (this.data.translationEngineType == TranslationEngineType.UNKNOWN) {
throw new ContractException(CoreTranslationError.UNKNWON_TRANSLATION_ENGINE_TYPE);
throw new ContractException(CoreTranslationError.UNKNOWN_TRANSLATION_ENGINE_TYPE);
}
}

Expand All @@ -401,7 +401,7 @@ Map<Class<?>, Class<?>> getChildParentClassMap() {
/**
* returns the {@link TranslationEngineType} of this TranslationEngine
*
* guarenteed to NOT be {@link TranslationEngineType#UNKNOWN}
* guaranteed to NOT be {@link TranslationEngineType#UNKNOWN}
*/
public TranslationEngineType getTranslationEngineType() {
return this.data.translationEngineType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ public boolean isInitialized() {
* Input Class and if so, calls the related method
* </p>
* <p>
* It then checks if the the object class is assinable from either the App or
* It then checks if the the object class is assignable from either the App or
* Input Class and if so, calls the related method
* </p>
* <p>
* If no match can be found, an exception is thrown
* </p>
*
* @param <T> the expected return type after translation/coversion
* @param <T> the expected return type after translation/conversion
* @throws ContractException {@linkplain CoreTranslationError#UNKNOWN_OBJECT} if
* no match can be found between the passed in object
* and the given appClass and InputClass
Expand Down Expand Up @@ -102,7 +102,7 @@ public boolean equals(Object obj) {
return false;
}

// if different intput class, not equal
// if different input class, not equal
if (getInputObjectClass() != other.getInputObjectClass()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ public Builder setInitializer(Consumer<TranslatorContext> initConsumer) {
* @throws ContractException
* <ul>
* <li>{@linkplain CoreTranslationError#NULL_DEPENDENCY}
* if the dependecy is null</li>
* if the dependency is null</li>
* <li>{@linkplain CoreTranslationError#DUPLICATE_DEPENDENCY}
* if the dependecy has already been added</li>
* if the dependency has already been added</li>
* </ul>
*/
public Builder addDependency(TranslatorId dependency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
public interface TranslatorId {
/**
* Implementationn consistent with equals()
* Implementation consistent with equals()
*/
@Override
public int hashCode();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package gov.hhs.aspr.ms.taskit.core.testsupport;

import java.io.File;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import gov.hhs.aspr.ms.taskit.core.TranslationSpec;
import gov.hhs.aspr.ms.util.resourcehelper.ResourceHelper;

public class TranslationSpecSupport {

private TranslationSpecSupport() {}
/*
* This method is to ensure that every translationSpec that is supposed to be
* tied to a Translator is defined in its list of translationSpecs. If a
* translationSpec is added and not subsequently added to the list in the
* Translator, then this test will fail and provide the name of the missing
* TranslationSpec
*/
public static <T> Set<String> testGetTranslationSpecs(Class<T> translatorClassRef,
List<TranslationSpec<?, ?>> translationSpecs) throws ClassNotFoundException {
Set<String> missingTranslationSpecs = new LinkedHashSet<>();
List<Class<?>> translationSpecClasses = new ArrayList<>();

// create a list with the translation spec class names
for (TranslationSpec<?, ?> translationSpec : translationSpecs) {
translationSpecClasses.add(translationSpec.getClass());
}

// get the package of the translator class to get its translationSpecs package
// path
String packageName = translatorClassRef.getPackageName() + ".translationSpecs";
String packagePath = packageName.replaceAll("[.]", "/");

ClassLoader classLoader = ClassLoader.getSystemClassLoader();

Path path = ResourceHelper.getResourceDir(translatorClassRef)
.getParent()
.resolve("classes")
.resolve(packagePath);

// the path from above will be referencing the test-classes compile folder. We
// want the classes folder, else it will fail because the test classes for
// translationSpecs are prefixed with AT_
File[] files = path.toFile().listFiles();

// loop over all the files in the directory, for every file that ends in .class,
// construct the full qualified class name. use the classLoader to load the
// class and assert that the provided list of translationSpecs contains that
// class
for (File file : files) {
String className = file.getName();
if (className.endsWith(".class")) {
// note the substring here is to eliminate the .class suffix of the filename
className = packageName + "." + className.substring(0, className.length() - 6);
Class<?> classRef = classLoader.loadClass(className);

if(!translationSpecClasses.contains(classRef)) {
missingTranslationSpecs.add(classRef.getSimpleName());
}
}
}

return missingTranslationSpecs;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
wombat
Loading

0 comments on commit af551c5

Please sign in to comment.