use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class BiomodelBNGLServerResource method getBiomodelBNGL.
private String getBiomodelBNGL(User vcellUser) {
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
// Make temporary resource compatible with restDatabaseService so we can re-use
BiomodelVCMLServerResource bmsr = new BiomodelVCMLServerResource() {
@Override
public Map<String, Object> getRequestAttributes() {
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put(VCellApiApplication.BIOMODELID, BiomodelBNGLServerResource.this.biomodelid);
return hashMap;
}
@Override
public Request getRequest() {
// TODO Auto-generated method stub
return BiomodelBNGLServerResource.this.getRequest();
}
};
StringWriter bnglStringWriter = new StringWriter();
PrintWriter pw = new PrintWriter(bnglStringWriter);
String biomodelVCML = restDatabaseService.query(bmsr, vcellUser);
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelVCML));
SimulationContext chosenSimContext = bioModel.getSimulationContext(0);
RbmNetworkGenerator.writeBngl(chosenSimContext, pw, false, true);
String resultString = bnglStringWriter.toString();
return resultString;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class PublicationServerResource method getPublicationRepresentation.
private static PublicationRepresentation getPublicationRepresentation(RestDatabaseService restDatabaseService, User vcellUser, KeyValue pubID) {
// RestDatabaseService restDatabaseService = ((VCellApiApplication)getApplication()).getRestDatabaseService();
try {
PublicationRep publicationRep = restDatabaseService.getPublicationRep(pubID, vcellUser);
PublicationRepresentation publicationRepresentation = new PublicationRepresentation(publicationRep);
return publicationRepresentation;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "publication not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class RestDatabaseService method query.
public SimulationRepresentation query(BiomodelSimulationServerResource resource, User vcellUser) throws SQLException, DataAccessException, ExpressionException, XmlParseException, MappingException, MathException, MatrixException, ModelException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
ArrayList<String> conditions = new ArrayList<String>();
String bioModelID = (String) resource.getRequestAttributes().get(VCellApiApplication.BIOMODELID);
if (bioModelID != null) {
conditions.add("(" + BioModelTable.table.id.getQualifiedColName() + " = " + bioModelID + ")");
} else {
throw new RuntimeException(VCellApiApplication.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) {
//
// try to determine if the current credentials are insufficient, try to fetch BioModel again with administrator privilege.
//
User adminUser = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
BioModelRep[] allBioModelReps = databaseServerImpl.getBioModelReps(adminUser, conditionsBuffer.toString(), null, startRow, 1);
if (allBioModelReps != null && allBioModelReps.length >= 0) {
throw new PermissionException("insufficient privilege to retrive BioModel " + bioModelID);
} else {
throw new RuntimeException("failed to get biomodel");
}
}
String simulationId = (String) resource.getRequestAttributes().get(VCellApiApplication.SIMULATIONID);
if (simulationId == null) {
throw new RuntimeException(VCellApiApplication.SIMULATIONID + " not specified");
}
SimulationRep simRep = getSimulationRep(new KeyValue(simulationId));
BigString bioModelXML = databaseServerImpl.getBioModelXML(vcellUser, bioModelReps[0].getBmKey());
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
return new SimulationRepresentation(simRep, bioModel);
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class SimDataValuesServerResource method getSimDataValuesRepresentation.
private SimDataValuesRepresentation getSimDataValuesRepresentation(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
DataSetTimeSeries dataSetTimeSeries = restDatabaseService.getDataSetTimeSeries(this, vcellUser);
SimDataValuesRepresentation simDataRepresentation = new SimDataValuesRepresentation(dataSetTimeSeries);
return simDataRepresentation;
} catch (PermissionException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "not authorized to stop simulation");
} catch (ObjectNotFoundException e) {
e.printStackTrace();
throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "simulation not found");
} catch (Exception e) {
throw new ResourceException(Status.SERVER_ERROR_INTERNAL, e.getMessage());
}
// }
}
use of org.vcell.util.PermissionException in project vcell by virtualcell.
the class SimulationTasksServerResource method getSimulationTaskRepresentations.
private SimulationTaskRepresentation[] getSimulationTaskRepresentations(User vcellUser) {
// if (!application.authenticate(getRequest(), getResponse())){
// // not authenticated
// return new SimulationTaskRepresentation[0];
// }else{
ArrayList<SimulationTaskRepresentation> simTaskReps = new ArrayList<SimulationTaskRepresentation>();
RestDatabaseService restDatabaseService = ((VCellApiApplication) getApplication()).getRestDatabaseService();
try {
SimpleJobStatus[] simJobStatusList = restDatabaseService.query(this, vcellUser);
for (SimpleJobStatus simpleJobStatus : simJobStatusList) {
SimulationTaskRepresentation simTaskRep = new SimulationTaskRepresentation(simpleJobStatus);
simTaskReps.add(simTaskRep);
}
} catch (PermissionException ee) {
throw new ResourceException(Status.CLIENT_ERROR_UNAUTHORIZED, "permission denied to requested resource");
} catch (DataAccessException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
} catch (SQLException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve active jobs from VCell Database : " + e.getMessage());
}
return simTaskReps.toArray(new SimulationTaskRepresentation[0]);
// }
}
Aggregations