From bfcd643abd32be020197940118e55f7febdebcea Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia <casualcucumber59@gmail.com> Date: Wed, 15 Jan 2025 11:15:49 -0500 Subject: [PATCH] Put DTO Functions in Separate Class --- .../io/FieldDataFileOperationResults.java | 16 --- .../field/io/FieldDataFileOperationSpec.java | 29 +---- .../main/java/cbit/vcell/math/Variable.java | 5 - .../java/cbit/vcell/math/VariableType.java | 13 --- .../cbit/vcell/simdata/DataIdentifier.java | 6 - .../util/document/ExternalDataIdentifier.java | 16 --- .../org/vcell/util/document/KeyValue.java | 9 -- .../java/org/vcell/util/document/User.java | 11 -- vcell-restclient/pom.xml | 5 + .../restclient/utils/DtoModelTransforms.java | 107 ++++++++++++++++++ vcell-util/pom.xml | 2 +- 11 files changed, 115 insertions(+), 104 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationResults.java b/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationResults.java index 97f08fee18..d7b6cfd6fd 100644 --- a/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationResults.java +++ b/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationResults.java @@ -53,20 +53,4 @@ public FieldDataFileOperationResults() { super(); } - public static FieldDataFileOperationResults fieldDataInfoDTOToFileOperationResults(FieldDataShape dto){ - FieldDataFileOperationResults results = new FieldDataFileOperationResults(); - results.extent = Extent.dtoToExtent(dto.getExtent()); - results.origin = Origin.dtoToOrigin(dto.getOrigin()); - results.iSize = ISize.dtoToISize(dto.getIsize()); - results.times = dto.getTimes().stream().mapToDouble(Double::doubleValue).toArray(); - results.dataIdentifierArr = dto.getDataIdentifier().stream().map(DataIdentifier::dtoToDataIdentifier).toArray(DataIdentifier[]::new); - return results; - } - - public static FieldDataFileOperationResults fieldDataSaveResultsDTOToFileOperationResults(FieldDataSaveResults dto, User owner){ - FieldDataFileOperationResults fieldDataFileOperationResults = new FieldDataFileOperationResults(); - fieldDataFileOperationResults.externalDataIdentifier = new ExternalDataIdentifier(new KeyValue(dto.getFieldDataID()), owner, dto.getFieldDataName()); - return fieldDataFileOperationResults; - } - } diff --git a/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationSpec.java b/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationSpec.java index 461c570309..6d3d339e42 100644 --- a/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationSpec.java +++ b/vcell-core/src/main/java/cbit/vcell/field/io/FieldDataFileOperationSpec.java @@ -10,7 +10,8 @@ package cbit.vcell.field.io; -import org.vcell.restclient.model.AnalyzedResultsFromFieldData; +import cbit.vcell.math.VariableType; +import cbit.vcell.solvers.CartesianMesh; import org.vcell.util.Extent; import org.vcell.util.ISize; import org.vcell.util.Origin; @@ -18,14 +19,6 @@ import org.vcell.util.document.KeyValue; import org.vcell.util.document.User; -import cbit.vcell.math.VariableType; -import cbit.vcell.solvers.CartesianMesh; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - /** * Insert the type's description here. * Creation date: (1/10/2007 11:00:51 AM) @@ -88,24 +81,6 @@ public FieldDataFileOperationSpec(short[][][] shortSpecData, double[][][] double this.sourceOwner = sourceOwner; } -public static AnalyzedResultsFromFieldData fieldDataSpecToAnalyzedResultsDTO(FieldDataFileOperationSpec fieldDataFileOperationSpec){ - List<List<List<Integer>>> listVersion = Arrays.stream(fieldDataFileOperationSpec.shortSpecData) // Stream of short[][] - .map(twoDArray -> Arrays.stream(twoDArray) // Stream of short[] - .map(oneDArray -> { - List<Integer> list = new ArrayList<>(); - for (short j : oneDArray) { - list.add((int) j); - } - return list; - }).collect(Collectors.toList())).collect(Collectors.toList()); - AnalyzedResultsFromFieldData analyzedResultsFromFieldData = new AnalyzedResultsFromFieldData(); - analyzedResultsFromFieldData.annotation(fieldDataFileOperationSpec.annotation); analyzedResultsFromFieldData.isize(ISize.iSizeToDTO(fieldDataFileOperationSpec.isize)); - analyzedResultsFromFieldData.extent(Extent.extentToDTO(fieldDataFileOperationSpec.extent)); analyzedResultsFromFieldData.origin(Origin.originToDTO(fieldDataFileOperationSpec.origin)); - analyzedResultsFromFieldData.times(Arrays.stream(fieldDataFileOperationSpec.times).boxed().toList()); analyzedResultsFromFieldData.setName(fieldDataFileOperationSpec.fieldDataName); - analyzedResultsFromFieldData.varNames(Arrays.stream(fieldDataFileOperationSpec.varNames).toList()); analyzedResultsFromFieldData.shortSpecData(listVersion); - return analyzedResultsFromFieldData; -} - @Deprecated public static FieldDataFileOperationSpec createCopySimFieldDataFileOperationSpec( diff --git a/vcell-core/src/main/java/cbit/vcell/math/Variable.java b/vcell-core/src/main/java/cbit/vcell/math/Variable.java index 440b498a1f..8f45596eb2 100644 --- a/vcell-core/src/main/java/cbit/vcell/math/Variable.java +++ b/vcell-core/src/main/java/cbit/vcell/math/Variable.java @@ -39,11 +39,6 @@ void rename(String newName) { public static class Domain implements Matchable, Serializable { private String name = null; - - public static Domain dtoToDomain(org.vcell.restclient.model.Domain dto){ - return new Domain(dto.getName()); - } - public Domain(String argName){ String nameWithPeriodsMangled = argName.replace('.','_'); diff --git a/vcell-core/src/main/java/cbit/vcell/math/VariableType.java b/vcell-core/src/main/java/cbit/vcell/math/VariableType.java index 11fbdb1a0d..93b770e142 100644 --- a/vcell-core/src/main/java/cbit/vcell/math/VariableType.java +++ b/vcell-core/src/main/java/cbit/vcell/math/VariableType.java @@ -36,19 +36,6 @@ public class VariableType implements java.io.Serializable, org.vcell.util.Matcha public VariableType(){} - public static org.vcell.restclient.model.VariableType variableTypeToDTO(VariableType vt) { - org.vcell.restclient.model.VariableType dto = new org.vcell.restclient.model.VariableType(); - dto.setType(vt.type); - dto.setName(vt.name); - dto.setUnits(vt.units); - dto.setLabel(vt.label); - return dto; - } - - public static VariableType dtoToVariableType(org.vcell.restclient.model.VariableType dto) { - return new VariableType(dto.getType(), dto.getName(), dto.getUnits(), dto.getLabel()); - } - /** * mark types that were not previously supported by {@link #getVariableTypeFromInteger(int)}, issue warning if triggered */ diff --git a/vcell-core/src/main/java/cbit/vcell/simdata/DataIdentifier.java b/vcell-core/src/main/java/cbit/vcell/simdata/DataIdentifier.java index 0145c24c7d..98c6f159d5 100644 --- a/vcell-core/src/main/java/cbit/vcell/simdata/DataIdentifier.java +++ b/vcell-core/src/main/java/cbit/vcell/simdata/DataIdentifier.java @@ -41,12 +41,6 @@ public DataIdentifier(String argName, VariableType argVariableType, Domain argDo displayName = argDisplayName; } -public static DataIdentifier dtoToDataIdentifier(org.vcell.restclient.model.DataIdentifier dto){ - return new DataIdentifier(dto.getName(), VariableType.dtoToVariableType(dto.getVariableType()), - dto.getDomain() == null ? null : Domain.dtoToDomain(dto.getDomain()), - dto.getbFunction() == null ? false : dto.getbFunction(), dto.getDisplayName()); -} - /** * Insert the method's description here. diff --git a/vcell-core/src/main/java/org/vcell/util/document/ExternalDataIdentifier.java b/vcell-core/src/main/java/org/vcell/util/document/ExternalDataIdentifier.java index 529bf77e2d..a2f4e4bc1a 100644 --- a/vcell-core/src/main/java/org/vcell/util/document/ExternalDataIdentifier.java +++ b/vcell-core/src/main/java/org/vcell/util/document/ExternalDataIdentifier.java @@ -26,22 +26,6 @@ public class ExternalDataIdentifier implements SimResampleInfoProvider,java.io.S private org.vcell.util.document.User owner; private String name; - public static org.vcell.restclient.model.ExternalDataIdentifier externalDataIdentifierToDTO(ExternalDataIdentifier externalDataIdentifier) { - org.vcell.restclient.model.ExternalDataIdentifier dto = new org.vcell.restclient.model.ExternalDataIdentifier(); - dto.key(KeyValue.keyValueToDTO(externalDataIdentifier.getKey())); - dto.owner(User.userToDTO(externalDataIdentifier.getOwner())); - dto.name(externalDataIdentifier.getName()); - return dto; - } - - public static ExternalDataIdentifier dtoToExternalDataIdentifier(org.vcell.restclient.model.ExternalDataIdentifier dto){ - ExternalDataIdentifier externalDataIdentifier = new ExternalDataIdentifier(); - externalDataIdentifier.key = KeyValue.dtoToKeyValue(dto.getDataKey()); - externalDataIdentifier.name = dto.getName(); - externalDataIdentifier.owner = User.dtoToUser(dto.getOwner()); - return externalDataIdentifier; - } - /** * FieldDataIdentifier constructor comment. */ diff --git a/vcell-core/src/main/java/org/vcell/util/document/KeyValue.java b/vcell-core/src/main/java/org/vcell/util/document/KeyValue.java index a786222e98..ec794efd06 100644 --- a/vcell-core/src/main/java/org/vcell/util/document/KeyValue.java +++ b/vcell-core/src/main/java/org/vcell/util/document/KeyValue.java @@ -20,15 +20,6 @@ public class KeyValue implements java.io.Serializable, Matchable { private java.math.BigDecimal value = null; - public static org.vcell.restclient.model.KeyValue keyValueToDTO(KeyValue kv) { - org.vcell.restclient.model.KeyValue k = new org.vcell.restclient.model.KeyValue(); - k.setValue(kv.value); - return k; - } - public static KeyValue dtoToKeyValue(org.vcell.restclient.model.KeyValue dto){ - return dto == null ? null : new KeyValue(dto.getValue()); - } - public KeyValue(String value) throws NumberFormatException { this.value = new java.math.BigDecimal(value); diff --git a/vcell-core/src/main/java/org/vcell/util/document/User.java b/vcell-core/src/main/java/org/vcell/util/document/User.java index 041727f4b3..35db5aff26 100644 --- a/vcell-core/src/main/java/org/vcell/util/document/User.java +++ b/vcell-core/src/main/java/org/vcell/util/document/User.java @@ -26,17 +26,6 @@ public class User implements java.io.Serializable, Matchable, Immutable { private final static String PREVIOUS_DATABASE_VALUE_POWERUSER = "special1"; private final static String PREVIOUS_DATABASE_VALUE_PUBLICATION = "publication"; - public static org.vcell.restclient.model.User userToDTO(User user) { - org.vcell.restclient.model.User userDTO = new org.vcell.restclient.model.User(); - userDTO.setUserName(user.userName); - userDTO.setKey(KeyValue.keyValueToDTO(user.key)); - return userDTO; - } - - public static User dtoToUser(org.vcell.restclient.model.User dto){ - return new User(dto.getUserName(), KeyValue.dtoToKeyValue(dto.getKey())); - } - public enum SPECIAL_CLAIM { admins/*special0*/, powerUsers/*special1*/, diff --git a/vcell-restclient/pom.xml b/vcell-restclient/pom.xml index 9b4a54926b..11c593b561 100644 --- a/vcell-restclient/pom.xml +++ b/vcell-restclient/pom.xml @@ -204,6 +204,11 @@ <artifactId>vcell-util</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> + <dependency> + <groupId>org.vcell</groupId> + <artifactId>vcell-core</artifactId> + <version>0.0.1-SNAPSHOT</version> + </dependency> <!-- JSON processing: jackson --> <dependency> diff --git a/vcell-restclient/src/main/java/org/vcell/restclient/utils/DtoModelTransforms.java b/vcell-restclient/src/main/java/org/vcell/restclient/utils/DtoModelTransforms.java index b3cbf8664d..13cb98a880 100644 --- a/vcell-restclient/src/main/java/org/vcell/restclient/utils/DtoModelTransforms.java +++ b/vcell-restclient/src/main/java/org/vcell/restclient/utils/DtoModelTransforms.java @@ -1,8 +1,25 @@ package org.vcell.restclient.utils; +import cbit.vcell.field.io.FieldDataFileOperationResults; +import cbit.vcell.field.io.FieldDataFileOperationSpec; +import cbit.vcell.math.Variable; +import cbit.vcell.math.VariableType; +import cbit.vcell.simdata.DataIdentifier; +import org.vcell.restclient.model.AnalyzedResultsFromFieldData; +import org.vcell.restclient.model.FieldDataSaveResults; +import org.vcell.restclient.model.FieldDataShape; import org.vcell.util.Extent; import org.vcell.util.Origin; +import org.vcell.util.document.ExternalDataIdentifier; +import org.vcell.util.document.KeyValue; +import org.vcell.util.document.User; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; public class DtoModelTransforms { @@ -43,5 +60,95 @@ public static Extent dtoToExtent(org.vcell.restclient.model.Extent dto) { return new Extent(dto.getX(), dto.getY(), dto.getZ()); } + public static DataIdentifier dtoToDataIdentifier(org.vcell.restclient.model.DataIdentifier dto){ + return new DataIdentifier(dto.getName(), dtoToVariableType(dto.getVariableType()), + dto.getDomain() == null ? null : dtoToDomain(dto.getDomain()), + dto.getbFunction() == null ? false : dto.getbFunction(), dto.getDisplayName()); + } + + public static org.vcell.restclient.model.VariableType variableTypeToDTO(VariableType vt) { + org.vcell.restclient.model.VariableType dto = new org.vcell.restclient.model.VariableType(); + dto.setType(vt.getType()); + dto.setName(vt.getTypeName()); + dto.setUnits(vt.getDefaultUnits()); + dto.setLabel(vt.getDefaultLabel()); + return dto; + } + + public static VariableType dtoToVariableType(org.vcell.restclient.model.VariableType dto) { + return VariableType.getVariableTypeFromInteger(dto.getType()); + } + + public static Variable.Domain dtoToDomain(org.vcell.restclient.model.Domain dto){ + return new Variable.Domain(dto.getName()); + } + + public static org.vcell.restclient.model.ExternalDataIdentifier externalDataIdentifierToDTO(ExternalDataIdentifier externalDataIdentifier) { + org.vcell.restclient.model.ExternalDataIdentifier dto = new org.vcell.restclient.model.ExternalDataIdentifier(); + dto.key(keyValueToDTO(externalDataIdentifier.getKey())); + dto.owner(userToDTO(externalDataIdentifier.getOwner())); + dto.name(externalDataIdentifier.getName()); + return dto; + } + + public static ExternalDataIdentifier dtoToExternalDataIdentifier(org.vcell.restclient.model.ExternalDataIdentifier dto){ + return new ExternalDataIdentifier( + dtoToKeyValue(dto.getKey()), dtoToUser(dto.getOwner()), dto.getName() + ); + } + + public static org.vcell.restclient.model.KeyValue keyValueToDTO(KeyValue kv) { + org.vcell.restclient.model.KeyValue k = new org.vcell.restclient.model.KeyValue(); + k.setValue(kv.toString().transform(BigDecimal::new)); + return k; + } + public static KeyValue dtoToKeyValue(org.vcell.restclient.model.KeyValue dto){ + return dto == null ? null : new KeyValue(dto.getValue()); + } + + public static org.vcell.restclient.model.User userToDTO(User user) { + org.vcell.restclient.model.User userDTO = new org.vcell.restclient.model.User(); + userDTO.setUserName(user.getName()); + userDTO.setKey(keyValueToDTO(user.getID())); + return userDTO; + } + + public static User dtoToUser(org.vcell.restclient.model.User dto){ + return new User(dto.getUserName(), dtoToKeyValue(dto.getKey())); + } + + public static FieldDataFileOperationResults fieldDataInfoDTOToFileOperationResults(FieldDataShape dto){ + FieldDataFileOperationResults results = new FieldDataFileOperationResults(); + results.extent = dtoToExtent(dto.getExtent()); + results.origin = dtoToOrigin(dto.getOrigin()); + results.iSize = dtoToISize(dto.getIsize()); + results.times = dto.getTimes().stream().mapToDouble(Double::doubleValue).toArray(); + results.dataIdentifierArr = dto.getDataIdentifier().stream().map(DtoModelTransforms::dtoToDataIdentifier).toArray(DataIdentifier[]::new); + return results; + } + + public static FieldDataFileOperationResults fieldDataSaveResultsDTOToFileOperationResults(FieldDataSaveResults dto, User owner){ + FieldDataFileOperationResults fieldDataFileOperationResults = new FieldDataFileOperationResults(); + fieldDataFileOperationResults.externalDataIdentifier = new ExternalDataIdentifier(new KeyValue(dto.getFieldDataID()), owner, dto.getFieldDataName()); + return fieldDataFileOperationResults; + } + + public static AnalyzedResultsFromFieldData fieldDataSpecToAnalyzedResultsDTO(FieldDataFileOperationSpec fieldDataFileOperationSpec){ + List<List<List<Integer>>> listVersion = Arrays.stream(fieldDataFileOperationSpec.shortSpecData) // Stream of short[][] + .map(twoDArray -> Arrays.stream(twoDArray) // Stream of short[] + .map(oneDArray -> { + List<Integer> list = new ArrayList<>(); + for (short j : oneDArray) { + list.add((int) j); + } + return list; + }).collect(Collectors.toList())).collect(Collectors.toList()); + AnalyzedResultsFromFieldData analyzedResultsFromFieldData = new AnalyzedResultsFromFieldData(); + analyzedResultsFromFieldData.annotation(fieldDataFileOperationSpec.annotation); analyzedResultsFromFieldData.isize(iSizeToDTO(fieldDataFileOperationSpec.isize)); + analyzedResultsFromFieldData.extent(extentToDTO(fieldDataFileOperationSpec.extent)); analyzedResultsFromFieldData.origin(originToDTO(fieldDataFileOperationSpec.origin)); + analyzedResultsFromFieldData.times(Arrays.stream(fieldDataFileOperationSpec.times).boxed().toList()); analyzedResultsFromFieldData.setName(fieldDataFileOperationSpec.fieldDataName); + analyzedResultsFromFieldData.varNames(Arrays.stream(fieldDataFileOperationSpec.varNames).toList()); analyzedResultsFromFieldData.shortSpecData(listVersion); + return analyzedResultsFromFieldData; + } } diff --git a/vcell-util/pom.xml b/vcell-util/pom.xml index 30b87cef09..585ef05567 100644 --- a/vcell-util/pom.xml +++ b/vcell-util/pom.xml @@ -138,7 +138,7 @@ <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> - <version>${jackson-version}</version> + <version>${jackson-annotations.version}</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId>