use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.
the class RestDatabaseService method getBioModelRep.
public BioModelRep getBioModelRep(KeyValue bmKey, User vcellUser) throws SQLException, ObjectNotFoundException, DataAccessException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
ArrayList<String> conditions = new ArrayList<String>();
if (bmKey != null) {
conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bmKey.toString() + ")");
} else {
throw new RuntimeException("bioModelID not specified");
}
StringBuffer conditionsBuffer = new StringBuffer();
for (String condition : conditions) {
if (conditionsBuffer.length() > 0) {
conditionsBuffer.append(" AND ");
}
conditionsBuffer.append(condition);
}
int startRow = 1;
int maxRows = 1;
BioModelRep[] bioModelReps = databaseServerImpl.getBioModelReps(vcellUser, conditionsBuffer.toString(), null, startRow, maxRows);
for (BioModelRep bioModelRep : bioModelReps) {
KeyValue[] simContextKeys = bioModelRep.getSimContextKeyList();
for (KeyValue scKey : simContextKeys) {
SimContextRep scRep = getSimContextRep(scKey);
if (scRep != null) {
bioModelRep.addSimContextRep(scRep);
}
}
KeyValue[] simulationKeys = bioModelRep.getSimKeyList();
for (KeyValue simKey : simulationKeys) {
SimulationRep simulationRep = getSimulationRep(simKey);
if (simulationRep != null) {
bioModelRep.addSimulationRep(simulationRep);
}
}
}
if (bioModelReps == null || bioModelReps.length != 1) {
throw new ObjectNotFoundException("failed to get biomodel");
}
return bioModelReps[0];
}
use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.
the class RestDatabaseService method stopSimulation.
public SimulationRep stopSimulation(BiomodelSimulationStopServerResource resource, User vcellUser) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException {
// resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
KeyValue simKey = new KeyValue(simId);
SimulationRep simRep = getSimulationRep(simKey);
if (simRep == null) {
throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
}
User owner = simRep.getOwner();
if (!owner.compareEqual(vcellUser)) {
throw new PermissionException("not authorized to stop simulation");
}
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
try {
userLoginInfo.setUser(vcellUser);
} catch (Exception e) {
e.printStackTrace();
throw new DataAccessException(e.getMessage());
}
RpcSimServerProxy rpcSimServerProxy = new RpcSimServerProxy(userLoginInfo, rpcSession);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
rpcSimServerProxy.stopSimulation(vcellUser, vcSimID);
return simRep;
} finally {
rpcSession.close();
}
}
use of cbit.vcell.modeldb.SimulationRep in project vcell by virtualcell.
the class SimDataServerResource method getSimDataRepresentation.
private SimDataRepresentation getSimDataRepresentation(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
DataSetMetadata dataSetMetadata = restDatabaseService.getDataSetMetadata(this, vcellUser);
SimulationRep simRep = restDatabaseService.getSimulationRep(dataSetMetadata.getSimKey());
SimDataRepresentation simDataRepresentation = new SimDataRepresentation(dataSetMetadata, simRep.getScanCount());
return simDataRepresentation;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation metadata not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
Aggregations