Skip to content

Commit

Permalink
Merge pull request #45 from openworm/development
Browse files Browse the repository at this point in the history
Release 0.3.6
  • Loading branch information
tarelli authored Jun 6, 2017
2 parents 6035817 + 5dfde86 commit 6279e4a
Show file tree
Hide file tree
Showing 9 changed files with 438 additions and 74 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.geppetto</groupId>
<artifactId>persistence</artifactId>
<name>Geppetto Persistence Bundle</name>
<version>0.3.5</version>
<version>0.3.6</version>
<packaging>bundle</packaging>
<properties>
<spring.version>3.1.3.RELEASE</spring.version>
Expand Down
149 changes: 102 additions & 47 deletions src/main/java/org/geppetto/persistence/GeppettoDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,16 @@

import java.io.Reader;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.SerializationUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.geppetto.core.common.GeppettoAccessException;
import org.geppetto.core.common.GeppettoExecutionException;
import org.geppetto.core.data.IGeppettoDataManager;
import org.geppetto.core.data.model.ExperimentStatus;
Expand All @@ -62,6 +56,7 @@
import org.geppetto.core.data.model.ISimulatorConfiguration;
import org.geppetto.core.data.model.IUser;
import org.geppetto.core.data.model.IUserGroup;
import org.geppetto.core.data.model.IView;
import org.geppetto.core.data.model.PersistedDataType;
import org.geppetto.core.data.model.ResultsFormat;
import org.geppetto.core.data.model.UserPrivileges;
Expand All @@ -75,8 +70,11 @@
import org.geppetto.persistence.db.model.SimulatorConfiguration;
import org.geppetto.persistence.db.model.User;
import org.geppetto.persistence.db.model.UserGroup;
import org.geppetto.persistence.db.model.View;
import org.geppetto.persistence.util.ViewSerializer;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class GeppettoDataManager implements IGeppettoDataManager
{
Expand Down Expand Up @@ -136,15 +134,16 @@ public User getUserByLogin(String login)
{
return dbManager.findUserByLogin(login);
}

/*
* (non-Javadoc)
*
* @see org.geppetto.core.data.IGeppettoDataManager#getUserGroupById(long)
*/
@Override
public IUserGroup getUserGroupById(long id){
return dbManager.findEntityById(UserGroup.class, id);
public IUserGroup getUserGroupById(long id)
{
return dbManager.findEntityById(UserGroup.class, id);
}

/*
Expand All @@ -158,10 +157,16 @@ public GeppettoProject getGeppettoProjectById(long id)
if(!projects.containsKey(id))
{
GeppettoProject project = dbManager.findEntityById(GeppettoProject.class, id);
if(project!=null){
if(project != null)
{
if(project.getView() == null)
{
project.setView(new View(null));
}
for(Experiment e : project.getExperiments())
{
if(e !=null){
if(e != null)
{
e.setParentProject(project);
}
}
Expand All @@ -179,8 +184,10 @@ public GeppettoProject getGeppettoProjectById(long id)
@Override
public List<GeppettoProject> getGeppettoProjectsForUser(String login)
{
User user = dbManager.findUserByLogin(login);
return user.getGeppettoProjects();
User user = dbManager.findUserByLogin(login);
List<GeppettoProject> userProjects = user.getGeppettoProjects();

return userProjects;
}

/*
Expand Down Expand Up @@ -217,45 +224,76 @@ public IParameter newParameter(String instancePath, String value)
public IExperiment newExperiment(String name, String description, IGeppettoProject project)
{
Experiment experiment = new Experiment(new ArrayList<AspectConfiguration>(), name, description, new Date(), new Date(), ExperimentStatus.DESIGN, new ArrayList<SimulationResult>(), new Date(),
new Date(), project);
new Date(), project, new View("{}"));
((GeppettoProject) project).getExperiments().add(experiment);
dbManager.storeEntity(project);

return experiment;
}

@Override
public IView newView(String view, IGeppettoProject project)
{
IView v = new View(view);
((GeppettoProject) project).setView(v);
if(!project.isVolatile())
{
dbManager.storeEntity(project);
}
return v;
}

@Override
public IView newView(String view, IExperiment experiment)
{
IView v = new View(view);
((IExperiment) experiment).setView(v);
if(!experiment.getParentProject().isVolatile())
{
dbManager.storeEntity(experiment);
}
return v;
}

/*
* (non-Javadoc)
*
* @see org.geppetto.core.data.IGeppettoDataManager#cloneExperiment(java.lang.String, java.lang.String,
* org.geppetto.core.data.model.IGeppettoProject,org.geppetto.core.data.model.IExperiment)
* @see org.geppetto.core.data.IGeppettoDataManager#cloneExperiment(java.lang.String, java.lang.String, org.geppetto.core.data.model.IGeppettoProject,org.geppetto.core.data.model.IExperiment)
*/
@Override
public IExperiment cloneExperiment(String name, String description, IGeppettoProject project, IExperiment originalExperiment)
{
{
Experiment experiment = new Experiment(new ArrayList<AspectConfiguration>(), name, description, new Date(), new Date(), ExperimentStatus.DESIGN, new ArrayList<SimulationResult>(), new Date(),
new Date(), project);
new Date(), project, null);
((GeppettoProject) project).getExperiments().add(experiment);
dbManager.storeEntity(project);
Collection<? extends AspectConfiguration> collection =
(Collection<? extends AspectConfiguration>) originalExperiment.getAspectConfigurations();
for(AspectConfiguration a : collection){
if(a.getSimulatorConfiguration()!=null){
Collection<? extends AspectConfiguration> collection = (Collection<? extends AspectConfiguration>) originalExperiment.getAspectConfigurations();
for(AspectConfiguration a : collection)
{
if(a.getSimulatorConfiguration() != null)
{
String simulator = a.getSimulatorConfiguration().getSimulatorId();
String conversion = a.getSimulatorConfiguration().getConversionServiceId();
float length = a.getSimulatorConfiguration().getLength();
float timeStep = a.getSimulatorConfiguration().getTimestep();
Map<String,String> parameters = a.getSimulatorConfiguration().getParameters();
Map<String, String> parameters = a.getSimulatorConfiguration().getParameters();
List<String> watchedVariables = a.getWatchedVariables();
List<Parameter> modelParameters = a.getModelParameter();
ISimulatorConfiguration simulatorConfiguration = this.newSimulatorConfiguration(simulator, conversion, timeStep,length,parameters);
AspectConfiguration aspectConfiguration = new AspectConfiguration(a.getInstance(), watchedVariables, modelParameters,
(SimulatorConfiguration) simulatorConfiguration);
List<Parameter> newParameters = new ArrayList<Parameter>();
for(Parameter m : modelParameters)
{
newParameters.add((Parameter) this.newParameter(m.getVariable(), m.getValue()));
}
ISimulatorConfiguration simulatorConfiguration = this.newSimulatorConfiguration(simulator, conversion, timeStep, length, parameters);
AspectConfiguration aspectConfiguration = new AspectConfiguration(a.getInstance(), watchedVariables, newParameters, (SimulatorConfiguration) simulatorConfiguration);
experiment.getAspectConfigurations().add(aspectConfiguration);
experiment.setView(new View("{}"));
}
}
dbManager.storeEntity(project);
return experiment;
}

/*
* (non-Javadoc)
*
Expand All @@ -265,25 +303,26 @@ public IExperiment cloneExperiment(String name, String description, IGeppettoPro
public IUser newUser(String name, String password, boolean persistent, IUserGroup group)
{
User user = new User(name, password, name, new ArrayList<GeppettoProject>(), group);

user.addLoginTimeStamp(new Date());

if(persistent)
{
dbManager.storeEntity(user);
}

return user;
}

/*
* (non-Javadoc)
*
* @see org.geppetto.core.data.IGeppettoDataManager#updateUser(org.geppetto.core.data.model.IUser, java.lang.String)
*/
@Override
public IUser updateUser(IUser user, String password){
((User)user).setPassword(password);
public IUser updateUser(IUser user, String password)
{
((User) user).setPassword(password);
dbManager.storeEntity(user);
return user;
}
Expand All @@ -296,7 +335,9 @@ public IUser updateUser(IUser user, String password){
@Override
public void addGeppettoProject(IGeppettoProject project, IUser user) throws GeppettoExecutionException
{
try{
try
{
dbManager.storeEntity(user);
long oldId = project.getId();
long oldActiveExperimentId = project.getActiveExperimentId();
String activeExperimentName = null;
Expand All @@ -311,9 +352,8 @@ public void addGeppettoProject(IGeppettoProject project, IUser user) throws Gepp
}
}
}
project.setVolatile(false);
dbManager.storeEntity(project);
((User) user).getGeppettoProjects().add((GeppettoProject) project);
((User)user).getGeppettoProjects().add((GeppettoProject) project);
dbManager.storeEntity(user);
if(activeExperimentName != null)
{
Expand All @@ -327,8 +367,10 @@ public void addGeppettoProject(IGeppettoProject project, IUser user) throws Gepp
}
}
projects.remove(oldId);
projects.put(project.getId(), (GeppettoProject) project);
}catch(Exception e){
projects.put(project.getId(),(GeppettoProject) project);
}
catch(Exception e)
{
throw new GeppettoExecutionException(e);
}
}
Expand All @@ -353,8 +395,7 @@ public Object deleteGeppettoProject(long id, IUser user)
@Override
public Object deleteExperiment(IExperiment experiment)
{
GeppettoProject project =
dbManager.findEntityById(GeppettoProject.class, experiment.getParentProject().getId());
GeppettoProject project = dbManager.findEntityById(GeppettoProject.class, experiment.getParentProject().getId());
Experiment e = dbManager.findEntityById(Experiment.class, experiment.getId());
project.getExperiments().remove(e);
dbManager.storeEntity(project);
Expand All @@ -370,9 +411,16 @@ public Object deleteExperiment(IExperiment experiment)
@Override
public IGeppettoProject getProjectFromJson(Gson gson, String json)
{
GeppettoProject project = gson.fromJson(json, GeppettoProject.class);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(GeppettoProject.class, new ViewSerializer());

GeppettoProject project = gsonBuilder.create().fromJson(json, GeppettoProject.class);
project.setId(getRandomId());
project.setVolatile(true);
if(project.getView() == null)
{
project.setView(new View(null));
}
for(Experiment e : project.getExperiments())
{
e.setParentProject(project);
Expand All @@ -387,11 +435,19 @@ public IGeppettoProject getProjectFromJson(Gson gson, String json)
* @see org.geppetto.core.data.IGeppettoDataManager#getProjectFromJson(com.google.gson.Gson, java.io.Reader)
*/
@Override
public IGeppettoProject getProjectFromJson(Gson gson, Reader json)
public IGeppettoProject getProjectFromJson(Gson gson, Reader json, String baseURL)
{
GeppettoProject project = gson.fromJson(json, GeppettoProject.class);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(GeppettoProject.class, new ViewSerializer());

GeppettoProject project = gsonBuilder.create().fromJson(json, GeppettoProject.class);
project.setId(getRandomId());
project.setVolatile(true);
project.setBaseURL(baseURL);
if(project.getView() == null)
{
project.setView(new View(null));
}
for(Experiment e : project.getExperiments())
{
e.setParentProject(project);
Expand Down Expand Up @@ -465,7 +521,6 @@ public ISimulationResult newSimulationResult(String parameterPath, IPersistedDat
return new SimulationResult(parameterPath, (PersistedData) results, format);
}


@Override
public IPersistedData newPersistedData(URL url, PersistedDataType type)
{
Expand All @@ -475,16 +530,15 @@ public IPersistedData newPersistedData(URL url, PersistedDataType type)
@Override
public IAspectConfiguration newAspectConfiguration(IExperiment experiment, String instancePath, ISimulatorConfiguration simulatorConfiguration)
{
AspectConfiguration aspectConfiguration = new AspectConfiguration(instancePath, new ArrayList<String>(), new ArrayList<Parameter>(),
(SimulatorConfiguration) simulatorConfiguration);
AspectConfiguration aspectConfiguration = new AspectConfiguration(instancePath, new ArrayList<String>(), new ArrayList<Parameter>(), (SimulatorConfiguration) simulatorConfiguration);
saveEntity(aspectConfiguration);
((Experiment) experiment).getAspectConfigurations().add(aspectConfiguration);
saveEntity(experiment);
return aspectConfiguration;
}

@Override
public ISimulatorConfiguration newSimulatorConfiguration(String simulator, String conversionService, float timestep, float length, Map<String,String> parameters)
public ISimulatorConfiguration newSimulatorConfiguration(String simulator, String conversionService, float timestep, float length, Map<String, String> parameters)
{
return new SimulatorConfiguration(simulator, conversionService, timestep, length, parameters);
}
Expand All @@ -502,8 +556,9 @@ public IUserGroup newUserGroup(String name, List<UserPrivileges> privileges, lon
}

@Override
public void makeGeppettoProjectPublic(long projectId,boolean isPublic) throws GeppettoExecutionException {

public void makeGeppettoProjectPublic(long projectId, boolean isPublic) throws GeppettoExecutionException
{

GeppettoProject project = this.getGeppettoProjectById(projectId);
project.setPublic(isPublic);
dbManager.storeEntity(project);
Expand Down
Loading

0 comments on commit 6279e4a

Please sign in to comment.