Skip to content

Commit

Permalink
Put DTO Functions in Separate Class
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Jan 15, 2025
1 parent 04e086d commit bfcd643
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,15 @@

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;
import org.vcell.util.document.ExternalDataIdentifier;
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)
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 0 additions & 5 deletions vcell-core/src/main/java/cbit/vcell/math/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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('.','_');
Expand Down
13 changes: 0 additions & 13 deletions vcell-core/src/main/java/cbit/vcell/math/VariableType.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions vcell-core/src/main/java/org/vcell/util/document/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -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*/,
Expand Down
5 changes: 5 additions & 0 deletions vcell-restclient/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand Down Expand Up @@ -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;
}

}
2 changes: 1 addition & 1 deletion vcell-util/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit bfcd643

Please sign in to comment.