Skip to content

Commit

Permalink
Protobuf Translation 1.0.0 (#62)
Browse files Browse the repository at this point in the history
* fix compile errors

* refactor of enum

* rename

* groupid update

* move folder

* move gitignore

* add back ignore sub gitignores

* add vscode folder to gitignore

* update demo with new changes

* remove flattened-poms

* update gitignore

* reorganization based on new groupid

* update proto with new package

* update input imports
update dependencies

* move app into test

* groups translator basic test

* refactor

* add basic test for materials

* add basic test for simulation time

* add basic test for people translator

* add basic test for person properties translator

* add basic test for properties plugin translator

* add basic test for regions translator

* clean up imports

* add basic test for resources translator

* move deep merge into util for safe keeping

* add basic test for stochastics translator

* update tests to run with maven

* add assembly jar to include all translators

* update demo

* remove commented out code

* 1.0.0 RC
  • Loading branch information
bischoffz authored Mar 22, 2023
1 parent ba3bc66 commit d2e4936
Show file tree
Hide file tree
Showing 224 changed files with 24,222 additions and 25,556 deletions.
5 changes: 4 additions & 1 deletion demos/demo1/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -321,4 +321,7 @@ Temporary Items

###################################
# END MacOS
###################################
###################################


.vscode
34 changes: 2 additions & 32 deletions demos/demo1/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,38 +62,8 @@
<version>${protobuf.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>core</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>nucleus-translator</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>regions-plugin-translator</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>people-plugin-translator</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>stochastics-plugin-translator</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>globalproperties-plugin-translator</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
<groupId>gov.hhs.aspr.gcm.translation</groupId>
<artifactId>personproperties-plugin-translator</artifactId>
<groupId>gov.hhs.aspr.gcm.translation.protobuf</groupId>
<artifactId>plugin-translators-all</artifactId>
<version>${gcm.proto-definitions.version}</version>
</dependency>
<dependency>
Expand Down
50 changes: 20 additions & 30 deletions demos/demo1/src/main/java/lesson/SerializationDemonstration.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@

import org.apache.commons.math3.random.RandomGenerator;

import gov.hhs.aspr.gcm.translation.core.Translator;
import gov.hhs.aspr.gcm.translation.core.TranslatorController;
import gov.hhs.aspr.gcm.translation.plugins.globalproperties.GlobalPropertiesTranslator;
import gov.hhs.aspr.gcm.translation.plugins.people.PeopleTranslator;
import gov.hhs.aspr.gcm.translation.plugins.personproperties.PersonPropertiesTranslator;
import gov.hhs.aspr.gcm.translation.plugins.properties.PropertiesTranslator;
import gov.hhs.aspr.gcm.translation.plugins.regions.RegionsTranslator;
import gov.hhs.aspr.gcm.translation.plugins.stochastics.StochasticsTranslator;
import gov.hss.aspr.gcm.translation.nucleus.NucleusTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.core.Translator;
import gov.hhs.aspr.gcm.translation.protobuf.core.TranslatorController;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.globalproperties.GlobalPropertiesTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.people.PeopleTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.personproperties.PersonPropertiesTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.properties.PropertiesTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.regions.RegionsTranslator;
import gov.hhs.aspr.gcm.translation.protobuf.plugins.stochastics.StochasticsTranslator;
import gov.hss.aspr.gcm.translation.protobuf.nucleus.NucleusTranslator;
import lesson.plugins.model.GlobalProperty;
import lesson.plugins.model.ModelPlugin;
import lesson.plugins.model.ModelReportLabel;
Expand All @@ -42,14 +42,11 @@
import plugins.people.PeoplePluginData;
import plugins.personproperties.PersonPropertiesPlugin;
import plugins.personproperties.PersonPropertiesPluginData;
import plugins.personproperties.reports.PersonPropertyReport;
import plugins.personproperties.reports.PersonPropertyReportPluginData;
import plugins.regions.RegionsPlugin;
import plugins.regions.RegionsPluginData;
import plugins.reports.ReportsPlugin;
import plugins.reports.ReportsPluginData;
import plugins.reports.support.NIOReportItemHandler;
import plugins.reports.support.ReportPeriod;
import plugins.stochastics.StochasticsPlugin;
import plugins.stochastics.StochasticsPluginData;
import plugins.util.properties.PropertyDefinition;
Expand Down Expand Up @@ -84,23 +81,14 @@ private SerializationDemonstration(Path outputDirectory) {
.addTranslatorSpec(new PersonPropertyTranslatorSpec())
.addTranslatorSpec(new GlobalPropertyTranslatorSpec())
.addTranslatorSpec(new RegionTranslatorSpec())
.build().init();
.build();
}

private RandomGenerator randomGenerator = RandomGeneratorProvider.getRandomGenerator(524055747550937602L);

private Plugin getReportsPlugin() {
ReportsPluginData reportsPluginData = //
ReportsPluginData.builder()//
.addReport(() -> {
PersonPropertyReportPluginData personPropertyReportPluginData = PersonPropertyReportPluginData
.builder()//
.setReportLabel(ModelReportLabel.PERSON_PROPERTY_REPORT)//
.setReportPeriod(ReportPeriod.END_OF_SIMULATION)//
.setDefaultInclusion(true)//
.build();//
return new PersonPropertyReport(personPropertyReportPluginData)::init;
})//
.addReport(() -> {
return new VaccineReport(ModelReportLabel.VACCINATION)::init;
})//
Expand Down Expand Up @@ -154,7 +142,8 @@ private Plugin getPersonPropertiesPlugin() {
builder.definePersonProperty(PersonProperty.VACCINATED, propertyDefinition);

PersonPropertiesPluginData personPropertiesPluginData = builder.build();
return PersonPropertiesPlugin.getPersonPropertyPlugin(personPropertiesPluginData);
return PersonPropertiesPlugin.builder().setPersonPropertiesPluginData(personPropertiesPluginData)
.getPersonPropertyPlugin();
}

private Plugin getStochasticsPlugin() {
Expand Down Expand Up @@ -248,7 +237,8 @@ private Plugin getGlobalPropertiesPlugin() {

GlobalPropertiesPluginData globalPropertiesPluginData = builder.build();

return GlobalPropertiesPlugin.getGlobalPropertiesPlugin(globalPropertiesPluginData);
return GlobalPropertiesPlugin.builder().setGlobalPropertiesPluginData(globalPropertiesPluginData)
.getGlobalPropertiesPlugin();
}

private void execute() {
Expand Down Expand Up @@ -293,8 +283,9 @@ private void execute() {
continue;
}
if (pluginData instanceof PersonPropertiesPluginData) {
personPropertiesPlugin = PersonPropertiesPlugin
.getPersonPropertyPlugin((PersonPropertiesPluginData) pluginData);
personPropertiesPlugin = PersonPropertiesPlugin.builder()
.setPersonPropertiesPluginData((PersonPropertiesPluginData) pluginData)
.getPersonPropertyPlugin();
continue;
}

Expand All @@ -304,8 +295,9 @@ private void execute() {
}

if (pluginData instanceof GlobalPropertiesPluginData) {
globalPropertiesPlugin = GlobalPropertiesPlugin
.getGlobalPropertiesPlugin((GlobalPropertiesPluginData) pluginData);
globalPropertiesPlugin = GlobalPropertiesPlugin.builder()
.setGlobalPropertiesPluginData((GlobalPropertiesPluginData) pluginData)
.getGlobalPropertiesPlugin();
continue;
}

Expand Down Expand Up @@ -402,8 +394,6 @@ private void handleExperiementOpen(ExperimentContext experimentContext) {
.addTranslatorSpec(new RegionTranslatorSpec());

this.writingTranslatorController = translatorControllerBuilder.build();

this.writingTranslatorController.init();
}

private void handleSimulationStateCollection(Integer scenarioId, List<Object> output) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
package lesson.translatorSpecs;

import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.ProtocolMessageEnum;

import gov.hhs.aspr.gcm.translation.core.AEnumTranslatorSpec;
import gov.hhs.aspr.gcm.translation.protobuf.core.AbstractTranslatorSpec;
import lesson.input.GlobalPropertyInput;
import lesson.plugins.model.GlobalProperty;

public class GlobalPropertyTranslatorSpec extends AEnumTranslatorSpec<GlobalPropertyInput, GlobalProperty> {
public class GlobalPropertyTranslatorSpec extends AbstractTranslatorSpec<GlobalPropertyInput, GlobalProperty> {

@Override
protected GlobalProperty convertInputObject(GlobalPropertyInput inputObject) {
return GlobalProperty.valueOf(inputObject.name());
}

@Override
protected GlobalPropertyInput convertSimObject(GlobalProperty simObject) {
protected GlobalPropertyInput convertAppObject(GlobalProperty simObject) {
return GlobalPropertyInput.valueOf(simObject.name());
}

@Override
public EnumDescriptor getDescriptorForInputObject() {
return GlobalPropertyInput.getDescriptor();
}

@Override
public EnumInstance getEnumInstance() {
return new EnumInstance() {

@Override
public ProtocolMessageEnum getFromString(String arg0) {
return GlobalPropertyInput.valueOf(arg0);
}

};
public GlobalPropertyInput getDefaultInstanceForInputObject() {
return GlobalPropertyInput.forNumber(0);
}

@Override
Expand All @@ -42,7 +27,7 @@ public Class<GlobalPropertyInput> getInputObjectClass() {
}

@Override
public Class<GlobalProperty> getSimObjectClass() {
public Class<GlobalProperty> getAppObjectClass() {
return GlobalProperty.class;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,24 @@
package lesson.translatorSpecs;

import com.google.protobuf.Descriptors.EnumDescriptor;
import com.google.protobuf.ProtocolMessageEnum;

import gov.hhs.aspr.gcm.translation.core.AEnumTranslatorSpec;
import gov.hhs.aspr.gcm.translation.protobuf.core.AbstractTranslatorSpec;
import lesson.input.PersonPropertyInput;
import lesson.plugins.model.PersonProperty;

public class PersonPropertyTranslatorSpec extends AEnumTranslatorSpec<PersonPropertyInput, PersonProperty> {
public class PersonPropertyTranslatorSpec extends AbstractTranslatorSpec<PersonPropertyInput, PersonProperty> {

@Override
protected PersonProperty convertInputObject(PersonPropertyInput inputObject) {
return PersonProperty.valueOf(inputObject.name());
}

@Override
protected PersonPropertyInput convertSimObject(PersonProperty simObject) {
protected PersonPropertyInput convertAppObject(PersonProperty simObject) {
return PersonPropertyInput.valueOf(simObject.name());
}

@Override
public EnumDescriptor getDescriptorForInputObject() {
return PersonPropertyInput.getDescriptor();
}

@Override
public EnumInstance getEnumInstance() {
return new EnumInstance() {

@Override
public ProtocolMessageEnum getFromString(String arg0) {
return PersonPropertyInput.valueOf(arg0);
}

};
public PersonPropertyInput getDefaultInstanceForInputObject() {
return PersonPropertyInput.forNumber(0);
}

@Override
Expand All @@ -42,9 +27,8 @@ public Class<PersonPropertyInput> getInputObjectClass() {
}

@Override
public Class<PersonProperty> getSimObjectClass() {
return
PersonProperty.class;
public Class<PersonProperty> getAppObjectClass() {
return PersonProperty.class;
}

}
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package lesson.translatorSpecs;

import com.google.protobuf.Descriptors.Descriptor;

import gov.hhs.aspr.gcm.translation.core.AObjectTranslatorSpec;
import gov.hhs.aspr.gcm.translation.protobuf.core.AbstractTranslatorSpec;
import lesson.input.RegionInput;
import lesson.plugins.model.Region;

public class RegionTranslatorSpec extends AObjectTranslatorSpec<RegionInput, Region> {
public class RegionTranslatorSpec extends AbstractTranslatorSpec<RegionInput, Region> {

@Override
protected Region convertInputObject(RegionInput inputObject) {
return new Region(inputObject.getId());
return new Region(inputObject.getId());
}

@Override
protected RegionInput convertSimObject(Region simObject) {
protected RegionInput convertAppObject(Region simObject) {
return RegionInput.newBuilder().setId(simObject.getValue()).build();
}

Expand All @@ -23,21 +21,14 @@ public RegionInput getDefaultInstanceForInputObject() {
return RegionInput.getDefaultInstance();
}

@Override
public Descriptor getDescriptorForInputObject() {
return RegionInput.getDescriptor();
}

@Override
public Class<RegionInput> getInputObjectClass() {
return RegionInput.class;
}

@Override
public Class<Region> getSimObjectClass() {
public Class<Region> getAppObjectClass() {
return Region.class;
}



}
2 changes: 1 addition & 1 deletion demos/demo1/src/main/proto/lesson.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package gov.hhs.aspr.gcm;
package gov.hhs.aspr.gcm.translation.demo;

option java_multiple_files = true;
option java_package = "lesson.input";
Expand Down
Loading

0 comments on commit d2e4936

Please sign in to comment.